createrepo: Allow making productid glob stricter

This patch updates the documentation to match the actual behavior, and
adds a configuration option to remove the leading prefix.

The extra wildcard is causing problems when there are two variants in
the compose and one UID is a suffix of the other (e.g. DevTools and
Tools), since multiple files will match the shorter name and an error
will be reported.

JIRA: RHELCMP-1086
Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2020-06-05 11:07:02 +02:00
parent 649ff095c0
commit b59bdcea92
3 changed files with 14 additions and 4 deletions

View File

@ -448,7 +448,7 @@ Options
**product_id** = None **product_id** = None
(:ref:`scm_dict <scm_support>`) -- If specified, it should point to a (:ref:`scm_dict <scm_support>`) -- If specified, it should point to a
directory with certificates ``<variant_uid>-<arch>-*.pem``. Pungi will directory with certificates ``*<variant_uid>-<arch>-*.pem``. Pungi will
copy each certificate file into the relevant Yum repositories as a copy each certificate file into the relevant Yum repositories as a
``productid`` file in the ``repodata`` directories. The purpose of these ``productid`` file in the ``repodata`` directories. The purpose of these
``productid`` files is to expose the product data to `subscription-manager ``productid`` files is to expose the product data to `subscription-manager
@ -462,6 +462,12 @@ Options
When you set this option to ``True``, Pungi will ignore the missing When you set this option to ``True``, Pungi will ignore the missing
certificate and simply log a warning message. certificate and simply log a warning message.
**product_id_allow_name_prefix** = True
(*bool*) -- Allow arbitrary prefix for the certificate file name (see
leading ``*`` in the pattern above). Setting this option to ``False`` will
make the pattern more strict by requiring the file name to start directly
with variant name.
Example Example
------- -------

View File

@ -859,6 +859,7 @@ def make_schema():
}, },
"product_id": {"$ref": "#/definitions/str_or_scm_dict"}, "product_id": {"$ref": "#/definitions/str_or_scm_dict"},
"product_id_allow_missing": {"type": "boolean", "default": False}, "product_id_allow_missing": {"type": "boolean", "default": False},
"product_id_allow_name_prefix": {"type": "boolean", "default": True},
# Deprecated in favour of regular local/phase/global setting. # Deprecated in favour of regular local/phase/global setting.
"live_target": {"type": "string"}, "live_target": {"type": "string"},
"tree_arches": {"$ref": "#/definitions/list_of_strings", "default": []}, "tree_arches": {"$ref": "#/definitions/list_of_strings", "default": []},

View File

@ -350,12 +350,15 @@ def get_productids_from_scm(compose):
return return
raise raise
if compose.conf["product_id_allow_name_prefix"]:
pattern = "%s/*%s-%s-*.pem"
else:
pattern = "%s/%s-%s-*.pem"
for arch in compose.get_arches(): for arch in compose.get_arches():
for variant in compose.get_variants(arch=arch): for variant in compose.get_variants(arch=arch):
# some layered products may use base product name before variant # some layered products may use base product name before variant
pem_files = glob.glob("%s/*%s-%s-*.pem" % (tmp_dir, variant.uid, arch)) pem_files = glob.glob(pattern % (tmp_dir, variant.uid, arch))
# use for development:
# pem_files = glob.glob("%s/*.pem" % tmp_dir)[-1:]
if not pem_files: if not pem_files:
warning = "No product certificate found (arch: %s, variant: %s)" % ( warning = "No product certificate found (arch: %s, variant: %s)" % (
arch, arch,