Multiple bug fixes and improvements for template dump/load#6446
Conversation
fe6c812 to
5ebb0a5
Compare
|
OK, I found a way to finesse the patch series: I combined the three major fixes to dump-templates into one. So the fix for accidentally defining As well as meaning the tests pass at each point, this actually makes sense. If we fix the two bugs before we change the dumping behavior, that makes us dump in both formats by default, which really isn't a good idea. And vice versa, if we do the dump-in-native-format-by-default fix first, it doesn't really work as intended because we'll actually fail to dump 'legacy' data entirely due to the logic bugs. So I think this isn't just convenient, it's also right. |
This comment was marked as resolved.
This comment was marked as resolved.
5ebb0a5 to
81716b9
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #6446 +/- ##
==========================================
+ Coverage 99.06% 99.08% +0.02%
==========================================
Files 399 399
Lines 40327 40401 +74
==========================================
+ Hits 39949 40031 +82
+ Misses 378 370 -8 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
ca0ad6b to
d3520ae
Compare
|
commit messages rewritten by J. Jonah Jameson, wall-of-text factor reduced by 43.786%. todo: the first commit doesn't quite do everything the message claims yet, I'll fix that in the morning. and add the missing coverage lines. |
|
The change looks generally good but I have a few nitpicks. Unfortunately not everything is covered according to codecov so it would be nice to add tests for those cases as well. Otherwise I'd also be fine with marking lines as uncoverable for these scripts as we don't care much about them anymore from our side. (But maybe with a remark that the code is not really uncoverable and we just avoiding the effort here.) |
|
I'm going to add a test for the uncovered bit, it's in the todo note above. It's not too hard to do. There's a couple of other things I still need to add to the tests too. |
|
wow, I'm calling the UN. |
747d704 to
71c81a5
Compare
This comment was marked as outdated.
This comment was marked as outdated.
|
to preserve a note on the whole "our test fixtures are logically impossible" thing: this situation developed during the big YAML template introduction, specifically in e458cda (added settings to a job template in the 'opensuse' group) and 819374a (added a description to another one). e458cda was the 'original sin' - it should either have made the 'opensuse' job group in the fixtures into a YAML group (by giving it a YAML template string and dropping explicit creation of the job templates in 04-products.pl) or used a separate YAML job group. Unfortunately, fixing this isn't trivial - if you turn the opensuse group into a YAML group now, several other tests start failing, including some of the YAML tests themselves. Adding a new YAML group fixture and adjusting appropriate tests to use it instead also isn't trivial. I didn't feel like putting the effort into fixing this mess, since I didn't create it and this PR was already taking forever. I might file a progress ticket pointing the problem out, though, for anybody else to fix if they feel so inclined. |
8fb5d82 to
519abe1
Compare
In os-autoinst#5973 , this script was changed to always send data as a JSON payload, based on an assumption that all the requests would be handled by the Table controller, which had been adjusted to handle JSON payloads. But job templates have their own JobTemplate controller, and the https://docs.mojolicious.org/Mojolicious/Plugin/DefaultHelpers#validation helper it uses works only with "GET and POST parameters extracted from the query string and application/x-www-form-urlencoded or multipart/form-data message body". Sending it JSON always fails: "Bad Request: Erroneous parameters (arch missing, distri missing, flavor missing, group_name missing, machine_name missing, prio missing, test_suite_name missing, version missing)" We should continue to pass it form data, not JSON, unless/until the controller is rewritten to accept JSON (maybe with a custom validator). Related: https://progress.opensuse.org/issues/181895 Signed-off-by: Adam Williamson <awilliam@redhat.com>
The job group creation API gives a 500 error if the group already exists. Instead of having another check here, let's attempt to create the group, then act according to the API response. Also, as for the other data types, ignore the group and move on if the group exists and --update wasn't passed, instead of erroring. Finally, even if the group exists, continue with the template string load if --clean was passed. --clean always means to start fresh and load all data from the template, so we should go ahead and post the template even if the group already exists. This is common in --clean mode because we can't fully delete the job groups, they have properties that aren't stored in the templates. --clean with JobTemplates doesn't yet work properly even with this fix, but I'm proposing a full fix for it in https://progress.opensuse.org/issues/182063 . Signed-off-by: Adam Williamson <awilliam@redhat.com>
It's not safe to only check one data type in the output. Let's check all the data types. Making this change exposes an issue: the machines in the test templates data also exist in the fixtures, so we skip loading them unless --update or --clean are passed. Let's give them non-conflicting names to ensure we fully test the data. Signed-off-by: Adam Williamson <awilliam@redhat.com>
eede394 to
2d8578d
Compare
2d8578d to
c502e91
Compare
okurz
left a comment
There was a problem hiding this comment.
I suggest to also use signatures in newly added code but the current state is ok. Actually really really good so approved :)
dump-templates would almost never dump any JobTemplates. First,
we fix two bugs that caused that:
1. `keys %{$options{group}}` triggers perl autovivification and
defines `$options{group}` as an empty array ref even if it was
previously undefined, so later boolean checks for it passed
unexpectedly
2. in 9d311d7, one of the filters in `handle_row` lost a check
for `$options{product}`, so it was incorrectly kicking us out
early unless `--full` or `--product` were passed
With that fixed, though, we default to dumping all job group
and template info both as JobTemplates (the format from before
YAML templates were introduced in
https://progress.opensuse.org/issues/44360) and JobGroups (the format that
can store YAML templates). This is redundant and it's unclear
what we intend load-templates to do with such data.
Instead we'll default to dumping the data in the form it currently
exists on the server. Legacy groups will be dumped to JobTemplates;
"modern" groups will be dumped to JobGroups. This is in line with
the intent of being able to dump the current configuration and
reload it exactly as-is.
We refuse to dump templates with settings or a description as
JobTemplates, as we could not reload them - the legacy API we use for
loading JobTemplates doesn't handle them. This state should be
unreachable without database manipulation, but let's be safe. The
test fixtures *do* start in this 'impossible' state, so we have to
tweak around that, and add a new explicit test that loading YAML
templates with settings/description works. Also test clean and update
with YAML templates: since the recent tweak to load-templates it
works almost correctly (but does not clear existing template
strings for groups not in the data being loaded). We remove
40-templates.json as it has not been used since d601c36.
We also add --convert for if you really want to convert all existing
legacy groups to modern YAML style. It will dump all groups to
JobGroups, and not dump JobTemplates at all.
We also custom sort the job templates before dumping them, to ensure
consistent output, because JSON::XS `canonical` doesn't manage this.
Finally we tweak a test check to use eq_or_diff_text instead of
is_deeply, because the output was much easier to read when debugging
this PR. It's from Test::Differences, which is in Test::Most.
Signed-off-by: Adam Williamson <awilliam@redhat.com>
c502e91 to
c8c91b6
Compare
|
OK, I did the signatures. I also snuck in a new check for |
Martchus
left a comment
There was a problem hiding this comment.
Looks good now and thanks for the detailed explanations.
wow, tidy is a psychopath.
Yes, it sometimes often overshoots the goal.
This series fixes a ton of issues I noticed in template dumping/loading while investigating https://progress.opensuse.org/issues/181895 . To summarize:
JobTemplatesare fixed--updateor--cleanare set, ignore it and move on if not), and we rely on the API to tell us whether the group already exists instead of explicitly checkingJobTemplates, modern YAML groups/templates are dumped toJobGroups; however, we add a--convertarg that will always dump toJobGroups, effectively "converting" legacy groups to modern (this is how it behaved before the whole patch series, but by default and more or less by accident)