Unit tests: Ensure StackDefinition is up to date
Update the resource data in the StackDefinition in unit tests where required to simulate how the real code works, e.g. after creating or updating a resource. Change-Id: Ie4aad264b8a776a323dcfd1843357c5a7eac094e
This commit is contained in:
parent
c0f281c142
commit
6c87950521
@ -27,6 +27,7 @@ from heat.engine.resources.aws.ec2 import eip
|
|||||||
from heat.engine import rsrc_defn
|
from heat.engine import rsrc_defn
|
||||||
from heat.engine import scheduler
|
from heat.engine import scheduler
|
||||||
from heat.engine import stack as parser
|
from heat.engine import stack as parser
|
||||||
|
from heat.engine import stk_defn
|
||||||
from heat.engine import template as tmpl
|
from heat.engine import template as tmpl
|
||||||
from heat.tests import common
|
from heat.tests import common
|
||||||
from heat.tests.openstack.nova import fakes as fakes_nova
|
from heat.tests.openstack.nova import fakes as fakes_nova
|
||||||
@ -228,6 +229,8 @@ class EIPTest(common.HeatTestCase):
|
|||||||
self.assertIsNone(rsrc.validate())
|
self.assertIsNone(rsrc.validate())
|
||||||
scheduler.TaskRunner(rsrc.create)()
|
scheduler.TaskRunner(rsrc.create)()
|
||||||
self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
|
self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
|
||||||
|
stk_defn.update_resource_data(stack.defn, resource_name,
|
||||||
|
rsrc.node_data())
|
||||||
return rsrc
|
return rsrc
|
||||||
|
|
||||||
def create_association(self, t, stack, resource_name):
|
def create_association(self, t, stack, resource_name):
|
||||||
@ -238,6 +241,8 @@ class EIPTest(common.HeatTestCase):
|
|||||||
self.assertIsNone(rsrc.validate())
|
self.assertIsNone(rsrc.validate())
|
||||||
scheduler.TaskRunner(rsrc.create)()
|
scheduler.TaskRunner(rsrc.create)()
|
||||||
self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
|
self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
|
||||||
|
stk_defn.update_resource_data(stack.defn, resource_name,
|
||||||
|
rsrc.node_data())
|
||||||
return rsrc
|
return rsrc
|
||||||
|
|
||||||
def _mock_server_get(self, server='WebServer', mock_server=None,
|
def _mock_server_get(self, server='WebServer', mock_server=None,
|
||||||
@ -482,6 +487,8 @@ class AllocTest(common.HeatTestCase):
|
|||||||
self.assertIsNone(rsrc.validate())
|
self.assertIsNone(rsrc.validate())
|
||||||
scheduler.TaskRunner(rsrc.create)()
|
scheduler.TaskRunner(rsrc.create)()
|
||||||
self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
|
self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
|
||||||
|
stk_defn.update_resource_data(stack.defn, resource_name,
|
||||||
|
rsrc.node_data())
|
||||||
return rsrc
|
return rsrc
|
||||||
|
|
||||||
def create_association(self, t, stack, resource_name):
|
def create_association(self, t, stack, resource_name):
|
||||||
@ -492,6 +499,8 @@ class AllocTest(common.HeatTestCase):
|
|||||||
self.assertIsNone(rsrc.validate())
|
self.assertIsNone(rsrc.validate())
|
||||||
scheduler.TaskRunner(rsrc.create)()
|
scheduler.TaskRunner(rsrc.create)()
|
||||||
self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
|
self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
|
||||||
|
stk_defn.update_resource_data(stack.defn, resource_name,
|
||||||
|
rsrc.node_data())
|
||||||
return rsrc
|
return rsrc
|
||||||
|
|
||||||
def mock_update_floatingip(self, port='the_nic'):
|
def mock_update_floatingip(self, port='the_nic'):
|
||||||
@ -833,6 +842,7 @@ class AllocTest(common.HeatTestCase):
|
|||||||
props))
|
props))
|
||||||
scheduler.TaskRunner(ass.update, update_snippet)()
|
scheduler.TaskRunner(ass.update, update_snippet)()
|
||||||
self.assertEqual((ass.UPDATE, ass.COMPLETE), ass.state)
|
self.assertEqual((ass.UPDATE, ass.COMPLETE), ass.state)
|
||||||
|
stk_defn.update_resource_data(stack.defn, ass.name, ass.node_data())
|
||||||
|
|
||||||
# change AllocationId to EIP
|
# change AllocationId to EIP
|
||||||
props = copy.deepcopy(ass.properties.data)
|
props = copy.deepcopy(ass.properties.data)
|
||||||
|
@ -21,6 +21,7 @@ from heat.engine import node_data
|
|||||||
from heat.engine.resources.aws.iam import user
|
from heat.engine.resources.aws.iam import user
|
||||||
from heat.engine.resources.openstack.heat import access_policy as ap
|
from heat.engine.resources.openstack.heat import access_policy as ap
|
||||||
from heat.engine import scheduler
|
from heat.engine import scheduler
|
||||||
|
from heat.engine import stk_defn
|
||||||
from heat.objects import resource_data as resource_data_object
|
from heat.objects import resource_data as resource_data_object
|
||||||
from heat.tests import common
|
from heat.tests import common
|
||||||
from heat.tests import fakes
|
from heat.tests import fakes
|
||||||
@ -316,6 +317,8 @@ class AccessKeyTest(common.HeatTestCase):
|
|||||||
self.assertIsNone(rsrc.validate())
|
self.assertIsNone(rsrc.validate())
|
||||||
scheduler.TaskRunner(rsrc.create)()
|
scheduler.TaskRunner(rsrc.create)()
|
||||||
self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
|
self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
|
||||||
|
stk_defn.update_resource_data(stack.defn, resource_name,
|
||||||
|
rsrc.node_data())
|
||||||
return rsrc
|
return rsrc
|
||||||
|
|
||||||
def create_access_key(self, t, stack, resource_name):
|
def create_access_key(self, t, stack, resource_name):
|
||||||
|
@ -30,6 +30,7 @@ from heat.engine.resources.aws.cfn import wait_condition_handle as aws_wch
|
|||||||
from heat.engine import rsrc_defn
|
from heat.engine import rsrc_defn
|
||||||
from heat.engine import scheduler
|
from heat.engine import scheduler
|
||||||
from heat.engine import stack as parser
|
from heat.engine import stack as parser
|
||||||
|
from heat.engine import stk_defn
|
||||||
from heat.engine import template as tmpl
|
from heat.engine import template as tmpl
|
||||||
from heat.objects import resource as resource_objects
|
from heat.objects import resource as resource_objects
|
||||||
from heat.tests import common
|
from heat.tests import common
|
||||||
@ -641,6 +642,8 @@ class WaitConditionUpdateTest(common.HeatTestCase):
|
|||||||
rsrc.type(),
|
rsrc.type(),
|
||||||
uprops)
|
uprops)
|
||||||
|
|
||||||
|
stk_defn.update_resource_data(self.stack.defn, 'WaitHandle',
|
||||||
|
self.stack['WaitHandle'].node_data())
|
||||||
updater = scheduler.TaskRunner(rsrc.update, update_snippet)
|
updater = scheduler.TaskRunner(rsrc.update, update_snippet)
|
||||||
updater()
|
updater()
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ from heat.engine.clients.os import nova
|
|||||||
from heat.engine.resources.aws.ec2 import volume as aws_vol
|
from heat.engine.resources.aws.ec2 import volume as aws_vol
|
||||||
from heat.engine.resources.openstack.cinder import volume as os_vol
|
from heat.engine.resources.openstack.cinder import volume as os_vol
|
||||||
from heat.engine import scheduler
|
from heat.engine import scheduler
|
||||||
|
from heat.engine import stk_defn
|
||||||
from heat.tests import common
|
from heat.tests import common
|
||||||
from heat.tests.openstack.nova import fakes as fakes_nova
|
from heat.tests.openstack.nova import fakes as fakes_nova
|
||||||
|
|
||||||
@ -84,6 +85,8 @@ class BaseVolumeTest(common.HeatTestCase):
|
|||||||
self.assertIsNone(rsrc.validate())
|
self.assertIsNone(rsrc.validate())
|
||||||
scheduler.TaskRunner(rsrc.create)()
|
scheduler.TaskRunner(rsrc.create)()
|
||||||
self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
|
self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
|
||||||
|
stk_defn.update_resource_data(stack.defn, resource_name,
|
||||||
|
rsrc.node_data())
|
||||||
return rsrc
|
return rsrc
|
||||||
|
|
||||||
def create_attachment(self, t, stack, resource_name):
|
def create_attachment(self, t, stack, resource_name):
|
||||||
@ -98,6 +101,8 @@ class BaseVolumeTest(common.HeatTestCase):
|
|||||||
self.assertIsNone(rsrc.validate())
|
self.assertIsNone(rsrc.validate())
|
||||||
scheduler.TaskRunner(rsrc.create)()
|
scheduler.TaskRunner(rsrc.create)()
|
||||||
self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
|
self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
|
||||||
|
stk_defn.update_resource_data(stack.defn, resource_name,
|
||||||
|
rsrc.node_data())
|
||||||
return rsrc
|
return rsrc
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ from heat.engine import node_data
|
|||||||
from heat.engine import rsrc_defn
|
from heat.engine import rsrc_defn
|
||||||
from heat.engine import scheduler
|
from heat.engine import scheduler
|
||||||
from heat.engine import stack as parser
|
from heat.engine import stack as parser
|
||||||
|
from heat.engine import stk_defn
|
||||||
from heat.engine import template as tmpl
|
from heat.engine import template as tmpl
|
||||||
from heat.tests import common
|
from heat.tests import common
|
||||||
from heat.tests import utils
|
from heat.tests import utils
|
||||||
@ -427,14 +428,17 @@ class NeutronFloatingIPTest(common.HeatTestCase):
|
|||||||
fip = stack['floating_ip']
|
fip = stack['floating_ip']
|
||||||
scheduler.TaskRunner(fip.create)()
|
scheduler.TaskRunner(fip.create)()
|
||||||
self.assertEqual((fip.CREATE, fip.COMPLETE), fip.state)
|
self.assertEqual((fip.CREATE, fip.COMPLETE), fip.state)
|
||||||
|
stk_defn.update_resource_data(stack.defn, fip.name, fip.node_data())
|
||||||
|
|
||||||
p = stack['port_floating']
|
p = stack['port_floating']
|
||||||
scheduler.TaskRunner(p.create)()
|
scheduler.TaskRunner(p.create)()
|
||||||
self.assertEqual((p.CREATE, p.COMPLETE), p.state)
|
self.assertEqual((p.CREATE, p.COMPLETE), p.state)
|
||||||
|
stk_defn.update_resource_data(stack.defn, p.name, p.node_data())
|
||||||
|
|
||||||
fipa = stack['floating_ip_assoc']
|
fipa = stack['floating_ip_assoc']
|
||||||
scheduler.TaskRunner(fipa.create)()
|
scheduler.TaskRunner(fipa.create)()
|
||||||
self.assertEqual((fipa.CREATE, fipa.COMPLETE), fipa.state)
|
self.assertEqual((fipa.CREATE, fipa.COMPLETE), fipa.state)
|
||||||
|
stk_defn.update_resource_data(stack.defn, fipa.name, fipa.node_data())
|
||||||
self.assertIsNotNone(fipa.id)
|
self.assertIsNotNone(fipa.id)
|
||||||
self.assertEqual(fipa.id, fipa.resource_id)
|
self.assertEqual(fipa.id, fipa.resource_id)
|
||||||
|
|
||||||
@ -692,10 +696,12 @@ class NeutronFloatingIPTest(common.HeatTestCase):
|
|||||||
p = stack['port_floating']
|
p = stack['port_floating']
|
||||||
scheduler.TaskRunner(p.create)()
|
scheduler.TaskRunner(p.create)()
|
||||||
self.assertEqual((p.CREATE, p.COMPLETE), p.state)
|
self.assertEqual((p.CREATE, p.COMPLETE), p.state)
|
||||||
|
stk_defn.update_resource_data(stack.defn, p.name, p.node_data())
|
||||||
|
|
||||||
fip = stack['floating_ip']
|
fip = stack['floating_ip']
|
||||||
scheduler.TaskRunner(fip.create)()
|
scheduler.TaskRunner(fip.create)()
|
||||||
self.assertEqual((fip.CREATE, fip.COMPLETE), fip.state)
|
self.assertEqual((fip.CREATE, fip.COMPLETE), fip.state)
|
||||||
|
stk_defn.update_resource_data(stack.defn, fip.name, fip.node_data())
|
||||||
|
|
||||||
# test update FloatingIp with port_id
|
# test update FloatingIp with port_id
|
||||||
props = copy.deepcopy(fip.properties.data)
|
props = copy.deepcopy(fip.properties.data)
|
||||||
@ -706,6 +712,7 @@ class NeutronFloatingIPTest(common.HeatTestCase):
|
|||||||
props))
|
props))
|
||||||
scheduler.TaskRunner(fip.update, update_snippet)()
|
scheduler.TaskRunner(fip.update, update_snippet)()
|
||||||
self.assertEqual((fip.UPDATE, fip.COMPLETE), fip.state)
|
self.assertEqual((fip.UPDATE, fip.COMPLETE), fip.state)
|
||||||
|
stk_defn.update_resource_data(stack.defn, fip.name, fip.node_data())
|
||||||
|
|
||||||
# test update FloatingIp with None port_id
|
# test update FloatingIp with None port_id
|
||||||
props = copy.deepcopy(fip.properties.data)
|
props = copy.deepcopy(fip.properties.data)
|
||||||
|
@ -22,6 +22,7 @@ from heat.common import template_format
|
|||||||
from heat.engine.clients.os import neutron
|
from heat.engine.clients.os import neutron
|
||||||
from heat.engine.resources.openstack.neutron import trunk
|
from heat.engine.resources.openstack.neutron import trunk
|
||||||
from heat.engine import scheduler
|
from heat.engine import scheduler
|
||||||
|
from heat.engine import stk_defn
|
||||||
from heat.tests import common
|
from heat.tests import common
|
||||||
from heat.tests import utils
|
from heat.tests import utils
|
||||||
from neutronclient.common import exceptions as ncex
|
from neutronclient.common import exceptions as ncex
|
||||||
@ -121,6 +122,8 @@ class NeutronTrunkTest(common.HeatTestCase):
|
|||||||
def _create_trunk(self, stack):
|
def _create_trunk(self, stack):
|
||||||
trunk = stack['trunk']
|
trunk = stack['trunk']
|
||||||
scheduler.TaskRunner(trunk.create)()
|
scheduler.TaskRunner(trunk.create)()
|
||||||
|
stk_defn.update_resource_data(stack.defn, trunk.name,
|
||||||
|
trunk.node_data())
|
||||||
|
|
||||||
self.assertEqual((trunk.CREATE, trunk.COMPLETE), trunk.state)
|
self.assertEqual((trunk.CREATE, trunk.COMPLETE), trunk.state)
|
||||||
|
|
||||||
@ -146,9 +149,12 @@ class NeutronTrunkTest(common.HeatTestCase):
|
|||||||
del t['resources']['subport_2']
|
del t['resources']['subport_2']
|
||||||
stack = utils.parse_stack(t)
|
stack = utils.parse_stack(t)
|
||||||
|
|
||||||
self.patchobject(
|
parent_port = stack['parent_port']
|
||||||
stack['parent_port'], 'FnGetRefId', return_value='parent port id')
|
self.patchobject(parent_port, 'get_reference_id',
|
||||||
|
return_value='parent port id')
|
||||||
self.find_resource_mock.return_value = 'parent port id'
|
self.find_resource_mock.return_value = 'parent port id'
|
||||||
|
stk_defn.update_resource_data(stack.defn, parent_port.name,
|
||||||
|
parent_port.node_data())
|
||||||
|
|
||||||
self._create_trunk(stack)
|
self._create_trunk(stack)
|
||||||
|
|
||||||
@ -166,10 +172,17 @@ class NeutronTrunkTest(common.HeatTestCase):
|
|||||||
del t['resources']['subport_2']
|
del t['resources']['subport_2']
|
||||||
stack = utils.parse_stack(t)
|
stack = utils.parse_stack(t)
|
||||||
|
|
||||||
self.patchobject(
|
parent_port = stack['parent_port']
|
||||||
stack['parent_port'], 'FnGetRefId', return_value='parent port id')
|
self.patchobject(parent_port, 'get_reference_id',
|
||||||
self.patchobject(
|
return_value='parent port id')
|
||||||
stack['subport_1'], 'FnGetRefId', return_value='subport id')
|
stk_defn.update_resource_data(stack.defn, parent_port.name,
|
||||||
|
parent_port.node_data())
|
||||||
|
|
||||||
|
subport_1 = stack['subport_1']
|
||||||
|
self.patchobject(subport_1, 'get_reference_id',
|
||||||
|
return_value='subport id')
|
||||||
|
stk_defn.update_resource_data(stack.defn, subport_1.name,
|
||||||
|
subport_1.node_data())
|
||||||
|
|
||||||
self._create_trunk(stack)
|
self._create_trunk(stack)
|
||||||
|
|
||||||
@ -191,12 +204,23 @@ class NeutronTrunkTest(common.HeatTestCase):
|
|||||||
del t['resources']['trunk']['properties']['sub_ports'][2:]
|
del t['resources']['trunk']['properties']['sub_ports'][2:]
|
||||||
stack = utils.parse_stack(t)
|
stack = utils.parse_stack(t)
|
||||||
|
|
||||||
self.patchobject(
|
parent_port = stack['parent_port']
|
||||||
stack['parent_port'], 'FnGetRefId', return_value='parent_port_id')
|
self.patchobject(parent_port, 'get_reference_id',
|
||||||
self.patchobject(
|
return_value='parent_port_id')
|
||||||
stack['subport_1'], 'FnGetRefId', return_value='subport_1_id')
|
stk_defn.update_resource_data(stack.defn, parent_port.name,
|
||||||
self.patchobject(
|
parent_port.node_data())
|
||||||
stack['subport_2'], 'FnGetRefId', return_value='subport_2_id')
|
|
||||||
|
subport_1 = stack['subport_1']
|
||||||
|
self.patchobject(subport_1, 'get_reference_id',
|
||||||
|
return_value='subport_1_id')
|
||||||
|
stk_defn.update_resource_data(stack.defn, subport_1.name,
|
||||||
|
subport_1.node_data())
|
||||||
|
|
||||||
|
subport_2 = stack['subport_2']
|
||||||
|
self.patchobject(subport_2, 'get_reference_id',
|
||||||
|
return_value='subport_2_id')
|
||||||
|
stk_defn.update_resource_data(stack.defn, subport_2.name,
|
||||||
|
subport_2.node_data())
|
||||||
|
|
||||||
self._create_trunk(stack)
|
self._create_trunk(stack)
|
||||||
|
|
||||||
@ -248,8 +272,11 @@ class NeutronTrunkTest(common.HeatTestCase):
|
|||||||
del t['resources']['trunk']['properties']['sub_ports']
|
del t['resources']['trunk']['properties']['sub_ports']
|
||||||
stack = utils.parse_stack(t)
|
stack = utils.parse_stack(t)
|
||||||
|
|
||||||
self.patchobject(
|
parent_port = stack['parent_port']
|
||||||
stack['parent_port'], 'FnGetRefId', return_value='parent port id')
|
self.patchobject(parent_port, 'get_reference_id',
|
||||||
|
return_value='parent port id')
|
||||||
|
stk_defn.update_resource_data(stack.defn, parent_port.name,
|
||||||
|
parent_port.node_data())
|
||||||
|
|
||||||
def find_resourceid_by_name_or_id(
|
def find_resourceid_by_name_or_id(
|
||||||
_client, _resource, name_or_id, **_kwargs):
|
_client, _resource, name_or_id, **_kwargs):
|
||||||
@ -280,10 +307,17 @@ class NeutronTrunkTest(common.HeatTestCase):
|
|||||||
'properties']['sub_ports'][0]['port'] = 'subport name'
|
'properties']['sub_ports'][0]['port'] = 'subport name'
|
||||||
stack = utils.parse_stack(t)
|
stack = utils.parse_stack(t)
|
||||||
|
|
||||||
self.patchobject(
|
parent_port = stack['parent_port']
|
||||||
stack['parent_port'], 'FnGetRefId', return_value='parent port id')
|
self.patchobject(parent_port, 'get_reference_id',
|
||||||
self.patchobject(
|
return_value='parent port id')
|
||||||
stack['subport_1'], 'FnGetRefId', return_value='subport id')
|
stk_defn.update_resource_data(stack.defn, parent_port.name,
|
||||||
|
parent_port.node_data())
|
||||||
|
|
||||||
|
subport_1 = stack['subport_1']
|
||||||
|
self.patchobject(subport_1, 'get_reference_id',
|
||||||
|
return_value='subport id')
|
||||||
|
stk_defn.update_resource_data(stack.defn, subport_1.name,
|
||||||
|
subport_1.node_data())
|
||||||
|
|
||||||
def find_resourceid_by_name_or_id(
|
def find_resourceid_by_name_or_id(
|
||||||
_client, _resource, name_or_id, **_kwargs):
|
_client, _resource, name_or_id, **_kwargs):
|
||||||
|
@ -39,6 +39,7 @@ from heat.engine import resource
|
|||||||
from heat.engine import scheduler
|
from heat.engine import scheduler
|
||||||
from heat.engine import service
|
from heat.engine import service
|
||||||
from heat.engine import stack
|
from heat.engine import stack
|
||||||
|
from heat.engine import stk_defn
|
||||||
from heat.engine import template
|
from heat.engine import template
|
||||||
from heat.engine import update
|
from heat.engine import update
|
||||||
from heat.objects import raw_template as raw_template_object
|
from heat.objects import raw_template as raw_template_object
|
||||||
@ -1099,9 +1100,13 @@ class StackTest(common.HeatTestCase):
|
|||||||
(rsrc.UPDATE, rsrc.COMPLETE),
|
(rsrc.UPDATE, rsrc.COMPLETE),
|
||||||
(rsrc.CHECK, rsrc.COMPLETE)):
|
(rsrc.CHECK, rsrc.COMPLETE)):
|
||||||
rsrc.state_set(action, status)
|
rsrc.state_set(action, status)
|
||||||
|
stk_defn.update_resource_data(self.stack.defn, rsrc.name,
|
||||||
|
rsrc.node_data())
|
||||||
self.assertEqual(rsrc, self.stack.resource_by_refid('aaaa'))
|
self.assertEqual(rsrc, self.stack.resource_by_refid('aaaa'))
|
||||||
|
|
||||||
rsrc.state_set(rsrc.DELETE, rsrc.IN_PROGRESS)
|
rsrc.state_set(rsrc.DELETE, rsrc.IN_PROGRESS)
|
||||||
|
stk_defn.update_resource_data(self.stack.defn, rsrc.name,
|
||||||
|
rsrc.node_data())
|
||||||
try:
|
try:
|
||||||
self.assertIsNone(self.stack.resource_by_refid('aaaa'))
|
self.assertIsNone(self.stack.resource_by_refid('aaaa'))
|
||||||
self.assertIsNone(self.stack.resource_by_refid('bbbb'))
|
self.assertIsNone(self.stack.resource_by_refid('bbbb'))
|
||||||
|
Loading…
Reference in New Issue
Block a user