|
6 | 6 |
|
7 | 7 | from cloudinit import subp, templater, util
|
8 | 8 | from tests.helpers import cloud_init_project_dir
|
| 9 | +from tests.unittests.helpers import skipUnlessJinjaVersionGreaterThan |
9 | 10 |
|
10 | 11 | # TODO(Look to align with tools.render-template or cloudinit.distos.OSFAMILIES)
|
11 | 12 | DISTRO_VARIANTS = [
|
@@ -124,3 +125,99 @@ def test_variant_sets_network_renderer_priority_in_cloud_cfg(
|
124 | 125 | system_cfg = util.load_yaml(stream.read())
|
125 | 126 |
|
126 | 127 | assert renderers == system_cfg["system_info"]["network"]["renderers"]
|
| 128 | + |
| 129 | + |
| 130 | +EXPECTED_DEBIAN = """\ |
| 131 | +deb testmirror testcodename main |
| 132 | +deb-src testmirror testcodename main |
| 133 | +deb testsecurity testcodename-security main |
| 134 | +deb-src testsecurity testcodename-security main |
| 135 | +deb testmirror testcodename-updates main |
| 136 | +deb-src testmirror testcodename-updates main |
| 137 | +deb testmirror testcodename-backports main |
| 138 | +deb-src testmirror testcodename-backports main |
| 139 | +""" |
| 140 | + |
| 141 | +EXPECTED_DEBIAN_DEB822 = """\ |
| 142 | +Types: deb deb-src |
| 143 | +URIs: testmirror |
| 144 | +Suites: testcodename testcodename-updates testcodename-backports |
| 145 | +Components: main |
| 146 | +Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg |
| 147 | +Types: deb deb-src |
| 148 | +URIs: testsecurity |
| 149 | +Suites: testcodename-security |
| 150 | +Components: main |
| 151 | +Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg |
| 152 | +""" |
| 153 | + |
| 154 | +EXPECTED_UBUNTU = """\ |
| 155 | +deb testmirror testcodename main restricted |
| 156 | +deb testmirror testcodename-updates main restricted |
| 157 | +deb testmirror testcodename universe |
| 158 | +deb testmirror testcodename-updates universe |
| 159 | +deb testmirror testcodename multiverse |
| 160 | +deb testmirror testcodename-updates multiverse |
| 161 | +deb testmirror testcodename-backports main restricted universe multiverse |
| 162 | +deb testsecurity testcodename-security main restricted |
| 163 | +deb testsecurity testcodename-security universe |
| 164 | +deb testsecurity testcodename-security multiverse |
| 165 | +""" |
| 166 | + |
| 167 | +EXPECTED_UBUNTU_DEB822 = """\ |
| 168 | +Types: deb |
| 169 | +URIs: testmirror |
| 170 | +Suites: testcodename testcodename-updates testcodename-backports |
| 171 | +Components: main universe restricted multiverse |
| 172 | +Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg |
| 173 | +Types: deb |
| 174 | +URIs: testsecurity |
| 175 | +Suites: testcodename-security |
| 176 | +Components: main universe restricted multiverse |
| 177 | +Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg |
| 178 | +""" |
| 179 | + |
| 180 | + |
| 181 | +class TestRenderSourcesList: |
| 182 | + @pytest.mark.parametrize( |
| 183 | + "template_path,expected", |
| 184 | + [ |
| 185 | + pytest.param( |
| 186 | + "templates/sources.list.debian.tmpl", |
| 187 | + EXPECTED_DEBIAN, |
| 188 | + id="debian", |
| 189 | + ), |
| 190 | + pytest.param( |
| 191 | + "templates/sources.list.debian.deb822.tmpl", |
| 192 | + EXPECTED_DEBIAN_DEB822, |
| 193 | + id="debian_822", |
| 194 | + ), |
| 195 | + pytest.param( |
| 196 | + "templates/sources.list.ubuntu.tmpl", |
| 197 | + EXPECTED_UBUNTU, |
| 198 | + id="ubuntu", |
| 199 | + ), |
| 200 | + pytest.param( |
| 201 | + "templates/sources.list.ubuntu.deb822.tmpl", |
| 202 | + EXPECTED_UBUNTU_DEB822, |
| 203 | + id="ubuntu_822", |
| 204 | + ), |
| 205 | + ], |
| 206 | + ) |
| 207 | + @skipUnlessJinjaVersionGreaterThan((3, 0, 0)) |
| 208 | + def test_render_sources_list_templates( |
| 209 | + self, tmpdir, template_path, expected |
| 210 | + ): |
| 211 | + params = { |
| 212 | + "mirror": "testmirror", |
| 213 | + "security": "testsecurity", |
| 214 | + "codename": "testcodename", |
| 215 | + } |
| 216 | + template_path = cloud_init_project_dir(template_path) |
| 217 | + rendered = templater.render_string(open(template_path).read(), params) |
| 218 | + filtered = "\n".join( |
| 219 | + line |
| 220 | + for line in rendered.splitlines() |
| 221 | + if line.strip() and not line.strip().startswith("#") |
| 222 | + ) |
| 223 | + assert filtered.strip() == expected.strip() |
0 commit comments