Skip to content

Commit 384ff63

Browse files
committed
black-reformatted
1 parent 7f5a5b4 commit 384ff63

File tree

11 files changed

+281
-97
lines changed

11 files changed

+281
-97
lines changed

src/gardenlinux/github/__main__.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
from gardenlinux.constants import GARDENLINUX_GITHUB_RELEASE_BUCKET_NAME
44
from gardenlinux.logger import LoggerSetup
55

6-
from .release import create_github_release, upload_to_github_release_page, write_to_release_id_file
6+
from .release import (
7+
create_github_release,
8+
upload_to_github_release_page,
9+
write_to_release_id_file,
10+
)
711
from .release_notes import create_github_release_notes
812

913
LOGGER = LoggerSetup.get_logger("gardenlinux.github", "INFO")
@@ -18,7 +22,7 @@ def main():
1822
create_parser.add_argument("--repo", default="gardenlinux")
1923
create_parser.add_argument("--tag", required=True)
2024
create_parser.add_argument("--commit", required=True)
21-
create_parser.add_argument('--latest', action='store_true', default=False)
25+
create_parser.add_argument("--latest", action="store_true", default=False)
2226
create_parser.add_argument("--dry-run", action="store_true", default=False)
2327

2428
upload_parser = subparsers.add_parser("upload")
@@ -31,7 +35,9 @@ def main():
3135
args = parser.parse_args()
3236

3337
if args.command == "create":
34-
body = create_github_release_notes(args.tag, args.commit, GARDENLINUX_GITHUB_RELEASE_BUCKET_NAME)
38+
body = create_github_release_notes(
39+
args.tag, args.commit, GARDENLINUX_GITHUB_RELEASE_BUCKET_NAME
40+
)
3541
if args.dry_run:
3642
print("Dry Run ...")
3743
print("This release would be created:")

src/gardenlinux/github/release/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ def create_github_release(owner, repo, tag, commitish, latest, body):
2727
"body": body,
2828
"draft": False,
2929
"prerelease": False,
30-
"make_latest": "true" if latest else "false"
30+
"make_latest": "true" if latest else "false",
3131
}
3232

3333
response = requests.post(
3434
f"https://api.github.com/repos/{owner}/{repo}/releases",
3535
headers=headers,
3636
data=json.dumps(data),
37-
timeout=REQUESTS_TIMEOUTS
37+
timeout=REQUESTS_TIMEOUTS,
3838
)
3939

4040
if response.status_code == 201:
@@ -84,7 +84,9 @@ def upload_to_github_release_page(
8484
LOGGER.error(f"Error reading file {file_to_upload}: {e}")
8585
return
8686

87-
response = requests.post(upload_url, headers=headers, data=file_contents, timeout=REQUESTS_TIMEOUTS)
87+
response = requests.post(
88+
upload_url, headers=headers, data=file_contents, timeout=REQUESTS_TIMEOUTS
89+
)
8890
if response.status_code == 201:
8991
LOGGER.info("Upload successful")
9092
else:

src/gardenlinux/github/release_notes/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
)
88

99

10-
def create_github_release_notes(gardenlinux_version, commitish, releases_s3_bucket_name):
10+
def create_github_release_notes(
11+
gardenlinux_version, commitish, releases_s3_bucket_name
12+
):
1113
package_list = get_package_list(gardenlinux_version)
1214

1315
output = ""
@@ -20,7 +22,9 @@ def create_github_release_notes(gardenlinux_version, commitish, releases_s3_buck
2022
gardenlinux_version, package_list
2123
)
2224

23-
metadata_files = download_all_metadata_files(gardenlinux_version, commitish, releases_s3_bucket_name)
25+
metadata_files = download_all_metadata_files(
26+
gardenlinux_version, commitish, releases_s3_bucket_name
27+
)
2428

2529
output += release_notes_image_ids_section(metadata_files)
2630

src/gardenlinux/github/release_notes/deployment_platform/__init__.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from gardenlinux.constants import GARDENLINUX_GITHUB_RELEASE_BUCKET_NAME
22

33

4-
class DeploymentPlatform():
4+
class DeploymentPlatform:
55
artifacts_bucket_name = GARDENLINUX_GITHUB_RELEASE_BUCKET_NAME
66

77
def short_name(self):
@@ -25,7 +25,9 @@ def image_extension(self):
2525
return "raw"
2626

2727
def artifact_for_flavor(self, flavor, markdown_format=True):
28-
base_url = f"https://{self.__class__.artifacts_bucket_name}.s3.amazonaws.com/objects"
28+
base_url = (
29+
f"https://{self.__class__.artifacts_bucket_name}.s3.amazonaws.com/objects"
30+
)
2931
filename = f"{flavor}.{self.image_extension()}"
3032
download_url = f"{base_url}/{flavor}/{filename}"
3133
if markdown_format:
@@ -48,7 +50,9 @@ def region_details(self, image_metadata):
4850
"image_id": image_id,
4951
"image_name": image_name,
5052
}:
51-
details += f"**{region_name}:** {image_id} ({image_name})<br>"
53+
details += (
54+
f"**{region_name}:** {image_id} ({image_name})<br>"
55+
)
5256
case {"region": region_name, "image_id": image_id}:
5357
details += f"**{region_name}:** {image_id}<br>"
5458
case {"details": details_dict}:
@@ -93,7 +97,9 @@ def summary_text(self, image_metadata):
9397
}:
9498
gallery_count = len(gallery_images)
9599
marketplace_count = len(marketplace_images)
96-
return f"{gallery_count} gallery + {marketplace_count} marketplace images"
100+
return (
101+
f"{gallery_count} gallery + {marketplace_count} marketplace images"
102+
)
97103
case {"gallery_images": gallery_images}:
98104
gallery_count = len(gallery_images)
99105
return f"{gallery_count} gallery images"

tests/constants.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
TEST_GARDENLINUX_COMMIT_SHORT = TEST_GARDENLINUX_COMMIT[:8]
2828
TEST_GARDENLINUX_RELEASE_BUCKET_NAME = "test__gardenlinux__releases"
2929

30-
RELEASE_NOTES_TEST_DATA_DIR = Path(os.path.dirname(__file__)) / ".." / "test-data" / "release_notes"
30+
RELEASE_NOTES_TEST_DATA_DIR = (
31+
Path(os.path.dirname(__file__)) / ".." / "test-data" / "release_notes"
32+
)
3133
RELEASE_NOTES_S3_ARTIFACTS_DIR = RELEASE_NOTES_TEST_DATA_DIR / "s3_bucket_artifacts"
3234

3335
RELEASE_ARTIFACTS_METADATA_FILES = [
@@ -83,5 +85,5 @@
8385
"openstack-gardener_prod_usi-amd64.s3_metadata.yaml",
8486
"openstack-gardener_prod_usi-arm64.s3_metadata.yaml",
8587
"vmware-gardener_prod-amd64.s3_metadata.yaml",
86-
"vmware-gardener_prod-arm64.s3_metadata.yaml"
88+
"vmware-gardener_prod-arm64.s3_metadata.yaml",
8789
]

tests/features/test_cname.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,7 @@ def test_cname_commit_id_setter():
4444
cname = CName("container", arch="amd64", version="today", commit_hash="local")
4545

4646
# Act / Assert
47-
with pytest.raises(RuntimeError, match="Commit hash given differs from commit ID already set"):
47+
with pytest.raises(
48+
RuntimeError, match="Commit hash given differs from commit ID already set"
49+
):
4850
cname.commit_hash = "broken"

tests/features/test_metadata_main.py

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,22 @@ def get_container_amd64_release_metadata(version, commit_hash):
3838
GARDENLINUX_COMMIT_ID_LONG="local"
3939
""".strip()
4040

41+
4142
def test_main_output(monkeypatch, capsys):
4243
"""
4344
Test successful "output-release-metadata"
4445
"""
4546
# Arrange
46-
argv = ["prog", "--cname", "container-amd64", "--version", "today", "--commit", "local", "output-release-metadata"]
47+
argv = [
48+
"prog",
49+
"--cname",
50+
"container-amd64",
51+
"--version",
52+
"today",
53+
"--commit",
54+
"local",
55+
"output-release-metadata",
56+
]
4757
monkeypatch.setattr(sys, "argv", argv)
4858

4959
# Act
@@ -53,14 +63,26 @@ def test_main_output(monkeypatch, capsys):
5363
expected = get_container_amd64_release_metadata("today", "local")
5464
assert expected == capsys.readouterr().out.strip()
5565

66+
5667
def test_main_write(monkeypatch, capsys):
5768
"""
5869
Test successful "write"
5970
"""
6071
# Arrange
6172
with TemporaryDirectory() as tmpdir:
6273
os_release_file = Path(tmpdir, "os_release")
63-
argv = ["prog", "--cname", "container-amd64", "--version", "today", "--commit", "local", "--release-file", str(os_release_file), "write"]
74+
argv = [
75+
"prog",
76+
"--cname",
77+
"container-amd64",
78+
"--version",
79+
"today",
80+
"--commit",
81+
"local",
82+
"--release-file",
83+
str(os_release_file),
84+
"write",
85+
]
6486
monkeypatch.setattr(sys, "argv", argv)
6587

6688
# Act
@@ -70,6 +92,7 @@ def test_main_write(monkeypatch, capsys):
7092
expected = get_container_amd64_release_metadata("today", "local")
7193
assert expected == os_release_file.open("r").read()
7294

95+
7396
def test_main_validation(monkeypatch):
7497
"""
7598
Test validation between release metadata and arguments given
@@ -81,7 +104,18 @@ def test_main_validation(monkeypatch):
81104
with os_release_file.open("w") as fp:
82105
fp.write(get_container_amd64_release_metadata("today", "local"))
83106

84-
argv = ["prog", "--cname", "base-python-amd64", "--version", "today", "--commit", "local", "--release-file", str(os_release_file), "output-release-metadata"]
107+
argv = [
108+
"prog",
109+
"--cname",
110+
"base-python-amd64",
111+
"--version",
112+
"today",
113+
"--commit",
114+
"local",
115+
"--release-file",
116+
str(os_release_file),
117+
"output-release-metadata",
118+
]
85119
monkeypatch.setattr(sys, "argv", argv)
86120

87121
# Act / Assert

tests/github/conftest.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ def release_id_file():
4444
def release_s3_bucket():
4545
with mock_aws():
4646
s3 = boto3.resource("s3", region_name="eu-central-1")
47-
s3.create_bucket(Bucket=TEST_GARDENLINUX_RELEASE_BUCKET_NAME,
48-
CreateBucketConfiguration={"LocationConstraint": "eu-central-1"})
47+
s3.create_bucket(
48+
Bucket=TEST_GARDENLINUX_RELEASE_BUCKET_NAME,
49+
CreateBucketConfiguration={"LocationConstraint": "eu-central-1"},
50+
)
4951
yield s3.Bucket(TEST_GARDENLINUX_RELEASE_BUCKET_NAME)
5052

5153

@@ -55,19 +57,20 @@ def blackhole_s3_bucket():
5557
any object can be found, but downloading a file always raises an exception.
5658
This is needed to test the retry mechanism as the object also counts
5759
how many times an exception was raised."""
58-
class BlackHoleObject():
60+
61+
class BlackHoleObject:
5962
def __init__(self, bucket_name, key):
6063
self.bucket_name = bucket_name
6164
self.key = key
6265

63-
class BlackHoleObjects():
66+
class BlackHoleObjects:
6467
def __init__(self, bucket_name):
6568
self.bucket_name = bucket_name
6669

6770
def filter(self, Prefix):
6871
return [BlackHoleObject(self.bucket_name, Prefix)]
6972

70-
class BlackHoleS3Bucket():
73+
class BlackHoleS3Bucket:
7174
def __init__(self, bucket_name):
7275
self.objects = BlackHoleObjects(bucket_name)
7376
self.download_attempts = 0

tests/github/test_create_github_release.py

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ def test_create_github_release_needs_github_token():
1919
TEST_GARDENLINUX_RELEASE,
2020
TEST_GARDENLINUX_COMMIT,
2121
False,
22-
"")
23-
assert str(exn.value) == "GITHUB_TOKEN environment variable not set", \
24-
"Expected an exception to be raised on missing GITHUB_TOKEN environment variable"
22+
"",
23+
)
24+
assert (
25+
str(exn.value) == "GITHUB_TOKEN environment variable not set"
26+
), "Expected an exception to be raised on missing GITHUB_TOKEN environment variable"
2527

2628

2729
def test_create_github_release_raise_on_failure(caplog, github_token):
@@ -30,33 +32,43 @@ def test_create_github_release_raise_on_failure(caplog, github_token):
3032
m.post(
3133
"https://api.github.com/repos/gardenlinux/gardenlinux/releases",
3234
text="{}",
33-
status_code=503
35+
status_code=503,
3436
)
3537
create_github_release(
3638
"gardenlinux",
3739
"gardenlinux",
3840
TEST_GARDENLINUX_RELEASE,
3941
TEST_GARDENLINUX_COMMIT,
4042
False,
41-
"")
42-
assert any("Failed to create release" in record.message for record in caplog.records), "Expected a failure log record"
43+
"",
44+
)
45+
assert any(
46+
"Failed to create release" in record.message for record in caplog.records
47+
), "Expected a failure log record"
4348

4449

4550
def test_create_github_release(caplog, github_token):
4651
with requests_mock.Mocker() as m:
4752
m.post(
4853
"https://api.github.com/repos/gardenlinux/gardenlinux/releases",
4954
text='{"id": 101}',
50-
status_code=201
55+
status_code=201,
56+
)
57+
assert (
58+
create_github_release(
59+
"gardenlinux",
60+
"gardenlinux",
61+
TEST_GARDENLINUX_RELEASE,
62+
TEST_GARDENLINUX_COMMIT,
63+
False,
64+
"",
65+
)
66+
== 101
5167
)
52-
assert create_github_release(
53-
"gardenlinux",
54-
"gardenlinux",
55-
TEST_GARDENLINUX_RELEASE,
56-
TEST_GARDENLINUX_COMMIT,
57-
False,
58-
"") == 101
59-
assert any("Release created successfully" in record.message for record in caplog.records), "Expected a success log record"
68+
assert any(
69+
"Release created successfully" in record.message
70+
for record in caplog.records
71+
), "Expected a success log record"
6072

6173

6274
def test_write_to_release_id_file(release_id_file):
@@ -69,4 +81,6 @@ def test_write_to_release_id_file_broken_file_permissions(release_id_file, caplo
6981

7082
with pytest.raises(SystemExit):
7183
write_to_release_id_file(TEST_GARDENLINUX_RELEASE)
72-
assert any("Could not create" in record.message for record in caplog.records), "Expected a failure log record"
84+
assert any(
85+
"Could not create" in record.message for record in caplog.records
86+
), "Expected a failure log record"

0 commit comments

Comments
 (0)