Skip to content

Commit 42fbda4

Browse files
committed
Add support to generate container tags based on given version input
Signed-off-by: Tobias Wolf <wolf@b1-systems.de> On-behalf-of: SAP <tobias.wolf@sap.com>
1 parent df87d4b commit 42fbda4

File tree

3 files changed

+60
-19
lines changed

3 files changed

+60
-19
lines changed

src/gardenlinux/features/__main__.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"cname",
2121
"cname_base",
2222
"container_name",
23+
"container_tag",
2324
"commit_id",
2425
"features",
2526
"platforms",
@@ -37,6 +38,7 @@
3738
CamelCase splitter RegExp
3839
"""
3940

41+
4042
def main() -> None:
4143
"""
4244
gl-features-parse main()
@@ -109,15 +111,26 @@ def main() -> None:
109111
commit_id_or_hash = cname.commit_id
110112
version = cname.version
111113

112-
if arch is None or arch == "" and (args.type in ("cname", "container_name", "arch")):
114+
if (arch is None or arch == "") and (
115+
args.type in ("cname", "container_name", "arch")
116+
):
113117
raise RuntimeError(
114118
"Architecture could not be determined and no default architecture set"
115119
)
116120

117-
if (
118-
version is None
119-
or version == ""
120-
and (args.type in ("cname", "commit_id", "version", "version_and_commit_id"))
121+
if (commit_id_or_hash is None or commit_id_or_hash == "") and (
122+
args.type in ("container_tag", "commit_id", "version_and_commit_id")
123+
):
124+
raise RuntimeError("Commit ID not specified")
125+
126+
if (version is None or version == "") and (
127+
args.type
128+
in (
129+
"container_tag",
130+
"commit_id",
131+
"version",
132+
"version_and_commit_id",
133+
)
121134
):
122135
raise RuntimeError("Version not specified and no default version set")
123136

@@ -146,6 +159,8 @@ def main() -> None:
146159
print_output_from_cname(args.type, cname)
147160
elif args.type == "commit_id":
148161
print(commit_id_or_hash[:8])
162+
elif args.type == "container_tag":
163+
print(re.sub("\\W+", "-", f"{version}-{commit_id_or_hash[:8]}"))
149164
elif args.type == "version":
150165
print(version)
151166
elif args.type == "version_and_commit_id":

tests/features/test_main.py

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,16 @@ def test_main_prints_arch(monkeypatch, capsys):
148148

149149
def test_main_prints_container_name(monkeypatch, capsys):
150150
# Arrange
151-
argv = ["prog", "--arch", "amd64", "--cname", "container-pythonDev", "--version", "1.0", "container_name"]
151+
argv = [
152+
"prog",
153+
"--arch",
154+
"amd64",
155+
"--cname",
156+
"container-pythonDev",
157+
"--version",
158+
"1.0",
159+
"container_name",
160+
]
152161
monkeypatch.setattr(sys, "argv", argv)
153162
monkeypatch.setattr(fema, "Parser", lambda *a, **kw: None)
154163

@@ -160,6 +169,31 @@ def test_main_prints_container_name(monkeypatch, capsys):
160169
assert "container-python-dev" in out
161170

162171

172+
def test_main_prints_container_tag(monkeypatch, capsys):
173+
# Arrange
174+
argv = [
175+
"prog",
176+
"--arch",
177+
"amd64",
178+
"--cname",
179+
"flav",
180+
"--version",
181+
"1.0",
182+
"--commit",
183+
"~post1",
184+
"container_tag",
185+
]
186+
monkeypatch.setattr(sys, "argv", argv)
187+
monkeypatch.setattr(fema, "Parser", lambda *a, **kw: None)
188+
189+
# Act
190+
fema.main()
191+
192+
# Assert
193+
out = capsys.readouterr().out.strip()
194+
assert "1-0-post1" == out
195+
196+
163197
def test_main_prints_commit_id(monkeypatch, capsys):
164198
# Arrange
165199
argv = ["prog", "--arch", "amd64", "--cname", "flav", "commit_id"]
@@ -252,17 +286,6 @@ def test_main_prints_version_and_commit_id(monkeypatch, capsys):
252286
assert "1.2.3-abcdef12" == captured.out.strip()
253287

254288

255-
def test_main_arch_raises_missing_verison(monkeypatch, capsys):
256-
# Arrange
257-
argv = ["prog", "--arch", "amd64", "--cname", "flav", "arch"]
258-
monkeypatch.setattr(sys, "argv", argv)
259-
monkeypatch.setattr(fema, "Parser", lambda *a, **kw: None)
260-
261-
# Act / Assert
262-
with pytest.raises(RuntimeError):
263-
fema.main()
264-
265-
266289
def test_main_with_cname_print_cname(monkeypatch, capsys):
267290
# Arrange
268291
class FakeGraph:

tests/s3/test_s3_artifacts.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,10 @@ def test_upload_from_directory_success(s3_setup):
120120
assert metadata["require_uefi"] is True
121121
assert metadata["secureboot"] is True
122122

123-
raw_tags_response = env.s3.meta.client.get_object_tagging(Bucket=env.bucket_name, Key=f"objects/{env.cname}/{env.cname}-file1")
124-
tags = { tag['Key']: tag['Value'] for tag in raw_tags_response["TagSet"] }
123+
raw_tags_response = env.s3.meta.client.get_object_tagging(
124+
Bucket=env.bucket_name, Key=f"objects/{env.cname}/{env.cname}-file1"
125+
)
126+
tags = {tag["Key"]: tag["Value"] for tag in raw_tags_response["TagSet"]}
125127
assert tags["platform"] == "container+kvm"
126128

127129

@@ -260,6 +262,7 @@ def test_upload_from_directory_invalid_artifact_name(s3_setup):
260262
bucket = env.s3.Bucket(env.bucket_name)
261263
assert len(list(bucket.objects.filter(Prefix=f"meta/singles/{env.cname}"))) == 1
262264

265+
263266
def test_upload_from_directory_commit_mismatch_raises(s3_setup):
264267
"""Raise RuntimeError when commit ID is not matching with cname."""
265268
# Arrange

0 commit comments

Comments
 (0)