Enable pungi to send compose_url patches to CTS

If cts_keytab is also enabled then the HTTP requests are handled with
Kerberos Authentication otherwise no authentication is used.

If cts_url is defined in the configuration, translate_paths is required.
This is needed in order to get the host and the path of the composes.

Jira: RHELCMP-6318

Signed-off-by: Ozan Unsal <ounsal@redhat.com>
This commit is contained in:
Ozan Unsal 2021-09-06 19:05:49 +02:00
parent 3d9335e90e
commit b7666ba4a4
3 changed files with 29 additions and 1 deletions

View File

@ -1339,6 +1339,7 @@ CONFIG_DEPS = {
"requires": ((lambda x: x, ["base_product_name", "base_product_short"]),),
"conflicts": ((lambda x: not x, ["base_product_name", "base_product_short"]),),
},
"cts_url": {"requires": ((lambda x: x, ["translate_paths"]),)},
"product_id": {"conflicts": [(lambda x: not x, ["product_id_allow_missing"])]},
"pkgset_scratch_modules": {"requires": ((lambda x: x, ["mbs_api_url"]),)},
"pkgset_source": {

View File

@ -41,6 +41,7 @@ from pungi.util import (
get_arch_variant_data,
get_format_substs,
get_variant_data,
translate_path_raw,
)
from pungi.metadata import compose_to_composeinfo
@ -95,9 +96,12 @@ def get_compose_info(
# So at first backup the current environment and revert to it
# after the requests.post call.
cts_keytab = conf.get("cts_keytab", None)
authentication = None
if cts_keytab:
environ_copy = dict(os.environ)
os.environ["KRB5_CLIENT_KTNAME"] = cts_keytab
# Enables Kerberos Authentication if cts_keytab is specified
authentication = HTTPKerberosAuth()
try:
# Create compose in CTS and get the reserved compose ID.
@ -108,7 +112,7 @@ def get_compose_info(
"parent_compose_ids": parent_compose_ids,
"respin_of": respin_of,
}
rv = requests.post(url, json=data, auth=HTTPKerberosAuth())
rv = requests.post(url, json=data, auth=authentication)
rv.raise_for_status()
finally:
if cts_keytab:
@ -120,6 +124,7 @@ def get_compose_info(
cts_ci.loads(rv.text)
ci.compose.respin = cts_ci.compose.respin
ci.compose.id = cts_ci.compose.id
else:
ci.compose.id = ci.create_compose_id()
@ -138,6 +143,22 @@ def write_compose_info(compose_dir, ci):
ci.dump(os.path.join(work_dir, "composeinfo-base.json"))
def update_compose_url(compose_dir, conf):
import requests
with open(os.path.join(compose_dir, "COMPOSE_ID"), "r") as f:
compose_id = f.read()
cts_url = conf.get("cts_url", None)
url = os.path.join(cts_url, "api/1/composes", compose_id)
tp = conf.get("translate_paths", None)
compose_url = translate_path_raw(tp, compose_dir)
data = {
"action": "set_url",
"compose_url": compose_url,
}
return requests.patch(url, json=data)
def get_compose_dir(
topdir,
conf,
@ -306,6 +327,7 @@ class Compose(kobo.log.LoggingBase):
get_compose_info = staticmethod(get_compose_info)
write_compose_info = staticmethod(write_compose_info)
get_compose_dir = staticmethod(get_compose_dir)
update_compose_url = staticmethod(update_compose_url)
def __getitem__(self, name):
return self.variants[name]

View File

@ -328,6 +328,11 @@ def main():
logger=logger,
notifier=notifier,
)
rv = Compose.update_compose_url(compose_dir, conf)
if not rv.ok:
logger.error("CTS compose_url update failed with the error: %s" % rv.text)
errors, warnings = pungi.checks.validate(conf, offline=False)
if errors:
for error in errors: