Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Fix/ota 3057/url determination #1267

Merged
merged 4 commits into from
Jul 29, 2019
Merged

Conversation

pattivacek
Copy link
Collaborator

The most interesting part is in sotauptaneclient.cc, where if the custom URL is not set in the Director target metadata, we check if it is set in the Images repo target metadata and use that if it is.

A lot of the changes relate to aktualizr-repo, where I added parameters to set the custom URL.

@codecov-io
Copy link

codecov-io commented Jul 25, 2019

Codecov Report

Merging #1267 into master will decrease coverage by 0.12%.
The diff coverage is 96.96%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1267      +/-   ##
==========================================
- Coverage    79.7%   79.57%   -0.13%     
==========================================
  Files         173      173              
  Lines       10301    10320      +19     
==========================================
+ Hits         8210     8212       +2     
- Misses       2091     2108      +17
Impacted Files Coverage Δ
src/aktualizr_repo/image_repo.h 100% <ø> (ø) ⬆️
src/aktualizr_repo/uptane_repo.h 100% <ø> (ø) ⬆️
src/libaktualizr/uptane/tuf.cc 89.04% <ø> (ø) ⬆️
src/libaktualizr/primary/sotauptaneclient.h 100% <ø> (ø) ⬆️
src/aktualizr_repo/director_repo.h 100% <ø> (ø) ⬆️
src/libaktualizr/primary/sotauptaneclient.cc 91.35% <100%> (-0.56%) ⬇️
src/aktualizr_repo/main.cc 82.45% <100%> (+0.74%) ⬆️
src/libaktualizr/uptane/tuf.h 93.69% <100%> (+0.05%) ⬆️
src/aktualizr_repo/director_repo.cc 91.54% <100%> (+0.37%) ⬆️
src/aktualizr_repo/uptane_repo.cc 96.55% <100%> (ø) ⬆️
... and 10 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8c8877f...7b0c026. Read the comment docs.

if (!url.empty()) {
director_targets["targets"][target_name]["custom"]["uri"] = url;
} else {
director_targets["targets"][target_name]["custom"].removeMember("uri");
Copy link
Collaborator

@mike-sul mike-sul Jul 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why a nested structure is required for the custom URI, not just a single attribute of target_name, to paraphrase why ["custom"]["uri"] not just ["custom-uri"] or there is/are other attribute(s) of ["custom"] ?
Perhaps, just the whole "custom" can be removed ?
Oh, I see another attribute of custom, it's "targetFormat", but still not clear why not remove the whole "custom" element.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is/are other attribute(s) of ["custom"] ?

Precisely. It's following the recommendation of Uptane to keep implementation-specific custom metadata in a custom section.

@@ -37,11 +37,14 @@ void ImageRepo::addBinaryImage(const boost::filesystem::path &image_path, const
target["hashes"]["sha256"] = boost::algorithm::to_lower_copy(boost::algorithm::hex(Crypto::sha256digest(image)));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that it's not related to this specific PR, but loading the whole file/image into memory doesn't look like optimal way to calculate file hash, unless aktualizr-repo is used just for testing purposes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid point. This is not what we do in libaktualizr itself, but aktualizr-repo is really just for testing, so it's not so critical.

for (auto it = targets.cbegin(); it != targets.cend(); ++it) {
auto res = downloadImage(*it, token);
for (const auto &it : targets) {
auto res = downloadImage(it, token);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for some reason downloadImage() passes a target object by value, maybe it makes sense to pass it by reference ?

Copy link
Contributor

@lbonn lbonn Jul 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was changed because the targets inside the vectors are modified with setUri() and we probably don't want to change it in the vector that lives in the caller.

That's a bit annoying though, I would maybe suggest passing by const reference and making a copy inside the function so that it's more explicit. (+ a comment about that)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would maybe suggest passing by const reference and making a copy inside the function so that it's more explicit. (+ a comment about that)

Agreed, done.

for (auto it = targets.cbegin(); it != targets.cend(); ++it) {
auto res = downloadImage(*it, token);
for (const auto &it : targets) {
auto res = downloadImage(it, token);
if (res.first) {
downloaded_targets.push_back(res.second);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to continue downloading if a current target image download fails, don't we consider a singe multi-target update as an atomic operation ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessarily. That logic is still being worked out as far as I understand. That should be up to the user to decide what to do. For now, we attempt to download everything regardless of failures.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, makes sense to make it configurable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. That requires some integration with the backend, though, and we haven't sorted out the details yet.

@@ -582,10 +587,9 @@ void SotaUptaneClient::reportResume() {
report_queue->enqueue(std_::make_unique<DeviceResumedReport>(correlation_id));
}

std::pair<bool, Uptane::Target> SotaUptaneClient::downloadImage(Uptane::Target target,
std::pair<bool, Uptane::Target> SotaUptaneClient::downloadImage(const Uptane::Target &target,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, you did it here :)

@@ -41,8 +41,7 @@ class SotaUptaneClient {

void initialize();
void addNewSecondary(const std::shared_ptr<Uptane::SecondaryInterface> &sec);
result::Download downloadImages(const std::vector<Uptane::Target> &targets,
const api::FlowControlToken *token = nullptr);
result::Download downloadImages(std::vector<Uptane::Target> targets, const api::FlowControlToken *token = nullptr);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not by reference, is it because of the move semantics ?

const api::FlowControlToken *token) {
// Uptane step 4 - download all the images and verify them against the metadata (for OSTree - pull without
// deploying)
std::lock_guard<std::mutex> guard(download_mutex);
result::Download result;
std::vector<Uptane::Target> downloaded_targets;
for (auto it = targets.cbegin(); it != targets.cend(); ++it) {
auto images_target = findTargetInDelegationTree(*it);
for (auto &it : targets) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When using this style of for, it makes it clearer to rename the variable to something other than it, as it's not an iterator anymore.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. Done.

URLs are not matched. If the Director provides one, we use that. If not,
but the Image repository does, use that. Otherwise, leave it empty and
use the default.

Signed-off-by: Patrick Vacek <patrickvacek@gmail.com>
Necessary for creating custom URLs.

Signed-off-by: Patrick Vacek <patrickvacek@gmail.com>
Signed-off-by: Patrick Vacek <patrickvacek@gmail.com>
Signed-off-by: Patrick Vacek <patrickvacek@gmail.com>
@pattivacek pattivacek force-pushed the fix/OTA-3057/url-determination branch from 8236d1b to 7b0c026 Compare July 26, 2019 08:55
@pattivacek pattivacek merged commit 7645037 into master Jul 29, 2019
@pattivacek pattivacek deleted the fix/OTA-3057/url-determination branch July 29, 2019 07:16
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants