Commit Graph
161 Commits
Author SHA1 Message Date
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
Castulo Martinez 15855e63b3 Fixing a race condition in testlib
When in a test we create a new version and a bundle update in that new
version, we copy the latest tar for each fullfile from the previous
versions into the new version. The code currently was searching for
those tars starting with the current directory, this was working fine
when running the tests locally because tests are run serially, but this
was causing an unexpected result when running in Travis since tests are
run in parallel, so this was causing the search to sometimes find the
tar in a different test environment (from another test), which was
causing unexpected results and a race condition.

This commit fixes the issue by narrowing the search of the tars to the
web-dir of the specific test environment.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-01-11 12:38:12 -08:00
Castulo Martinez 39e2d40127 Define size of test environment
Sometimes is useful to be able to limit the size of a test environment
to validate some scenarios that are bound to disk size.

This commit adds a -s (size) option that can be used when creating test
environments so the user can control how much space is available in that
environment. If not used, the test environment works the same as before.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-01-10 14:05:01 -08:00
Castulo Martinez 116a4c612e Verify skip unsafe to delete files without warning
When running verify --fix, if there are files in the system that are
marked as deleted in the manifest, then they are removed from the
system. However, if a component of the path of the file is a
symbolic link, the file is determined to be unsafe to be removed and
it is left in the system, the user is warned, and the not-deleted
file count is incremented.

This commit modifies this behavior so verify just skips the file, the
user is not warned with the "Not safe to delete: <FILE>" error message,
and so the not-deleted file count is not incremented since it is really
not useful for the end user.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-01-10 14:00:51 -08:00
Castulo Martinez e2b4a7642b Testlib: symlinks to directories in bundles
The test library provided capabilities to create bundles that contained
symlinks to files in it, but it was not possible to create bundles with
symlinks that pointed to directories.

This commit adds the capability to create a test bundle that contains a
symlink to a directory by using the option "-c" when creating the
bundle.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-01-10 14:00:51 -08:00
Castulo Martinez 93d0d065d4 Testlib: Fixing symlinks of test bundles
When creating a test bundle that contains a symlink like this:
create_bundle -L -n my_bundle -f /my_file -l /my_link my_test_environment
A test bundle called my_bundle is created in my_test_environment,
this bundle has one link called my_link and this link points to a
file that is also added to the bundle's manifest. The problem is
that during the creation of the bundle the symbolic link is created
to point to an existing file but later in the process the file is
renamed, causing the symlink to become dangling. This dangling link
is then added to the bundle's manifest.  If we run "swupd verify
--fix" the installed bundle will always show a hash mismatch and the
good symlink will be replaced with the dangling symlink.

This commit changes the way symlinks are being created when creating a
bundle so they point to the correct file.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-01-10 14:00:51 -08:00
Castulo Martinez 77c47fcc6b Use std out if there is no fd 3 in testlib
Bash (test framework) uses the file descriptor 3 to print messages on
screen when running with the option "-t". The testlib provides a print
funtion that can be used to redirect the output to this file descriptor
easily. However if the print function is used and the testlib was
sourced and used from the command line instead if from a test script,
the shell will complain about an invalid file descriptor 3.

This commit fixes the issue by redirecting the message to the file
descriptor 3 only if it is available, if is not, it will use std out
instead.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2018-12-17 12:43:04 -08:00
Castulo Martinez 4c54f426a7 Silencing output when starting a test web server
When starting the web server from the test library, we wait for the
server to be up by doing some http requests and waiting for the server
to respond to them. When the server finally responds it sends some data
which pollutes the std output.

This commit silences those connection tests so we don't see any response
from the test server on the screen.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2018-12-17 12:43:04 -08:00
Castulo Martinez a0691a7ad9 Create files with specific size with testlib
Testlib provides a function to create random files that are used
when creating test bundles. The size of these files vary but
it is always fairly small, which is best for most test scenarios. In
some special circumstances it would be helpful to have bundles with very
large files, or just with files of a known size.

This commit adds the ability to choose the file size when creating this
files via testlib.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2018-12-17 12:43:04 -08:00
Castulo Martinez 2e30eb128a Setting upstream server in client cert tests
The tests that attempt to verify the client certificate were using the
swupd -u option to set the url of the "upstream server". Recently a
function was added to the test library to set the default upstream
server.

This commit modifies these tests so they used the new function to set
the upstream server instead of using the -u option. This will provide
the benefit of the test environment being more similar to a prod
environment, also makes the test setup less convoluted and the tests
easier to read.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2018-12-17 06:19:14 -08:00
Castulo Martinez 58443d50d7 Adding options to further control server.py
The server.py script is used in some functional tests to simulate
a slow content server. This commit provides a few extra options
that extend the use of this script for testing purposes.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2018-12-13 14:11:55 -08:00
Castulo Martinez 8ed78a3758 Add separators for output when using "bash -t"
When running functional tests using "bash -t" shows info about the test
being run. This commit adds some separators to the output so it is
easier to identify when the output of one test finishes and the next one
starts.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2018-12-13 12:18:47 -08:00
Castulo Martinez 4a3a5762db Functions to set content & version URLs in testlib
Every test environment gets created with a default value for versionurl
and contenturl that points to the appropriate place using the "file://"
protocol. In some occassions the user may want to change this value to
something different, for example if he/she is planning on using an http
server to host the version/content. This commit provides a couple of
functions that allow the user to change the values of the contenturl and
versionurl files.

This commit also makes a small improvement on the start_web_server
function which was sometimes causing the python server to hang.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2018-12-13 12:18:47 -08:00
Castulo Martinez af5833d589 Add git user and email by default in new tests
When using the test generator from the testlib to create a new empty
test, it will pre-fill the user name and email from the git config in the
test if possible.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2018-12-13 10:53:22 -08:00
Castulo Martinez 4a06d58c97 Moving experimental flag from 4th to 2nd position
There was a change of plans in the mixer side and looks like the flag
that will be used to mark a bundle as an experimental will be the 2nd
one instead of the 4th one.

This commit moves the flag to the 2nd position in the swupd client.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2018-12-11 14:30:05 -08:00
Castulo Martinez 21218f324b Adding function to create/set a mirror in testlib
This commits adds a function that creates a mirror (copy) of the
web-dir content and sets up the mirror in the target-dir as if the
user had used the swupd mirror --set command.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2018-12-06 14:53:19 -08:00
Castulo Martinez 85c8e9f816 Define versionurl and contenturl in test env
The versionurl and contenturl files are used by swupd to see where
the upstream server is.

This commit adds those files into the test environment and sets
them up so they point to the appropriate content in the test
environment, this way we can get rid of the -u option for most of
the tests, also this resembles closer a real environment.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2018-12-06 14:53:19 -08:00
Castulo Martinez c130e7a9b1 Ability to create experimental bundles in testlib
Adding a flag to create a bundle with the status as
experimental in a test environment.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2018-12-03 13:07:03 -08:00
Castulo Martinez 93aa418069 Fix the path used by the test generator
There was a bug defining the path for a test in the test generator
that was causing the script to fail if the command was executed from
the wrong path.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2018-11-28 13:45:49 -08:00
Castulo Martinez 4c2b636f07 Correct test group code for checkupdate
The check-update tests should use a group code of CHK, but the
test library was using AUT incorrectly which belongs to the autoupdate
tests.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2018-11-15 10:51:19 -08:00
John Akre 6186a177c8 test: clean up tests when interrupted
Tests will be cleaned up by a trap routine when interrupted early. This
change also moves test web server and certificate store clean up to the
destroy_test_environment function.

Signed-off-by: John Akre <john.w.akre@intel.com>
2018-11-12 14:30:45 -08:00
John Akre 1640fadc8a test: Move test files out of /tmp
Some tests wrote files and directories to /tmp. This change moves the
test certificates directory into the swupd repo's top level directory
and moves other test files into their corresponding test directories.

Fixes #650

Signed-off-by: John Akre <john.w.akre@intel.com>
2018-11-12 14:30:45 -08:00
Castulo Martinez 1438148bbd Adding functions to get test IDs in testlib
Every test should include a unique ID, so it is necessary to have
a way of knowing what is the next available ID for the group of
tests.

This commit helps with that issue by implementing the following
features in the test library:
 - Adds the function get_test_list which can be used to print a
list of tests in a specific group directory.
 - Adds the function get_next_available_id which return the next
test ID that can be used in a new test.
 - When using the generate_test function to generate an empty test
the next available ID will be used for the template.

This commit also adds the ID to a bundle-add test that was missing it.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2018-11-02 15:25:09 -07:00