Environment is a dict, which can't use 'extend'

The tests were not testing the possibility of one the extension fields
being a dict. This fixes that.

Change-Id: Ifb9ca990d9f1d3a69b3243183d91ceffeefdafa0
Closes-Bug: #1646119
This commit is contained in:
Brad P. Crochet 2016-11-30 11:10:46 -05:00
parent 83fa35fd3f
commit bfecf2763a
2 changed files with 9 additions and 2 deletions

View File

@ -34,9 +34,11 @@ class BaseImageManager(object):
self.images = images
def _extend_or_set_attribute(self, existing_image, image, attribute_name):
attribute = image.get(attribute_name, [])
attribute = image.get(attribute_name)
if attribute:
try:
existing_image[attribute_name].update(attribute)
except AttributeError:
existing_image[attribute_name].extend(attribute)
except KeyError:
existing_image[attribute_name] = attribute

View File

@ -54,6 +54,8 @@ class TestBaseImageManager(testbase.TestCase):
self.assertRaises(IOError, base_manager.load_config_files,
'disk_images')
@mock.patch('tripleo_common.image.base.BaseImageManager.APPEND_ATTRIBUTES',
['elements', 'options', 'packages', 'environment'])
@mock.patch('yaml.load', autospec=True)
@mock.patch('os.path.isfile', autospec=True)
def test_load_config_files_multiple_files(self, mock_os_path_isfile,
@ -64,7 +66,8 @@ class TestBaseImageManager(testbase.TestCase):
'imagename': 'overcloud',
'distro': 'some_awesome_distro',
'type': 'qcow2',
'elements': ['image_element']
'elements': ['image_element'],
'environment': {'test_env': '1'},
}]},
{
'disk_images': [{
@ -72,6 +75,7 @@ class TestBaseImageManager(testbase.TestCase):
'elements': ['another_image_element'],
'packages': ['a_package'],
'otherkey': 'some_other_key',
'environment': {'test_env2': '0'},
}]}]
mock_os_path_isfile.return_value = True
@ -92,6 +96,7 @@ class TestBaseImageManager(testbase.TestCase):
'elements': ['image_element', 'another_image_element'],
'packages': ['a_package'],
'otherkey': 'some_other_key',
'environment': {'test_env': '1', 'test_env2': '0'},
}], disk_images)
@mock.patch('yaml.load', autospec=True)