Skip to content

Commit

Permalink
feat: when checking EOL tags check for digit
Browse files Browse the repository at this point in the history
  • Loading branch information
clay-lake committed Dec 20, 2024
1 parent 3111ccb commit 59f6877
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/image/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,25 @@ def remove_eol_tags(tag_to_revision, all_releases):

filtered_tag_to_revision = tag_to_revision.copy()
for base_tag, _ in tag_to_revision.items():

path = [] # track revisions to prevent inf loop
tag = base_tag # init state
while True:

if tag in path:
raise shared.BadChannel(
f"Circular tracks found in release JSON:\n {all_releases}"
)

path.append(tag)

# if we find a numeric revision, break since we reached the end of the path
if tag.isdigit():
break

# we allways expect len == 2 unless we reach the final numeric tag
if not len(split := tag.split("_")) == 2:
break
raise shared.BadChannel(
f"Malformed tag. Expected format is <track>_<risk>. Found tag: {tag}."
)

track, risk = split

Expand All @@ -85,7 +89,6 @@ def remove_eol_tags(tag_to_revision, all_releases):
< execution_timestamp
and base_tag in filtered_tag_to_revision
):

print(f"Warning: Removing EOL tag {repr(base_tag)}, date: {eol_date}")
filtered_tag_to_revision.pop(base_tag)

Expand All @@ -96,7 +99,6 @@ def remove_eol_tags(tag_to_revision, all_releases):


def main():

args = parser.parse_args()
img_name = (
args.image_name
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/test_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ def test_remove_eol_tags_no_change(release_json):
assert revision_to_tag == result, "No change should have occured"


def test_remove_eol_tags_malformed_tag(release_json):
"""Ensure malformed tag raises BadChannel exception."""

revision_to_tag = {
"malformed-tag": "1033",
}

with pytest.raises(shared.BadChannel):
remove_eol_tags(revision_to_tag, release_json)


def test_remove_eol_tags(release_json):
"""Ensure EOL tags are removed."""

Expand Down

0 comments on commit 59f6877

Please sign in to comment.