-
Notifications
You must be signed in to change notification settings - Fork 60
Add --wait-until-provisioned option to aktualizr-info #1253
Conversation
4c0923b
to
529af68
Compare
There was a problem hiding this 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!
src/aktualizr_info/main.cc
Outdated
std::shared_ptr<INvStorage> storage = INvStorage::newStorage(config.storage, readonly); | ||
bool cmd_trigger = false; | ||
bool provision_trigger = true; |
There was a problem hiding this comment.
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.
src/aktualizr_info/main.cc
Outdated
if (provision_trigger) { | ||
break; | ||
} else { | ||
sleep(5); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Much clear now!
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, thanks!
src/aktualizr_info/main.cc
Outdated
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); |
There was a problem hiding this comment.
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 Report
@@ 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
Continue to review full report at Codecov.
|
2beae00
to
7bb47e7
Compare
src/aktualizr_info/main.cc
Outdated
if (vm.count("name-only") != 0u) { | ||
std::cout << device_id << std::endl; | ||
return EXIT_SUCCESS; | ||
while (!provisioned && wait_provisioning) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
74617f8
to
82ba09b
Compare
There was a problem hiding this 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?
src/aktualizr_info/main.cc
Outdated
while (wait_provisioning && !provisioned) { | ||
registered = storage->loadEcuRegistered(); | ||
has_metadata = storage->loadLatestRoot(&director_root, Uptane::RepositoryType::Director()); | ||
provisioned = (registered && has_metadata); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, thanks!
There was a problem hiding this 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?
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.
There was a problem hiding this comment.
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.
556700f
to
24c5e59
Compare
registered = storage->loadEcuRegistered(); | ||
has_metadata = storage->loadLatestRoot(&director_root, Uptane::RepositoryType::Director()); | ||
|
||
sleep(1); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 [[
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.
There was a problem hiding this comment.
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>
24c5e59
to
78d32b6
Compare
There was a problem hiding this 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!
Draft code.