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

Add --wait-until-provisioned option to aktualizr-info #1253

Merged
merged 1 commit into from
Jul 17, 2019

Conversation

Zee314159
Copy link
Contributor

Draft code.

@Zee314159 Zee314159 force-pushed the aktualizr-info-wait-until-provisioned branch 2 times, most recently from 4c0923b to 529af68 Compare July 11, 2019 06:20
Copy link
Collaborator

@pattivacek pattivacek left a comment

Choose a reason for hiding this comment

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

Looks good so far!

std::shared_ptr<INvStorage> storage = INvStorage::newStorage(config.storage, readonly);
bool cmd_trigger = false;
bool provision_trigger = true;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Might be simpler to initialize this to false and just use a while(!provisioned) loop.

if (provision_trigger) {
break;
} else {
sleep(5);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think a much smaller sleep time would be better. 1 second is probably plenty. However, that will result in a lot of garbage printed to the screen, so we might want to any output until the loop finishes.

Does anyone else have opinions on what they'd like to see printed while waiting for provisioning to complete? Perhaps most ideal would be to only print the successful parts as they happen.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I am just wondering if there is/are condition(s) under which this 'for' loop can last forever, e.g. device hasn't been registered at the server for some reason.

Copy link
Contributor Author

@Zee314159 Zee314159 Jul 12, 2019

Choose a reason for hiding this comment

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

I might have the same question as Mike said, under what condition(s) would the loop last forever? Now I just assume the conditions are :device ID and ECU serials could be loaded, device has been registered, metadata is available. I actually am not sure about it. Is provisioned means those four conditions are met? @patrickvacek

Copy link
Collaborator

Choose a reason for hiding this comment

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

You can't register without device ID and ECU serials, and you can't fetch metadata without provisioning, so the only conditions that need to be checked are registration and metadata successfully fetched. It is true that this loop could last forever if something goes wrong. We've discussed a possible timeout feature, but for a first go of this feature, I don't think we need that yet.

Copy link
Contributor

Choose a reason for hiding this comment

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

It probably shouldn't output anything until it's provisioned, so that the output can be parsed without errors / duplicates.

The body of the while loop looks quite big as well. Is it possible to have something like that?

bool provisioned = false;
while (wait_provisioning && !provisioned) {
  // some simple condition, no output
}

// regular aktualizr-info body

For the timeout parameter, as it's usually called as a subprocess by other tools (in python for example), we can use a timeout there for the moment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. Much clear now!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For the timeout parameter, as it's usually called as a subprocess by other tools (in python for example), we can use a timeout there for the moment.

So, how does the other tools(in python for example) outside aktualizr-info main function body break this loop?

Copy link
Contributor

Choose a reason for hiding this comment

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

For example, in Python:

https://docs.python.org/3/library/subprocess.html#subprocess.run

The timeout argument is passed to Popen.communicate(). If the timeout expires, the child process will be killed and waited for. The TimeoutExpired exception will be re-raised after the child process has terminated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, thanks!

std::cout << "Provisioned on server: " << (registered ? "yes" : "no") << std::endl;
std::cout << "Fetched metadata: " << (has_metadata ? "yes" : "no") << std::endl;
provision_trigger = (provision_trigger && registered);
provision_trigger = (provision_trigger && has_metadata);
Copy link
Collaborator

Choose a reason for hiding this comment

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

These can be merged into one line: provisioned = (registered && has_metadata);

@codecov-io
Copy link

codecov-io commented Jul 12, 2019

Codecov Report

Merging #1253 into master will decrease coverage by 0.03%.
The diff coverage is 66.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1253      +/-   ##
==========================================
- Coverage   79.32%   79.28%   -0.04%     
==========================================
  Files         171      171              
  Lines       10158    10164       +6     
==========================================
+ Hits         8058     8059       +1     
- Misses       2100     2105       +5
Impacted Files Coverage Δ
src/aktualizr_info/main.cc 91.58% <66.66%> (-2.17%) ⬇️
src/libaktualizr-posix/ipuptanesecondary.cc 82.66% <0%> (-4%) ⬇️
src/libaktualizr/package_manager/ostreemanager.cc 75.42% <0%> (-1.7%) ⬇️
src/aktualizr_primary/secondary.cc 82.89% <0%> (-1.32%) ⬇️
src/libaktualizr/primary/sotauptaneclient.cc 91.45% <0%> (-0.31%) ⬇️
src/libaktualizr/http/httpclient.cc 91.92% <0%> (-0.2%) ⬇️
src/libaktualizr/storage/sqlstorage.cc 76.19% <0%> (+0.9%) ⬆️
src/libaktualizr/storage/sqlstorage_base.cc 80.4% <0%> (+2.02%) ⬆️

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 0cbc6f3...24c5e59. Read the comment docs.

@Zee314159 Zee314159 force-pushed the aktualizr-info-wait-until-provisioned branch from 2beae00 to 7bb47e7 Compare July 12, 2019 04:39
if (vm.count("name-only") != 0u) {
std::cout << device_id << std::endl;
return EXIT_SUCCESS;
while (!provisioned && wait_provisioning) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will break anything that doesn't use the --wait-until-provisioned flag since the loop will get skipped.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I realized that too. I'm fixing it right now.

@Zee314159 Zee314159 force-pushed the aktualizr-info-wait-until-provisioned branch 4 times, most recently from 74617f8 to 82ba09b Compare July 16, 2019 01:58
Copy link
Collaborator

@pattivacek pattivacek left a comment

Choose a reason for hiding this comment

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

Seems cool, looks quite close! Thanks.

@rdanitz @balajirrao @Raigi Is this useful for your needs?

while (wait_provisioning && !provisioned) {
registered = storage->loadEcuRegistered();
has_metadata = storage->loadLatestRoot(&director_root, Uptane::RepositoryType::Director());
provisioned = (registered && has_metadata);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure this provisioned variable is doing much anymore. Also, currently storage->loadEcuRegistered() and storage->loadLatestRoot() will always run at least twice. If the while loop's condition directly used has_metadata and registered, you wouldn't have that problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, thanks!

Copy link

Choose a reason for hiding this comment

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

Seems cool, looks quite close! Thanks.

@rdanitz @balajirrao @Raigi Is this useful for your needs?

Currently I have a loop that will check aktualizr-info multiple times for provisioned: yes and metadata: yes if it received false. But it might be faster and better with aktualizr-info-wait-until-provisioned when I am creating like 50 devices.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Cool, that's exactly the type of thing we're hoping this will help optimize.

@Zee314159 Zee314159 force-pushed the aktualizr-info-wait-until-provisioned branch 3 times, most recently from 556700f to 24c5e59 Compare July 17, 2019 02:19
registered = storage->loadEcuRegistered();
has_metadata = storage->loadLatestRoot(&director_root, Uptane::RepositoryType::Director());

sleep(1);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will result in sleeping even if registration and loading the metadata is successful, which is undesirable. I think the previous way you had it where you called those two load calls outside of the loop first was actually fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I've changed it back and pushed it here. By the way, I didn't change anywhere else but sometimes the CI failed sometimes it passed. It's confusing. I'll check the output again after the CI process is done.

Copy link
Contributor

Choose a reason for hiding this comment

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

About the CI, we've had problem with Travis timing out but it should be much better after some recent changes. If you rebase your PR on master, it should go much faster and fail less often.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

About the CI, we've had problem with Travis timing out but it should be much better after some recent changes. If you rebase your PR on master, it should go much faster and fail less often.

It's not the Travis timing out issue. The confusing part is sometimes the prosess will pass. I'll check the output later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

CI is passing this time.

When it failed the message for Travis might be:
The command "if [[ $RELEASE_NAME = ubuntu_16.04 ]]; then ./scripts/test_aktualizr_deb_ubuntu.sh /persistent "${INSTALL_DOCKERFILE}"; fi" exited with 1.
If GitLab CI failed , it's mostly with 'coverage'.

I don't know if this infomation is useful. I'm sure I'll run into the same situation again. Then I can dig deeper.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sounds like it might be a race condition with the deb generation, probably not related to your PR. If you do see it again, please do let the rest of the team know, though.

Print messages until the loop finishes

Optimized the logic of loop condition

Add timeout feature

Optimized the loop condition

Signed-off-by: Zee314159 <252806294@qq.com>
@Zee314159 Zee314159 force-pushed the aktualizr-info-wait-until-provisioned branch from 24c5e59 to 78d32b6 Compare July 17, 2019 07:32
Copy link
Collaborator

@pattivacek pattivacek left a comment

Choose a reason for hiding this comment

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

Looks good, let's merge it!

@pattivacek pattivacek merged commit 953386c into master Jul 17, 2019
@pattivacek pattivacek deleted the aktualizr-info-wait-until-provisioned branch July 17, 2019 12:26
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

6 participants