Skip to content

Commit

Permalink
Add rulebook schema
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Mar 1, 2023
1 parent 296cb4d commit a35eb8e
Show file tree
Hide file tree
Showing 11 changed files with 504 additions and 68 deletions.
6 changes: 4 additions & 2 deletions .config/dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ aarch64
abspath
addoption
addopts
alertmanager
ansiblelint
apidoc
apport
Expand Down Expand Up @@ -124,6 +125,7 @@ extlinks
facelessuser
facter
fakerole
fastapi
fileglob
filelock
filesspot
Expand Down Expand Up @@ -172,6 +174,7 @@ keyserver
konstruktoid
kubernetes
kubevirt
lalo
languageservice
letsencrypt
levelname
Expand Down Expand Up @@ -347,6 +350,7 @@ toidentifier
tomli
toolset
tripleo
tuco
typehint
typehints
ulimits
Expand Down Expand Up @@ -388,5 +392,3 @@ xfail
xunit
yatesr
zuul
tuco
lalo
2 changes: 1 addition & 1 deletion .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
WSLENV: FORCE_COLOR:PYTEST_REQPASS:TOXENV:GITHUB_STEP_SUMMARY
# Number of expected test passes, safety measure for accidental skip of
# tests. Update value if you add/remove tests.
PYTEST_REQPASS: 801
PYTEST_REQPASS: 803
steps:
- name: Activate WSL1
if: "contains(matrix.shell, 'wsl')"
Expand Down
9 changes: 5 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ exclude: >
.vscode/extensions.json|
.vscode/settings.json|
examples/broken/encoding.j2|
examples/broken/yaml-with-tabs/invalid-due-tabs.yaml|
examples/playbooks/collections/.*|
src/ansiblelint/schemas/rulebook.json|
test/schemas/data/licenses.json|
test/schemas/package-lock.json|
test/schemas/negative_test|
examples/broken/yaml-with-tabs/invalid-due-tabs.yaml|
examples/playbooks/collections/.*
test/schemas/package-lock.json
)$
repos:
- repo: meta
Expand All @@ -48,7 +49,7 @@ repos:
test/fixtures/formatting-before/.*|
test/schemas/data/.*|
test/schemas/(negative_test|test)/.*\.md|
src/ansiblelint/schemas/(molecule|tasks|playbook).json|
src/ansiblelint/schemas/(molecule|tasks|playbook|rulebook).json|
src/ansiblelint/schemas/ansible-navigator-config.json
)$
always_run: true
Expand Down
2 changes: 2 additions & 0 deletions examples/changelogs/changelog.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
foo: bar
21 changes: 21 additions & 0 deletions examples/rulebooks/rulebook-fail.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
- names: Sample rulebooks
hosts: all
unexpected_key: foo
sources: # should be "sources"
- name: listen for alerts
ansible.eda.alertmanager:
host: 0.0.0.0
port: 8000
rules:
- name: restart web server
condition: event.alert.labels.job == "fastapi" and event.alert.status == "firing"
action:
run_playbook:
name: ansible.eda.start_app
copy_files: true
post_events: true
- name: debug
condition: event.alert.labels.job == "fastapi"
action:
debug: sss
File renamed without changes.
1 change: 1 addition & 0 deletions src/ansiblelint/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
{"playbook": "**/molecule/*/*.{yaml,yml}"}, # molecule playbooks
{"yaml": "**/{.ansible-lint,.yamllint}"},
{"changelog": "**/changelogs/changelog.yaml"},
{"rulebooks": "**/rulebooks/*.{yaml,yml}"},
{"yaml": "**/*.{yaml,yml}"},
{"yaml": "**/.*.{yaml,yml}"},
]
Expand Down
86 changes: 50 additions & 36 deletions src/ansiblelint/rules/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,107 +110,121 @@ def matchyaml(self, file: Lintable) -> list[MatchError]:
@pytest.mark.parametrize(
("file", "expected_kind", "expected"),
(
(
pytest.param(
"examples/collection/galaxy.yml",
"galaxy",
["'GPL' is not one of"],
id="galaxy",
),
(
pytest.param(
"examples/roles/invalid_requirements_schema/meta/requirements.yml",
"requirements",
["{'foo': 'bar'} is not valid under any of the given schemas"],
id="requirements",
),
(
pytest.param(
"examples/roles/invalid_meta_schema/meta/main.yml",
"meta",
["False is not of type 'string'"],
id="meta",
),
(
pytest.param(
"examples/playbooks/vars/invalid_vars_schema.yml",
"vars",
["'123' does not match any of the regexes"],
id="vars",
),
(
pytest.param(
"examples/execution-environment.yml",
"execution-environment",
[],
id="execution-environment",
),
(
pytest.param(
"examples/ee_broken/execution-environment.yml",
"execution-environment",
["Additional properties are not allowed ('foo' was unexpected)"],
id="execution-environment-broken",
),
("examples/meta/runtime.yml", "meta-runtime", []),
(
pytest.param(
"examples/broken_collection_meta_runtime/meta/runtime.yml",
"meta-runtime",
["Additional properties are not allowed ('foo' was unexpected)"],
id="meta-runtime-broken",
),
(
pytest.param(
"examples/inventory/production.yml",
"inventory",
[],
id="inventory",
),
(
pytest.param(
"examples/inventory/broken_dev_inventory.yml",
"inventory",
["Additional properties are not allowed ('foo' was unexpected)"],
id="inventory-broken",
),
(
pytest.param(
".ansible-lint",
"ansible-lint-config",
[],
id="ansible-lint-config",
),
(
pytest.param(
"examples/.config/ansible-lint.yml",
"ansible-lint-config",
[],
id="ansible-lint-config2",
),
(
pytest.param(
"examples/broken/.ansible-lint",
"ansible-lint-config",
["Additional properties are not allowed ('foo' was unexpected)"],
id="ansible-lint-config-broken",
),
(
pytest.param(
"examples/ansible-navigator.yml",
"ansible-navigator-config",
[],
id="ansible-navigator-config",
),
(
pytest.param(
"examples/broken/ansible-navigator.yml",
"ansible-navigator-config",
["Additional properties are not allowed ('ansible' was unexpected)"],
id="ansible-navigator-config-broken",
),
(
pytest.param(
"examples/roles/hello/meta/argument_specs.yml",
"arg_specs",
[],
id="arg_specs",
),
(
pytest.param(
"examples/roles/broken_argument_specs/meta/argument_specs.yml",
"arg_specs",
["Additional properties are not allowed ('foo' was unexpected)"],
id="arg_specs-broken",
),
pytest.param(
"examples/changelogs/changelog.yaml",
"changelog",
["Additional properties are not allowed ('foo' was unexpected)"],
id="changelog",
),
pytest.param(
"examples/rulebooks/rulebook-fail.yml",
"rulebooks",
[],
id="rulebook",
),
pytest.param(
"examples/rulebooks/rulebook-pass.yml",
"rulebooks",
[],
id="rulebook2",
),
),
ids=(
# "playbook-fail",
"galaxy",
"requirements",
"meta",
"vars",
"ee",
"ee-broken",
"meta-runtime",
"meta-runtime-broken",
"inventory",
"inventory-broken",
"lint-config",
"lint-config2",
"lint-config-broken",
"navigator",
"navigator-broken",
"argspecs",
"argspecs-broken",
),
)
def test_schema(file: str, expected_kind: str, expected: list[str]) -> None:
Expand Down
6 changes: 5 additions & 1 deletion src/ansiblelint/schemas/__store__.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"url": "https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/execution-environment.json"
},
"galaxy": {
"etag": "90d0beb8a8ec0fc9ebdc146f3d19f1566c648ed5574b381ed63e06cb15de4d37",
"etag": "8a7b0505c5b42a6a0fb065b1e1b6ba864f53d69b54d1cfbeaab1fa4b03b705a7",
"url": "https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/galaxy.json"
},
"inventory": {
Expand All @@ -47,6 +47,10 @@
"etag": "a11edf24f416043f2da8dd329f1d61338fc9708e017bd3cbe43d8c06e4b30090",
"url": "https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/requirements.json"
},
"rulebook": {
"etag": "06451cf6a1b2437ea835daa15163e5d6085586de9074654ebf4e323d49f68f8c",
"url": "https://raw.githubusercontent.com/ansible/ansible-rulebook/main/ansible_rulebook/schema/ruleset_schema.json"
},
"tasks": {
"etag": "7725d87e98752a96967cce8a62bc8593c15a85582f1cdefef6afce61a6a9bbe5",
"url": "https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/tasks.json"
Expand Down
Loading

0 comments on commit a35eb8e

Please sign in to comment.