Commit Graph
51 Commits
Author SHA1 Message Date
Castulo Martinez 3f3ff08c8f Add ability to search files in specific version
The search-file command is restricted to looking for files in the
current version. This commit adds the --version option to the command
that can be used to seach for files in specific versions of Clear.

Closes #1155

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2020-01-08 11:36:48 -08: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 08650efcc6 bundle_add: Rework on bundle-add main function
Reorganize bundle add main function to reuse more code and improve performance.
Stopped using subscription code from bundles and now using a new function to
recurse manifests, gaining around 30% cpu time on manifest processing.

Started using staging code from update and preventing checking hashes more than
once for some files on bundle-add operations gaining around of 30% CPU time too.

Overall executions of this new bundle-add uses 30% less CPU time but because this
operation is very IO intensitive this reflects to a gain in around 10% of total
time in systems I tested.
2019-10-04 17:43:18 -05:00
Otavio Pontes 35161d623b search-file: Make manifest related function from search-file generic
And moved it to manifest file. This function will be used in other
swupd operations

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-10-04 17:43:18 -05: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 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
Otavio Pontes f19e8dce06 search-file: Don't estimate the total download size for manifest
Estimating the total download size is almost as slow as downloading the
manifests. So just don't do it.

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-08-14 13:04:23 -07:00
Castulo Martinez eb579bcdae Adding a line break when reaching 100% in progress
This commit adds a line break at the end of the progress report (when we
reach 100%) so we don't have to manually include it every time we report
progress.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-06-06 15:37:21 -07:00
Castulo Martinez eb694590a4 Re-enable the json tests
The json tests had been disabled because they were unstable. This issue
was fixed in a previous commit, so these tests should be enabled again.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-04-18 10:29:49 -07:00
Otavio Pontes fb57047151 search: Fix test ID duplication on search
Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-04-15 13:28:44 -07:00
Otavio Pontes 9525c93265 test: Disabling json tests for now
Disabling json tests that checks for progress because tests are unstable.
If we have any minor changes in the code that could affect how curl is called
we could have different progress reports and because of that we would have false
negatives.

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-04-10 15:27:30 -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
Otavio Pontes b34390efec search: Fix incorrect usages of printf
Use log functions instead

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-03-28 16:35:01 -07:00
Otavio Pontes 7d6fa1db05 search: Add support to regular expressions in search-file
Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-03-28 16:35:01 -07:00
Otavio Pontes 9d6d8aa894 search: Improving search-file results and speed
Reimplement search file to print output in search time instead of saving
everything to be printed later. This makes search a lot faster and reduce
the memory footprint of this function.

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-03-28 16:35:01 -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
Castulo Martinez 6b8dd6f817 Adding option to choose how to order results
The search results were being sorted alphabetically if a user would use
the -T option (--top) and they were being sorted by bundle size by
default.

This commit adds a -o/--order flag to the old search command so users have
more control over how to order the test results.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-03-06 09:46:09 -08:00
Castulo Martinez 2d720a2e86 Removing score-based ordering from search
The search command uses a score system to weight the results it finds,
the purpose of this is to try and show the most relevant results to the
user on top, however since the focus of the search command is changing,
we don't need to guess what the user is looking for and just show all we
find.

This commit removes the score ordering from the search command.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-03-06 09:46:09 -08:00
Otavio Pontes 5269627f9c search: Rename search-legacy to search-file
Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-03-05 16:55:49 -08:00
Castulo Martinez 23dbbbafa8 Running local search when searching
swupd-search is a script that searches locally for the best bundle that
matches a search-term.

This commit runs the swupd-search script when users use the "swupd search"
command instead of calling the previous search code.

The previous search functionality will still be available for now using
the "search-legacy" command.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-03-01 15:01:19 -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 880191fd1b Return non-0 code if search does not find entries
swupd search returns 0 both when something is found and when nothing
is found.

This commit makes a change so it returns 0 (SWUPD_OK) if search found
somthing and 1 (SWUPD_NO) if it didn't.

Closes #731

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-02-05 13:03:25 -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 e7946b5bb2 Verifying the whole output of the search command
There was a problem in the curl configuration that was causing curl to
leak the downloaded content in some scenarios, because of that we were
doing only partial checks on the search command output. Now that the
leak has been fixed we can now check the whole output by using
assert_is_output instead of assert_in_output.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-01-10 14:05:01 -08:00
Castulo Martinez 57ad825a33 Tests for searching when there is no disk space
When searching content, 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
Otavio Pontes e07c9bc6fa curl: swupd_curl_query_content_size is leaking file content
When CURLOPT_NOBODY is set to true, curl shouldn't get the body of a file,
we should get only headers. This works fine for all tested scenarios using
http and https. It's also working in most scenarios that uses file://, but
it fails on travis environment. So, add a dummy function to ignore body data
if present.

There was a hack in search tests to ignore leaked file content. Removing that
hack.

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-01-04 15:41:41 -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 f9fd62a33e Show when a bundle is experimental in swupd search
This commit adds ability to show when a bundle is experimental in the
results of a swupd search.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2018-12-11 12:46:58 -08:00
Castulo Martinez 38dddc09a1 Adding ID to search tests
Adding ID to search tests and changing the description of some of
them to make them clearer.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2018-11-20 10:03:49 -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 3b37d0192e test: Fix errors reported by shellcheck
Shellcheck is a shell script static analysis tool that looks for errors and
programming pitfalls in shell scripts.
Fixing errors reported by running that tool on bats scripts

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2018-10-31 09:51:42 -07: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 d354652d24 Replacing old search tests
The old search tests used the swupdlib.bash library that was
replaced by testlib.bash.

This commit replaces those old search 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
Matthew Johnson e68a8a6db6 Update tests to remove version download string
Signed-off-by: Matthew Johnson <matthew.johnson@intel.com>
2018-04-30 14:54:23 -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
Matthew Johnson 3ec1ed5780 Update tests to reflect swupd search improvements
Signed-off-by: Matthew Johnson <matthew.johnson@intel.com>
2018-02-21 17:45:28 -08: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
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 2143fbf513 Only grep the output for search tests
It's not clear to me why the 'swupd search' output for the functional
tests is so much different than running it outside that environment, but
regardless, the most interesting output line is what is grepped for.

This output disparity needs further debugging.

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 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
William Douglas a52eeb42cb Move functional tests to use the BATS framework 2016-04-26 22:15:04 +00:00
Patrick McCarty 5407e70e44 Use formatstaging for functional tests
Since a numeric format now requires a config file, and aligning the
client format with the test format is a maintenance problem, use the
"staging" format for all tests.

Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-04-04 11:42:25 -07:00