Skip to content

Multiple bug fixes and improvements for template dump/load#6446

Merged
mergify[bot] merged 4 commits into
os-autoinst:masterfrom
AdamWill:template-dump-load-bugs
May 14, 2025
Merged

Multiple bug fixes and improvements for template dump/load#6446
mergify[bot] merged 4 commits into
os-autoinst:masterfrom
AdamWill:template-dump-load-bugs

Conversation

@AdamWill

@AdamWill AdamWill commented May 13, 2025

Copy link
Copy Markdown
Contributor

This series fixes a ton of issues I noticed in template dumping/loading while investigating https://progress.opensuse.org/issues/181895 . To summarize:

  • Loading JobTemplates is fixed by reverting to sending the request with form data, not as JSON
  • Two logic bugs in openqa-dump-templates which meant it inadvertently almost never dumped JobTemplates are fixed
  • Behavior of openqa-load-templates when a job group already exists is brought into line with other forms of data (modify the group if --update or --clean are 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 checking
  • We make openqa-dump-templates by default dump job groups / job templates in the format corresponding with how they exist on the server: legacy groups/templates are dumped to JobTemplates, modern YAML groups/templates are dumped to JobGroups; however, we add a --convert arg that will always dump to JobGroups, 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)
  • The tests are substantially improved and extended to more clearly cover all the expected behaviors

@AdamWill
AdamWill force-pushed the template-dump-load-bugs branch from fe6c812 to 5ebb0a5 Compare May 13, 2025 01:53
@AdamWill

Copy link
Copy Markdown
Contributor Author

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 $options{group}, the broken product filter line, and the change to dumping as the data exist on the server all go together.

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.

@AdamWill

This comment was marked as resolved.

@AdamWill
AdamWill force-pushed the template-dump-load-bugs branch from 5ebb0a5 to 81716b9 Compare May 13, 2025 02:06
@codecov

codecov Bot commented May 13, 2025

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.08%. Comparing base (98c95ea) to head (c8c91b6).
Report is 5 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@AdamWill
AdamWill force-pushed the template-dump-load-bugs branch 2 times, most recently from ca0ad6b to d3520ae Compare May 13, 2025 06:27
@AdamWill

AdamWill commented May 13, 2025

Copy link
Copy Markdown
Contributor Author

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.

Comment thread script/openqa-load-templates Outdated
Comment thread t/40-script_load_dump_templates.t Outdated
Comment thread t/40-script_load_dump_templates.t
Comment thread t/40-script_load_dump_templates.t Outdated
Comment thread script/openqa-dump-templates Outdated
Comment thread script/openqa-dump-templates Outdated
Comment thread script/openqa-load-templates Outdated
Comment thread t/40-script_load_dump_templates.t Outdated
Comment thread t/40-script_load_dump_templates.t Outdated
@Martchus

Copy link
Copy Markdown
Contributor

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.)

@AdamWill

Copy link
Copy Markdown
Contributor Author

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.

@AdamWill

AdamWill commented May 13, 2025

Copy link
Copy Markdown
Contributor Author

wow, tidy is a psychopath. it flat out refuses to allow braces on the next line. I have no words.

[adamw@toolbx openQA (template-dump-load-bugs %)]$ ./tools/tidyall -a
[tidied]  script/openqa-dump-templates
[adamw@toolbx openQA (template-dump-load-bugs *%)]$ git diff
diff --git a/script/openqa-dump-templates b/script/openqa-dump-templates
index af926520d..54adb28b5 100755
--- a/script/openqa-dump-templates
+++ b/script/openqa-dump-templates
@@ -275,8 +275,7 @@ sub jt_key ($jt) {
         $jt->{group_name},
         $jt->{test_suite}->{name},
         $jt->{machine}->{name},
-        $prod->{arch}, $prod->{distri}, $prod->{flavor}, $prod->{version}
-    );
+        $prod->{arch}, $prod->{distri}, $prod->{flavor}, $prod->{version});
 }
 
 sub handle_table ($table) {

I'm calling the UN.

@AdamWill
AdamWill force-pushed the template-dump-load-bugs branch 5 times, most recently from 747d704 to 71c81a5 Compare May 13, 2025 18:21
@AdamWill

This comment was marked as outdated.

@AdamWill

Copy link
Copy Markdown
Contributor Author

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.

@AdamWill
AdamWill force-pushed the template-dump-load-bugs branch 3 times, most recently from 8fb5d82 to 519abe1 Compare May 13, 2025 22:01
AdamWill added 3 commits May 13, 2025 15:06
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>
@AdamWill
AdamWill force-pushed the template-dump-load-bugs branch 3 times, most recently from eede394 to 2d8578d Compare May 13, 2025 23:24
@AdamWill
AdamWill force-pushed the template-dump-load-bugs branch from 2d8578d to c502e91 Compare May 13, 2025 23:44
@AdamWill

Copy link
Copy Markdown
Contributor Author

@Martchus @okurz let me know if you want me to change the things I left outstanding; I'm happy with the state of this now.

@okurz okurz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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>
@AdamWill
AdamWill force-pushed the template-dump-load-bugs branch from c502e91 to c8c91b6 Compare May 14, 2025 06:25
@AdamWill

AdamWill commented May 14, 2025

Copy link
Copy Markdown
Contributor Author

OK, I did the signatures. I also snuck in a new check for --clean and --update with YAML templates: with the changes in "job groups: simplify, don't error on group exists" we actually get almost correct behavior for free, since the only sensible thing for --update or --clean to do for a JobGroup is to re-POST the YAML string. The only thing that's wrong is that (IMO) --clean should wipe the YAML strings for any groups that exist on the server but are not in the data being loaded, but it does not. I added this check in the final commit rather than the "job groups: simplify, don't error on group exists" commit because it's convenient to use the 40-templates-jgs.pl that I added in that commit, but I suppose I could move the addition of that file up into the earlier commit if we're really being obsessive.

@Martchus Martchus left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good now and thanks for the detailed explanations.


wow, tidy is a psychopath.

Yes, it sometimes often overshoots the goal.

@mergify
mergify Bot merged commit 72510c7 into os-autoinst:master May 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants