Allow removing non-alnum chars from volid
This mimics similar change in lorax. JIRA: RCM-36970 Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
parent
10bdb370ba
commit
add9835b56
@ -275,6 +275,11 @@ There a couple common format specifiers available for both the options:
|
||||
(*list*) -- A list of format strings for generating volume id for layered
|
||||
products. The keys available are the same as for ``image_volid_formats``.
|
||||
|
||||
**restricted_volid** = False
|
||||
(*bool*) -- New versions of lorax replace all non-alphanumerical characters
|
||||
with dashes (underscores are preserved). This option will mimic similar
|
||||
behaviour in Pungi.
|
||||
|
||||
**volume_id_substitutions** [optional]
|
||||
(*dict*) -- A mapping of string replacements to shorten the volume id.
|
||||
|
||||
|
@ -803,6 +803,10 @@ def make_schema():
|
||||
"{release_short}-{version} {base_product_short}-{base_product_version} {arch}",
|
||||
],
|
||||
},
|
||||
"restricted_volid": {
|
||||
"type": "boolean",
|
||||
"default": False,
|
||||
},
|
||||
"volume_id_substitutions": {
|
||||
"type": "object",
|
||||
"default": {},
|
||||
|
@ -392,8 +392,14 @@ def get_volid(compose, arch, variant=None, escape_spaces=False, disc_type=False,
|
||||
raise ValueError("Could not create volume ID longer than 32 bytes, options are %r",
|
||||
sorted(tried, key=len))
|
||||
|
||||
if compose.conf["restricted_volid"]:
|
||||
# Replace all non-alphanumeric characters and non-underscores) with
|
||||
# dashes.
|
||||
volid = re.sub(r"\W", "-", volid, flags=re.I)
|
||||
|
||||
if volid and escape_spaces:
|
||||
volid = volid.replace(" ", r"\x20")
|
||||
|
||||
return volid
|
||||
|
||||
|
||||
|
@ -182,6 +182,43 @@ class TestVolumeIdGenerator(unittest.TestCase):
|
||||
'image_volid_formats': [format],
|
||||
'image_volid_layered_product_formats': [],
|
||||
'volume_id_substitutions': {},
|
||||
'restricted_volid': False,
|
||||
}
|
||||
variant = mock.Mock(uid='Server', type='variant')
|
||||
ci.return_value.compose.respin = 2
|
||||
ci.return_value.compose.id = 'compose_id'
|
||||
ci.return_value.compose.date = '20160107'
|
||||
ci.return_value.compose.type = 'nightly'
|
||||
ci.return_value.compose.type_suffix = '.n'
|
||||
ci.return_value.compose.label = 'RC-1.0'
|
||||
ci.return_value.compose.label_major_version = '1'
|
||||
|
||||
ci.return_value.release.version = '3.0'
|
||||
ci.return_value.release.short = 'rel_short'
|
||||
|
||||
c = compose.Compose(conf, self.tmp_dir)
|
||||
|
||||
volid = util.get_volid(c, 'x86_64', variant, escape_spaces=False, disc_type=False)
|
||||
|
||||
self.assertEqual(volid, expected)
|
||||
|
||||
@mock.patch('pungi.compose.ComposeInfo')
|
||||
def test_get_restricted_volid(self, ci):
|
||||
all_keys = [
|
||||
(['arch', 'compose_id', 'date', 'disc_type'], 'x86_64-compose_id-20160107-'),
|
||||
(['label', 'label_major_version', 'release_short', 'respin'], 'RC-1-0-1-rel_short2-2'),
|
||||
(['type', 'type_suffix', 'variant', 'version'], 'nightly--n-Server-6-0')
|
||||
]
|
||||
for keys, expected in all_keys:
|
||||
format = '-'.join(['%(' + k + ')s' for k in keys])
|
||||
conf = {
|
||||
'release_short': 'rel_short2',
|
||||
'release_version': '6.0',
|
||||
'release_is_layered': False,
|
||||
'image_volid_formats': [format],
|
||||
'image_volid_layered_product_formats': [],
|
||||
'volume_id_substitutions': {},
|
||||
'restricted_volid': True,
|
||||
}
|
||||
variant = mock.Mock(uid='Server', type='variant')
|
||||
ci.return_value.compose.respin = 2
|
||||
|
Loading…
Reference in New Issue
Block a user