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

@ -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):