Commit Graph
57 Commits
Author SHA1 Message Date
Castulo Martinez e5324c39ab Warn user when using dangerous bundle-remove flags
When user uses the --force or --recursive flag swupd prints a message
explaining what effects it will have on the system. This commit changes
this message from informational to warning to attract more attention.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-10-30 13:38:41 -06:00
Castulo Martinez c796cd310c Also remove deps when bundle-remove --recursive
If the -R / --recursive flag is used, remove the specified bundles along
with their "deletable" dependencies.

In this context deletable means:
- the dependency is not os-core
- the dependency is not required by other installed bundle that is not
to be removed
- the dependency is not tracked (specifically installed by the user)

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-10-30 13:38:41 -06:00
Castulo Martinez 744bd4774a Adding tests for bundle-remove --recursive
Functional tests for the new "--recursive" flag in bundle-remove that
will be used to remove a bundle and its dependencies.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-10-30 13:38:41 -06:00
Otavio Pontes 66ea5fea0f progress: Make progress bar and spinner more similar in style
And protect spinner from printf's during spinner time

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-10-18 09:27:25 -07:00
Otavio Pontes 95271fc410 progress: Always print a progress bar or a spinner on json output
Changing the progress report lib to always print 0 or -1 when a step is
started and a 100 when a step finishes.

Also reorganizing all commands to have less steps (when possible) and that
are more meaningful to progress report. Hide some internal steps that doesn't
provide useful information to end users.

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-10-18 09:27:25 -07:00
Otavio Pontes bb1559ef6e compliant: Add check for trailing whitespaces on tests
Note that the clang-format already does this for the source code

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-10-04 16:05:21 -07:00
Otavio Pontes 3e674a66c7 json: Remove trailing spaces at the end of strings
Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-10-03 15:26:54 -07:00
Castulo Martinez e419e7fa9d Refactor bundle-remove to include improvements
This commit does a major refactor of the bundle-remove command to
include these improvements:

- Adds a "--force" flag that can be used to remove a bundle that is
required by other installed bundles along with all the bundles that
depend on it
- When attempting to remove a bundle which is required by other
installed bundles, swupd used to show the list of dependencies in a tree
view, this list was very large in some cases. This commit changes the
output of such cases from a tree view to a simple deduplicated list of
bundles that require the bundle to be removed. The user can still see
the old tree view by including the --verbose when running the command
- Stops notifying telemetry of user errors, like user trying to remove
an invalid bundle, or a bundle that was not installed, etc
- Consider all bundles provided in the bundle-remove command when
checking for dependencies (required by)
- Instead of removing each bundle in the command one by one, consolidate
all bundles to be removed, validate them and remove them all at once.
This will optimize the tasks to be executed for removing bundles.

One change included in this commit for bundle-remove is propagated to
bundle-list:

- When using "bundle-list -D BUNDLE" to find what bundles depend on
BUNDLE. The list will be presented in a simplified deduplicated list of
dependencies by default instead of the tree view that used to be
default. The user can still see the old tree view by running the command
appending the --verbose flag

Closes #891
Closes #732
Closes #674

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-09-30 14:40:01 -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
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 c5ba016331 bundle-add skips optional bundles if specified
Swupd will install optional bundles on bundle-add by default,
but will skip them if specified by the user by using the
--skip-optional / -o flag..

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-07-03 14:59:47 -07:00
Castulo Martinez 069af9decf Enabling the --json-output flag as a global option
The --json-output flag can be enabled for every swupd command.

This commit converts it to be a global flag, and enables it in every
swupd command.

Closes #869

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-04-01 12:03:23 -07:00
Castulo Martinez c545a02378 Use logger to print all messages in screen
swupd prints some messages to stdout and others to stderr, this makes
the code somewhat confusing and also it creates a mess regarding which
messages go where. Messages are usually printed using fprintf() and
printf().

This commit replaces all calls to printf and fprintf with one of the
functions that are part of the logger. This will bring many advantages
to the code:
 - readability, it is straightforward to identify where a message needs
to go based on the name of the logger functions.
 - consistency, the output will go to either stderr or stdout depending
on the type of message being printed.
 - the format of the messages will also be consistent, so for example,
if the message is an error the message will automatically include the
"Error: " label in the beginning of the message, this way we avoid
having things like "ERROR:", "error - ", etc...

Closes #864
Closes #294
Closes #489
Closes #433

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-03-25 16:07:40 -07: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 b6422f89d1 curl: Improve error messages when using fallback SSL certificates
Instead of printing errors and warnings, just print debug information
when we are looking for the right ca path to use. If we couldn't
connect to the server, abort and print a clear error message.

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-02-12 16:01:03 -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
Otavio Pontes 8d0556f20d curl: Use functions from log.h instead of printf in curl
This will make outputs a lot better when using --quiet because optional
curl messages wont be printed.

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-01-24 13:29:31 -08:00
Otavio Pontes f8f44ee945 curl: Use same error handling from sync downloads in async
The biggest change is handling timeout in a better way. The response
code in a timeout (and some other curl errors) is the response from
the last successful operation, so on timeouts we can get 200 (OK)
response code instead of 206(partial content) in a partial download. So
we should look at curl return and not on http return code to decide if we
are going to try to resume the download or not.

Changing slow-server test because error message has changed

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-01-16 08:42:04 -08:00
Castulo Martinez 1db5e9290c Tests for removing a bundle with a full disk
When removing a bundle, if downloading the files fail because of disk
space, swupd should not re-attempt to download the files since it will
fail again for sure.

This commit adds tests that verify this behavior.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-01-10 14:05:01 -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
Otavio Pontes 58ed52d39e curl: Show warnings instead of errors on recoverable SSL problems
When we have SSL connections errors we try to use fallback CA paths added by the
--with-fallback-ca-paths configuration flag.

Instead of printing errors in this case, just print a warning. An error
message will be printed when we fail when trying all fallbacks.

Fixes: #746

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2018-12-20 08:49:45 -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 71d48a5033 Reporting of deleted files in bundle-remove
When running bundle-remove to remove a bundle the number in "Total
deleted files" is often wrong. This is happening because when deleting
the files from a bundle sometimes we start by deleting a directory
(with all the files within it), so all the files that got deleted are not
accounted for, only one file will be counted as deleted (the directory),
this will yield to an incorrect count of deleted files.

This commit fixes this issue by printing the total number of
files that should be deleted, minus those that failed to be deleted,
instead of counting those that succeeded.

Closes #690

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2018-12-06 14:50:32 -08:00
Otavio Pontes 7ef9870365 global: Unify global parameters parsing.
There was a lot of copy and paste of parameters and parameters help, making it
hard to maintain global parameters sanity, like sanitizing values, keep help
updated and making sure all commands had the appropriate options.

Move all global parameters parsing to global.c and leave only specific parameters
to commands files.

Fixes: #571

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2018-12-06 14:50:00 -08:00
Castulo Martinez 26a748394f Adding IDs to bundle-remove tests
This commit adds the test ID to every bundle-remove test, removes
duplicates and make readability improvements.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2018-11-14 13:09:42 -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
Otavio Pontes 02546caade test: Fix flag name on certificate tests
sed s/fallback-ca-paths/with-fallback-capaths/g

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2018-10-22 16:34:48 -07:00
Castulo Martinez 57e82bb51b Replacing old bundleremove tests
The old bundleremove tests used the swupdlib.bash library that was
replaced by testlib.bash.

This commit replaces those old bundleremove tests with new versions
of the same tests that now use testlib.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2018-09-27 12:48:14 -07:00
Otavio Pontes 1764559ea5 Use strdup_or_die() instead of strdup()
Consolidate calls to abort() on out of memory errors on doing a strdup()
2018-07-13 17:34:17 -07:00
Castulo Martinez 8dcc46edb3 Removing unnecesary code to untrack bundles
Every bundle includes a tracking file which tells the OS the
bundle is installed, every bundle has this tracking file as
part of its manifest. When removing a bundle from a system,
all the files that are part of that bundle, and are not needed,
for any other bundle are removed, including the tracking file.

This patch removes a function call that is intended to remove
the tracking bundle from the system, since it is not necessary,
by the time the code calls that function, all files from the
manifest that can be removed are already removed, and this includes
the tracking file.

This patch also modifies a few tests to reflect the change in the
command output.
2018-07-10 16:08:47 -07:00
Castulo Martinez 81d616b605 Be consistent in bundle-add/remove error messages
The operations have different command result output styles. Also,
in particular bundle-remove error is a bit redundant.

This commit changes the messages displayed by the bundle-add and
bundle-remove functions so they have consistent messages for their
corresponding operations.

Fixes #475
2018-06-13 14:47:36 -07:00
Matthew Johnson 58f80eb5b5 tests: fix tests for bundle-add fullfile downloads
Signed-off-by: Matthew Johnson <matthew.johnson@intel.com>
2018-06-12 13:28:02 -07:00
Castulo Martinez f49fb714fe Fixing typo in remove bundle message
When 1 or more bundles fail to be removed from the system a message
was being displayed, a message that looked like this:
"1 bundle(s) of 2 failed to remove"

This commit changes that message so it uses pasive voice, like this:
"1 bundle(s) of 2 failed to be removed"
2018-06-08 10:49:21 -07:00
Castulo Martinez 71a2a4cb0e Refactor bundle-remove to handle multiple bundles
The current remove_bundle() function was designed to only be called
once, but for multiple bundle removals, it is currently called
multiple times.

This commit refactors this function so the bundle removal code can
handle multiple bundles at once.

Fixes #449
2018-06-08 10:49:21 -07:00
Icarus Sparry e52ba1e7df Change contentsize in Manifest.MoM to 0
The previous value - 13,805,671,819 is bogus, and we want to be able
to test if the value is reasonable.

Signed-off-by: Icarus Sparry <icarus.w.sparry@intel.com>
2018-03-19 14:42:22 -07:00
Arzhan Kinzhalin feadea96b6 Implement fallback CApath support.
A colon-separated list of alternative CApath options can be passed to
swupd-client at the configuration time using --with-fallback-capaths
option.

In runtime, fallback CApath support is implemented as part of the
connectivity check. The implementation will try the default (built into
curl) and then will iterate through the list in the order they were
specified. It is done only once on the first call.

The code is reorganized to keep the connectivity check inside curl
wrapper:

* Deleted check_network implementation from version.c
* Removed have_network global (globals.c)
* Scoped swupd_curl_test_resume to curl.c
* Change use of check_network to swupd_curl_check_network

Also:

* Fixed an issue where SSL was only enabled if a URL was matching the
  content URL
2017-10-02 11:30:48 -07:00
Matthew Johnson c83c4ce78f Add functional tests for bundle-list --has-deps
Signed-off-by: Matthew Johnson <matthew.johnson@intel.com>
2017-08-31 09:50:50 -07:00
Matthew Johnson ee06e85931 Add --has-dep argument to bundle list
The --has-dep=BUNDLE argument will display a tree representing all
installed bundles that recursively include BUNDLE.

One may pass the --all argument as well to list the dependency tree for
BUNDLE including all installable bundles available on the server.

**Example output without --all:**

Installed bundles that have os-installer as a dependency:
format:
 # * is-required-by
 #   |-- is-required-by
 # * is-also-required-by
 # ...

  * mixer
    |-- os-clr-on-clr

**Example output with --all:**

Attempting to download version string to memory
All installable and installed bundles that have os-installer as a dependency:
format:
 # * is-required-by
 #   |-- is-required-by
 # * is-also-required-by
 # ...

  * clr-devops
  * mixer
    |-- os-clr-on-clr
        |-- os-clr-on-clr-dev
    |-- clr-devops
    |-- os-clr-on-clr-dev

Signed-off-by: Matthew Johnson <matthew.johnson@intel.com>
2017-08-31 09:50:50 -07:00
Matthew Johnson 6108f50bb9 Print bundle dependencies when failing to remove
A bundle will fail to be removed from the filesystem when other bundles
require that bundle as a dependency. Print a list of each of these
bundles along with the error message.

Signed-off-by: Matthew Johnson <matthew.johnson@intel.com>
2017-08-31 09:50:50 -07:00
Matthew Johnson ae011954f4 Add status checks for test swupd commands
Adds status checks for each swupd command called in the functional
tests. At this point several of these tests fail due to some successful
commands returning error statuses.

Signed-off-by: Matthew Johnson <matthew.johnson@intel.com>
2017-08-10 15:33:59 -07:00
Matthew Johnson 6f52e62854 Fix typo in clr_bundle_rm.c
succesfully -> successfully

Signed-off-by: Matthew Johnson <matthew.johnson@intel.com>
2017-08-07 14:23:30 -07:00
Jaime A. Garcia 6a8d36763b Accept multiple bundles at bundle-remove
This is a wrapper around remove_bundle()
to add consistency for bundle-remove
subcommand respect bundle-add that accepts
one or more bundles to be removed.

This must not be the optimal implementation
but it works fine and gives a better user
usage experience.
2017-04-04 11:50:21 -07:00
Patrick McCarty bce9fb436f test: remove unused .signed files
These files have never been used by the functional tests, so remove them
from the tree.

Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2017-01-31 12:39:09 -08:00
Tudor Marcu a565cd0304 Update tests for mandatory signature verification
With mandatory signature verification being enabled, the tests will have
to generate a certificate and sign their Manifest.MoMs to properly run the
swupd operations.

Signed-off-by: Tudor Marcu <tudor.marcu@intel.com>
2016-12-20 16:13:55 -08:00
Patrick McCarty 2b6db84fe3 Check bundle-remove exit status instead of checking output
The bundle-remove subcommand returns a unique error code for invalid
usage, so check that instead. This also avoids the need to track
bundle-remove --help output, or ignore it.

Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-11-03 09:32:36 -07:00
Patrick McCarty 0ca1975ed5 Convert all functional tests to the new interface
This commit adds "lines-checked" files for every test that checks
swupd-client output and removes the old bash-array-style checks from
the test scripts.

Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-11-02 21:02:46 -07:00
Patrick McCarty 3e0fff6a47 Ignore signature verification errors in functional tests
Because signature verification is a feature that we need separate
testing for, and swupd's output may print a verification error (or not)
depending on how swupd was built, add a helper function to remove the
verification error message when swupd is built with verification
enabled. If verification is not enabled, swupd will not print any
message, and the function is a no-op.

Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-06-27 11:56:01 -07:00
Patrick McCarty a384265d88 Refactor test cases; update bundle manifest hashes
This commit expands the swupd BATS library to encapsulate more of the
boilerplate steps in the test cases.

Additionally, bundle manifest hashes needed updating now that swupd is
emitting warnings (and later on, errors). Better to be prepared for the
switch to errors on mismatches.

Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-06-22 16:12:38 -07:00