diff --git a/plugins/builder/osbuild.py b/plugins/builder/osbuild.py index e6b6922..3853fc0 100644 --- a/plugins/builder/osbuild.py +++ b/plugins/builder/osbuild.py @@ -272,13 +272,13 @@ class OAuth2(requests.auth.AuthBase): """ class Token: - def __init__(self, data): + def __init__(self, data, created): self.data = data["access_token"] self.type = data["token_type"] self.expires_in = int(data["expires_in"]) self.scope = data.get("scope") - self.created = time.time() + self.created = created @property def expired(self) -> bool: @@ -299,6 +299,11 @@ def token_expired(self) -> bool: return not self.token or self.token.expired def fetch_token(self, http: requests.Session): + # Set token creation time here. If we set it after the request was + # fulfilled, it would be offsetted by the time it took the token to + # get from the server here, which can result into us refreshing + # the token late. + token_created = time.time() data = { "grant_type": "client_credentials", "client_id": self.id, @@ -312,7 +317,7 @@ def fetch_token(self, http: requests.Session): raise koji.GenericError(msg) from None token_data = res.json() - self.token = self.Token(token_data) + self.token = self.Token(token_data, token_created) def __call__(self, r: requests.Request): """Called by requests to obtain authorization""" @@ -519,7 +524,7 @@ def attach_logs(self, compose_id: str, ireqs: List[ImageRequest]): ilogs = zip(logs.image_logs, ireqs) for log, ireq in ilogs: - name = "%s-%s.log" % (ireq.architecture, ireq.image_type) + name = f"{ireq.architecture}-{ireq.image_type}.log" self.logger.debug("Uploading logs: %s", name) self.upload_json(log, name) @@ -534,7 +539,7 @@ def attach_manifests(self, compose_id: str, ireqs: List[ImageRequest]): imanifests = zip(manifests, ireqs) for manifest, ireq in imanifests: - name = "%s-%s.manifest" % (ireq.architecture, ireq.image_type) + name = f"{ireq.architecture}-{ireq.image_type}.manifest" self.logger.debug("Uploading manifest: %s", name) self.upload_json(manifest, name) diff --git a/plugins/cli/osbuild.py b/plugins/cli/osbuild.py index ff167f3..ae6527c 100755 --- a/plugins/cli/osbuild.py +++ b/plugins/cli/osbuild.py @@ -93,12 +93,11 @@ def check_target(session, name): target = session.getBuildTarget(name) if not target: - raise koji.GenericError("Unknown build target: %s" % name) + raise koji.GenericError(f"Unknown build target: {name}") tag = session.getTag(target['dest_tag']) if not tag: - raise koji.GenericError("Unknown destination tag: %s" % - target['dest_tag_name']) + raise koji.GenericError(f"Unknown destination tag: {target['dest_tag_name']}") # pylint: disable=too-many-branches @@ -161,8 +160,8 @@ def handle_osbuild_image(options, session, argv): task_id = session.osbuildImage(name, version, distro, image_types, target, arch, opts=opts) if not options.quiet: - print("Created task: %s" % task_id) - print("Task info: %s/taskinfo?taskID=%s" % (options.weburl, task_id)) + print(f"Created task: {task_id}") + print(f"Task info: {options.weburl}/taskinfo?taskID={task_id}") # pylint: disable=protected-access if (args.wait is None and kl._running_in_bg()) or args.wait is False: diff --git a/test/integration/test_koji.py b/test/integration/test_koji.py index 50e728f..779f82b 100644 --- a/test/integration/test_koji.py +++ b/test/integration/test_koji.py @@ -39,7 +39,7 @@ def koji_command(*args, _input=None, _globals=None, **kwargs): def parse_os_release(): info = {} - with open("/etc/os-release") as f: + with open("/etc/os-release", encoding="utf-8") as f: for line in f: line = line.strip() if not line: diff --git a/test/run-builder.sh b/test/run-builder.sh index 86d47a8..e8c35bd 100755 --- a/test/run-builder.sh +++ b/test/run-builder.sh @@ -22,7 +22,12 @@ else fi builder_start() { - GATEWAY_IP=$(${CONTAINER_RUNTIME} network inspect org.osbuild.koji | jq -r ".[0].plugins[0].ipam.ranges[0][0].gateway") + source /etc/os-release + if [[ $ID == rhel ]]; then + GATEWAY_IP=$(${CONTAINER_RUNTIME} network inspect org.osbuild.koji | jq -r ".[0].subnets[0].gateway") + else + GATEWAY_IP=$(${CONTAINER_RUNTIME} network inspect org.osbuild.koji | jq -r ".[0].plugins[0].ipam.ranges[0][0].gateway") + fi echo "Gateway IP is $GATEWAY_IP" # maybe copy the 'builder' plugin to the share dir diff --git a/test/unit/test_builder.py b/test/unit/test_builder.py index adf05e7..890335a 100644 --- a/test/unit/test_builder.py +++ b/test/unit/test_builder.py @@ -478,7 +478,7 @@ def creator(): with tempfile.TemporaryDirectory() as tmp: cfgfile = os.path.abspath(os.path.join(tmp, "ko.cfg")) - with open(cfgfile, 'w') as f: + with open(cfgfile, 'w', encoding="utf-8") as f: config.write(f) self.plugin.DEFAULT_CONFIG_FILES = [cfgfile]