Pass glance image parameters as a hash

This change updates the deployment serializer for the test vm data to
pass the glance properties as a hash that can be used by the
glance_image provider rather than using the glance_properties string
that is currently in place. The glance_properties string should be
considered deprecated and anything that uses it should switch to the
properties hash.

DocImpact: glance_properties string provided as part of the
test_vm_image hiera data is deprecated in favor of the properties hash
provided by this change

Change-Id: I79a9b20d89ae00a7ceaa24c4ce655cbd16972c30
Partial-Bug: #1566434
This commit is contained in:
Alex Schultz 2016-04-05 11:09:49 -06:00
parent d74cdcf3de
commit 85e9a608f4
4 changed files with 64 additions and 9 deletions

View File

@ -150,6 +150,8 @@ class MuranoMetadataSerializerMixin(object):
murano_data = ' '.join(["""--property murano_image_info='{"title":"""
""" "Murano Demo", "type": "cirros.demo"}'"""])
test_vm_image['glance_properties'] = existing_properties + murano_data
test_vm_image['properties']['murano_image_info'] = \
"""'{"title": "Murano Demo", "type": "cirros.demo"}'"""
return {'test_vm_image': test_vm_image}

View File

@ -230,6 +230,14 @@ class DeploymentMultinodeSerializer(object):
return node_attrs
def generate_properties_arguments(self, properties_data):
"""build a string of properties from a key value hash"""
properties = []
for key, value in six.iteritems(properties_data):
properties.append('--property {key}={value}'.format(
key=key, value=value))
return ' '.join(properties)
def generate_test_vm_image_data(self, node):
# Instantiate all default values in dict.
image_data = {
@ -241,6 +249,7 @@ class DeploymentMultinodeSerializer(object):
'os_name': 'cirros',
'min_ram': 64,
'glance_properties': '',
'properties': {},
}
# Generate a right path to image.
c_attrs = node.cluster.attributes
@ -250,7 +259,7 @@ class DeploymentMultinodeSerializer(object):
img_dir = '/opt/vm/'
image_data['img_path'] = '{0}cirros-x86_64-disk.img'.format(img_dir)
glance_properties = []
properties_data = {}
# Alternate VMWare specific values.
if c_attrs['editable']['common']['libvirt_type']['value'] == 'vcenter':
@ -258,11 +267,17 @@ class DeploymentMultinodeSerializer(object):
'disk_format': 'vmdk',
'img_path': '{0}cirros-i386-disk.vmdk'.format(img_dir),
})
glance_properties.append('--property vmware_disktype=sparse')
glance_properties.append('--property vmware_adaptertype=lsiLogic')
glance_properties.append('--property hypervisor_type=vmware')
properties_data = {
'vmware_disktype': 'sparse',
'vmware_adaptertype': 'lsiLogic',
'hypervisor_type': 'vmware'
}
image_data['glance_properties'] = ' '.join(glance_properties)
# NOTE(aschultz): properties was added as part of N and should be
# used infavor of glance_properties
image_data['glance_properties'] = self.generate_properties_arguments(
properties_data)
image_data['properties'] = properties_data
return {'test_vm_image': image_data}
@ -471,10 +486,18 @@ class DeploymentHASerializer61(DeploymentHASerializer,
'disk_format': 'vmdk',
'img_path': img_path,
})
image_vmdk_data['glance_properties'] = ' '.join([
'--property vmware_disktype=sparse',
'--property vmware_adaptertype=lsiLogic',
'--property hypervisor_type=vmware'])
properties_data = {
'vmware_disktype': 'sparse',
'vmware_adaptertype': 'lsiLogic',
'hypervisor_type': 'vmware'
}
glance_properties = self.generate_properties_arguments(
properties_data)
# NOTE(aschultz): properties was added as part of N and should be
# used infavor of glance_properties
image_vmdk_data['glance_properties'] = glance_properties
image_vmdk_data['properties'] = properties_data
images_data['test_vm_image'].append(image_vmdk_data)
images_data['test_vm_image'].append(image_data['test_vm_image'])
else:

View File

@ -163,6 +163,10 @@ class TestHandlers(BaseIntegrationTest):
"""--property murano_image_info="""
"""'{"title": "Murano Demo", "type": "cirros.demo"}'"""
),
'properties': {
'murano_image_info': """'{"title": "Murano Demo", "type":"""
""" "cirros.demo"}'""",
},
}
critical_mapping = {
@ -576,6 +580,10 @@ class TestHandlers(BaseIntegrationTest):
"""--property murano_image_info="""
"""'{"title": "Murano Demo", "type": "cirros.demo"}'"""
),
'properties': {
'murano_image_info': """'{"title": "Murano Demo", "type":"""
""" "cirros.demo"}'""",
},
}
critical_mapping = {
@ -1060,6 +1068,10 @@ class TestHandlers(BaseIntegrationTest):
"""--property murano_image_info="""
"""'{"title": "Murano Demo", "type": "cirros.demo"}'"""
),
'properties': {
'murano_image_info': """'{"title": "Murano Demo", "type":"""
""" "cirros.demo"}'""",
},
}
critical_mapping = {

View File

@ -2469,6 +2469,14 @@ class BaseDeploymentSerializer(BaseSerializerTest):
img_name = 'TestVM-VMDK'
disk_format = 'vmdk'
img_path = '/opt/vm/cirros-i386-disk.vmdk'
properties_data = {
'vmware_disktype': 'sparse',
'vmware_adaptertype': 'lsiLogic',
'hypervisor_type': 'vmware'
}
glance_properties = []
for k, v in six.iteritems(properties_data):
glance_properties.append('--property {k}={v}'.format(k=k, v=v))
self.assertEqual(
len(self.serializer.generate_test_vm_image_data(
@ -2489,6 +2497,16 @@ class BaseDeploymentSerializer(BaseSerializerTest):
self.env.nodes[0])['test_vm_image'][0]['img_path'],
img_path)
self.assertEqual(
self.serializer.generate_test_vm_image_data(
self.env.nodes[0])['test_vm_image'][0]['glance_properties'],
' '.join(glance_properties))
self.assertEqual(
self.serializer.generate_test_vm_image_data(
self.env.nodes[0])['test_vm_image'][0]['properties'],
properties_data)
def check_generate_vmware_attributes_data(self):
cluster_db = self.db.query(Cluster).get(self.cluster['id'])
cluster_attrs = objects.Cluster.get_editable_attributes(cluster_db)