-
Notifications
You must be signed in to change notification settings - Fork 205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expand Machine and Medium Type settings when creating job with 'jobs post' #2083
Conversation
You need to find out whether the failing CI test is related:
|
Codecov Report
@@ Coverage Diff @@
## master #2083 +/- ##
==========================================
+ Coverage 85.04% 85.07% +0.03%
==========================================
Files 159 160 +1
Lines 10596 10638 +42
==========================================
+ Hits 9011 9050 +39
- Misses 1585 1588 +3
Continue to review full report at Codecov.
|
01cdbbb
to
075a220
Compare
8666a6b
to
41784b3
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.
And since you've asked for general improvements of the algorithm: I also don't know a better way to detect cycles other then remembering visited elements. I'd only use a hash to store and check for them.
41784b3
to
a45f17b
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.
please see inline comments. Also, I think we should extend the documentation a bit? I can offer my help but so far unfortunately I am not yet sure what exactly the new behaviour is supposed to support
t/api/04-jobs.t
Outdated
@@ -693,6 +693,76 @@ subtest 'TEST is only mandatory parameter' => sub { | |||
$t->json_is('/job/settings/DISTRI' => undef); | |||
}; | |||
|
|||
subtest 'Expand specified Machine, Testsuit, Product variables' => sub { |
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.
typo "Testsuit"
a45f17b
to
6f9b838
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.
see unresolved inline comments
lib/OpenQA/Settings.pm
Outdated
my $key_in_value = $1; | ||
last unless defined $settings->{$key_in_value}; | ||
|
||
return "The key $key_in_value contains a circular reference, its value is " . $settings->{$key_in_value} |
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 a fan of exceptions.
Returning a string and then relying on the calling code is usually less maintainable.
In lib/OpenQA/WebAPI/Controller/API/V1/Job.pm
for example there is already a try/catch
block. So I would just die
instead of returning a string.
lib/OpenQA/Settings.pm
Outdated
sub expand_placeholders { | ||
my ($settings) = @_; | ||
|
||
my $error_string; |
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 can't see that this variable is used anywhere.
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, I will remove it.
lib/OpenQA/Settings.pm
Outdated
use warnings; | ||
|
||
# replace %NAME% with $settings{NAME} | ||
sub expand_placeholders { |
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.
May I suggest an alternative to the expand_placeholders subroutine?
sub expand_placeholders {
my ($settings) = @_;
for my $value (sort values %$settings) {
next unless defined $value;
my %seen;
$value =~ s/%(\w+)%/expand_placeholder($settings, $1, \%seen)/ge;
}
return 1;
}
sub expand_placeholder {
my ($settings, $key, $global_seen) = @_;
unless (exists $settings->{ $key }) {
return '';
}
my %seen = %$global_seen;
# prevent circular replacement
if ($seen{ $key }++) {
die sprintf "The key %s contains a circular reference, its value is %s",
$key, $settings->{ $key };
}
my $value = $settings->{ $key };
$value =~ s/%(\w+)%/expand_placeholder($settings, $1, \%seen)/ge;
return $value;
}
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 prefer throwing exceptions too. But i don't think we have an exception class in openQA yet to filter which exceptions to show the user.
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.
@perlpunk If I may give a suggestion, start your github code section comments with the word "perl" immediately after the three backticks as I just did with your comment for cool syntax highlighting :)
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.
@okurz done, thanks :)
edit: oh, somehow I didn't see that you already updated it. github didn't warn me...
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.
If you don't mind in your PR description and also git commit could you please describe what the important change or benefit is? Also there is a typo "testsuit" in one commit message, should be "test suite" instead |
c0f2ccd
to
f2ac486
Compare
@Martchus @kraih @okurz @perlpunk Please help me review this PR if you have time. Thanks.
@okurz I modify the commit message. Wrote the related tickets in it. I am wondering if it is enough to describe this PR's aim. |
Just for the record: The change 1. is not required. Those are different |
Yes, the reference to the ticket is fine. But please rewrite the subject line of the PR and the commit message to point out what the important change of behaviour is. For example the openSUSE package's changelog is generated from the commit messages. The changelog should in an obvious way describe what is important for the user. "Rewrite code …" is what we do with every commit in general and not very exciting to read for users ;) |
f2ac486
to
030ce69
Compare
41a3e90
to
5289954
Compare
@Martchus Thanks for your comments. I already modified the code. If you have time please have a review. 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.
Sorry for nitpicking on variable name but it really helps to understand the code better (especially in a language without static types).
5289954
to
026fa0f
Compare
Please feel free to give me suggestions. All names you suggested are more meaningful and I am a pleasure to modify them. |
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.
There are outstanding changes for the other reviews but the issues I mentioned have been addressed.
post' When users created jobs using 'client jobs post', the jobs settings did not expand Machine and Medium Type settings. This PR is used to support to expand settings from Machine and Medium Type when creating jobs with 'jobs post'. See: https://progress.opensuse.org/issues/20464 Related: https://progress.opensuse.org/issues/51479
026fa0f
to
9cb48b8
Compare
|
||
BEGIN { | ||
unshift @INC, 'lib'; | ||
} |
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 know this BEGIN block is used in many other tests.
Just a note that this was the way to do it in older perls, but the modern way is to use
use FindBin;
use lib "$FindBin::Bin/../lib";
eval { $value =~ s/%(\w+)%/_expand_placeholder($settings, $1, \%visited_top_level_placeholders)/eg; }; | ||
if ($@) { | ||
return "Error: $@"; | ||
} |
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.
@perlpunk I think you suggested the simple loop but without the eval/if
, can you comment on this? I don't see why a call to an internal method should be wrapped by eval
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 we had a discussion about exceptions in the chat.
Using exceptions consequently and catching them at the upmost level possible would be preferable, but we decided that we make this improvement later.
Still, I think _expand_placeholder
should die instead of returning a string, because handling this would be more work here, so we need that eval.
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.
Last weekend i made a new exception handling mechanism for Mojolicious. That might come in handy for this stuff in the future.
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, in the future :) we should not yet rely on this new version
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.
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.
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.
IMHO keep it as it is
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.
All errors are presented to the user, right? I'm always very sceptical of doing that, even in cases like this were there is not much risk of leaking information the user shouldn't have. Maybe just to be sure make the die statements throw arrayrefs and rethrow non-arrayref exceptions? Maybe that's the pattern we should encourage until we have real exception objects.
eval { ... };
if (my $err = $@) {
if ($err eq 'ARRAY') { return "Error: @$err" }
else { die $err }
}
sub _expand_placeholder {
...
die ["The key $key contains a circular reference, its value is $settings->{$key}."];
...
}
Think this would be setting a good example.
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.
The exception handling could still be better, but i don't think it's required at this time.
commit 7a26251 Merge: 6a8f9a5 9cb48b8 Author: LiuXiaojing <xiaojing.liu@suse.com> AuthorDate: Tue Jul 23 16:46:19 2019 +0800 Commit: GitHub <noreply@github.com> CommitDate: Tue Jul 23 16:46:19 2019 +0800 Merge pull request #2083 from Amrysliu/redone_job_setting Expand Machine and Medium Type settings when creating job with 'jobs post'
When users created jobs using 'client jobs post', the jobs settings did
not expand Machine and Medium Type settings. This PR is used to support
to expand settings from Machine and Medium Type when creating jobs with
'jobs post'.
See: https://progress.opensuse.org/issues/20464
Related: https://progress.opensuse.org/issues/51479