Commit Graph
131 Commits
Author SHA1 Message Date
Castulo Martinez a562fb4fd3 Implement --file option for diagnose/repair
When diagnosing/repairing a system, sometimes is useful to only
diagnose/repair a specific file or path.

This commit implements the --file option for diagnose/repair so a file
or path can be diagnosed only instead of doing it to the whole OS or a
whole bundle.

Closes #1150

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2020-01-28 15:01:47 -08:00
Castulo Martinez b5bd920611 Fix the number of steps in swupd functions
In order to report progress accuratelly, currently swupd requires a
hardcoded number of steps per operation so we can report how far in the
operation we are. Most of these step totals are wrong.

This commit fixes the number of steps in many swupd functions.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-12-27 17:28:53 -08:00
Castulo Martinez d0c2f881cf Update testlib to support 3rd-party bundle updates
This commit modifies some of the functions of the test library so it is
possible to update bundles that belong to 3rd-party repositories.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-12-12 08:41:45 -08:00
Otavio Pontes d2590a1b9e fullfile: Improve output of fullfile downloads
Print a "Validate downloaded files" message to separate 2 different progress bars
and improve the output when downloading extra fullfiles

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-10-18 09:27:25 -07: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 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 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
Castulo Martinez a41bea9fd5 Show the real latest version using check-update
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>
2019-08-14 14:31:33 -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
Otavio Pontes 299977fec4 update: Download search-files indexes on update
If --update-search-file-index flag is used on update, all search-file indexes, i.e.
all Manifests will be downloaded on update. This shouldn't be used if you have
disk or network restrictions, but it shouldn't be very download intensive after the
first usage because delta manifests are going to be used.

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-08-14 13:04:23 -07:00
John Akre 970f3a257a bundle.c: Return included manifest loading errors
Previously, when adding included manifests errors were thrown away which
resulted in swupd operations that could succeed, even when failing to
load an included manifest. Now when an included manifest fails to load,
swupd will return a failure.

Signed-off-by: John Akre <john.w.akre@intel.com>
2019-08-12 14:38:34 -07:00
Castulo Martinez 5608930be5 Fixing a bug using ignore-ilst files in tests
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>
2019-08-02 14:17:19 -07:00
Otavio Pontes cd1aac63f1 style: Removing all prints that ends with a '.'
It was defined to not use period at the end of output messages.
Removing the left over cases

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-07-17 14:16:56 -07:00
Otavio Pontes 7f0bee1f6f bundle: Support circular includes/also-adds
Circular includes shoudn't exist, but we can handle that without crashing.
Also-add circular includes are common and expected. So we just add the
first occurence found.

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-07-15 17:24:12 -07:00
Otavio Pontes 43034997f5 test: Fix test name
Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-07-15 16:23:50 -07:00
Otavio Pontes 382c1d782f also-add: Update, diagnose and repair shoudn't consider the also-add bundles
In the case that we have a bundle installed as also-add and removed later,
repair shouldn't reinstall that bundle. The same is valid for diagnose and update.
Os-install is the only exception. We should always install all bundles that are
listed as also-add in os-install.

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-07-12 15:44:25 -07:00
Castulo Martinez 515c7c71fe Checking mirror status only if necessary
When doing an update, we check to see if a mirror is stale, this only
needs to be done if there is a mirror set and if the upstream server is
up and reachable.

This commit checks to see if a mirror is set and there is an upstream
server to compare against, and only then it checks to see if it is stale.

Closes #922

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-07-03 16:10:46 -07:00
Castulo Martinez 43ba5def2a Require a force flag to continue with insecure URL
Currently users can set content and version urls based on http or https
protocols. This pose a security risk if users decide to use http.

This commit blocks swupd from working with http unless is specifically
allowed by using the --allow-insecure-http flag.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-06-27 14:48:50 -07:00
Castulo Martinez c521417205 Including a few more cosmetic changes for "verify"
This commit adds a few more cosmetic changes to the commands that run
verify in the back for consistency.
- Different steps in the update process are separated by a blank line.
- Messages from swupd should not finish with a '.'

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-06-14 14:50:09 -07:00
Castulo Martinez a89f61e4e8 Fixing false positive in a test
The update/update-json.bats functional test is giving a false positive
since one hardcoded value (time) was taking longer to run, than in a
local environment.
This commit fixes the issue by using a regex to accept any time value.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-05-29 03:09:48 +00:00
Otavio Pontes 41ac4f76f3 check_update: Unify check_update and update -s
Update --status is now calling code on check_update.

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-05-14 15:51:47 -07:00
Castulo Martinez a7cf50d360 Improving output messages in bundle-add
Adding messages where swupd could take some time to finish a step so
users know better where the process is at.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-05-13 14:38:20 -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
Castulo Martinez 755e7e1527 Use swupd_progress_callback for fullfile download
This commit makes use of the swupd_progress_callback() function to
report progress downloading fullfiles based on how much data we have
downloaded vs the number of files downloaded. This callback will only be
used when the number of files to be downloaded are less than MAX_FILES,
calculating the total download size can be very costly if the files are
too many. If the files to be downloaded are more than MAX_FILES we will
fallback to reporting download progress based on file count as before.

When installing bundles or doing updates, swupd creates a list of files
that need to be downloaded. This list may contain files that were
already downloaded via packages and it often does. These files are then
skipped at the moment of downloading them since they are already in the
system. This causes a misleading output that shows the user that
fullfiles will be downloaded when they are actually not.

This commit filters the list of fullfiles to be downloaded to only
contain those ones that actually need to be downloaded.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-04-18 10:29:49 -07:00
Castulo Martinez d7210882e6 Use the swupd_progress_callback for packs download
This commit makes use of the swupd_progress_callback() function to
report progress downloading packs based on how much data we have
downloaded vs the number of files downloaded.

This commit also fixes a bug in the download_subscribed_packs function.
Swupd was not downloading the correct pack for bundles not installed in
the system that had been recently added as dependency of another
installed bundle.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-04-18 10:29:49 -07:00
Otavio Pontes d9dedbac91 scripts: Use run_command() instead of system() for all scripts
Also reorganize, change some functions name and create a .h for scripts module.

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-04-10 16:13:54 -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
Otavio Pontes 1cd5688ea3 update: use execv() instead of system() to re-execute update
Note that we don't need to use run_command() (fork + exec) because
we don't need to handle any output on swupd. We can just replace current
process with the new swupd execution.

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-04-09 12:26:50 -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
Castulo Martinez a09476380e Implementing the --json-output in bundle-add
When using bundle-add to install bundles with the --json-output flag,
the output generated by swupd will be formatted to json. This is useful
for other applications that are reading the swupd output to determine
real time progress.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-03-25 16:07:40 -07: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 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 70264e33ea Fixing the time shown using update -t
When running an update using the flag --time/-t the user is presented
with a verbose time output of the update operations. The time collected
for those operations was wrong.

This commit fixes the issue and presents a verbose output that is
consistent with other commands like bundle-add --time.

Closes #584

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-03-05 13:32:25 -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
Otavio Pontes 4f6064beff curl: Make messages consistent
Replace all usages of "Curl: " to "Curl - "

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-02-12 16:01:03 -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
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
Otavio Pontes 71b334159a update: Be consistent in exit codes when trying to update to the same version
Use similar output and same exit code used when you are already in the
last version in the case where you are updating to the same version you
already are.

i.e. if you are in version 100, both commands are going to have the same
exit code:

 - swupd update
 - swupd update -m 100

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-02-12 14:38:58 -08:00
Otavio Pontes 70200b3251 test: Fix tests broken by curl changes
Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-02-11 12:32:40 -08:00
Castulo Martinez e28c24a50a Refactoring retry code for fullfiles
The retry code in swupd is not an ideal implementation, making it
difficult to use throughout the code base. Some parts retry
differently based on needing to support retries for network errors,
or retry based on IO errors.

This commit refactors this code into a consistent implementation so
the retry code is not spread across the code base.

Closes #211

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-02-01 12:30:45 -08:00
Castulo Martinez 6b49ca562b Checking if the boot script exist before running
When swupd needs to run a boot script it does so without checking if the
file exists in the system or not. This will cause an error to be raised
by the shell if the script does not exist.

This commit adds a check for the existance of the script before
attempting to run it.

Closes #795

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-01-31 10:03:41 -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 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