Retain references to stacks in all unit tests

This will allow Resources to hold weak references to Stacks (so as to avoid
circular references) without causing the Stack object to be prematurely
deleted.

Change-Id: Ia76da7bc51042fb3598ef2a660d6fbf78137a37b
Related-Bug: #1454873
changes/15/183215/1
Zane Bitter 8 years ago
parent 2032548c4e
commit 203b8e8ecf
  1. 83
      contrib/heat_docker/heat_docker/tests/test_docker_container.py
  2. 30
      contrib/heat_gnocchi/heat_gnocchi/tests/test_gnocchi_alarm.py
  3. 10
      contrib/heat_manila/heat_manila/tests/test_share_type.py
  4. 4
      contrib/rackspace/rackspace/tests/test_cloud_loadbalancer.py
  5. 6
      contrib/rackspace/rackspace/tests/test_rackspace_cloud_server.py
  6. 12
      contrib/rackspace/rackspace/tests/test_rackspace_dns.py
  7. 16
      heat/tests/autoscaling/test_heat_scaling_group.py
  8. 6
      heat/tests/autoscaling/test_heat_scaling_policy.py
  9. 12
      heat/tests/autoscaling/test_scaling_group.py
  10. 4
      heat/tests/autoscaling/test_scaling_policy.py
  11. 7
      heat/tests/aws/test_instance.py
  12. 20
      heat/tests/aws/test_instance_network.py
  13. 12
      heat/tests/aws/test_loadbalancer.py
  14. 3
      heat/tests/aws/test_waitcondition.py
  15. 18
      heat/tests/neutron/test_neutron_firewall.py
  16. 93
      heat/tests/neutron/test_neutron_loadbalancer.py
  17. 12
      heat/tests/neutron/test_neutron_metering.py
  18. 12
      heat/tests/neutron/test_neutron_network_gateway.py
  19. 7
      heat/tests/neutron/test_neutron_provider_net.py
  20. 14
      heat/tests/test_ceilometer_alarm.py
  21. 10
      heat/tests/test_instance_group.py
  22. 8
      heat/tests/test_nested_stack.py
  23. 14
      heat/tests/test_nova_floatingip.py
  24. 6
      heat/tests/test_nova_keypair.py
  25. 36
      heat/tests/test_nova_servergroup.py
  26. 12
      heat/tests/test_os_database.py
  27. 5
      heat/tests/test_properties.py
  28. 11
      heat/tests/test_provider_template.py
  29. 6
      heat/tests/test_restarter.py
  30. 4
      heat/tests/test_sahara_cluster.py
  31. 8
      heat/tests/test_sahara_templates.py
  32. 12
      heat/tests/test_server.py
  33. 8
      heat/tests/test_server_tags.py
  34. 8
      heat/tests/test_stack_user.py
  35. 4
      heat/tests/test_swift.py

@ -65,10 +65,11 @@ class DockerContainerTest(common.HeatTestCase):
def create_container(self, resource_name):
t = template_format.parse(template)
stack = utils.parse_stack(t)
self.stack = utils.parse_stack(t)
resource = docker_container.DockerContainer(
resource_name,
stack.t.resource_definitions(stack)[resource_name], stack)
self.stack.t.resource_definitions(self.stack)[resource_name],
self.stack)
self.m.StubOutWithMock(resource, 'get_client')
resource.get_client().MultipleTimes().AndReturn(
fakeclient.FakeDockerClient())
@ -94,11 +95,11 @@ class DockerContainerTest(common.HeatTestCase):
def test_create_with_name(self):
t = template_format.parse(template)
stack = utils.parse_stack(t)
definition = stack.t.resource_definitions(stack)['Blog']
self.stack = utils.parse_stack(t)
definition = self.stack.t.resource_definitions(self.stack)['Blog']
definition['Properties']['name'] = 'super-blog'
resource = docker_container.DockerContainer(
'Blog', definition, stack)
'Blog', definition, self.stack)
self.m.StubOutWithMock(resource, 'get_client')
resource.get_client().MultipleTimes().AndReturn(
fakeclient.FakeDockerClient())
@ -133,13 +134,13 @@ class DockerContainerTest(common.HeatTestCase):
def test_start_with_bindings_and_links(self):
t = template_format.parse(template)
stack = utils.parse_stack(t)
definition = stack.t.resource_definitions(stack)['Blog']
self.stack = utils.parse_stack(t)
definition = self.stack.t.resource_definitions(self.stack)['Blog']
definition['Properties']['port_bindings'] = {
'80/tcp': [{'HostPort': '80'}]}
definition['Properties']['links'] = {'db': 'mysql'}
resource = docker_container.DockerContainer(
'Blog', definition, stack)
'Blog', definition, self.stack)
self.m.StubOutWithMock(resource, 'get_client')
resource.get_client().MultipleTimes().AndReturn(
fakeclient.FakeDockerClient())
@ -223,12 +224,12 @@ class DockerContainerTest(common.HeatTestCase):
def test_start_with_restart_policy_no(self):
t = template_format.parse(template)
stack = utils.parse_stack(t)
definition = stack.t.resource_definitions(stack)['Blog']
self.stack = utils.parse_stack(t)
definition = self.stack.t.resource_definitions(self.stack)['Blog']
definition['Properties']['restart_policy'] = {
'Name': 'no', 'MaximumRetryCount': 0}
resource = docker_container.DockerContainer(
'Blog', definition, stack)
'Blog', definition, self.stack)
get_client_mock = self.patchobject(resource, 'get_client')
get_client_mock.return_value = fakeclient.FakeDockerClient()
self.assertIsNone(resource.validate())
@ -242,12 +243,12 @@ class DockerContainerTest(common.HeatTestCase):
def test_start_with_restart_policy_on_failure(self):
t = template_format.parse(template)
stack = utils.parse_stack(t)
definition = stack.t.resource_definitions(stack)['Blog']
self.stack = utils.parse_stack(t)
definition = self.stack.t.resource_definitions(self.stack)['Blog']
definition['Properties']['restart_policy'] = {
'Name': 'on-failure', 'MaximumRetryCount': 10}
resource = docker_container.DockerContainer(
'Blog', definition, stack)
'Blog', definition, self.stack)
get_client_mock = self.patchobject(resource, 'get_client')
get_client_mock.return_value = fakeclient.FakeDockerClient()
self.assertIsNone(resource.validate())
@ -261,12 +262,12 @@ class DockerContainerTest(common.HeatTestCase):
def test_start_with_restart_policy_always(self):
t = template_format.parse(template)
stack = utils.parse_stack(t)
definition = stack.t.resource_definitions(stack)['Blog']
self.stack = utils.parse_stack(t)
definition = self.stack.t.resource_definitions(self.stack)['Blog']
definition['Properties']['restart_policy'] = {
'Name': 'always', 'MaximumRetryCount': 0}
resource = docker_container.DockerContainer(
'Blog', definition, stack)
'Blog', definition, self.stack)
get_client_mock = self.patchobject(resource, 'get_client')
get_client_mock.return_value = fakeclient.FakeDockerClient()
self.assertIsNone(resource.validate())
@ -280,12 +281,12 @@ class DockerContainerTest(common.HeatTestCase):
def test_start_with_caps(self):
t = template_format.parse(template)
stack = utils.parse_stack(t)
definition = stack.t.resource_definitions(stack)['Blog']
self.stack = utils.parse_stack(t)
definition = self.stack.t.resource_definitions(self.stack)['Blog']
definition['Properties']['cap_add'] = ['NET_ADMIN']
definition['Properties']['cap_drop'] = ['MKNOD']
resource = docker_container.DockerContainer(
'Blog', definition, stack)
'Blog', definition, self.stack)
get_client_mock = self.patchobject(resource, 'get_client')
get_client_mock.return_value = fakeclient.FakeDockerClient()
self.assertIsNone(resource.validate())
@ -299,11 +300,11 @@ class DockerContainerTest(common.HeatTestCase):
def test_start_with_read_only(self):
t = template_format.parse(template)
stack = utils.parse_stack(t)
definition = stack.t.resource_definitions(stack)['Blog']
self.stack = utils.parse_stack(t)
definition = self.stack.t.resource_definitions(self.stack)['Blog']
definition['Properties']['read_only'] = True
resource = docker_container.DockerContainer(
'Blog', definition, stack)
'Blog', definition, self.stack)
get_client_mock = self.patchobject(resource, 'get_client')
get_client_mock.return_value = fakeclient.FakeDockerClient()
get_client_mock.return_value.set_api_version('1.17')
@ -317,11 +318,11 @@ class DockerContainerTest(common.HeatTestCase):
def arg_for_low_api_version(self, arg, value, low_version):
t = template_format.parse(template)
stack = utils.parse_stack(t)
definition = stack.t.resource_definitions(stack)['Blog']
self.stack = utils.parse_stack(t)
definition = self.stack.t.resource_definitions(self.stack)['Blog']
definition['Properties'][arg] = value
my_resource = docker_container.DockerContainer(
'Blog', definition, stack)
'Blog', definition, self.stack)
get_client_mock = self.patchobject(my_resource, 'get_client')
get_client_mock.return_value = fakeclient.FakeDockerClient()
get_client_mock.return_value.set_api_version(low_version)
@ -343,11 +344,11 @@ class DockerContainerTest(common.HeatTestCase):
def test_create_with_cpu_shares(self):
t = template_format.parse(template)
stack = utils.parse_stack(t)
definition = stack.t.resource_definitions(stack)['Blog']
self.stack = utils.parse_stack(t)
definition = self.stack.t.resource_definitions(self.stack)['Blog']
definition['Properties']['cpu_shares'] = 512
my_resource = docker_container.DockerContainer(
'Blog', definition, stack)
'Blog', definition, self.stack)
get_client_mock = self.patchobject(my_resource, 'get_client')
get_client_mock.return_value = fakeclient.FakeDockerClient()
self.assertIsNone(my_resource.validate())
@ -363,8 +364,8 @@ class DockerContainerTest(common.HeatTestCase):
def test_start_with_mapping_devices(self):
t = template_format.parse(template)
stack = utils.parse_stack(t)
definition = stack.t.resource_definitions(stack)['Blog']
self.stack = utils.parse_stack(t)
definition = self.stack.t.resource_definitions(self.stack)['Blog']
definition['Properties']['devices'] = (
[{'path_on_host': '/dev/sda',
'path_in_container': '/dev/xvdc',
@ -373,7 +374,7 @@ class DockerContainerTest(common.HeatTestCase):
'path_in_container': '/dev/xvdd',
'permissions': 'rw'}])
my_resource = docker_container.DockerContainer(
'Blog', definition, stack)
'Blog', definition, self.stack)
get_client_mock = self.patchobject(my_resource, 'get_client')
get_client_mock.return_value = fakeclient.FakeDockerClient()
self.assertIsNone(my_resource.validate())
@ -388,15 +389,15 @@ class DockerContainerTest(common.HeatTestCase):
def test_start_with_mapping_devices_also_with_privileged(self):
t = template_format.parse(template)
stack = utils.parse_stack(t)
definition = stack.t.resource_definitions(stack)['Blog']
self.stack = utils.parse_stack(t)
definition = self.stack.t.resource_definitions(self.stack)['Blog']
definition['Properties']['devices'] = (
[{'path_on_host': '/dev/sdb',
'path_in_container': '/dev/xvdc',
'permissions': 'r'}])
definition['Properties']['privileged'] = True
my_resource = docker_container.DockerContainer(
'Blog', definition, stack)
'Blog', definition, self.stack)
get_client_mock = self.patchobject(my_resource, 'get_client')
get_client_mock.return_value = fakeclient.FakeDockerClient()
self.assertIsNone(my_resource.validate())
@ -415,13 +416,13 @@ class DockerContainerTest(common.HeatTestCase):
def test_start_with_mapping_devices_not_set_path_in_container(self):
t = template_format.parse(template)
stack = utils.parse_stack(t)
definition = stack.t.resource_definitions(stack)['Blog']
self.stack = utils.parse_stack(t)
definition = self.stack.t.resource_definitions(self.stack)['Blog']
definition['Properties']['devices'] = (
[{'path_on_host': '/dev/sda',
'permissions': 'rwm'}])
my_resource = docker_container.DockerContainer(
'Blog', definition, stack)
'Blog', definition, self.stack)
get_client_mock = self.patchobject(my_resource, 'get_client')
get_client_mock.return_value = fakeclient.FakeDockerClient()
self.assertIsNone(my_resource.validate())
@ -435,11 +436,11 @@ class DockerContainerTest(common.HeatTestCase):
def test_create_with_cpu_set(self):
t = template_format.parse(template)
stack = utils.parse_stack(t)
definition = stack.t.resource_definitions(stack)['Blog']
self.stack = utils.parse_stack(t)
definition = self.stack.t.resource_definitions(self.stack)['Blog']
definition['Properties']['cpu_set'] = '0-8,16-24,28'
my_resource = docker_container.DockerContainer(
'Blog', definition, stack)
'Blog', definition, self.stack)
get_client_mock = self.patchobject(my_resource, 'get_client')
get_client_mock.return_value = fakeclient.FakeDockerClient()
self.assertIsNone(my_resource.validate())

@ -125,10 +125,10 @@ class GnocchiResourcesAlarmTest(common.HeatTestCase):
}
).AndReturn(FakeCeilometerAlarm())
snippet = template_format.parse(gnocchi_resources_alarm_template)
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
self.stack = utils.parse_stack(snippet)
resource_defns = self.stack.t.resource_definitions(self.stack)
return gnocchi.CeilometerGnocchiResourcesAlarm(
'GnoResAlarm', resource_defns['GnoResAlarm'], stack)
'GnoResAlarm', resource_defns['GnoResAlarm'], self.stack)
def test_update(self):
rsrc = self.create_alarm()
@ -151,8 +151,8 @@ class GnocchiResourcesAlarmTest(common.HeatTestCase):
def _prepare_check_resource(self):
snippet = template_format.parse(gnocchi_resources_alarm_template)
stack = utils.parse_stack(snippet)
res = stack['GnoResAlarm']
self.stack = utils.parse_stack(snippet)
res = self.stack['GnoResAlarm']
res.ceilometer = mock.Mock()
mock_alarm = mock.Mock(enabled=True, state='ok')
res.ceilometer().alarms.get.return_value = mock_alarm
@ -260,11 +260,11 @@ class GnocchiAggregationByMetricsAlarmTest(GnocchiResourcesAlarmTest):
).AndReturn(FakeCeilometerAlarm())
snippet = template_format.parse(
gnocchi_aggregation_by_metrics_alarm_template)
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
self.stack = utils.parse_stack(snippet)
resource_defns = self.stack.t.resource_definitions(self.stack)
return gnocchi.CeilometerGnocchiAggregationByMetricsAlarm(
'GnoAggregationByMetricsAlarm',
resource_defns['GnoAggregationByMetricsAlarm'], stack)
resource_defns['GnoAggregationByMetricsAlarm'], self.stack)
def test_update(self):
rsrc = self.create_alarm()
@ -290,8 +290,8 @@ class GnocchiAggregationByMetricsAlarmTest(GnocchiResourcesAlarmTest):
def _prepare_check_resource(self):
snippet = template_format.parse(
gnocchi_aggregation_by_metrics_alarm_template)
stack = utils.parse_stack(snippet)
res = stack['GnoAggregationByMetricsAlarm']
self.stack = utils.parse_stack(snippet)
res = self.stack['GnoAggregationByMetricsAlarm']
res.ceilometer = mock.Mock()
mock_alarm = mock.Mock(enabled=True, state='ok')
res.ceilometer().alarms.get.return_value = mock_alarm
@ -327,11 +327,11 @@ class GnocchiAggregationByResourcesAlarmTest(GnocchiResourcesAlarmTest):
).AndReturn(FakeCeilometerAlarm())
snippet = template_format.parse(
gnocchi_aggregation_by_resources_alarm_template)
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
self.stack = utils.parse_stack(snippet)
resource_defns = self.stack.t.resource_definitions(self.stack)
return gnocchi.CeilometerGnocchiAggregationByResourcesAlarm(
'GnoAggregationByResourcesAlarm',
resource_defns['GnoAggregationByResourcesAlarm'], stack)
resource_defns['GnoAggregationByResourcesAlarm'], self.stack)
def test_update(self):
rsrc = self.create_alarm()
@ -355,8 +355,8 @@ class GnocchiAggregationByResourcesAlarmTest(GnocchiResourcesAlarmTest):
def _prepare_check_resource(self):
snippet = template_format.parse(
gnocchi_aggregation_by_resources_alarm_template)
stack = utils.parse_stack(snippet)
res = stack['GnoAggregationByResourcesAlarm']
self.stack = utils.parse_stack(snippet)
res = self.stack['GnoAggregationByResourcesAlarm']
res.ceilometer = mock.Mock()
mock_alarm = mock.Mock(enabled=True, state='ok')
res.ceilometer().alarms.get.return_value = mock_alarm

@ -47,14 +47,14 @@ class ManilaShareTypeTest(common.HeatTestCase):
resource._register_class("OS::Manila::ShareType",
mshare_type.ManilaShareType)
@staticmethod
def _init_share(stack_name, share_type_name="test_share_type"):
def _init_share(self, stack_name, share_type_name="test_share_type"):
# parse stack
tmp = template_format.parse(manila_template)
stack = utils.parse_stack(tmp, stack_name=stack_name)
res_def = stack.t.resource_definitions(stack)["test_share_type"]
self.stack = utils.parse_stack(tmp, stack_name=stack_name)
defns = self.stack.t.resource_definitions(self.stack)
res_def = defns["test_share_type"]
share_type = mshare_type.ManilaShareType(
share_type_name, res_def, stack)
share_type_name, res_def, self.stack)
# mock clients and plugins
mock_client = mock.MagicMock()
client = mock.MagicMock(return_value=mock_client)

@ -358,9 +358,9 @@ class LoadBalancerTest(common.HeatTestCase):
def _mock_loadbalancer(self, lb_template, expected_name, expected_body):
t = template_format.parse(json.dumps(lb_template))
s = utils.parse_stack(t, stack_name=utils.random_name())
self.stack = utils.parse_stack(t, stack_name=utils.random_name())
rsrc, fake_loadbalancer = self._mock_create(s.t, s,
rsrc, fake_loadbalancer = self._mock_create(self.stack.t, self.stack,
self.
_get_first_resource_name(
lb_template),

@ -92,9 +92,9 @@ class CloudServersTest(common.HeatTestCase):
templ = template.Template(
t, env=environment.Environment({'key_name': 'test'}))
stack = parser.Stack(self.ctx, stack_name, templ,
stack_id=uuidutils.generate_uuid())
return (templ, stack)
self.stack = parser.Stack(self.ctx, stack_name, templ,
stack_id=uuidutils.generate_uuid())
return (templ, self.stack)
def _setup_test_server(self, return_server, name, image_id=None,
override_name=False, stub_create=True, exit_code=0):

@ -103,15 +103,15 @@ class RackspaceDnsTest(common.HeatTestCase):
t = parsed_t
templ = template.Template(
t, env=environment.Environment({'name': 'test'}))
stack = parser.Stack(utils.dummy_context(),
stack_name,
templ,
stack_id=str(uuid.uuid4()))
self.stack = parser.Stack(utils.dummy_context(),
stack_name,
templ,
stack_id=str(uuid.uuid4()))
instance = cloud_dns.CloudDns(
'%s_name' % name,
templ.resource_definitions(stack)['domain'],
stack)
templ.resource_definitions(self.stack)['domain'],
self.stack)
return instance
def _stubout_create(self, instance, fake_dnsinstance, **create_args):

@ -54,8 +54,8 @@ class TestScalingGroupTags(common.HeatTestCase):
def setUp(self):
super(TestScalingGroupTags, self).setUp()
t = template_format.parse(inline_templates.as_heat_template)
stack = utils.parse_stack(t, params=inline_templates.as_params)
self.group = stack['my-group']
self.stack = utils.parse_stack(t, params=inline_templates.as_params)
self.group = self.stack['my-group']
def test_tags_default(self):
expected = [{'Key': 'metering.groupname',
@ -118,8 +118,8 @@ class TestGroupAdjust(common.HeatTestCase):
generic_resource.ResourceWithPropsAndAttrs)
t = template_format.parse(inline_templates.as_heat_template)
stack = utils.parse_stack(t, params=inline_templates.as_params)
self.group = stack['my-group']
self.stack = utils.parse_stack(t, params=inline_templates.as_params)
self.group = self.stack['my-group']
self.stub_ImageConstraint_validate()
self.stub_FlavorConstraint_validate()
self.stub_SnapshotConstraint_validate()
@ -292,8 +292,8 @@ class TestGroupCrud(common.HeatTestCase):
self.stub_SnapshotConstraint_validate()
t = template_format.parse(inline_templates.as_heat_template)
stack = utils.parse_stack(t, params=inline_templates.as_params)
self.group = stack['my-group']
self.stack = utils.parse_stack(t, params=inline_templates.as_params)
self.group = self.stack['my-group']
self.assertIsNone(self.group.validate())
def test_handle_create(self):
@ -370,8 +370,8 @@ class HeatScalingGroupAttrTest(common.HeatTestCase):
generic_resource.ResourceWithPropsAndAttrs)
t = template_format.parse(inline_templates.as_heat_template)
stack = utils.parse_stack(t, params=inline_templates.as_params)
self.group = stack['my-group']
self.stack = utils.parse_stack(t, params=inline_templates.as_params)
self.group = self.stack['my-group']
self.assertIsNone(self.group.validate())
def test_no_instance_list(self):

@ -210,9 +210,9 @@ class ScalingPolicyAttrTest(common.HeatTestCase):
cfg.CONF.set_default('heat_waitcondition_server_url',
'http://server.test:8000/v1/waitcondition')
t = template_format.parse(as_template)
stack = utils.parse_stack(t, params=as_params)
self.stack_name = stack.name
self.policy = stack['my-policy']
self.stack = utils.parse_stack(t, params=as_params)
self.stack_name = self.stack.name
self.policy = self.stack['my-policy']
self.assertIsNone(self.policy.validate())
scheduler.TaskRunner(self.policy.create)()
self.assertEqual((self.policy.CREATE, self.policy.COMPLETE),

@ -235,8 +235,8 @@ class TestScalingGroupTags(common.HeatTestCase):
def setUp(self):
super(TestScalingGroupTags, self).setUp()
t = template_format.parse(as_template)
stack = utils.parse_stack(t, params=inline_templates.as_params)
self.group = stack['WebServerGroup']
self.stack = utils.parse_stack(t, params=inline_templates.as_params)
self.group = self.stack['WebServerGroup']
def test_tags_default(self):
expected = [{'Key': 'metering.groupname',
@ -299,8 +299,8 @@ class TestGroupAdjust(common.HeatTestCase):
'http://server.test:8000/v1/waitcondition')
t = template_format.parse(as_template)
stack = utils.parse_stack(t, params=inline_templates.as_params)
self.group = stack['WebServerGroup']
self.stack = utils.parse_stack(t, params=inline_templates.as_params)
self.group = self.stack['WebServerGroup']
self.stub_ImageConstraint_validate()
self.stub_FlavorConstraint_validate()
self.stub_SnapshotConstraint_validate()
@ -468,8 +468,8 @@ class TestGroupCrud(common.HeatTestCase):
'http://server.test:8000/v1/waitcondition')
t = template_format.parse(as_template)
stack = utils.parse_stack(t, params=inline_templates.as_params)
self.group = stack['WebServerGroup']
self.stack = utils.parse_stack(t, params=inline_templates.as_params)
self.group = self.stack['WebServerGroup']
self.assertIsNone(self.group.validate())
def test_handle_create(self):

@ -208,8 +208,8 @@ class ScalingPolicyAttrTest(common.HeatTestCase):
def setUp(self):
super(ScalingPolicyAttrTest, self).setUp()
t = template_format.parse(as_template)
stack = utils.parse_stack(t, params=as_params)
self.policy = stack['WebServerScaleUpPolicy']
self.stack = utils.parse_stack(t, params=as_params)
self.policy = self.stack['WebServerScaleUpPolicy']
self.assertIsNone(self.policy.validate())
scheduler.TaskRunner(self.policy.create)()
self.assertEqual((self.policy.CREATE, self.policy.COMPLETE),

@ -108,9 +108,10 @@ class InstancesTest(common.HeatTestCase):
def _setup_test_instance(self, return_server, name, image_id=None,
stub_create=True):
stack_name = '%s_s' % name
tmpl, stack = self._get_test_template(stack_name, image_id)
resource_defns = tmpl.resource_definitions(stack)
instance = instances.Instance(name, resource_defns['WebServer'], stack)
tmpl, self.stack = self._get_test_template(stack_name, image_id)
resource_defns = tmpl.resource_definitions(self.stack)
instance = instances.Instance(name, resource_defns['WebServer'],
self.stack)
bdm = {"vdb": "9ef5496e-7426-446a-bbc8-01f84d9c9972:snap::True"}
self._mock_get_image_id_success(image_id or 'CentOS 5.2', 1)

@ -204,13 +204,13 @@ class instancesTest(common.HeatTestCase):
'SubnetId': '4156c7a5-e8c4-4aff-a6e1-8f3c7bc83861'}
tmpl = template.Template(t,
env=environment.Environment(kwargs))
stack = parser.Stack(utils.dummy_context(), stack_name, tmpl,
stack_id=str(uuid.uuid4()))
self.stack = parser.Stack(utils.dummy_context(), stack_name, tmpl,
stack_id=str(uuid.uuid4()))
image_id = 'CentOS 5.2'
t['Resources']['WebServer']['Properties']['ImageId'] = image_id
resource_defns = stack.t.resource_definitions(stack)
resource_defns = self.stack.t.resource_definitions(self.stack)
instance = instances.Instance('%s_name' % name,
resource_defns['WebServer'], stack)
resource_defns['WebServer'], self.stack)
metadata = instance.metadata_get()
self.m.StubOutWithMock(nova.NovaClientPlugin, '_create')
@ -259,18 +259,18 @@ class instancesTest(common.HeatTestCase):
'SubnetId': '4156c7a5-e8c4-4aff-a6e1-8f3c7bc83861'}
tmpl = template.Template(t,
env=environment.Environment(kwargs))
stack = parser.Stack(utils.dummy_context(), stack_name, tmpl,
stack_id=str(uuid.uuid4()))
self.stack = parser.Stack(utils.dummy_context(), stack_name, tmpl,
stack_id=str(uuid.uuid4()))
image_id = 'CentOS 5.2'
t['Resources']['WebServer']['Properties']['ImageId'] = image_id
resource_defns = stack.t.resource_definitions(stack)
resource_defns = self.stack.t.resource_definitions(self.stack)
nic = net_interfaces.NetworkInterface('%s_nic' % name,
resource_defns['nic1'],
stack)
self.stack)
instance = instances.Instance('%s_name' % name,
resource_defns['WebServer'], stack)
resource_defns['WebServer'], self.stack)
metadata = instance.metadata_get()
self._mock_get_image_id_success(image_id, 1)
@ -310,7 +310,7 @@ class instancesTest(common.HeatTestCase):
# create network interface
scheduler.TaskRunner(nic.create)()
stack.resources["nic1"] = nic
self.stack.resources["nic1"] = nic
scheduler.TaskRunner(instance.create)()
return instance

@ -159,11 +159,11 @@ class LoadBalancerTest(common.HeatTestCase):
if not include_magic:
del template['Parameters']['KeyName']
del template['Parameters']['LbFlavor']
stack = utils.parse_stack(template)
self.stack = utils.parse_stack(template)
resource_name = 'LoadBalancer'
lb_defn = stack.t.resource_definitions(stack)[resource_name]
return lb.LoadBalancer(resource_name, lb_defn, stack)
lb_defn = self.stack.t.resource_definitions(self.stack)[resource_name]
return lb.LoadBalancer(resource_name, lb_defn, self.stack)
def test_loadbalancer_refid(self):
rsrc = self.setup_loadbalancer()
@ -253,10 +253,10 @@ class LoadBalancerTest(common.HeatTestCase):
class HaProxyConfigTest(common.HeatTestCase):
def setUp(self):
super(HaProxyConfigTest, self).setUp()
stack = utils.parse_stack(template_format.parse(lb_template))
self.stack = utils.parse_stack(template_format.parse(lb_template))
resource_name = 'LoadBalancer'
lb_defn = stack.t.resource_definitions(stack)[resource_name]
self.lb = lb.LoadBalancer(resource_name, lb_defn, stack)
lb_defn = self.stack.t.resource_definitions(self.stack)[resource_name]
self.lb = lb.LoadBalancer(resource_name, lb_defn, self.stack)
self.lb.client_plugin = mock.Mock()
def _mock_props(self, props):

@ -593,7 +593,8 @@ class WaitConditionUpdateTest(common.HeatTestCase):
self.m.VerifyAll()
self.m.UnsetStubs()
wait_condition_handle = self.stack['WaitHandle']
handle_stack = self.stack
wait_condition_handle = handle_stack['WaitHandle']
test_metadata = {'Data': 'foo', 'Reason': 'bar',
'Status': 'SUCCESS', 'UniqueId': '1'}
self._handle_signal(wait_condition_handle, test_metadata, 2)

@ -86,10 +86,10 @@ class FirewallTest(common.HeatTestCase):
).AndReturn({'firewall': {'id': '5678'}})
snippet = template_format.parse(firewall_template)
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
self.stack = utils.parse_stack(snippet)
resource_defns = self.stack.t.resource_definitions(self.stack)
return firewall.Firewall(
'firewall', resource_defns['firewall'], stack)
'firewall', resource_defns['firewall'], self.stack)
def test_create(self):
rsrc = self.create_firewall()
@ -214,10 +214,10 @@ class FirewallPolicyTest(common.HeatTestCase):
).AndReturn({'firewall_policy': {'id': '5678'}})
snippet = template_format.parse(firewall_policy_template)
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
self.stack = utils.parse_stack(snippet)
resource_defns = self.stack.t.resource_definitions(self.stack)
return firewall.FirewallPolicy(
'firewall_policy', resource_defns['firewall_policy'], stack)
'firewall_policy', resource_defns['firewall_policy'], self.stack)
def test_create(self):
rsrc = self.create_firewall_policy()
@ -340,10 +340,10 @@ class FirewallRuleTest(common.HeatTestCase):
).AndReturn({'firewall_rule': {'id': '5678'}})
snippet = template_format.parse(firewall_rule_template)
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
self.stack = utils.parse_stack(snippet)
resource_defns = self.stack.t.resource_definitions(self.stack)
return firewall.FirewallRule(
'firewall_rule', resource_defns['firewall_rule'], stack)
'firewall_rule', resource_defns['firewall_rule'], self.stack)
def test_create(self):
rsrc = self.create_firewall_rule()

@ -170,10 +170,10 @@ class HealthMonitorTest(common.HeatTestCase):
).AndReturn({'health_monitor': {'id': '5678'}})
snippet = template_format.parse(health_monitor_template)
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
self.stack = utils.parse_stack(snippet)
resource_defns = self.stack.t.resource_definitions(self.stack)
return loadbalancer.HealthMonitor(
'monitor', resource_defns['monitor'], stack)
'monitor', resource_defns['monitor'], self.stack)
def test_create(self):
rsrc = self.create_health_monitor()
@ -191,10 +191,10 @@ class HealthMonitorTest(common.HeatTestCase):
self.m.ReplayAll()
snippet = template_format.parse(health_monitor_template)
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
self.stack = utils.parse_stack(snippet)
resource_defns = self.stack.t.resource_definitions(self.stack)
rsrc = loadbalancer.HealthMonitor(
'monitor', resource_defns['monitor'], stack)
'monitor', resource_defns['monitor'], self.stack)
error = self.assertRaises(exception.ResourceFailure,
scheduler.TaskRunner(rsrc.create))
self.assertEqual(
@ -344,10 +344,10 @@ class PoolTest(common.HeatTestCase):
snippet = template_format.parse(pool_template_deprecated)
neutronclient.Client.create_vip(stvippsn
).AndReturn({'vip': {'id': 'xyz'}})
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
self.stack = utils.parse_stack(snippet)
resource_defns = self.stack.t.resource_definitions(self.stack)
return loadbalancer.Pool(
'pool', resource_defns['pool'], stack)
'pool', resource_defns['pool'], self.stack)
def test_create(self):
self._test_create()
@ -398,10 +398,10 @@ class PoolTest(common.HeatTestCase):
{'vip': {'status': 'ACTIVE'}})
snippet = template_format.parse(pool_template)
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
self.stack = utils.parse_stack(snippet)
resource_defns = self.stack.t.resource_definitions(self.stack)
rsrc = loadbalancer.Pool(
'pool', resource_defns['pool'], stack)
'pool', resource_defns['pool'], self.stack)
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
@ -432,10 +432,10 @@ class PoolTest(common.HeatTestCase):
{'pool': {'status': 'ERROR', 'name': '5678'}})
snippet = template_format.parse(pool_template)
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
self.stack = utils.parse_stack(snippet)
resource_defns = self.stack.t.resource_definitions(self.stack)
rsrc = loadbalancer.Pool(
'pool', resource_defns['pool'], stack)
'pool', resource_defns['pool'], self.stack)
self.m.ReplayAll()
error = self.assertRaises(exception.ResourceFailure,
scheduler.TaskRunner(rsrc.create))
@ -470,10 +470,10 @@ class PoolTest(common.HeatTestCase):
{'vip': {'status': 'SOMETHING', 'name': 'xyz'}})
snippet = template_format.parse(pool_template)
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
self.stack = utils.parse_stack(snippet)
resource_defns = self.stack.t.resource_definitions(self.stack)
rsrc = loadbalancer.Pool(
'pool', resource_defns['pool'], stack)
'pool', resource_defns['pool'], self.stack)
self.m.ReplayAll()
error = self.assertRaises(exception.ResourceFailure,
scheduler.TaskRunner(rsrc.create))
@ -499,10 +499,10 @@ class PoolTest(common.HeatTestCase):
self.m.ReplayAll()
snippet = template_format.parse(pool_template)
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
self.stack = utils.parse_stack(snippet)
resource_defns = self.stack.t.resource_definitions(self.stack)
rsrc = loadbalancer.Pool(
'pool', resource_defns['pool'], stack)
'pool', resource_defns['pool'], self.stack)
error = self.assertRaises(exception.ResourceFailure,
scheduler.TaskRunner(rsrc.create))
self.assertEqual(
@ -538,10 +538,10 @@ class PoolTest(common.HeatTestCase):
{'vip': {'status': 'ACTIVE'}})
snippet = template_format.parse(pool_with_session_persistence_template)
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
self.stack = utils.parse_stack(snippet)
resource_defns = self.stack.t.resource_definitions(self.stack)
rsrc = loadbalancer.Pool(
'pool', resource_defns['pool'], stack)
'pool', resource_defns['pool'], self.stack)
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
@ -558,9 +558,10 @@ class PoolTest(common.HeatTestCase):
persistence['type'] = 'APP_COOKIE'
persistence['cookie_name'] = None
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
resource = loadbalancer.Pool('pool', resource_defns['pool'], stack)
self.stack = utils.parse_stack(snippet)
resource_defns = self.stack.t.resource_definitions(self.stack)
resource = loadbalancer.Pool('pool', resource_defns['pool'],
self.stack)
error = self.assertRaises(exception.StackValidationFailed,
resource.validate)
@ -569,9 +570,10 @@ class PoolTest(common.HeatTestCase):
def test_validation_not_failing_without_session_persistence(self):
snippet = template_format.parse(pool_template)
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
resource = loadbalancer.Pool('pool', resource_defns['pool'], stack)
self.stack = utils.parse_stack(snippet)
resource_defns = self.stack.t.resource_definitions(self.stack)
resource = loadbalancer.Pool('pool', resource_defns['pool'],
self.stack)
self.stub_SubnetConstraint_validate()
self.m.ReplayAll()
self.assertIsNone(resource.validate())
@ -610,9 +612,10 @@ class PoolTest(common.HeatTestCase):
persistence['type'] = 'HTTP_COOKIE'
del persistence['cookie_name']
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
resource = loadbalancer.Pool('pool', resource_defns['pool'], stack)
self.stack = utils.parse_stack(snippet)
resource_defns = self.stack.t.resource_definitions(self.stack)
resource = loadbalancer.Pool('pool', resource_defns['pool'],
self.stack)
# assert that properties contain cookie_name property with None value
persistence = resource.properties['vip']['session_persistence']
@ -760,11 +763,11 @@ class PoolTest(common.HeatTestCase):
'5678', {'health_monitor': {'id': 'mon789'}})
snippet = template_format.parse(pool_template)
stack = utils.parse_stack(snippet)
self.stack = utils.parse_stack(snippet)
snippet['resources']['pool']['properties']['monitors'] = [
'mon123', 'mon456']
resource_defns = stack.t.resource_definitions(stack)
rsrc = loadbalancer.Pool('pool', resource_defns['pool'], stack)
resource_defns = self.stack.t.resource_definitions(self.stack)
rsrc = loadbalancer.Pool('pool', resource_defns['pool'], self.stack)
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
@ -792,10 +795,10 @@ class PoolMemberTest(common.HeatTestCase):
'address': '1.2.3.4', 'admin_state_up': True}}
).AndReturn({'member': {'id': 'member5678'}})
snippet = template_format.parse(member_template)
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
self.stack = utils.parse_stack(snippet)
resource_defns = self.stack.t.resource_definitions(self.stack)
return loadbalancer.PoolMember(
'member', resource_defns['member'], stack)
'member', resource_defns['member'], self.stack)
def test_create(self):
rsrc = self.create_member()
@ -816,10 +819,10 @@ class PoolMemberTest(common.HeatTestCase):
snippet = template_format.parse(member_template)
snippet['resources']['member']['properties']['admin_state_up'] = False
snippet['resources']['member']['properties']['weight'] = 100
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
self.stack = utils.parse_stack(snippet)
resource_defns = self.stack.t.resource_definitions(self.stack)
rsrc = loadbalancer.PoolMember(
'member', resource_defns['member'], stack)
'member', resource_defns['member'], self.stack)
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
@ -893,10 +896,10 @@ class LoadBalancerTest(common.HeatTestCase):
'address': '1.2.3.4'}}
).AndReturn({'member': {'id': 'member5678'}})
snippet = template_format.parse(lb_template)
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
self.stack = utils.parse_stack(snippet)
resource_defns = self.stack.t.resource_definitions(self.stack)
return loadbalancer.LoadBalancer(
'lb', resource_defns['lb'], stack)
'lb', resource_defns['lb'], self.stack)
def test_create(self):
rsrc = self.create_load_balancer()

@ -67,10 +67,10 @@ class MeteringLabelTest(common.HeatTestCase):
}).AndReturn({'metering_label': {'id': '1234'}})
snippet = template_format.parse(metering_template)
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
self.stack = utils.parse_stack(snippet)
resource_defns = self.stack.t.resource_definitions(self.stack)
return metering.MeteringLabel(
'label', resource_defns['label'], stack)
'label', resource_defns['label'], self.stack)
def test_create(self):
rsrc = self.create_metering_label()
@ -180,10 +180,10 @@ class MeteringRuleTest(common.HeatTestCase):
}).AndReturn({'metering_label_rule': {'id': '5678'}})
snippet = template_format.parse(metering_template)
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
self.stack = utils.parse_stack(snippet)
resource_defns = self.stack.t.resource_definitions(self.stack)
return metering.MeteringRule(
'rule', resource_defns['rule'], stack)
'rule', resource_defns['rule'], self.stack)
def test_create(self):
rsrc = self.create_metering_label_rule()

@ -129,11 +129,11 @@ class NeutronNetworkGatewayTest(common.HeatTestCase):
t = template_format.parse(gw_template)
stack = utils.parse_stack(t)
resource_defns = stack.t.resource_definitions(stack)
self.stack = utils.parse_stack(t)
resource_defns = self.stack.t.resource_definitions(self.stack)
rsrc = network_gateway.NetworkGateway(
'test_network_gateway',
resource_defns['NetworkGateway'], stack)
resource_defns['NetworkGateway'], self.stack)
return rsrc
def prepare_create_network_gateway(self, resolve_neutron=True):
@ -180,11 +180,11 @@ class NeutronNetworkGatewayTest(common.HeatTestCase):
else:
t = template_format.parse(gw_template_deprecated)
stack = utils.parse_stack(t)
resource_defns = stack.t.resource_definitions(stack)
self.stack = utils.parse_stack(t)
resource_defns = self.stack.t.resource_definitions(self.stack)
rsrc = network_gateway.NetworkGateway(
'test_network_gateway',
resource_defns['NetworkGateway'], stack)
resource_defns['NetworkGateway'], self.stack)
return rsrc
def _test_network_gateway_create(self, resolve_neutron=True):

@ -88,10 +88,11 @@ class NeutronProviderNetTest(common.HeatTestCase):
).AndReturn(stpna)
t = template_format.parse(provider_network_template)
stack = utils.parse_stack(t)
resource_defns = stack.t.resource_definitions(stack)
self.stack = utils.parse_stack(t)
resource_defns = self.stack.t.resource_definitions(self.stack)
rsrc = provider_net.ProviderNet(
'provider_net', resource_defns['provider_network_vlan'], stack)
'provider_net', resource_defns['provider_network_vlan'],
self.stack)
return rsrc

@ -441,8 +441,8 @@ class CeilometerAlarmTest(common.HeatTestCase):
def _prepare_check_resource(self):
snippet = template_format.parse(not_string_alarm_template)
stack = utils.parse_stack(snippet)
res = stack['MEMAlarmHigh']
self.stack = utils.parse_stack(snippet)
res = self.stack['MEMAlarmHigh']
res.ceilometer = mock.Mock()
mock_alarm = mock.Mock(enabled=True, state='ok')
res.ceilometer().alarms.get.return_value = mock_alarm
@ -499,10 +499,10 @@ class CombinationAlarmTest(common.HeatTestCase):
'operator': u'and'}
).AndReturn(FakeCeilometerAlarm())
snippet = template_format.parse(combination_alarm_template)
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
self.stack = utils.parse_stack(snippet)
resource_defns = self.stack.t.resource_definitions(self.stack)
return alarm.CombinationAlarm(
'CombinAlarm', resource_defns['CombinAlarm'], stack)
'CombinAlarm', resource_defns['CombinAlarm'], self.stack)
def test_create(self):
rsrc = self.create_alarm()
@ -596,8 +596,8 @@ class CombinationAlarmTest(common.HeatTestCase):
def _prepare_check_resource(self):
snippet = template_format.parse(combination_alarm_template)
stack = utils.parse_stack(snippet)
res = stack['CombinAlarm']
self.stack = utils.parse_stack(snippet)
res = self.stack['CombinAlarm']
res.ceilometer = mock.Mock()
mock_alarm = mock.Mock(enabled=True, state='ok')
res.ceilometer().alarms.get.return_value = mock_alarm

@ -34,13 +34,13 @@ class TestInstanceGroup(common.HeatTestCase):
def setUp(self):
super(TestInstanceGroup, self).setUp()
t = template_format.parse(inline_templates.as_template)
stack = utils.parse_stack(t, params=inline_templates.as_params)
self.stack = utils.parse_stack(t, params=inline_templates.as_params)
self.defn = rsrc_defn.ResourceDefinition(
'asg', 'OS::Heat::InstanceGroup',
{'Size': 2, 'AvailabilityZones': ['zoneb'],
'LaunchConfigurationName': 'config'})
self.instance_group = instgrp.InstanceGroup('asg',
self.defn, stack)
self.defn, self.stack)
def test_child_template(self):
self.instance_group._create_template = mock.Mock(return_value='tpl')
@ -327,14 +327,14 @@ class ReplaceTest(common.HeatTestCase):
resource._register_class('ResourceWithPropsAndAttrs',
generic_resource.ResourceWithPropsAndAttrs)
t = template_format.parse(inline_templates.as_template)
stack = utils.parse_stack(t, params=inline_templates.as_params)
lc = self.create_launch_config(t, stack)
self.stack = utils.parse_stack(t, params=inline_templates.as_params)
lc = self.create_launch_config(t, self.stack)
lcid = lc.FnGetRefId()
self.defn = rsrc_defn.ResourceDefinition(
'asg', 'OS::Heat::InstanceGroup',
{'Size': 2, 'AvailabilityZones': ['zoneb'],
'LaunchConfigurationName': lcid})
self.group = instgrp.InstanceGroup('asg', self.defn, stack)
self.group = instgrp.InstanceGroup('asg', self.defn, self.stack)
self.group._lb_reload = mock.Mock()
self.group.update_with_template = mock.Mock()

@ -311,9 +311,9 @@ Outputs:
self.ctx = utils.dummy_context('test_username', 'aaaa', 'password')
empty_template = {"HeatTemplateFormatVersion": "2012-12-12"}
stack = parser.Stack(self.ctx, 'test',
template.Template(empty_template))
stack.store()
self.stack = parser.Stack(self.ctx, 'test',
template.Template(empty_template))
self.stack.store()
self.patchobject(urlfetch, 'get', return_value=self.nested_template)
self.nested_parsed = yaml.load(self.nested_template)
@ -324,7 +324,7 @@ Outputs:
{"TemplateURL": "https://server.test/the.template",
"Parameters": self.nested_params})