From bbdc62224d53a76c1f6ff616e4fb209ffbf95037 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 8 Nov 2023 11:03:20 +0100 Subject: [PATCH] stages(kickstart): run ksvalidator as part of the tests Run `ksvalidator` as part of the test_kickstart.py tests. This ensures that the file we write is valid. --- stages/test/test_kickstart.py | 42 ++++++++++++++++++++++++++++++++++- tox.ini | 1 + 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/stages/test/test_kickstart.py b/stages/test/test_kickstart.py index 22a3b78ca3..5266a5b011 100644 --- a/stages/test/test_kickstart.py +++ b/stages/test/test_kickstart.py @@ -16,6 +16,42 @@ "timezone": "UTC", }, "lang en_US.UTF-8\nkeyboard us\ntimezone UTC"), + ({"ostree": + { + "osname": "some-osname", + "url": "http://some-ostree-url.com/foo", + "ref": "some-ref", + "remote": "some-remote", + "gpg": True, + }, + "liveimg": { + "url": "some-liveimg-url", + }, + "groups": { + "somegrp": { + "gid": 2337, + }, + }, + "users": { + "someusr": { + "uid": 1337, + "gid": 1337, + "groups": [ + "grp1", + "grp2", + ], + "home": "/other/home/someusr", + "shell": "/bin/ksh", + "password": "$1$notreally", + "key": "ssh-rsa not-really-a-real-key", + }, + }, + }, + "ostreesetup --osname=some-osname --url=http://some-ostree-url.com/foo --ref=some-ref --remote=some-remote\n" + + "liveimg --url some-liveimg-url\ngroup --name somegrp --gid 2337\n" + + "user --name someusr --password $1$notreally --iscrypted --shell /bin/ksh --uid 1337 --gid 1337 --groups grp1,grp2 --homedir /other/home/someusr\n" + + 'sshkey --username someusr "ssh-rsa not-really-a-real-key"' + ), ]) def test_kickstart(tmp_path, test_input, expected): ks_stage_path = os.path.join(os.path.dirname(__file__), "../org.osbuild.kickstart") @@ -27,6 +63,10 @@ def test_kickstart(tmp_path, test_input, expected): ks_stage.main(tmp_path, options) - with open(os.path.join(tmp_path, ks_path), encoding="utf-8") as fp: + ks_path = os.path.join(tmp_path, ks_path) + with open(ks_path, encoding="utf-8") as fp: ks_content = fp.read() assert ks_content == expected + "\n" + + # double check with pykickstart if the file looks valid + subprocess.check_call(["ksvalidator", ks_path]) diff --git a/tox.ini b/tox.ini index f5843a1b0e..2fdbd3d21a 100644 --- a/tox.ini +++ b/tox.ini @@ -18,6 +18,7 @@ deps = mako iniparse pyyaml + pykickstart setenv = LINTABLES = osbuild/ assemblers/* devices/* inputs/* mounts/* runners/* sources/* stages/*.* stages/test/*.py