133 Commits
Author SHA1 Message Date
Castulo Martinez 265983e622 Test: Adding debug messages for some common functs
Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-09-16 15:22:08 -07:00
Castulo Martinez dd8e693ad1 Test: Fix a bug in global_teardown call
There was an error in the logic of testlib which was causing the
global_teardown to not be executed when tests were being run with bats
like this "bats <directory>/".
Let's say you have 2 test files with 2 tests each file, if the tests are
run like this "bats my_dir/test1.bats; bats my_dir/test2.bats" (this is
the way make check runs the tests), then the tests are going to be
numbered by bats as 1,2,1,2, and the current logic worked fine. But if
you run the same tests using "bats my_dir/", then the tests are going to be
numbered 1,2,3,4. This difference in the numbering of tests was causing
issues with the library. This commit fixes the issue.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-09-16 15:22:08 -07:00
Castulo Martinez da8dd88837 Test: Fix call to global_setup in tests
There was a bug in the logic of the setup function in testlib which was
causing the globale_teardown to be incorrectly called when tests were
being run using "bats <directory>/". This commit fixs the issue.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-09-16 15:22:08 -07:00
Castulo Martinez 0f463da668 Test: Add --force flag to destroy_test_environment
Sometimes we want to keep a test environment after the test has finished
running so we can see the state directory and target_dir, this is useful
to troubleshoot failing tests. This was being controlled via an
environment variable but it was not always working properly.

This commit des two things:
- Changes the environment variable used to save a test environment from
DEBUG_TEST to KEEP_ENV, that way both env variables can be used
separatelly, the first one to printo more debug info and the second one
to save the test environment.
- Fixes an issue with the tests by adding a --force flag to force the
deletion of the environment even when the environment variable is set.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-09-16 15:22:08 -07:00
Castulo Martinez ed1a4ead65 Test: Add debug messages to testlib
Sometimes it is difficult to figure out why a test starts failing,
so having a lot more messages printed during the test makes it easier.

This commit adds a function to print messages only when the environment
variable DEBUG_TEST is set to true, this way we can print a lot more
information from the functions in testlib without polluting the output
of a test in a normal run.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-09-16 15:22:08 -07:00
Otavio Pontes 69cd7d9395 test: Support running tests in a different directory
All files that are written by tests should be written in the directory
where the tests were executed and not the directory where code is.

Make distcheck now works fine

Fixes #343

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-09-13 15:35:03 -07:00
Karthik Prabhu Vinod 9679835c40 Update: Perform sig check on latest file
Fixes #1051

Signed-off-by: Karthik Prabhu <karthik.prabhu.vinod@intel.com>
2019-09-11 15:25:32 -07:00
Otavio Pontes 0696de4435 curl: Initialize curl as needed
Instead of initializing curl library on start, initialize it only when needed.
The advantage of this approach is that we can run some commands offline, if
there's no file to download.

Fixes #801
Fixes #895
Fixes #277

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-08-20 10:48:20 -07:00
Castulo Martinez a41bea9fd5 Show the real latest version using check-update
When running the check-update command we get the latest version for the
format we are currently in, but we really want to get the latest version
regardless of the format.

This commit fixes the issue.

Closes #482

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-08-14 14:31:33 -07:00
John Akre 30cb21260a testlib: Enable validate_item to check statedir
Sudo is needed to validate items in the statedir.

Signed-off-by: John Akre <john.w.akre@intel.com>
2019-08-07 14:12:34 -07:00
Castulo Martinez 5608930be5 Fixing a bug using ignore-ilst files in tests
When using testlib to create tests, ignore lists can be used which
include lines of output that should be ignored when running tests.

The ignore lists can exist at three different levels:
- an ignore file that applies to all tests
- an ignore file that applies to all files of one theme
- an ignore file that applies to all tests within the same file

There was a bug in this last one that was causing ignore-list files to
be unrecognized unless the test number was also used as part of the
ignore-list name. This was causing issues because the test number
can change depending on how you run the test.

This commit fixes the issue.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-08-02 14:17:19 -07:00
Castulo Martinez 2e3a584558 Removing --bundle flag from repair
The -B/--bundle option is confusing and causing users to wipe out their
systems. This option was really just meant for os-install, so this
commit removes it from "swupd repair".

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-07-29 15:20:56 -07:00
Castulo Martinez c0b340bbd2 Fixes a bug when deleting extra files
When swupd repair is run with --picky or --extra-files-only it attempts
to remove all those files that are in the picky tree and that are not
mentioned in any manifest (from installed bundles). If swupd
encounters an error removing any of these files or directories, it
prints a message showing the failure. This message was wrong since it
was not showing the whole path to the file being deleted when the path
included a prefix.

This commit fixes the issue by appending the prefix to the path so it
shows correctly.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-07-29 13:43:49 -07:00
Otavio Pontes 0968948389 test: Rename the name of the distro for tests
We don't need to have a real distribution name for tests. Use a swupd
specific value.

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-07-19 14:20:00 -07:00
Castulo Martinez 069ec11ca8 Fix format of do_staging when reporting progress
The function do_staging is regularly used within a loop to stage all the
files for a given bundle-add or update, repair, etc. However when the
loop contains a progress report (with a percentage), if there are errors
in the do_staging function, they get printed in the same line as the
percentage, messing up the output. Like this:

...22%Warning: Update target directory does not exist: some_file...

This commit fixes that output by adding a carriage return at the
beginning of each message do_staging could print so it would overlap
with the percentage value effectively deleting it.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-07-17 14:24:01 -07:00
Otavio Pontes f337da5b9c bundleadd: Rename flag from optional to also-add
Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-07-08 13:58:24 -07:00
Castulo Martinez 9924bf7ee2 bundle-add installs optional bundles by default
An optional bundle is not required to be installed in the system while
included bundles are. Swupd will install optional bundles on bundle-add
by default.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-07-03 14:59:47 -07:00
Castulo Martinez a9acd78753 Wait until the config file is deleted in tests
When running tests that use the config file, it is important to make
sure the config file from the previous test is deleted before the next
test is run. This is necessary since config files are not contained to
the test environment of each test as the rest of the test resources. So
a config file from one test can affect the output of another test if we
don't wait.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-07-01 16:28:26 -07:00
Otavio Pontes ac210d375d test: Remove a swupd option specific for mirror
We shouldn't use a swupd without setting without -S and there's no reason to
have a custom option for mirror anymore

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-07-01 16:12:08 -07:00
Otavio Pontes cf92789ca6 test: Add a key rotation test
Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-06-28 14:49:13 -07:00
Otavio Pontes 8068e3e422 testlib: Improve udpate_bundle --add command
When --add is used on update_bundle we can inform the file to be installed in
the system. But the function doesn't rename the file to the correct name, using
the file hash and it doesn't create the tarball automatically. That's because
it wasn't needed for other usages of --add. But not we are willing to add files
that were not present in content, so adding a feature to rename the file to
the correct hash and to create the tarball if it didn't exist.

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-06-28 14:49:13 -07:00
Otavio Pontes ccbf2620b5 test: Adding signature checking tests
Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-06-28 14:49:13 -07:00
Castulo Martinez c2a4763ff3 Adding configuration file parser for swupd
swupd has many flags that can be used for fine tunning its
functionality. In some cases users may want to include a flag with every
swupd command they run.

This commit gives the ability to provide swupd flags via options in a
configuration file that swupd will read before running the command.

The configuration file is an INI style file tha  can include sections
so users can specify options that should only apply to a specific
command. The biggest advantage of this is to be able to fine tune the
flags that should apply for each command.

For example a user could set a global flag that would apply to every
swupd command, and then turn that flag off for a specific command by
unsetting it in the command's section.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-06-28 13:06:11 -07:00
Castulo Martinez 2cb0dd80b4 Renaming "swupd verify" to "swupd diagnose"
This commit renames the "verify" command to "diagnose" to make it
more straightforward for the user to understand the purpose of the
command.

Closes #918

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-05-14 15:51:28 -07:00
Castulo Martinez dc8e9235d5 Making verify --fix a top-level command
The purpose of "swupd verify --fix" is to repair local issues relative
to a server manifest. However the verify command currently has many
flags, and some flags are mutually exclusive, this makes the command
very confusing to use for users.

This commit makes "swupd verify --fix" the top level command
"swupd repair". This new command still uses the verify code under the
covers.

Closes #914

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-05-14 14:33:49 -07:00
Castulo Martinez a84c60a500 Making verify --install a top-level command
The purpose of swupd verify --install is so it can be used to install
a new Clear OS in a target system. However since currently it is part
of the swupd verify command it makes it confusing as of to what its
purpose is.

This commit moves the swupd verify --install option to be a top level
command (swupd os-install) so its purpose is more straightforward. The
new command still uses the verify code to perform the task underneath.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-05-14 14:26:30 -07:00
Castulo Martinez a294fcb0d7 Use percentages to report progress when not a tty
When swupd is run and the stdout is not a tty (for example when
redirecting the output to a file) the progress of a step is being
reported as a sequence of dots, which is not very useful to really
identify how far in the process we are.

This commit changes that behavior so percentages are used to report
progress when not using a tty instead of dots.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-03-25 16:07:40 -07:00
Castulo Martinez dd278c9da8 Adding the --quiet flag to hashdump
Currently when calculating the hash from a file two lines are printed:

Calculating hash with xattrs for: my_file
5114e8e3cc667fa80eb5407e5825c618e6668503aba53c8cca7f8daf84cec03f

The first line goes to STDERR while the second one goes to STDOUT. The
test library uses the hash that goes to STDOUT to perform many tasks, so
it is important the output can be filtered to just print the hash.

In the near future, all messages printed with printf or fprintf will be
replaced by logger functions in all the source code which will cause both
lines to be printed to the output which will break the test library.

This commit adds the --quiet flag to the hashdump command so that only
the calculated hashdump is printed on screen.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-03-25 15:25:03 -07:00
Castulo Martinez 44f83ade9b Testlib: file renames should be in all packs
When creating an update that renames a file, the file delta is added to the
delta pack to update from the previous version, but the delta should be in
fact in all the delta packs previous to that one as well so a user could
use a delta pack to update from any previous version to the latest one.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-03-05 14:47:30 -08:00
Castulo Martinez 446735ff2a Testlib: file updates should be in all packs
When creating an update that updates a file, the file delta is added to the
delta pack to update from the previous version, but the delta should be in
fact in all the delta packs previous to that one as well so a user could
use a delta pack to update from any previous version to the latest one.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-03-05 14:47:30 -08:00
Castulo Martinez 167b25442b Testlib: Dirs added in updates should be in packs
When creating an update that adds a directory, the dir is added to the delta
pack to update from the previous version, but the new dir should be in
fact in all the delta packs previous to that one as well so a user could
use a delta pack to update from any previous version to the latest one.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-03-05 14:47:30 -08:00
Castulo Martinez 35aca608ce Testlib: Files added in updates should be in packs
When creating an update that adds a file, the file is added to the delta
pack to update from the previous version, but the new file should be in
fact in all the delta packs previous to that one as well so a user could
use a delta pack to update from any previous version to the latest one.

This commit adds that new file to all delta packs from versions older
than the one containing the update.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-03-05 14:47:30 -08:00
Castulo Martinez d78e1405ea Testlib: making update_bundle more modular
This commit extracts some functionality from the update_bundle function
from the test library so it is more modular, easier to reuse and
maintain.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-03-05 14:47:30 -08:00
Castulo Martinez 8798c4c154 testlib: Consolidate minversion implementation
The update_minversion and bump_format testlib functions both perform a
minversion update, but with separate implementations.

This commit consolidate both implementations.

Closes #618

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-03-01 09:58:06 -08:00
John Akre c8272d85f2 testlib: Add minversion support to bump_format
The bump_format testlib function created new minversions for the +10 and
+20 versions, but it should only create a new minversion for the +20
version. This change copies the +20 update content into the +10 update
and preserves the versions of unchanged files in the +10 version. Also,
this change updates the minversion header field for the +20 version to
reflect a minversion update.

Signed-off-by: John Akre <john.w.akre@intel.com>
2019-03-01 09:58:06 -08:00
William Douglas 6da50ee5d7 Fix manually installed bundle tracking and add tests
Update bundle tracking to correctly initialize tracked bundle state
and add testing to validate tracking works as expected.
2019-02-13 12:23:28 -08:00
Otavio Pontes 53a0984da9 update: Use manifest-deltas in swupd on update
Before downloading full manifests try to use manifest deltas if available.
If deltas are missing, use full manifest.

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-02-12 15:11:00 -08:00
Castulo Martinez b135d49deb Testlib: option to force a response in web server
Sometimes is useful for some tests to be able to force an http code that
corresponds to a filure when using the test web server, that way we can
simulate network problems very easily.

This commit adds an option for forcing the web server to return a
specified http code.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-02-01 12:30:45 -08:00
Castulo Martinez 03ee2623b4 Reorganizing codes to match old values
This commit reorganize the codes in the swupd_code enum so the codes
that were already defined before are still the same. This commit also
renames some of those codes so they are more consistent with the rest of
the codes in the enum.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-01-24 15:23:15 -08:00
Castulo Martinez a723c0bc4a verify should return consistent exit codes
Regardless of what codes are used internally, swupd should always
exit with a code defined in swupd_exit_codes.h.

This commit makes those changes for verify.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-01-24 15:23:15 -08:00
Castulo Martinez 1aed824085 update should return consistent exit codes
Regardless of what codes are used internally, swupd should always
exit with a code defined in swupd_exit_codes.h.

This commit makes those changes for update.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-01-24 15:23:15 -08:00
Castulo Martinez 84046e107f mirror should return consistent exit codes
Regardless of what codes are used internally, swupd should always
exit with a code defined in swupd_exit_codes.h.

This commit makes those changes for mirror.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-01-24 15:23:15 -08:00
Castulo Martinez ff18daa680 clean should return consistent exit codes
Regardless of what codes are used internally, swupd should always
exit with a code defined in swupd_exit_codes.h.

This commit makes those changes for clean.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-01-24 15:23:15 -08:00
Castulo Martinez b653c6308d hashdump should return consistent exit codes
Regardless of what codes are used internally, swupd should always
exit with a code defined in swupd_exit_codes.h.

This commit makes those changes for hashdump.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-01-24 15:23:15 -08:00
Castulo Martinez acdc0e0d74 bundle-list should return consistent exit codes
Regardless of what codes are used internally, swupd should always
exit with a code defined in swupd_exit_codes.h.

This commit makes those changes for bundle-list.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-01-24 15:23:15 -08:00
Castulo Martinez ce0dccf95c Make autoupdate return consistent exit codes
Regardless of what codes are used internally, swupd should always
exit with a code defined in swupd_exit_codes.h.

This commit makes those changes for autoupdate.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-01-24 15:23:15 -08:00
Castulo Martinez 6c7b9e203b Return a more meaningful code on add failure
Some functions currently mask error codes by using a very general error
like SWUPD_COULDNT_INSTALL_BUNDLE (formerly EBUNDLE_INSTALL) in the case of
the bundle-add command.

This commit modifies the codes returned by the bundle-add in case of
failures so they are more meaningful for the actual issue.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-01-24 15:23:15 -08:00
Castulo Martinez 1b9f4f749e Return a more meaningful code on remove failure
Some functions currently mask error codes by using a very general error
like SWUPD_COULDNT_REMOVE_BUNDLE (formerly EBUNDLE_REMOVE) in the case of
the bundle-remove command.

This commit modifies the codes returned by the bundle-remove in case of
failures so they are more meaningful for the actual issue.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-01-24 15:23:15 -08:00
Castulo Martinez f71b84f22d Renaming existing exit codes for consistency
Renaming codes following these rules:
- All codes should start with SWUPD_ so we never get confused what
code comes from swupd
- Always separate codes that contain multiple words using an underscore
SWUPD_MULTI_WORD_ERROR instead of using SWUPDMULTIWORDERROR
- Code 0 is reserved for SWUPD_SUCCESS (or SWUPD_OK)
- Code 1 is reserved to be used as "no" by commands that return a boolean
state (e.g. swupd autoupdate, check-update)

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-01-24 15:23:15 -08:00
Castulo Martinez 945eb52d61 Making testlib shellcheck compliant
Shellcheck provides many useful recommendations for writing shell code.
This commit makes testlib.bash shellcheck compliant.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-01-16 08:49:42 -08:00