Unit tests: Don't use ResourceDefinition as cfn snippet

Eliminate from the unit tests the deprecated use of a ResourceDefinition as
if it were a snippet from a CloudFormation template, in preparation for
this being removed in future.

Change-Id: I0449d3bff19c1294a9d0a475a4a9b623c73e11db
changes/38/305538/2
Zane Bitter 7 years ago
parent 52925a99bb
commit 23cc15687b

@ -96,9 +96,10 @@ class DockerContainerTest(common.HeatTestCase):
t = template_format.parse(template)
self.stack = utils.parse_stack(t)
definition = self.stack.t.resource_definitions(self.stack)['Blog']
definition['Properties']['name'] = 'super-blog'
props = t['Resources']['Blog']['Properties'].copy()
props['name'] = 'super-blog'
resource = docker_container.DockerContainer(
'Blog', definition, self.stack)
'Blog', definition.freeze(properties=props), self.stack)
self.m.StubOutWithMock(resource, 'get_client')
resource.get_client().MultipleTimes().AndReturn(
docker.Client())
@ -136,11 +137,11 @@ class DockerContainerTest(common.HeatTestCase):
t = template_format.parse(template)
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'}
props = t['Resources']['Blog']['Properties'].copy()
props['port_bindings'] = {'80/tcp': [{'HostPort': '80'}]}
props['links'] = {'db': 'mysql'}
resource = docker_container.DockerContainer(
'Blog', definition, self.stack)
'Blog', definition.freeze(properties=props), self.stack)
self.m.StubOutWithMock(resource, 'get_client')
resource.get_client().MultipleTimes().AndReturn(
docker.Client())
@ -228,10 +229,10 @@ class DockerContainerTest(common.HeatTestCase):
t = template_format.parse(template)
self.stack = utils.parse_stack(t)
definition = self.stack.t.resource_definitions(self.stack)['Blog']
definition['Properties']['restart_policy'] = {
'Name': 'no', 'MaximumRetryCount': 0}
props = t['Resources']['Blog']['Properties'].copy()
props['restart_policy'] = {'Name': 'no', 'MaximumRetryCount': 0}
resource = docker_container.DockerContainer(
'Blog', definition, self.stack)
'Blog', definition.freeze(properties=props), self.stack)
get_client_mock = self.patchobject(resource, 'get_client')
get_client_mock.return_value = docker.Client()
self.assertIsNone(resource.validate())
@ -247,10 +248,11 @@ class DockerContainerTest(common.HeatTestCase):
t = template_format.parse(template)
self.stack = utils.parse_stack(t)
definition = self.stack.t.resource_definitions(self.stack)['Blog']
definition['Properties']['restart_policy'] = {
'Name': 'on-failure', 'MaximumRetryCount': 10}
props = t['Resources']['Blog']['Properties'].copy()
props['restart_policy'] = {'Name': 'on-failure',
'MaximumRetryCount': 10}
resource = docker_container.DockerContainer(
'Blog', definition, self.stack)
'Blog', definition.freeze(properties=props), self.stack)
get_client_mock = self.patchobject(resource, 'get_client')
get_client_mock.return_value = docker.Client()
self.assertIsNone(resource.validate())
@ -266,10 +268,10 @@ class DockerContainerTest(common.HeatTestCase):
t = template_format.parse(template)
self.stack = utils.parse_stack(t)
definition = self.stack.t.resource_definitions(self.stack)['Blog']
definition['Properties']['restart_policy'] = {
'Name': 'always', 'MaximumRetryCount': 0}
props = t['Resources']['Blog']['Properties'].copy()
props['restart_policy'] = {'Name': 'always', 'MaximumRetryCount': 0}
resource = docker_container.DockerContainer(
'Blog', definition, self.stack)
'Blog', definition.freeze(properties=props), self.stack)
get_client_mock = self.patchobject(resource, 'get_client')
get_client_mock.return_value = docker.Client()
self.assertIsNone(resource.validate())
@ -285,10 +287,11 @@ class DockerContainerTest(common.HeatTestCase):
t = template_format.parse(template)
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']
props = t['Resources']['Blog']['Properties'].copy()
props['cap_add'] = ['NET_ADMIN']
props['cap_drop'] = ['MKNOD']
resource = docker_container.DockerContainer(
'Blog', definition, self.stack)
'Blog', definition.freeze(properties=props), self.stack)
get_client_mock = self.patchobject(resource, 'get_client')
get_client_mock.return_value = docker.Client()
self.assertIsNone(resource.validate())
@ -304,9 +307,10 @@ class DockerContainerTest(common.HeatTestCase):
t = template_format.parse(template)
self.stack = utils.parse_stack(t)
definition = self.stack.t.resource_definitions(self.stack)['Blog']
definition['Properties']['read_only'] = True
props = t['Resources']['Blog']['Properties'].copy()
props['read_only'] = True
resource = docker_container.DockerContainer(
'Blog', definition, self.stack)
'Blog', definition.freeze(properties=props), self.stack)
get_client_mock = self.patchobject(resource, 'get_client')
get_client_mock.return_value = docker.Client()
get_client_mock.return_value.set_api_version('1.17')
@ -322,9 +326,10 @@ class DockerContainerTest(common.HeatTestCase):
t = template_format.parse(template)
self.stack = utils.parse_stack(t)
definition = self.stack.t.resource_definitions(self.stack)['Blog']
definition['Properties'][arg] = value
props = t['Resources']['Blog']['Properties'].copy()
props[arg] = value
my_resource = docker_container.DockerContainer(
'Blog', definition, self.stack)
'Blog', definition.freeze(properties=props), self.stack)
get_client_mock = self.patchobject(my_resource, 'get_client')
get_client_mock.return_value = docker.Client()
get_client_mock.return_value.set_api_version(low_version)
@ -348,9 +353,10 @@ class DockerContainerTest(common.HeatTestCase):
t = template_format.parse(template)
self.stack = utils.parse_stack(t)
definition = self.stack.t.resource_definitions(self.stack)['Blog']
definition['Properties']['cpu_shares'] = 512
props = t['Resources']['Blog']['Properties'].copy()
props['cpu_shares'] = 512
my_resource = docker_container.DockerContainer(
'Blog', definition, self.stack)
'Blog', definition.freeze(properties=props), self.stack)
get_client_mock = self.patchobject(my_resource, 'get_client')
get_client_mock.return_value = docker.Client()
self.assertIsNone(my_resource.validate())
@ -368,7 +374,8 @@ class DockerContainerTest(common.HeatTestCase):
t = template_format.parse(template)
self.stack = utils.parse_stack(t)
definition = self.stack.t.resource_definitions(self.stack)['Blog']
definition['Properties']['devices'] = (
props = t['Resources']['Blog']['Properties'].copy()
props['devices'] = (
[{'path_on_host': '/dev/sda',
'path_in_container': '/dev/xvdc',
'permissions': 'r'},
@ -376,7 +383,7 @@ class DockerContainerTest(common.HeatTestCase):
'path_in_container': '/dev/xvdd',
'permissions': 'rw'}])
my_resource = docker_container.DockerContainer(
'Blog', definition, self.stack)
'Blog', definition.freeze(properties=props), self.stack)
get_client_mock = self.patchobject(my_resource, 'get_client')
get_client_mock.return_value = docker.Client()
self.assertIsNone(my_resource.validate())
@ -393,13 +400,14 @@ class DockerContainerTest(common.HeatTestCase):
t = template_format.parse(template)
self.stack = utils.parse_stack(t)
definition = self.stack.t.resource_definitions(self.stack)['Blog']
definition['Properties']['devices'] = (
props = t['Resources']['Blog']['Properties'].copy()
props['devices'] = (
[{'path_on_host': '/dev/sdb',
'path_in_container': '/dev/xvdc',
'permissions': 'r'}])
definition['Properties']['privileged'] = True
props['privileged'] = True
my_resource = docker_container.DockerContainer(
'Blog', definition, self.stack)
'Blog', definition.freeze(properties=props), self.stack)
get_client_mock = self.patchobject(my_resource, 'get_client')
get_client_mock.return_value = docker.Client()
self.assertIsNone(my_resource.validate())
@ -420,11 +428,11 @@ class DockerContainerTest(common.HeatTestCase):
t = template_format.parse(template)
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'}])
props = t['Resources']['Blog']['Properties'].copy()
props['devices'] = [{'path_on_host': '/dev/sda',
'permissions': 'rwm'}]
my_resource = docker_container.DockerContainer(
'Blog', definition, self.stack)
'Blog', definition.freeze(properties=props), self.stack)
get_client_mock = self.patchobject(my_resource, 'get_client')
get_client_mock.return_value = docker.Client()
self.assertIsNone(my_resource.validate())
@ -440,9 +448,10 @@ class DockerContainerTest(common.HeatTestCase):
t = template_format.parse(template)
self.stack = utils.parse_stack(t)
definition = self.stack.t.resource_definitions(self.stack)['Blog']
definition['Properties']['cpu_set'] = '0-8,16-24,28'
props = t['Resources']['Blog']['Properties'].copy()
props['cpu_set'] = '0-8,16-24,28'
my_resource = docker_container.DockerContainer(
'Blog', definition, self.stack)
'Blog', definition.freeze(properties=props), self.stack)
get_client_mock = self.patchobject(my_resource, 'get_client')
get_client_mock.return_value = docker.Client()
self.assertIsNone(my_resource.validate())

@ -316,26 +316,28 @@ class LoadBalancerTest(common.HeatTestCase):
def setUp(self):
super(LoadBalancerTest, self).setUp()
self.lb_props = {
"name": "test-clb",
"nodes": [{"addresses": ["166.78.103.141"],
"port": 80,
"condition": "ENABLED"}],
"protocol": "HTTP",
"port": 80,
"virtualIps": [
{"type": "PUBLIC", "ipVersion": "IPV6"}],
"algorithm": 'LEAST_CONNECTIONS',
"connectionThrottle": {'maxConnectionRate': 1000},
'timeout': 110,
'contentCaching': 'DISABLED'
}
self.lb_template = {
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "fawef",
"Resources": {
self._get_lb_resource_name(): {
"Type": "Rackspace::Cloud::LoadBalancer",
"Properties": {
"name": "test-clb",
"nodes": [{"addresses": ["166.78.103.141"],
"port": 80,
"condition": "ENABLED"}],
"protocol": "HTTP",
"port": 80,
"virtualIps": [
{"type": "PUBLIC", "ipVersion": "IPV6"}],
"algorithm": 'LEAST_CONNECTIONS',
"connectionThrottle": {'maxConnectionRate': 1000},
'timeout': 110,
'contentCaching': 'DISABLED'
}
"Properties": self.lb_props,
}
}
}
@ -812,9 +814,9 @@ class LoadBalancerTest(common.HeatTestCase):
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
update_template = copy.deepcopy(rsrc.t)
props = copy.deepcopy(self.lb_props)
expected_ip = '172.168.1.4'
update_template['Properties']['nodes'] = [
props['nodes'] = [
{"addresses": ["166.78.103.141"],
"port": 80,
"condition": "ENABLED",
@ -825,6 +827,7 @@ class LoadBalancerTest(common.HeatTestCase):
"condition": "ENABLED",
"type": "PRIMARY",
"weight": 1}]
update_template = rsrc.t.freeze(properties=props)
self.m.UnsetStubs()
self.m.StubOutWithMock(rsrc.clb, 'get')
@ -894,9 +897,9 @@ class LoadBalancerTest(common.HeatTestCase):
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
update_template = copy.deepcopy(rsrc.t)
props = copy.deepcopy(self.lb_props)
expected_ip = '4.4.4.4'
update_template['Properties']['nodes'] = [
props['nodes'] = [
{"addresses": ["1.1.1.1"], "port": 80, "condition": "ENABLED",
"type": "PRIMARY", "weight": 1},
{"addresses": ["2.2.2.2"], "port": 80, "condition": "DISABLED",
@ -904,6 +907,7 @@ class LoadBalancerTest(common.HeatTestCase):
{"addresses": [expected_ip], "port": 80, "condition": "ENABLED",
"type": "PRIMARY", "weight": 1}
]
update_template = rsrc.t.freeze(properties=props)
self.m.UnsetStubs()
self.m.StubOutWithMock(rsrc.clb, 'get')
@ -978,8 +982,9 @@ class LoadBalancerTest(common.HeatTestCase):
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
update_template = copy.deepcopy(rsrc.t)
update_template['Properties']['name'] = "updated_name"
props = copy.deepcopy(self.lb_props)
props['name'] = "updated_name"
update_template = rsrc.t.freeze(properties=props)
self.m.UnsetStubs()
self.m.StubOutWithMock(rsrc.clb, 'get')
@ -1005,8 +1010,9 @@ class LoadBalancerTest(common.HeatTestCase):
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
update_template = copy.deepcopy(rsrc.t)
update_template['Properties']['name'] = "updated_name"
props = copy.deepcopy(self.lb_props)
props['name'] = "updated_name"
update_template = rsrc.t.freeze(properties=props)
self.m.UnsetStubs()
self.m.StubOutWithMock(rsrc.clb, 'get')
@ -1060,8 +1066,9 @@ class LoadBalancerTest(common.HeatTestCase):
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
update_template = copy.deepcopy(rsrc.t)
update_template['Properties']['name'] = "updated_name"
props = copy.deepcopy(self.lb_props)
props['name'] = "updated_name"
update_template = rsrc.t.freeze(properties=props)
self.m.UnsetStubs()
self.m.StubOutWithMock(rsrc.clb, 'get')
@ -1085,9 +1092,10 @@ class LoadBalancerTest(common.HeatTestCase):
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
update_template = copy.deepcopy(rsrc.t)
update_template['Properties']['name'] = "updated_name"
update_template['Properties']['algorithm'] = "RANDOM"
props = copy.deepcopy(self.lb_props)
props['name'] = "updated_name"
props['algorithm'] = "RANDOM"
update_template = rsrc.t.freeze(properties=props)
self.m.UnsetStubs()
self.m.StubOutWithMock(rsrc.clb, 'get')
@ -1115,8 +1123,9 @@ class LoadBalancerTest(common.HeatTestCase):
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
update_template = copy.deepcopy(rsrc.t)
update_template['Properties']['algorithm'] = "RANDOM"
props = copy.deepcopy(self.lb_props)
props['algorithm'] = "RANDOM"
update_template = rsrc.t.freeze(properties=props)
self.m.UnsetStubs()
self.m.StubOutWithMock(rsrc.clb, 'get')
@ -1143,8 +1152,9 @@ class LoadBalancerTest(common.HeatTestCase):
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
update_template = copy.deepcopy(rsrc.t)
update_template['Properties']['protocol'] = "IMAPS"
props = copy.deepcopy(self.lb_props)
props['protocol'] = "IMAPS"
update_template = rsrc.t.freeze(properties=props)
self.m.UnsetStubs()
self.m.StubOutWithMock(rsrc.clb, 'get')
@ -1174,8 +1184,9 @@ class LoadBalancerTest(common.HeatTestCase):
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
update_template = copy.deepcopy(rsrc.t)
update_template['Properties']['httpsRedirect'] = True
props = copy.deepcopy(template['Resources'][rsrc.name]['Properties'])
props['httpsRedirect'] = True
update_template = rsrc.t.freeze(properties=props)
self.m.UnsetStubs()
self.m.StubOutWithMock(rsrc.clb, 'get')
@ -1261,8 +1272,9 @@ class LoadBalancerTest(common.HeatTestCase):
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
update_template = copy.deepcopy(rsrc.t)
update_template['Properties']['halfClosed'] = True
props = copy.deepcopy(self.lb_props)
props['halfClosed'] = True
update_template = rsrc.t.freeze(properties=props)
self.m.UnsetStubs()
self.m.StubOutWithMock(rsrc.clb, 'get')
@ -1286,8 +1298,9 @@ class LoadBalancerTest(common.HeatTestCase):
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
update_template = copy.deepcopy(rsrc.t)
update_template['Properties']['port'] = 1234
props = copy.deepcopy(self.lb_props)
props['port'] = 1234
update_template = rsrc.t.freeze(properties=props)
self.m.UnsetStubs()
self.m.StubOutWithMock(rsrc.clb, 'get')
@ -1311,8 +1324,9 @@ class LoadBalancerTest(common.HeatTestCase):
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
update_template = copy.deepcopy(rsrc.t)
update_template['Properties']['timeout'] = 120
props = copy.deepcopy(self.lb_props)
props['timeout'] = 120
update_template = rsrc.t.freeze(properties=props)
self.m.UnsetStubs()
self.m.StubOutWithMock(rsrc.clb, 'get')
@ -1336,12 +1350,13 @@ class LoadBalancerTest(common.HeatTestCase):
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
update_template = copy.deepcopy(rsrc.t)
update_template['Properties']['healthMonitor'] = {
props = copy.deepcopy(self.lb_props)
props['healthMonitor'] = {
'type': "HTTP", 'delay': 10, 'timeout': 10,
'attemptsBeforeDeactivation': 4, 'path': "/",
'statusRegex': "^[234][0-9][0-9]$", 'bodyRegex': ".* testing .*",
'hostHeader': "example.com"}
update_template = rsrc.t.freeze(properties=props)
self.m.StubOutWithMock(fake_lb, 'get_health_monitor')
fake_lb.get_health_monitor().AndReturn({})
@ -1379,8 +1394,7 @@ class LoadBalancerTest(common.HeatTestCase):
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
update_template = copy.deepcopy(rsrc.t)
del update_template['Properties']['healthMonitor']
update_template = rsrc.t.freeze(properties=self.lb_props)
self.m.StubOutWithMock(fake_lb, 'get_health_monitor')
fake_lb.get_health_monitor().AndReturn(
@ -1406,8 +1420,9 @@ class LoadBalancerTest(common.HeatTestCase):
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
update_template = copy.deepcopy(rsrc.t)
update_template['Properties']['sessionPersistence'] = 'SOURCE_IP'
props = copy.deepcopy(self.lb_props)
props['sessionPersistence'] = 'SOURCE_IP'
update_template = rsrc.t.freeze(properties=props)
self.m.ReplayAll()
@ -1430,8 +1445,7 @@ class LoadBalancerTest(common.HeatTestCase):
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
update_template = copy.deepcopy(rsrc.t)
del update_template['Properties']['sessionPersistence']
update_template = rsrc.t.freeze(properties=self.lb_props)
self.m.ReplayAll()
@ -1447,10 +1461,15 @@ class LoadBalancerTest(common.HeatTestCase):
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
update_template = copy.deepcopy(rsrc.t)
update_template['Properties']['sslTermination'] = {
'securePort': 443, 'privatekey': private_key, 'certificate': cert,
'secureTrafficOnly': False, 'intermediateCertificate': ''}
props = copy.deepcopy(self.lb_props)
props['sslTermination'] = {
'securePort': 443,
'privatekey': private_key,
'certificate': cert,
'secureTrafficOnly': False,
'intermediateCertificate': ''
}
update_template = rsrc.t.freeze(properties=props)
self.m.StubOutWithMock(fake_lb, 'get_ssl_termination')
fake_lb.get_ssl_termination().AndReturn({})
@ -1497,8 +1516,7 @@ class LoadBalancerTest(common.HeatTestCase):
scheduler.TaskRunner(rsrc.create)()
self.m.UnsetStubs()
update_template = copy.deepcopy(rsrc.t)
del update_template['Properties']['sslTermination']
update_template = rsrc.t.freeze(properties=self.lb_props)
self.m.StubOutWithMock(rsrc.clb, 'get')
rsrc.clb.get(mox.IgnoreArg()).MultipleTimes().AndReturn(
@ -1527,8 +1545,9 @@ class LoadBalancerTest(common.HeatTestCase):
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
update_template = copy.deepcopy(rsrc.t)
update_template['Properties']['metadata'] = {'a': 1, 'b': 2}
props = copy.deepcopy(self.lb_props)
props['metadata'] = {'a': 1, 'b': 2}
update_template = rsrc.t.freeze(properties=props)
self.m.StubOutWithMock(fake_lb, 'get_metadata')
fake_lb.get_metadata().AndReturn({})
@ -1557,8 +1576,7 @@ class LoadBalancerTest(common.HeatTestCase):
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
update_template = copy.deepcopy(rsrc.t)
del update_template['Properties']['metadata']
update_template = rsrc.t.freeze(properties=self.lb_props)
self.m.StubOutWithMock(fake_lb, 'get_metadata')
fake_lb.get_metadata().AndReturn({'a': 1, 'b': 2})
@ -1584,8 +1602,9 @@ class LoadBalancerTest(common.HeatTestCase):
'<html><head><title>Service Unavailable</title></head><body><h2>'
'Service Unavailable</h2>The service is unavailable</body></html>')
update_template = copy.deepcopy(rsrc.t)
update_template['Properties']['errorPage'] = error_page
props = copy.deepcopy(self.lb_props)
props['errorPage'] = error_page
update_template = rsrc.t.freeze(properties=props)
self.m.StubOutWithMock(fake_lb, 'get_error_page')
fake_lb.get_error_page().AndReturn(
@ -1627,8 +1646,7 @@ class LoadBalancerTest(common.HeatTestCase):
scheduler.TaskRunner(rsrc.create)()
self.m.UnsetStubs()
update_template = copy.deepcopy(rsrc.t)
del update_template['Properties']['errorPage']
update_template = rsrc.t.freeze(properties=self.lb_props)
self.m.StubOutWithMock(rsrc.clb, 'get')
rsrc.clb.get(mox.IgnoreArg()).MultipleTimes().AndReturn(
@ -1655,8 +1673,9 @@ class LoadBalancerTest(common.HeatTestCase):
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
update_template = copy.deepcopy(rsrc.t)
update_template['Properties']['connectionLogging'] = True
props = copy.deepcopy(self.lb_props)
props['connectionLogging'] = True
update_template = rsrc.t.freeze(properties=props)
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.update, update_template)()
@ -1688,8 +1707,7 @@ class LoadBalancerTest(common.HeatTestCase):
fake_lb2.connection_logging = False
rsrc.clb.get(mox.IgnoreArg()).AndReturn(fake_lb2)
update_template = copy.deepcopy(rsrc.t)
del update_template['Properties']['connectionLogging']
update_template = rsrc.t.freeze(properties=self.lb_props)
self.m.ReplayAll()
@ -1712,8 +1730,9 @@ class LoadBalancerTest(common.HeatTestCase):
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
update_template = copy.deepcopy(rsrc.t)
update_template['Properties']['connectionLogging'] = False
props = copy.deepcopy(self.lb_props)
props['connectionLogging'] = False
update_template = rsrc.t.freeze(properties=props)
self.m.ReplayAll()
@ -1729,9 +1748,9 @@ class LoadBalancerTest(common.HeatTestCase):
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
update_template = copy.deepcopy(rsrc.t)
update_template['Properties']['connectionThrottle'] = {
'maxConnections': 1000}
props = copy.deepcopy(self.lb_props)
props['connectionThrottle'] = {'maxConnections': 1000}
update_template = rsrc.t.freeze(properties=props)
self.m.StubOutWithMock(fake_lb, 'add_connection_throttle')
self.m.StubOutWithMock(fake_lb, 'get_connection_throttle')
@ -1768,8 +1787,9 @@ class LoadBalancerTest(common.HeatTestCase):
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
update_template = copy.deepcopy(rsrc.t)
del update_template['Properties']['connectionThrottle']
props = copy.deepcopy(self.lb_props)
del props['connectionThrottle']
update_template = rsrc.t.freeze(properties=props)
self.m.StubOutWithMock(fake_lb, 'get_connection_throttle')
fake_lb.get_connection_throttle().AndReturn({
@ -1793,8 +1813,9 @@ class LoadBalancerTest(common.HeatTestCase):
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
update_template = copy.deepcopy(rsrc.t)
update_template['Properties']['contentCaching'] = 'ENABLED'
props = copy.deepcopy(self.lb_props)
props['contentCaching'] = 'ENABLED'
update_template = rsrc.t.freeze(properties=props)
self.m.UnsetStubs()
self.m.StubOutWithMock(rsrc.clb, 'get')
@ -1823,8 +1844,9 @@ class LoadBalancerTest(common.HeatTestCase):
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
update_template = copy.deepcopy(rsrc.t)
del update_template['Properties']['contentCaching']
props = copy.deepcopy(self.lb_props)
del props['contentCaching']
update_template = rsrc.t.freeze(properties=props)
self.m.UnsetStubs()
self.m.StubOutWithMock(rsrc.clb, 'get')
@ -1854,8 +1876,9 @@ class LoadBalancerTest(common.HeatTestCase):
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
update_template = copy.deepcopy(rsrc.t)
update_template['Properties']['contentCaching'] = 'DISABLED'
props = copy.deepcopy(self.lb_props)
props['contentCaching'] = 'DISABLED'
update_template = rsrc.t.freeze(properties=props)
self.m.UnsetStubs()
self.m.StubOutWithMock(rsrc.clb, 'get')
@ -2051,9 +2074,9 @@ class LoadBalancerTest(common.HeatTestCase):
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
update_template = copy.deepcopy(rsrc.t)
props = copy.deepcopy(self.lb_props)
expected_ip = '172.168.1.4'
update_template['Properties']['nodes'] = [
props['nodes'] = [
{"addresses": ["166.78.103.141"],
"port": 80,
"condition": "DRAINING",
@ -2064,6 +2087,7 @@ class LoadBalancerTest(common.HeatTestCase):
"condition": "DRAINING",
"type": "PRIMARY",
"weight": 1}]
update_template = rsrc.t.freeze(properties=props)
self.m.UnsetStubs()
self.m.StubOutWithMock(rsrc.clb, 'get')
@ -2100,8 +2124,8 @@ class LoadBalancerTest(common.HeatTestCase):
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
update_template = copy.deepcopy(rsrc.t)
update_template['Properties']['nodes'] = [
props = copy.deepcopy(self.lb_props)
props['nodes'] = [
{"addresses": ["166.78.103.141"],
"port": 80,
"condition": "ENABLED",
@ -2112,6 +2136,7 @@ class LoadBalancerTest(common.HeatTestCase):
"condition": "ENABLED",
"type": "PRIMARY",
"weight": 1}]
update_template = rsrc.t.freeze(properties=props)
self.m.UnsetStubs()
self.m.StubOutWithMock(rsrc.clb, 'get')
@ -2160,10 +2185,9 @@ class LoadBalancerTest(common.HeatTestCase):
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
update_template = copy.deepcopy(rsrc.t)
update_template['Properties']['nodes'] = [
{"addresses": ["166.78.103.141"],
"port": 80}]
props = copy.deepcopy(self.lb_props)
props['nodes'] = [{"addresses": ["166.78.103.141"], "port": 80}]
update_template = rsrc.t.freeze(properties=props)
self.m.UnsetStubs()
self.m.StubOutWithMock(rsrc.clb, 'get')

@ -561,14 +561,9 @@ class RollingUpdatePolicyDiffTest(common.HeatTestCase):
else None)
self.assertTrue(tmpl_diff.properties_changed())
# test application of the new update policy in handle_update
update_snippet = rsrc_defn.ResourceDefinition(
current_grp.name,
current_grp.type(),
properties=updated_grp.t['Properties'])
current_grp._try_rolling_update = mock.MagicMock()
current_grp.resize = mock.MagicMock()
current_grp.handle_update(update_snippet, tmpl_diff, None)
current_grp.handle_update(updated_grp_json, tmpl_diff, None)
if updated_policy is None:
self.assertIsNone(
current_grp.properties.data.get('rolling_updates'))

@ -705,23 +705,14 @@ class RollingUpdatePolicyDiffTest(common.HeatTestCase):
# identify the template difference
tmpl_diff = updated_grp.update_template_diff(
updated_grp_json, current_grp_json)
updated_policy = (updated_grp.t['UpdatePolicy']
if 'UpdatePolicy' in updated_grp.t else None)
self.assertTrue(tmpl_diff.update_policy_changed())
# test application of the new update policy in handle_update
update_snippet = rsrc_defn.ResourceDefinition(
current_grp.name,
current_grp.type(),
properties=updated_grp.t['Properties'],
update_policy=updated_policy)
current_grp._try_rolling_update = mock.MagicMock()
current_grp.resize = mock.MagicMock()
current_grp.handle_update(update_snippet, tmpl_diff, None)
if updated_policy is None:
self.assertEqual({}, current_grp.update_policy.data)
else:
self.assertEqual(updated_policy, current_grp.update_policy.data)
current_grp.handle_update(updated_grp_json, tmpl_diff, None)
self.assertEqual(updated_grp_json._update_policy or {},
current_grp.update_policy.data)
def test_update_policy_added(self):
self.validate_update_policy_diff(inline_templates.as_template,

@ -124,6 +124,7 @@ class InstancesTest(common.HeatTestCase):
stack_name = '%s_s' % name
tmpl, self.stack = self._get_test_template(stack_name, image_id,
volumes=volumes)
self.instance_props = tmpl.t['Resources']['WebServer']['Properties']
resource_defns = tmpl.resource_definitions(self.stack)
instance = instances.Instance(name, resource_defns['WebServer'],
self.stack)
@ -723,8 +724,9 @@ class InstancesTest(common.HeatTestCase):
instance = self._create_test_instance(return_server,
'ud_type')
update_template = copy.deepcopy(instance.t)
update_template['Properties']['InstanceType'] = 'm1.small'
update_props = self.instance_props.copy()
update_props['InstanceType'] = 'm1.small'
update_template = instance.t.freeze(properties=update_props)
def side_effect(*args):
return 2 if args[0] == 'm1.small' else 1
@ -786,8 +788,9 @@ class InstancesTest(common.HeatTestCase):
self.patchobject(glance.GlanceClientPlugin, 'find_image_by_name_or_id',
return_value=1)
update_template = copy.deepcopy(instance.t)
update_template['Properties']['InstanceType'] = 'm1.small'
update_props = self.instance_props.copy()
update_props['InstanceType'] = 'm1.small'
update_template = instance.t.freeze(properties=update_props)
self.m.StubOutWithMock(self.fc.servers, 'get')
@ -850,9 +853,13 @@ class InstancesTest(common.HeatTestCase):
{'NetworkInterfaceId': '34b752ec-14de-416a-8722-9531015e04a5',
'DeviceIndex': '3'}]
instance.t['Properties']['NetworkInterfaces'] = old_interfaces
update_template = copy.deepcopy(instance.t)
update_template['Properties']['NetworkInterfaces'] = new_interfaces
before_props = self.instance_props.copy()
before_props['NetworkInterfaces'] = old_interfaces
update_props = self.instance_props.copy()
update_props['NetworkInterfaces'] = new_interfaces
update_template = instance.t.freeze(properties=update_props)
instance.t = instance.t.freeze(properties=before_props)
instance.reparse()
self.m.StubOutWithMock(self.fc.servers, 'get')
self.fc.servers.get('1234').MultipleTimes().AndReturn(return_server)
@ -889,9 +896,13 @@ class InstancesTest(common.HeatTestCase):
{'NetworkInterfaceId': 'ea29f957-cd35-4364-98fb-57ce9732c10d',
'DeviceIndex': '2'}]
instance.t['Properties']['NetworkInterfaces'] = old_interfaces
update_template = copy.deepcopy(instance.t)
update_template['Properties']['NetworkInterfaces'] = new_interfaces
before_props = self.instance_props.copy()
before_props['NetworkInterfaces'] = old_interfaces
update_props = self.instance_props.copy()
update_props['NetworkInterfaces'] = new_interfaces
update_template = instance.t.freeze(properties=update_props)
instance.t = instance.t.freeze(properties=before_props)
instance.reparse()
self.m.StubOutWithMock(self.fc.servers, 'get')
self.fc.servers.get('1234').MultipleTimes().AndReturn(return_server)
@ -925,9 +936,13 @@ class InstancesTest(common.HeatTestCase):
{'NetworkInterfaceId': 'd1e9c73c-04fe-4e9e-983c-d5ef94cd1a46',
'DeviceIndex': '1'}]
instance.t['Properties']['NetworkInterfaces'] = old_interfaces
update_template = copy.deepcopy(instance.t)
update_template['Properties']['NetworkInterfaces'] = new_interfaces
before_props = self.instance_props.copy()
before_props['NetworkInterfaces'] = old_interfaces
update_props = self.instance_props.copy()
update_props['NetworkInterfaces'] = new_interfaces
update_template = instance.t.freeze(properties=update_props)
instance.t = instance.t.freeze(properties=before_props)
instance.reparse()
self.m.StubOutWithMock(self.fc.servers, 'get')
self.fc.servers.get('1234').MultipleTimes().AndReturn(return_server)
@ -961,9 +976,13 @@ class InstancesTest(common.HeatTestCase):
{'NetworkInterfaceId': 'd1e9c73c-04fe-4e9e-983c-d5ef94cd1a46',
'DeviceIndex': '1'}]
instance.t['Properties']['NetworkInterfaces'] = old_interfaces
update_template = copy.deepcopy(instance.t)
update_template['Properties']['NetworkInterfaces'] = new_interfaces
before_props = self.instance_props.copy()
before_props['NetworkInterfaces'] = old_interfaces
update_props = self.instance_props.copy()
update_props['NetworkInterfaces'] = new_interfaces
update_template = instance.t.freeze(properties=update_props)
instance.t = instance.t.freeze(properties=before_props)
instance.reparse()
self.m.StubOutWithMock(self.fc.servers, 'get')
self.fc.servers.get('1234').MultipleTimes().AndReturn(return_server)
@ -1001,8 +1020,9 @@ class InstancesTest(common.HeatTestCase):
'c4485ba1-283a-4f5f-8868-0cd46cdda52f',
'10.0.0.4')
update_template = copy.deepcopy(instance.t)
update_template['Properties']['NetworkInterfaces'] = new_interfaces
update_props = self.instance_props.copy()
update_props['NetworkInterfaces'] = new_interfaces
update_template = instance.t.freeze(properties=update_props)
self.m.StubOutWithMock(self.fc.servers, 'get')
self.fc.servers.get('1234').MultipleTimes().AndReturn(return_server)
@ -1037,8 +1057,9 @@ class InstancesTest(common.HeatTestCase):
'c4485ba1-283a-4f5f-8868-0cd46cdda52f',
'10.0.0.4')
update_template = copy.deepcopy(instance.t)
update_template['Properties']['NetworkInterfaces'] = []
update_props = self.instance_props.copy()
update_props['NetworkInterfaces'] = []
update_template = instance.t.freeze(properties=update_props)
self.m.StubOutWithMock(self.fc.servers, 'get')
self.fc.servers.get('1234').MultipleTimes().AndReturn(return_server)
@ -1069,12 +1090,18 @@ class InstancesTest(common.HeatTestCase):
'10.0.0.4')
subnet_id = '8c1aaddf-e49e-4f28-93ea-ca9f0b3c6240'
nics = [{'port-id': 'ea29f957-cd35-4364-98fb-57ce9732c10d'}]
before_props = self.instance_props.copy()
if old_interfaces is not None:
instance.t['Properties']['NetworkInterfaces'] = old_interfaces
update_template = copy.deepcopy(instance.t)
before_props['NetworkInterfaces'] = old_interfaces
update_props = self.instance_props.copy()
if new_interfaces is not None:
update_template['Properties']['NetworkInterfaces'] = new_interfaces
update_template['Properties']['SubnetId'] = subnet_id
update_props['NetworkInterfaces'] = new_interfaces
update_props['SubnetId'] = subnet_id
update_template = instance.t.freeze(properties=update_props)
instance.t = instance.t.freeze(properties=before_props)
instance.reparse()
self.m.StubOutWithMock(self.fc.servers, 'get')
@ -1133,8 +1160,9 @@ class InstancesTest(common.HeatTestCase):
self.stub_ImageConstraint_validate()
self.m.ReplayAll()
update_template = copy.deepcopy(instance.t)
update_template['Properties']['ImageId'] = 'mustreplace'
update_props = self.instance_props.copy()
update_props['ImageId'] = 'mustreplace'
update_template = instance.t.freeze(properties=update_props)
updater = scheduler.TaskRunner(instance.update, update_template)
self.assertRaises(exception.UpdateReplace, updater)

@ -228,12 +228,12 @@ class instancesTest(common.HeatTestCase):
# need to resolve the template functions
server_userdata = instance.client_plugin().build_userdata(
metadata,
instance.t['Properties']['UserData'],
instance.properties['UserData'],
'ec2-user')
self.m.StubOutWithMock(nova.NovaClientPlugin, 'build_userdata')
nova.NovaClientPlugin.build_userdata(
metadata,
instance.t['Properties']['UserData'],
instance.properties['UserData'],
'ec2-user').AndReturn(server_userdata)
self.m.StubOutWithMock(self.fc.servers, 'create')
@ -288,12 +288,12 @@ class instancesTest(common.HeatTestCase):
# need to resolve the template functions
server_userdata = instance.client_plugin().build_userdata(
metadata,
instance.t['Properties']['UserData'],
instance.properties['UserData'],
'ec2-user')
self.m.StubOutWithMock(nova.NovaClientPlugin, 'build_userdata')
nova.NovaClientPlugin.build_userdata(
metadata,
instance.t['Properties']['UserData'],
instance.properties['UserData'],
'ec2-user').AndReturn(server_userdata)
self.m.StubOutWithMock(self.fc.servers, 'create')

@ -128,27 +128,25 @@ class LoadBalancerTest(common.HeatTestCase):
md.metadata_set.assert_called_once_with(expected_md)
def test_loadbalancer_validate_hchk_good(self):
rsrc = self.setup_loadbalancer()
rsrc._parse_nested_stack = mock.Mock()
hc = {
'Target': 'HTTP:80/',
'HealthyThreshold': '3',
'UnhealthyThreshold': '5',
'Interval': '30',
'Timeout': '5'}
rsrc.t['Properties']['HealthCheck'] = hc
rsrc = self.setup_loadbalancer(hc=hc)
rsrc._parse_nested_stack = mock.Mock()
self.assertIsNone(rsrc.validate())
def test_loadbalancer_validate_hchk_int_gt_tmo(self):
rsrc = self.setup_loadbalancer()
rsrc._parse_nested_stack = mock.Mock()
hc = {
'Target': 'HTTP:80/',
'HealthyThreshold': '3',
'UnhealthyThreshold': '5',
'Interval': '30',
'Timeout': '35'}
rsrc.t['Properties']['HealthCheck'] = hc
rsrc = self.setup_loadbalancer(hc=hc)
rsrc._parse_nested_stack = mock.Mock()
self.assertEqual(
{'Error': 'Interval must be larger than Timeout'},
rsrc.validate())
@ -159,12 +157,15 @@ class LoadBalancerTest(common.HeatTestCase):
rsrc = self.setup_loadbalancer()
self.assertRaises(exception.StackValidationFailed, rsrc.validate)
def setup_loadbalancer(self, include_magic=True, cache_data=None):
def setup_loadbalancer(self, include_magic=True, cache_data=None, hc=None):
template = template_format.parse(lb_template)
if not include_magic:
del template['Parameters']['KeyName']
del template['Parameters']['LbFlavor']
del template['Parameters']['LbImageId']
if hc is not None:
props = template['Resources']['LoadBalancer']['Properties']
props['HealthCheck'] = hc
self.stack = utils.parse_stack(template, cache_data=cache_data)
resource_name = 'LoadBalancer'

@ -192,7 +192,7 @@ def setup_mocks(mocks, stack, mock_image_constraint=True,
metadata = instance.metadata_get()
if mock_image_constraint:
setup_mock_for_image_constraint(mocks,
instance.t['Properties']['ImageId'])
instance.properties['ImageId'])
if mock_keystone:
setup_keystone_mocks(mocks, stack)
@ -203,7 +203,7 @@ def setup_mocks(mocks, stack, mock_image_constraint=True,
mocks.StubOutWithMock(nova.NovaClientPlugin, 'build_userdata')
nova.NovaClientPlugin.build_userdata(
metadata,
instance.t['Properties']['UserData'],
user_data,
'ec2-user').AndReturn(server_userdata)
mocks.StubOutWithMock(fc.servers, 'create')

@ -11,8 +11,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import copy
import mock
import six
@ -87,8 +85,10 @@ class TestOrder(common.HeatTestCase):
self.assertEqual(256, args['bit_length'])
def test_create_order_without_type_fail(self):
snippet = copy.deepcopy(self.res_template)
del snippet['Properties']['type']
props = self.props.copy()
del props['type']
snippet = self.res_template.freeze(properties=props)
self.assertRaisesRegexp(exception.ResourceFailure,
'Property type not assigned',
self._create_resource,
@ -96,9 +96,10 @@ class TestOrder(common.HeatTestCase):
snippet, self.stack)
def test_validate_non_certificate_order(self):
snippet = copy.deepcopy(self.res_template)
del snippet['Properties']['bit_length']
del snippet['Properties']['algorithm']
props = self.props.copy()
del props['bit_length']
del props['algorithm']
snippet = self.res_template.freeze(properties=props)
res = self._create_resource('test', snippet, self.stack)
msg = ("Properties algorithm and bit_length are required for "
"key type of order.")
@ -107,9 +108,10 @@ class TestOrder(common.HeatTestCase):
res.validate)
def test_validate_certificate_with_profile_without_ca_id(self):
snippet = copy.deepcopy(self.res_template)
snippet['Properties']['profile'] = 'cert'
snippet['Properties']['type'] = 'certificate'
props = self.props.copy()
props['profile'] = 'cert'
props['type'] = 'certificate'
snippet = self.res_template.freeze(properties=props)
res = self._create_resource('test', snippet, self.stack)
msg = ("profile cannot be specified without ca_id.")
self.assertRaisesRegexp(exception.ResourcePropertyDependency,
@ -117,8 +119,9 @@ class TestOrder(common.HeatTestCase):
res.validate)
def test_key_order_validation_fail(self):
snippet = copy.deepcopy(self.res_template)
snippet['Properties']['pass_phrase'] = "something"
props = self.props.copy()
props['pass_phrase'] = "something"
snippet = self.res_template.freeze(properties=props)
res = self._create_resource('test', snippet, self.stack)
msg = ("Unexpected properties: pass_phrase. Only these properties "
"are allowed for key type of order: algorithm, "
@ -128,8 +131,9 @@ class TestOrder(common.HeatTestCase):
res.validate)
def test_certificate_validation_fail(self):
snippet = copy.deepcopy(self.res_template)
snippet['Properties']['type'] = 'certificate'
props = self.props.copy()
props['type'] = 'certificate'
snippet = self.res_template.freeze(properties=props)
res = self._create_resource('test', snippet, self.stack)
msg = ("Unexpected properties: algorithm, bit_length, mode. Only "
"these properties are allowed for certificate type of order: "
@ -140,9 +144,10 @@ class TestOrder(common.HeatTestCase):
res.validate)
def test_asymmetric_order_validation_fail(self):
snippet = copy.deepcopy(self.res_template)
snippet['Properties']['type'] = 'asymmetric'
snippet['Properties']['subject_dn'] = 'asymmetric'
props = self.props.copy()
props['type'] = 'asymmetric'
props['subject_dn'] = 'asymmetric'
snippet = self.res_template.freeze(properties=props)
res = self._create_resource('test', snippet, self.stack)
msg = ("Unexpected properties: subject_dn. Only these properties are "
"allowed for asymmetric type of order: algorithm, bit_length, "

@ -668,8 +668,8 @@ class CombinationAlarmTest(common.HeatTestCase):
time_constraints=[],
severity='low'
).AndReturn(FakeCeilometerAlarm())
snippet = template_format.parse(combination_alarm_template)
self.stack = utils.parse_stack(snippet)
self.tmpl = template_format.parse(combination_alarm_template)
self.stack = utils.parse_stack(self.tmpl)
resource_defns = self.stack.t.resource_definitions(self.stack)
return alarm.CombinationAlarm(
'CombinAlarm', resource_defns['CombinAlarm'], self.stack)
@ -707,8 +707,9 @@ class CombinationAlarmTest(common.HeatTestCase):
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
update_template = copy.deepcopy(rsrc.t)
update_template['Properties']['alarm_ids'] = ['alarm1', 'alarm3']
props = self.tmpl['Resources']['CombinAlarm']['Properties'].copy()
props['alarm_ids'] = ['alarm1', 'alarm3']
update_template = rsrc.t.freeze(properties=props)
scheduler.TaskRunner(rsrc.update, update_template)()
self.assertEqual((rsrc.UPDATE, rsrc.COMPLETE), rsrc.state)

@ -11,8 +11,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import copy