Skip to content
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

Merged
merged 1 commit into from May 4, 2020

Conversation

perlpunk
Copy link
Contributor

@perlpunk perlpunk commented Apr 30, 2020

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.

Please see the TODO item in t/schema/Schedule-1.yaml. Maybe we should make sure that every schedule file contains a description.

@@ -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';
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

@rwx788 rwx788 left a 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
Copy link
Member

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

Copy link
Contributor Author

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

Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

@perlpunk perlpunk Apr 30, 2020

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.

Copy link
Member

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!

Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

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

Point taken :)

@perlpunk
Copy link
Contributor Author

Any idea for a nice short description of what YAML schedules are, for the schema file?

@rwx788
Copy link
Member

rwx788 commented Apr 30, 2020

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."
This would be the best definition I can come up with right now =). Hope it helps.

@perlpunk perlpunk force-pushed the json-schema branch 3 times, most recently from def633c to 2667518 Compare April 30, 2020 12:51
@perlpunk perlpunk marked this pull request as ready for review April 30, 2020 12:51
@foursixnine
Copy link
Member

"YAML schedules are test suite definitions with data required for the

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

YAML schedules define the list of test modules to be executed by a given job, it also allows setting variables that will affect the job to be executed in the end.

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
Copy link
Member

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
Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Member

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.

@rwx788
Copy link
Member

rwx788 commented May 4, 2020

Let's merge or is anything we still should consider doing before that?

@foursixnine
Copy link
Member

Let's merge or is anything we still should consider doing before that?

I think we're good to go

@rwx788 rwx788 merged commit bd6af6e into os-autoinst:master May 4, 2020
@perlpunk perlpunk deleted the json-schema branch May 26, 2020 10:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants