Skip to content

Commit

Permalink
Merge pull request #561 from negillett/18849
Browse files Browse the repository at this point in the history
Resolve releasever aliases when publishing [RHELDST-18849]
  • Loading branch information
negillett committed Jul 21, 2023
2 parents eae8359 + c5aa143 commit aa3b9de
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 27 deletions.
13 changes: 8 additions & 5 deletions exodus_gw/aws/dynamodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def definitions(self):
self._definitions = self.query_definitions()
return self._definitions

def query_definitions(self):
def query_definitions(self) -> Dict[str, Any]:
"""Query the definitions in the config_table. If definitions are found, return them. Otherwise,
return an empty dictionary."""

Expand Down Expand Up @@ -78,11 +78,14 @@ def create_request(
table_name = self.env_obj.table
request: Dict[str, List[Any]] = {table_name: []}

uri_aliases = []
for k, v in self.definitions.items():
# Exclude rhui aliases (for now? RHELDST-18849).
if k in ("origin_alias", "releasever_alias"):
uri_aliases.extend(v)

for item in items:
# Resolve aliases relating to origin, e.g. content/origin <=> origin
web_uri = uri_alias(
item.web_uri, self.definitions.get("origin_alias")
)
web_uri = uri_alias(item.web_uri, uri_aliases)

if delete:
request[table_name].append(
Expand Down
20 changes: 10 additions & 10 deletions exodus_gw/worker/autoindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import hashlib
import logging
from time import monotonic
from typing import AsyncGenerator, Optional
from typing import AsyncGenerator, Generator, Optional

from repo_autoindex import ContentError, Fetcher, autoindex
from sqlalchemy import inspect
Expand Down Expand Up @@ -109,20 +109,20 @@ def pulp_manifest_items(self) -> list[Item]:
).all()

@property
def repo_base_uris(self):
def repo_base_uris(self) -> Generator[str, None, None]:
yielded = set()

for item in self.repomd_xml_items:
uri: str = item.web_uri[: -len("/repodata/repomd.xml")]
if uri not in yielded:
yielded.add(uri)
yield uri
repomd_uri: str = item.web_uri[: -len("/repodata/repomd.xml")]
if repomd_uri not in yielded:
yielded.add(repomd_uri)
yield repomd_uri

for item in self.pulp_manifest_items:
uri: str = item.web_uri[: -len("/PULP_MANIFEST")]
if uri not in yielded:
yielded.add(uri)
yield uri
manifest_uri: str = item.web_uri[: -len("/PULP_MANIFEST")]
if manifest_uri not in yielded:
yielded.add(manifest_uri)
yield manifest_uri

@property
def uris_for_autoindex(self) -> list[str]:
Expand Down
39 changes: 29 additions & 10 deletions tests/aws/test_uri_alias.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,39 @@
from logging import DEBUG

import pytest

from exodus_gw.aws.util import uri_alias


def test_uri_alias(caplog):
@pytest.mark.parametrize(
"input,aliases,output",
[
(
"/content/origin/rpms/path/to/file.iso",
[
{"dest": "/origin", "src": "/content/origin"},
{"dest": "/origin/rpms", "src": "/origin/rpm"},
],
"/origin/rpms/path/to/file.iso",
),
(
"/content/dist/rhel8/8/path/to/file.rpm",
[
{
"src": "/content/dist/rhel8/8",
"dest": "/content/dist/rhel8/8.5",
}
],
"/content/dist/rhel8/8.5/path/to/file.rpm",
),
],
ids=["origin", "releasever"],
)
def test_uri_alias(input, aliases, output, caplog):
caplog.set_level(DEBUG, logger="exodus-gw")
uri = "/content/origin/rpms/path/to/file.iso"
aliases = [
{"dest": "/origin", "src": "/content/origin"},
{"dest": "/origin/rpms", "src": "/origin/rpm"},
]
expected = "/origin/rpms/path/to/file.iso"

assert uri_alias(uri, aliases) == expected
assert uri_alias(input, aliases) == output
assert (
f'"message": "Resolved alias:\\n\\tsrc: {uri}\\n\\tdest: {expected}", '
f'"message": "Resolved alias:\\n\\tsrc: {input}\\n\\tdest: {output}", '
'"event": "publish", '
'"success": true' in caplog.text
)
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,11 @@ def fake_config():
],
"releasever_alias": [
{
"dest": "/content/dist/rhel8/8.5",
"src": "/content/dist/rhel8/8",
"dest": "/content/dist/rhel8/8.5",
},
],
"rhui_alias": [
{"dest": "/content/dist/rhel8", "src": "/content/dist/rhel8/rhui"},
{"src": "/content/dist/rhel8/rhui", "dest": "/content/dist/rhel8"},
],
}

0 comments on commit aa3b9de

Please sign in to comment.