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:
parent
83fa35fd3f
commit
bfecf2763a
@ -34,9 +34,11 @@ class BaseImageManager(object):
|
|||||||
self.images = images
|
self.images = images
|
||||||
|
|
||||||
def _extend_or_set_attribute(self, existing_image, image, attribute_name):
|
def _extend_or_set_attribute(self, existing_image, image, attribute_name):
|
||||||
attribute = image.get(attribute_name, [])
|
attribute = image.get(attribute_name)
|
||||||
if attribute:
|
if attribute:
|
||||||
try:
|
try:
|
||||||
|
existing_image[attribute_name].update(attribute)
|
||||||
|
except AttributeError:
|
||||||
existing_image[attribute_name].extend(attribute)
|
existing_image[attribute_name].extend(attribute)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
existing_image[attribute_name] = attribute
|
existing_image[attribute_name] = attribute
|
||||||
|
@ -54,6 +54,8 @@ class TestBaseImageManager(testbase.TestCase):
|
|||||||
self.assertRaises(IOError, base_manager.load_config_files,
|
self.assertRaises(IOError, base_manager.load_config_files,
|
||||||
'disk_images')
|
'disk_images')
|
||||||
|
|
||||||
|
@mock.patch('tripleo_common.image.base.BaseImageManager.APPEND_ATTRIBUTES',
|
||||||
|
['elements', 'options', 'packages', 'environment'])
|
||||||
@mock.patch('yaml.load', autospec=True)
|
@mock.patch('yaml.load', autospec=True)
|
||||||
@mock.patch('os.path.isfile', autospec=True)
|
@mock.patch('os.path.isfile', autospec=True)
|
||||||
def test_load_config_files_multiple_files(self, mock_os_path_isfile,
|
def test_load_config_files_multiple_files(self, mock_os_path_isfile,
|
||||||
@ -64,7 +66,8 @@ class TestBaseImageManager(testbase.TestCase):
|
|||||||
'imagename': 'overcloud',
|
'imagename': 'overcloud',
|
||||||
'distro': 'some_awesome_distro',
|
'distro': 'some_awesome_distro',
|
||||||
'type': 'qcow2',
|
'type': 'qcow2',
|
||||||
'elements': ['image_element']
|
'elements': ['image_element'],
|
||||||
|
'environment': {'test_env': '1'},
|
||||||
}]},
|
}]},
|
||||||
{
|
{
|
||||||
'disk_images': [{
|
'disk_images': [{
|
||||||
@ -72,6 +75,7 @@ class TestBaseImageManager(testbase.TestCase):
|
|||||||
'elements': ['another_image_element'],
|
'elements': ['another_image_element'],
|
||||||
'packages': ['a_package'],
|
'packages': ['a_package'],
|
||||||
'otherkey': 'some_other_key',
|
'otherkey': 'some_other_key',
|
||||||
|
'environment': {'test_env2': '0'},
|
||||||
}]}]
|
}]}]
|
||||||
|
|
||||||
mock_os_path_isfile.return_value = True
|
mock_os_path_isfile.return_value = True
|
||||||
@ -92,6 +96,7 @@ class TestBaseImageManager(testbase.TestCase):
|
|||||||
'elements': ['image_element', 'another_image_element'],
|
'elements': ['image_element', 'another_image_element'],
|
||||||
'packages': ['a_package'],
|
'packages': ['a_package'],
|
||||||
'otherkey': 'some_other_key',
|
'otherkey': 'some_other_key',
|
||||||
|
'environment': {'test_env': '1', 'test_env2': '0'},
|
||||||
}], disk_images)
|
}], disk_images)
|
||||||
|
|
||||||
@mock.patch('yaml.load', autospec=True)
|
@mock.patch('yaml.load', autospec=True)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user