Merge "Pushing image traits to ironic node"

This commit is contained in:
Zuul 2018-06-11 08:05:45 +00:00 committed by Gerrit Code Review
commit ef6b4f43f4
2 changed files with 52 additions and 1 deletions

View File

@ -145,6 +145,57 @@ class IronicDriverFieldsTestCase(test.NoDBTestCase):
self.instance, self.image_meta, self.flavor)
self.assertPatchEqual(expected, patch)
def test_generic_get_deploy_patch_image_traits_required(self):
node = ironic_utils.get_test_node(driver='fake')
self.image_meta.properties = objects.ImageMetaProps(
traits_required=['CUSTOM_TRUSTED'])
expected = [{'path': '/instance_info/traits',
'value': ["CUSTOM_TRUSTED"],
'op': 'add'}]
expected += self._expected_deploy_patch
patch = patcher.create(node).get_deploy_patch(
self.instance, self.image_meta, self.flavor)
self.assertPatchEqual(expected, patch)
def test_generic_get_deploy_patch_image_flavor_traits_required(self):
node = ironic_utils.get_test_node(driver='fake')
self.flavor['extra_specs']['trait:CUSTOM_FOO'] = 'required'
self.image_meta.properties = objects.ImageMetaProps(
traits_required=['CUSTOM_TRUSTED'])
expected = [{'path': '/instance_info/traits',
'value': ["CUSTOM_FOO", "CUSTOM_TRUSTED"],
'op': 'add'}]
expected += self._expected_deploy_patch
patch = patcher.create(node).get_deploy_patch(
self.instance, self.image_meta, self.flavor)
self.assertPatchEqual(expected, patch)
def test_generic_get_deploy_patch_image_flavor_traits_none(self):
node = ironic_utils.get_test_node(driver='fake')
self.image_meta.properties = objects.ImageMetaProps()
expected = self._expected_deploy_patch
patch = patcher.create(node).get_deploy_patch(
self.instance, self.image_meta, self.flavor)
self.assertPatchEqual(expected, patch)
def test_generic_get_deploy_patch_boot_from_volume_image_traits_required(
self):
node = ironic_utils.get_test_node(driver='fake')
self.image_meta.properties = objects.ImageMetaProps(
traits_required=['CUSTOM_TRUSTED'])
expected_deploy_patch_volume = [patch for patch in
self._expected_deploy_patch
if patch['path'] !=
'/instance_info/image_source']
expected = [{'path': '/instance_info/traits',
'value': ["CUSTOM_TRUSTED"],
'op': 'add'}]
expected += expected_deploy_patch_volume
patch = patcher.create(node).get_deploy_patch(
self.instance, self.image_meta, self.flavor,
boot_from_volume=True)
self.assertPatchEqual(expected, patch)
def test_generic_get_deploy_patch_ephemeral(self):
CONF.set_override('default_ephemeral_format', 'testfmt')
node = ironic_utils.get_test_node(driver='fake')

View File

@ -110,7 +110,7 @@ class GenericDriverFields(object):
# to filter out traits not supported by the node.
if val == 'required':
traits.append(parsed_key)
traits.extend(image_meta.properties.get('traits_required', []))
if capabilities:
patch.append({'path': '/instance_info/capabilities',
'op': 'add', 'value': jsonutils.dumps(capabilities)})