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
Validate YAML schedules against JSON Schema #10160
Conversation
4917ca9
to
28d66b2
Compare
@@ -61,5 +61,5 @@ on 'test' => sub { | |||
requires 'Test::MockObject'; | |||
requires 'Test::More', '0.88'; | |||
requires 'Test::Warnings'; | |||
requires 'Test::YAML::Valid'; | |||
requires 'JSON::Validator'; |
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.
Do not forget to run tools/update_spec
to update spec file.
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 did, but it did not change the spec file. Probably because it's only a test requirement.
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 very promising!
additionalProperties: false | ||
required: | ||
# TODO Every file should have a description? | ||
#- description |
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.
Definitely, it should be required
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.
That's weird, I commented it out because I got some files that didn't have a description.
Just tried it out again and now all files pass =)
Will remove the comment...
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 guess not every schedule has it atm, and on top we have sometimes multiple schedules, where we duplicate description, but will use merge keys feature to avoid it in future. So I would not force description to be defined here, as there are multiple approaches in different teams. Some rely on openQA test suites, for 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.
Hm, I removed a description from a file and tests still pass. Somethings wrong with the schema...
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.
Stupid me.
I made a mistake in test_yaml_valid.
So we have around 60 files without a description field, so I suggest I keep that commented out for now.
Also there are 5 files that have a description:
without a 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.
@rwx788 do you have an example on where the description is duplicated?. My point on description being obligatory would be: There has to be a reason for that particular schedule to exist. But I guess that could be enabled later on.
PS: @perlpunk FSM is using it's tentacles to mess with JSON and YAML altogether! RUN!
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.
@foursixnine For example https://github.com/os-autoinst/os-autoinst-distri-opensuse/tree/master/schedule/yast/lvm_raid1 as instead putting complex conditions in the schedule itself we sometimes create separate file for some exotic backend or setup. In this case we could have imported common description for all of them, as well as some settings.
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.
Point taken :)
Any idea for a nice short description of what YAML schedules are, for the schema file? |
"YAML schedules are test suite definitions with data required for the tests and list of test modules to be executed." |
def633c
to
2667518
Compare
|
Issue: https://progress.opensuse.org/issues/66230 This makes sure that the schedule files contain the correct structure. Otherwise it can happen that it contains things like: schedule: - {{foo}} Which is valid YAML, but it's actually a YAML mapping, short for: schedule: - { { foo: null }: null } and it must be quoted. The JSON Schema validation will make sure it is always a string.
$(eval YAMLS=$(shell sh -c "git --no-pager diff --diff-filter=dr --name-only master | grep '\(schedule\|test_data\)/.*\.y.\?ml$$'")) | ||
if test -n "$(YAMLS)"; then \ | ||
export PERL5LIB=${PERL5LIB_} ; tools/test_yaml_valid $(YAMLS);\ | ||
@# Get list of changed yaml files. We only want to lint changed files for |
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.
@#
🤨 Not something you introduced I guess but it seems odd to me to hide comments specifically here.
if test -n "$(YAMLS)"; then \ | ||
export PERL5LIB=${PERL5LIB_} ; tools/test_yaml_valid $(YAMLS);\ | ||
@# Get list of changed yaml files. We only want to lint changed files for | ||
@# now because yamllint complains about a lot of existing files |
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.
Can you re-phrase that? Should that be a TODO? Is this about limiting the files you are fixing 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.
Before only changed files were validated with test_yaml_valid
and linted with yamllint.
Now we validate all files, but still we can't run yamllint on all files because there are too many errors to fix in this PR.
This should be done in a followup IMHO.
Any suggestion for rephrasing?
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.
Okay, I see the intention behind it... how about this:
@# Lint files that have been changed only
@# TODO: Update all existing files to conform to the schema
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 I use the word 'TODO' then @okurz will reject the PR ;-)
Also the message "Update all existing files to conform to the schema" is wrong. They conform to the schema but they don't conform to the yamllint rules.
I would like to repeat that it was like that before, and I didn't change that.
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.
Leave it as is. It just results in slight confusion.
Let's merge or is anything we still should consider doing before that? |
I think we're good to go |
Issue: https://progress.opensuse.org/issues/66230
This makes sure that the schedule files contain the correct structure.
Otherwise it can happen that it contains things like:
Which is valid YAML, but it's actually a YAML mapping, short for:
and it must be quoted.
The JSON Schema validation will make sure it is always a string.
Please see the TODO item in
t/schema/Schedule-1.yaml
. Maybe we should make sure that every schedule file contains a description.