util: Show choices for volid if all are too long

When we fail to generate a volume ID that fits in 32 characters, the
error message should include the options that were considered. It could
show that there might be a substitution that could fix the problem.

Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2017-04-18 16:12:04 +02:00
parent 63327e7d88
commit 2bc719a33a
2 changed files with 26 additions and 1 deletions

View File

@ -366,6 +366,7 @@ def get_volid(compose, arch, variant=None, escape_spaces=False, disc_type=False)
else:
all_products = products
tried = set()
for i in all_products:
if not variant_uid and "%(variant)s" in i:
continue
@ -384,9 +385,11 @@ def get_volid(compose, arch, variant=None, escape_spaces=False, disc_type=False)
volid = _apply_substitutions(compose, volid)
if len(volid) <= 32:
break
tried.add(volid)
if volid and len(volid) > 32:
raise ValueError("Could not create volume ID <= 32 characters")
raise ValueError("Could not create volume ID longer than 32 bytes, options are %r",
sorted(tried, key=len))
if volid and escape_spaces:
volid = volid.replace(" ", r"\x20")

View File

@ -158,6 +158,28 @@ class TestVolumeIdGenerator(unittest.TestCase):
self.assertEqual(volid, expected)
@mock.patch('pungi.compose.ComposeInfo')
def test_get_volid_too_long(self, ci):
conf = {
'release_short': 'rel_short2',
'release_version': '6.0',
'release_is_layered': False,
'image_volid_formats': [
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', # 34 chars
'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', # 33 chars
],
'image_volid_layered_product_formats': [],
'volume_id_substitutions': {},
}
variant = mock.Mock(uid='Server', type='variant')
c = compose.Compose(conf, self.tmp_dir)
with self.assertRaises(ValueError) as ctx:
util.get_volid(c, 'x86_64', variant, escape_spaces=False, disc_type=False)
self.assertIn('bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', str(ctx.exception))
self.assertIn('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', str(ctx.exception))
class TestFindOldCompose(unittest.TestCase):
def setUp(self):