|
2 | 2 | from debian import deb822 |
3 | 3 | import os |
4 | 4 | import pytest |
| 5 | +import re |
5 | 6 |
|
6 | 7 | from pulp_deb.tests.functional.constants import ( |
7 | 8 | DEB_FIXTURE_ALT_SINGLE_DIST, |
|
18 | 19 | DEB_PUBLICATION_ARGS_ONLY_SIMPLE, |
19 | 20 | DEB_PUBLICATION_ARGS_ONLY_STRUCTURED, |
20 | 21 | DEB_PUBLICATION_ARGS_SIMPLE_AND_STRUCTURED, |
| 22 | + DEB_PUBLICATION_ARGS_NESTED_ALPHABETICALLY, |
| 23 | + DEB_PUBLICATION_ARGS_NESTED_BY_DIGEST, |
| 24 | + DEB_PUBLICATION_ARGS_NESTED_BY_BOTH, |
21 | 25 | DEB_PUBLISH_COMPLEX_DEBIAN_SECURITY, |
22 | 26 | DEB_PUBLISH_COMPLEX_UBUNTU_BACKPORTS, |
23 | 27 | DEB_PUBLISH_EMPTY_REPOSITORY, |
@@ -196,6 +200,66 @@ def test_publish_any_repo_version( |
196 | 200 | deb_delete_publication(second_publication) |
197 | 201 |
|
198 | 202 |
|
| 203 | +@pytest.mark.parallel |
| 204 | +@pytest.mark.parametrize( |
| 205 | + "publication_args", |
| 206 | + [ |
| 207 | + DEB_PUBLICATION_ARGS_ONLY_STRUCTURED, |
| 208 | + DEB_PUBLICATION_ARGS_NESTED_ALPHABETICALLY, |
| 209 | + DEB_PUBLICATION_ARGS_NESTED_BY_DIGEST, |
| 210 | + DEB_PUBLICATION_ARGS_NESTED_BY_BOTH, |
| 211 | + ], |
| 212 | +) |
| 213 | +def test_publish_layout( |
| 214 | + apt_distribution_api, |
| 215 | + create_publication_and_verify_repo_version, |
| 216 | + deb_distribution_factory, |
| 217 | + download_content_unit, |
| 218 | + publication_args, |
| 219 | +): |
| 220 | + """Test whether a the layout parameter is generating expected package URLs |
| 221 | + and the packages are available. |
| 222 | +
|
| 223 | + The following cases are tested: |
| 224 | +
|
| 225 | + * `Publish a repo where layout is not specified (alphabetical by default).`_ |
| 226 | + * `Publish a repo explicit alphabetical layout.`_ |
| 227 | + * `Publish a repo explicit digest layout.`_ |
| 228 | + * `Publish a repo explicit "both" layout.`_ |
| 229 | + """ |
| 230 | + remote_args = {"distributions": DEB_FIXTURE_SINGLE_DIST} |
| 231 | + |
| 232 | + # Create a repository and publication. |
| 233 | + publication, _, _, _ = create_publication_and_verify_repo_version( |
| 234 | + remote_args, publication_args, is_modified=True |
| 235 | + ) |
| 236 | + |
| 237 | + # Create a distribution |
| 238 | + distribution = deb_distribution_factory(publication) |
| 239 | + distribution = apt_distribution_api.read(distribution.pulp_href) |
| 240 | + |
| 241 | + # Expected filename format |
| 242 | + if "layout" not in publication_args or publication_args["layout"] == "nested_alphabetically": |
| 243 | + expected = r"pool/asgard/[a-z]/" |
| 244 | + else: # nested_by_digest or nested_by_both |
| 245 | + expected = r"pool/asgard/[0-9a-f]{2}/[0-9a-f]{4}/" |
| 246 | + |
| 247 | + # Verify than an expected Package index exists, and that the expected URL is |
| 248 | + # generated and that the package is actually available. |
| 249 | + package_index = download_content_unit( |
| 250 | + distribution.to_dict()["base_path"], "dists/ragnarok/asguard/binary-ppc64/Packages" |
| 251 | + ) |
| 252 | + for line in str(package_index): |
| 253 | + if not line.startswith("Filename:"): |
| 254 | + continue |
| 255 | + |
| 256 | + _, _, filename = line.partition(": ") |
| 257 | + assert re.match(expected, filename) |
| 258 | + |
| 259 | + package = download_content_unit(distribution.to_dict()["base_path"], filename) |
| 260 | + assert "404" not in str(package) |
| 261 | + |
| 262 | + |
199 | 263 | @pytest.mark.parallel |
200 | 264 | @pytest.mark.parametrize( |
201 | 265 | "set_on, expect_signed", |
|
0 commit comments