Add default values to resource templates

Change-Id: I55e5b66cdc1d861651658d8e3bad204618ad2e35
Closes-Bug: 1687943
This commit is contained in:
Enol Fernandez 2017-07-24 11:25:59 +01:00 committed by Alvaro Lopez Garcia
parent 9a98331c7f
commit 8500d14450
2 changed files with 11 additions and 5 deletions

View File

@ -35,19 +35,19 @@ class OpenStackResourceTemplate(templates.OCCIResourceTemplate):
def __init__(self, id, name, cores, memory, disk, ephemeral=0, swap=0):
attrs = [
attribute.InmutableAttribute(
"occi.compute.cores", cores,
"occi.compute.cores", cores, default=cores,
attr_type=attribute.AttributeType.number_type),
attribute.InmutableAttribute(
"occi.compute.memory", memory,
"occi.compute.memory", memory, default=memory,
attr_type=attribute.AttributeType.number_type),
attribute.InmutableAttribute(
"org.openstack.flavor.disk", disk,
"org.openstack.flavor.disk", disk, default=disk,
attr_type=attribute.AttributeType.number_type),
attribute.InmutableAttribute(
"org.openstack.flavor.ephemeral", ephemeral,
"org.openstack.flavor.ephemeral", ephemeral, default=ephemeral,
attr_type=attribute.AttributeType.number_type),
attribute.InmutableAttribute(
"org.openstack.flavor.swap", swap,
"org.openstack.flavor.swap", swap, default=swap,
attr_type=attribute.AttributeType.number_type),
attribute.InmutableAttribute(
"org.openstack.flavor.name", name,

View File

@ -70,6 +70,12 @@ class TestOpenStackResourceTemplate(base.TestCase):
self.assertEqual(disk, tpl.disk)
self.assertEqual(swap, tpl.swap)
self.assertEqual(ephemeral, tpl.ephemeral)
for attr in [("occi.compute.cores", cores),
("occi.compute.memory", memory),
("org.openstack.flavor.swap", swap),
("org.openstack.flavor.ephemeral", ephemeral),
("org.openstack.flavor.disk", disk)]:
self.assertEqual(tpl.attributes[attr[0]].default, attr[1])
self.assertEqual(name, tpl.name)
self.assertEqual(location, tpl.location)
self.assertEqual([compute.ComputeResource.kind],