diff options
author | zdc <zdc@users.noreply.github.com> | 2022-03-26 15:41:59 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-26 15:41:59 +0200 |
commit | aa60d48c2711cdcd9f88a4e5c77379adb0408231 (patch) | |
tree | 349631a02467dae0158f6f663cc8aa8537974a97 /tests/unittests/test_render_cloudcfg.py | |
parent | 5c4b3943343a85fbe517e5ec1fc670b3a8566b4b (diff) | |
parent | 31448cccedd8f841fb3ac7d0f2e3cdefe08a53ba (diff) | |
download | vyos-cloud-init-aa60d48c2711cdcd9f88a4e5c77379adb0408231.tar.gz vyos-cloud-init-aa60d48c2711cdcd9f88a4e5c77379adb0408231.zip |
Merge pull request #51 from zdc/T2117-sagitta-22.1
T2117: Cloud-init updated to 22.1
Diffstat (limited to 'tests/unittests/test_render_cloudcfg.py')
-rw-r--r-- | tests/unittests/test_render_cloudcfg.py | 91 |
1 files changed, 64 insertions, 27 deletions
diff --git a/tests/unittests/test_render_cloudcfg.py b/tests/unittests/test_render_cloudcfg.py index 495e2669..30fbd1a4 100644 --- a/tests/unittests/test_render_cloudcfg.py +++ b/tests/unittests/test_render_cloudcfg.py @@ -1,59 +1,96 @@ """Tests for tools/render-cloudcfg""" -import os import sys import pytest -from cloudinit import subp -from cloudinit import util +from cloudinit import subp, templater, util +from tests.unittests.helpers import cloud_init_project_dir # TODO(Look to align with tools.render-cloudcfg or cloudinit.distos.OSFAMILIES) -DISTRO_VARIANTS = ["amazon", "arch", "centos", "debian", "fedora", "freebsd", - "netbsd", "openbsd", "rhel", "suse", "ubuntu", "unknown"] +DISTRO_VARIANTS = [ + "amazon", + "arch", + "centos", + "debian", + "eurolinux", + "fedora", + "freebsd", + "gentoo", + "netbsd", + "openbsd", + "photon", + "rhel", + "suse", + "ubuntu", + "unknown", +] @pytest.mark.allow_subp_for(sys.executable) class TestRenderCloudCfg: - cmd = [sys.executable, os.path.realpath('tools/render-cloudcfg')] - tmpl_path = os.path.realpath('config/cloud.cfg.tmpl') + cmd = [sys.executable, cloud_init_project_dir("tools/render-cloudcfg")] + tmpl_path = cloud_init_project_dir("config/cloud.cfg.tmpl") - @pytest.mark.parametrize('variant', (DISTRO_VARIANTS)) + def test_variant_sets_distro_in_cloud_cfg_subp(self, tmpdir): + outfile = tmpdir.join("outcfg").strpath + + subp.subp(self.cmd + ["--variant", "ubuntu", self.tmpl_path, outfile]) + with open(outfile) as stream: + system_cfg = util.load_yaml(stream.read()) + assert system_cfg["system_info"]["distro"] == "ubuntu" + + @pytest.mark.parametrize("variant", (DISTRO_VARIANTS)) def test_variant_sets_distro_in_cloud_cfg(self, variant, tmpdir): - outfile = tmpdir.join('outcfg').strpath - subp.subp( - self.cmd + ['--variant', variant, self.tmpl_path, outfile]) + """Testing parametrized inputs with imported function saves ~0.5s per + call versus calling as subp + """ + outfile = tmpdir.join("outcfg").strpath + + templater.render_cloudcfg(variant, self.tmpl_path, outfile) with open(outfile) as stream: system_cfg = util.load_yaml(stream.read()) - if variant == 'unknown': - variant = 'ubuntu' # Unknown is defaulted to ubuntu - assert system_cfg['system_info']['distro'] == variant + if variant == "unknown": + variant = "ubuntu" # Unknown is defaulted to ubuntu + assert system_cfg["system_info"]["distro"] == variant - @pytest.mark.parametrize('variant', (DISTRO_VARIANTS)) + @pytest.mark.parametrize("variant", (DISTRO_VARIANTS)) def test_variant_sets_default_user_in_cloud_cfg(self, variant, tmpdir): - outfile = tmpdir.join('outcfg').strpath - subp.subp( - self.cmd + ['--variant', variant, self.tmpl_path, outfile]) + """Testing parametrized inputs with imported function saves ~0.5s per + call versus calling as subp + """ + outfile = tmpdir.join("outcfg").strpath + templater.render_cloudcfg(variant, self.tmpl_path, outfile) with open(outfile) as stream: system_cfg = util.load_yaml(stream.read()) default_user_exceptions = { - 'amazon': 'ec2-user', 'debian': 'ubuntu', 'unknown': 'ubuntu'} - default_user = system_cfg['system_info']['default_user']['name'] + "amazon": "ec2-user", + "debian": "ubuntu", + "unknown": "ubuntu", + } + default_user = system_cfg["system_info"]["default_user"]["name"] assert default_user == default_user_exceptions.get(variant, variant) - @pytest.mark.parametrize('variant,renderers', ( - ('freebsd', ['freebsd']), ('netbsd', ['netbsd']), - ('openbsd', ['openbsd']), ('ubuntu', ['netplan', 'eni', 'sysconfig'])) + @pytest.mark.parametrize( + "variant,renderers", + ( + ("freebsd", ["freebsd"]), + ("netbsd", ["netbsd"]), + ("openbsd", ["openbsd"]), + ("ubuntu", ["netplan", "eni", "sysconfig"]), + ), ) def test_variant_sets_network_renderer_priority_in_cloud_cfg( self, variant, renderers, tmpdir ): - outfile = tmpdir.join('outcfg').strpath - subp.subp( - self.cmd + ['--variant', variant, self.tmpl_path, outfile]) + """Testing parametrized inputs with imported function saves ~0.5s per + call versus calling as subp + """ + outfile = tmpdir.join("outcfg").strpath + templater.render_cloudcfg(variant, self.tmpl_path, outfile) with open(outfile) as stream: system_cfg = util.load_yaml(stream.read()) - assert renderers == system_cfg['system_info']['network']['renderers'] + assert renderers == system_cfg["system_info"]["network"]["renderers"] |