Commit 7ca500a4 authored by Benjamin Tissoires's avatar Benjamin Tissoires
Browse files

ci_fairy: ensure the `ci_fairy` keyword is reserved



`ci_fairy` is already a reserved keyword. We should
bail out if the given config file attempts at
overwriting it.
Signed-off-by: Benjamin Tissoires's avatarBenjamin Tissoires <benjamin.tissoires@gmail.com>
parent 6fef7815
...@@ -166,7 +166,7 @@ ci-fairy images: ...@@ -166,7 +166,7 @@ ci-fairy images:
.ci-fairy-tag: .ci-fairy-tag:
variables: variables:
FDO_DISTRIBUTION_TAG: sha256-41ee4d1ca15ea24c7d171a573fab18538561e526253b742b8172dd7a6412035f FDO_DISTRIBUTION_TAG: sha256-00c33dfcd5406e9924516d4104cd1e0ad08c8f15ef82a2f5ed622135cb603439
.ci-fairy-local-image: .ci-fairy-local-image:
extends: extends:
...@@ -355,7 +355,7 @@ test published images: ...@@ -355,7 +355,7 @@ test published images:
stage: test published images stage: test published images
script: script:
- skopeo inspect docker://quay.io/freedesktop.org/ci-templates:buildah-2021-03-18.0 - skopeo inspect docker://quay.io/freedesktop.org/ci-templates:buildah-2021-03-18.0
- skopeo inspect docker://quay.io/freedesktop.org/ci-templates:ci-fairy-sha256-41ee4d1ca15ea24c7d171a573fab18538561e526253b742b8172dd7a6412035f - skopeo inspect docker://quay.io/freedesktop.org/ci-templates:ci-fairy-sha256-00c33dfcd5406e9924516d4104cd1e0ad08c8f15ef82a2f5ed622135cb603439
- skopeo inspect docker://quay.io/freedesktop.org/ci-templates:qemu-base-2021-03-18.0 - skopeo inspect docker://quay.io/freedesktop.org/ci-templates:qemu-base-2021-03-18.0
- skopeo inspect docker://quay.io/freedesktop.org/ci-templates:qemu-mkosi-base-2021-03-18.0 - skopeo inspect docker://quay.io/freedesktop.org/ci-templates:qemu-mkosi-base-2021-03-18.0
rules: rules:
......
...@@ -23,7 +23,7 @@ ci-fairy-base-image: ...@@ -23,7 +23,7 @@ ci-fairy-base-image:
.ci-fairy-tag: .ci-fairy-tag:
variables: variables:
FDO_DISTRIBUTION_TAG: sha256-41ee4d1ca15ea24c7d171a573fab18538561e526253b742b8172dd7a6412035f FDO_DISTRIBUTION_TAG: sha256-00c33dfcd5406e9924516d4104cd1e0ad08c8f15ef82a2f5ed622135cb603439
# The actual ci-fairy image with ci-fairy installed # The actual ci-fairy image with ci-fairy installed
# This image uses the sha of the ci-fairy script itself as tag. # This image uses the sha of the ci-fairy script itself as tag.
......
...@@ -246,6 +246,8 @@ allows for the selection of the root node. For example: :: ...@@ -246,6 +246,8 @@ allows for the selection of the root node. For example: ::
variables: variables:
CHECKSUM: {{ci_fairy.sha256sum('tarball.tar.xz')}} CHECKSUM: {{ci_fairy.sha256sum('tarball.tar.xz')}}
.. note:: Root nodes in the config files must not be named ``ci_fairy``
to avoid namespace clashes.
.. _ci-fairy-commit-checks: .. _ci-fairy-commit-checks:
......
...@@ -31,6 +31,6 @@ ...@@ -31,6 +31,6 @@
# Variables provided by this template should be considered read-only. # Variables provided by this template should be considered read-only.
# #
.fdo.ci-fairy: .fdo.ci-fairy:
image: quay.io/freedesktop.org/ci-templates:ci-fairy-sha256-41ee4d1ca15ea24c7d171a573fab18538561e526253b742b8172dd7a6412035f image: quay.io/freedesktop.org/ci-templates:ci-fairy-sha256-00c33dfcd5406e9924516d4104cd1e0ad08c8f15ef82a2f5ed622135cb603439
variables: variables:
FDO_DISTRIBUTION_IMAGE: quay.io/freedesktop.org/ci-templates:ci-fairy-sha256-41ee4d1ca15ea24c7d171a573fab18538561e526253b742b8172dd7a6412035f FDO_DISTRIBUTION_IMAGE: quay.io/freedesktop.org/ci-templates:ci-fairy-sha256-00c33dfcd5406e9924516d4104cd1e0ad08c8f15ef82a2f5ed622135cb603439
\ No newline at end of file \ No newline at end of file
...@@ -962,6 +962,9 @@ def generate_template(ctx, config, root, template, output_file, verify): ...@@ -962,6 +962,9 @@ def generate_template(ctx, config, root, template, output_file, verify):
data.update(cdata) data.update(cdata)
if 'ci_fairy' in data:
raise click.BadParameter('"ci_fairy" is a reserved keyword for node names')
templatedir = templatefile.parent templatedir = templatefile.parent
env = jinja2.Environment(loader=jinja2.FileSystemLoader(os.fspath(templatedir)), env = jinja2.Environment(loader=jinja2.FileSystemLoader(os.fspath(templatedir)),
trim_blocks=True, lstrip_blocks=True, trim_blocks=True, lstrip_blocks=True,
......
...@@ -622,6 +622,21 @@ def test_template_ci_fairy_sha256sum(): ...@@ -622,6 +622,21 @@ def test_template_ci_fairy_sha256sum():
f'file4: {sha}' f'file4: {sha}'
def test_template_no_ci_fairy():
runner = CliRunner()
with runner.isolated_filesystem():
with open('test.yml', 'w') as fd:
fd.write('ci_fairy: {}')
with open('test.tmpl', 'w') as fd:
fd.write('this should not work.')
args = ['generate-template', '--config', 'test.yml',
'test.tmpl']
result = runner.invoke(ci_fairy.ci_fairy, args)
assert result.exit_code == 2
# Run twice, once with trailing newline in the source file, once without # Run twice, once with trailing newline in the source file, once without
@pytest.mark.parametrize("last_line", @pytest.mark.parametrize("last_line",
['line to be removed\n', 'line to be removed']) ['line to be removed\n', 'line to be removed'])
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment