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#801Fixes#895Fixes#277
Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>