systemctl reports that the timer file is missing now as a return code
4 so update the unknown start number.
Also with this change SWUPD_NO is no longer always returned so add a
new helper to check if a status is one of multiple options.
Signed-off-by: William Douglas <william.douglas@intel.com>
Currently sys_rm_recursive was used in any instance of deleting swupd
content from the system (update, repair and bundle-remove). This can
cause user data loss when unkown files are in directories that swupd
is deleting.
To prevent this, this patch changes how deleting content in swupd
operates. Swupd content removal is now done with sys_rm and the return
value is checked in case the removal failed due to a directory that
still had files in it. When this specific failure occurs, the
directory is added to a new list for reprocessing removals as it is
expected once the rest of the deletes on the system occur the failures
will go away as the directories will be empty (these deletes are
processed in alphabetical reverse order so leaf directories are
processed first). If the removal fails again it is presumed the
contents of the directory are not files swupd knows about and as such
should be kept somewhere else.
For handling the retention of user data, directories (with only the
content unknown to swupd) are renamed (currently using a
.deleted.$timestamp. prefix of the old name) and stored at the same
directory level they were previously found with one exception. The
exception is for nested deleted content best illustrated with an
example:
/swupd-dir1/user-file1
/swupd-dir1/swupd-dir2/user-file2
When swupd tries to remove the /swupd-dir1 content, it will store the
user files as follows:
/.deleted.$timestamp1.swupd-dir1/user-file1
/.deleted.$timestamp1.swupd-dir1/.deleted.$timestamp1.swupd-dir2/user-file2
To demarcate what was part of swupd content vs user content.
Signed-off-by: William Douglas <william.douglas@intel.com>
Instead of relying on a custom global_setup and global_teardown
functions, migrate to the use of bats' setup_file and teardown_file
functions.
Signed-off-by: William Douglas <william.douglas@intel.com>
Correctly quote arrays.
Also improve some commands getting the array content (fixes space
issues with quoting).
Signed-off-by: William Douglas <william.douglas@intel.com>
The setup() function is run at the beginning of each test by the BATS
system, we leverage this function to implement a global_setup() and a
test_setup().
This commit refactors the function to make it easier to understand, also
makes sure it loads the environment variables correctly for tests.
Variables are available just after being exported, however variables are
not kept between tests since the process that orchestrate the tests of a
test file is a parent process and child processes cannot set variables
of a parent process. This is problematic because we were loosing some
variables (like all third party variables) when running multiple tests
using a global_setup().
This commit fixes the issue by making all the environment variables
available to all tests in a test file regardless of if they use
test_setup() o global_setup().
Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
Unfortunatelly not all environment variables can be set in the same
place, since some values may depend on a specific function being run
before. However it is important to have easy to lacte places where env
variables are being set.
This commit adds a few more setter functions for envrionment variables
so they are easily identified.
Closes#1489
Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
Some env variables in testlib can be exported when the file is sourced,
but some other have to be exported only after the test environment has
been created because they depend on it and in values gotten from it.
However testlib should try to set env variables in as little places as
possible.
This commit moves the definition of variables that can be defined in
set_env_variables() to consolidate them there if possible.
Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
Environment variables are used everywhere in testilb. This environment
variables are global variables that define the way testlib behaves.
However is was confusing to use the variables because they were
inconsistent between each other, for example some variables that define
paths would have absolute paths while other would have relative paths,
making it error prone while using them.
This commit makes the environment variables more consistent by following
a name convention for each type of variable, as an example, variables
that define absolute paths follow this convention ABS_<path_name>_DIR,
while variables that define relative paths are defined like this
<path_name>_DIR.
Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
Global constants in testlib are just exported variables, so they should
be in all upper case so we know they were defined globally.
Closes#1484
Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
When the path provided by a user for the --statedir (or --cachedir)
contains a symlink swupd will fail to extrar tar files since
libarchive does not support extracting files through symlinks.
This commit fixes the issue allowing users to use symlinks in the
--statediri/--cachedir path.
Closes#1581
Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
After sourcing testlib, if the user runs testlib from the terminal,
the help of the library is displayed which includes the list of
commands provided by the library.
Testlib uses some environment variables to modify the way tests are
run. This commit adds information about those env variables to the
testlib help.
Closes#1479
Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
Currently there is only one location, known as "statedir", where swupd
stores data and cache. Normally it make sense to keep the data in a
path that is relative to the path prefix of the target system, since the
data is specific to that system, but cache can be independent of the
system, and that way it can be reused for other target systems if
desired.
This commit splits the cache and data into two different locations.
It also stores the cache in a path that is dependent of the mirror url
being used by swupd. The commit also makes all references to files in
the cache or data directories through getter functions thus removing the
hardcoded reference to the file's location, making it easier to move the
location in the future if needed. Lastly, this commit changes the read
permissions for the data directory and the manifest directories in the
cache to be user readable.
When swupd downloads manifests to the statedir they are downloaded in
directories that represent the version of clear that the manifests
belong to. However those version directories are stored in the statedir,
root directory. This commit moves them into their own "manifest"
directory so there is more consistency with the downloaded files.
Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
When swupd downloads manifests to the statedir they are downloaded in
directories that represent the version of clear that the manifests
belong to. However those version directories are stored in the statedir,
root directory. This commit moves them into their own "manifest"
directory so there is more consistency with the downloaded files.
Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
Instead of relying on all tests of the same group to exist in the same
directory, testlib should assume those tests could be scattered across
multiple directories.
Closes#1485
Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
Ignoring error SC2119 because they are false positives and I don't see cases
where that would return anything useful for us.
Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
For some tests is useful to have a minimal version of the os-core-update
bundle since some system files are tracked there.
Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
Make sure files with unsual characters are successfully installed. Most
characters used in test are filtered by mixer, but there's no reason to
not support them in swupd
Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
When creating the fullfile and installing the bundle in targetfs we
need to preserve the owner and mode of file
Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
XDG_CONFIG_DIRS variable was added with an incorrect name. XDG_CONF_DIRS was used instead.
Fixing that.
Fix#1443
Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
When a MoM contains an experimental bundle and the hashes in the MoM are
regenerated, the experimental bundles are being skipped. This commit
fixes that issue.
Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
When creating test bundles, we are not including os-core in them by
default. This is how it works in production so we should do it so it
resembles the real production environment more accurately.
Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
When the template used for creating the wrapper scripts changes, all
exported binaries should have the scripts regenerated during updates
regardless of if the binary changed.
Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
The update_bundle() function of testlib has many different options to
create updates for test bundles, all of those supported the creation of
the update in a 3rd-party repository except for the --header-only
option. This commit adds that support do --header-nly flag can also be
used for 3rd-party repos.
Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
This commit provides a minimal output to be displayed when the --quiet
flag is used for this command:
- swupd autoupdate
Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
This commit provides a minimal output to be displayed when the --quiet
flag is used for these commands:
- swupd info
- swupd 3rd-party info
Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
Current implementation was only removing test enviroment for envs created
on test setup. And test_teardown function needed to be overriden in case
global_setup() was used.
Now always cleaning the enviroment for both use cases, test_setup() and
global_setup(). The user doesn't have the control anymore on that and
if the user wants to keep the env KEEP_ENV variable should be used.
Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
Test environment can be created on global_setup() or test_setup() and that
change the behavior of several operations on testlib.
Because of that, let the user create the test environment as desired instead
of forcing it on test_setup()
Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
When generating the certificate for tests, openssl is printing messages
to the terminal, we are already selecting what to print by using the
debug_msg() function, so these unwanted messages shouldnot be printed.
Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
Instead of requiring an external script (.prereq) to generate the certificates
we can regenerate them before running each test.
Also removes completly the .prereq script
Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
When updating a bundle using testlib, if the file is updated, and the
update includes a file type change, testlib was updating the manifest
with the correct type but was overwriting the other status flags, so if
a file was marked as 'x' (exported) before, that flag was being removed.
This commit fixes the issue by only updating the flag that relates to
the file type.
Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
When running tests sometimes is useful to see how the filesystem of the
test target system looks like before and after a test. This commit adds
a function to show that chroot fs in a tree view, and it calls that
function in the setup and teardown of tests if DEBUG_TESTS is set.
Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
This commit provides a function that can be used to generate update
content based on the content from a directory specified by the user.
Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
This commit adds a function that retrieve the matching entry from a
manifest or all entries if no key is provided.
Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
This commit adds a function to create a bundle based on the content form
a directory specified by the user.
Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
This commit has a few small corrections in testlib:
- it removes some code that was used for iterative manifests
- it correct some help menus
- favors the use of debug_msg over an if statement for filtering
messages
- do not follow links in the function that creates tars from
fullfiles
Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
When a test is adding a symlink to a manifest, the file the link is
pointing to is also added to the manifest. This commit prevents the file
pointed by the link to be added, if the user wants to add this file they
can do it explicitely.
Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
This commit adds support for file type changes when using bundle_update,
so the correct type is added to the manifest.
Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
When trying to update if the mirror has an invalid signature file we should
try to use the default source url instead.
Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>