Unit tests: Always use ResourceDefinition for updates

Change-Id: I85ab9d0a3ed824020c7a38f7a814e7755a437b1a
This commit is contained in:
Zane Bitter 2014-06-16 11:05:16 -04:00
parent a5b78a2e0a
commit ead7117331
14 changed files with 251 additions and 115 deletions

View File

@ -16,6 +16,7 @@ from heat.common import template_format
from heat.engine import parser
from heat.engine import resource
from heat.engine import scheduler
from heat.engine import template
from heat.tests.common import HeatTestCase
from heat.tests import utils
@ -202,9 +203,10 @@ class MarconiMessageQueueTest(HeatTestCase):
t = template_format.parse(wp_template)
new_queue = t['Resources']['MyQueue2']
new_queue['Properties']['metadata'] = {'key1': 'value'}
resource_defns = template.Template(t).resource_definitions(self.stack)
scheduler.TaskRunner(queue.create)()
scheduler.TaskRunner(queue.update, new_queue)()
scheduler.TaskRunner(queue.update, resource_defns['MyQueue2'])()
self.m.VerifyAll()
def test_update_replace(self):
@ -223,7 +225,8 @@ class MarconiMessageQueueTest(HeatTestCase):
t = template_format.parse(wp_template)
t['Resources']['MyQueue2']['Properties']['name'] = 'new_queue'
new_queue = t['Resources']['MyQueue2']
resource_defns = template.Template(t).resource_definitions(self.stack)
new_queue = resource_defns['MyQueue2']
scheduler.TaskRunner(queue.create)()
err = self.assertRaises(resource.UpdateReplace,

View File

@ -18,6 +18,7 @@ from heat.common import exception
from heat.common import template_format
from heat.engine import clients
from heat.engine import resource
from heat.engine import rsrc_defn
from heat.engine import scheduler
from heat.tests.common import HeatTestCase
from heat.tests import utils
@ -315,8 +316,11 @@ Resources:
self._setup_test_stack()
resource = self.stack['my_group']
new_template = copy.deepcopy(resource.parsed_template())
new_template['Properties']['groupConfiguration']['minEntities'] = 5
uprops = copy.deepcopy(dict(resource.properties.data))
uprops['groupConfiguration']['minEntities'] = 5
new_template = rsrc_defn.ResourceDefinition(resource.name,
resource.type(),
uprops)
scheduler.TaskRunner(resource.update, new_template)()
self.assertEqual(1, len(self.fake_auto_scale.groups))
@ -331,9 +335,13 @@ Resources:
self._setup_test_stack()
resource = self.stack['my_group']
new_template = copy.deepcopy(resource.parsed_template())
lcargs = new_template['Properties']['launchConfiguration']['args']
uprops = copy.deepcopy(dict(resource.properties.data))
lcargs = uprops['launchConfiguration']['args']
lcargs['loadBalancers'] = [{'loadBalancerId': '1', 'port': 80}]
new_template = rsrc_defn.ResourceDefinition(resource.name,
resource.type(),
uprops)
scheduler.TaskRunner(resource.update, new_template)()
self.assertEqual(1, len(self.fake_auto_scale.groups))
@ -505,9 +513,12 @@ class PolicyTest(HeatTestCase):
"""
self._setup_test_stack(self.policy_template)
resource = self.stack['my_policy']
template = copy.deepcopy(resource.parsed_template())
template['Properties']['changePercent'] = 50
del template['Properties']['change']
uprops = copy.deepcopy(dict(resource.properties.data))
uprops['changePercent'] = 50
del uprops['change']
template = rsrc_defn.ResourceDefinition(resource.name,
resource.type(),
uprops)
scheduler.TaskRunner(resource.update, template)()
self.assertEqual(
@ -595,9 +606,12 @@ class WebHookTest(HeatTestCase):
def test_update(self):
self._setup_test_stack(self.webhook_template)
resource = self.stack['my_webhook']
template = copy.deepcopy(resource.parsed_template())
template['Properties']['metadata']['a'] = 'different!'
template['Properties']['name'] = 'newhook'
uprops = copy.deepcopy(dict(resource.properties.data))
uprops['metadata']['a'] = 'different!'
uprops['name'] = 'newhook'
template = rsrc_defn.ResourceDefinition(resource.name,
resource.type(),
uprops)
scheduler.TaskRunner(resource.update, template)()
self.assertEqual(

View File

@ -11,13 +11,13 @@
# License for the specific language governing permissions and limitations
# under the License.
import copy
import uuid
from heat.common import template_format
from heat.engine import environment
from heat.engine import parser
from heat.engine import resource
from heat.engine import rsrc_defn
from heat.engine import scheduler
from heat.tests import common
from heat.tests import utils
@ -224,12 +224,17 @@ class RackspaceDnsTest(common.HeatTestCase):
updateRecords,
**update_args)
ut = copy.deepcopy(instance.parsed_template())
ut['Properties']['emailAddress'] = 'updatedEmail@example.com'
ut['Properties']['ttl'] = 5555
ut['Properties']['comment'] = 'updated comment'
uprops = dict(instance.properties)
uprops.update({
'emailAddress': 'updatedEmail@example.com',
'ttl': 5555,
'comment': 'updated comment',
})
if updateRecords:
ut['Properties']['records'] = updateRecords
uprops['records'] = updateRecords
ut = rsrc_defn.ResourceDefinition(instance.name,
instance.type(),
uprops)
scheduler.TaskRunner(instance.update, ut)()
self.assertEqual((instance.UPDATE, instance.COMPLETE), instance.state)

View File

@ -496,6 +496,8 @@ class Resource(object):
'''
action = self.UPDATE
assert isinstance(after, rsrc_defn.ResourceDefinition)
(cur_class_def, cur_ver) = self.implementation_signature()
prev_ver = cur_ver
if prev_resource is not None:

View File

@ -284,8 +284,11 @@ class AutoScalingTest(HeatTestCase):
self.assertEqual(1, len(instance_names))
# Reduce the min size to 0, should complete without adjusting
update_snippet = copy.deepcopy(rsrc.parsed_template())
update_snippet['Properties']['MinSize'] = '0'
props = copy.copy(rsrc.properties.data)
props['MinSize'] = '0'
update_snippet = rsrc_defn.ResourceDefinition(rsrc.name,
rsrc.type(),
props)
scheduler.TaskRunner(rsrc.update, update_snippet)()
self.assertEqual(instance_names, rsrc.get_instance_names())
@ -314,8 +317,11 @@ class AutoScalingTest(HeatTestCase):
self.assertEqual(utils.PhysName(stack.name, rsrc.name),
rsrc.FnGetRefId())
self.assertEqual(1, len(rsrc.get_instance_names()))
update_snippet = copy.deepcopy(rsrc.parsed_template())
update_snippet['Properties']['AvailabilityZones'] = ['foo']
props = copy.copy(rsrc.properties.data)
props['AvailabilityZones'] = ['foo']
update_snippet = rsrc_defn.ResourceDefinition(rsrc.name,
rsrc.type(),
props)
updater = scheduler.TaskRunner(rsrc.update, update_snippet)
self.assertRaises(resource.UpdateReplace, updater)
@ -584,8 +590,11 @@ class AutoScalingTest(HeatTestCase):
instance_names = rsrc.get_instance_names()
# Reduce the max size to 2, should complete without adjusting
update_snippet = copy.deepcopy(rsrc.parsed_template())
update_snippet['Properties']['MaxSize'] = '2'
props = copy.copy(rsrc.properties.data)
props['MaxSize'] = '2'
update_snippet = rsrc_defn.ResourceDefinition(rsrc.name,
rsrc.type(),
props)
scheduler.TaskRunner(rsrc.update, update_snippet)()
self.assertEqual(instance_names, rsrc.get_instance_names())
self.assertEqual(2, rsrc.properties['MaxSize'])
@ -614,8 +623,11 @@ class AutoScalingTest(HeatTestCase):
self._stub_create(1)
self.m.ReplayAll()
update_snippet = copy.deepcopy(rsrc.parsed_template())
update_snippet['Properties']['MinSize'] = '2'
props = copy.copy(rsrc.properties.data)
props['MinSize'] = '2'
update_snippet = rsrc_defn.ResourceDefinition(rsrc.name,
rsrc.type(),
props)
scheduler.TaskRunner(rsrc.update, update_snippet)()
self.assertEqual(2, len(rsrc.get_instance_names()))
self.assertEqual(2, rsrc.properties['MinSize'])
@ -644,8 +656,11 @@ class AutoScalingTest(HeatTestCase):
self._stub_create(1)
self.m.ReplayAll()
update_snippet = copy.deepcopy(rsrc.parsed_template())
update_snippet['Properties']['DesiredCapacity'] = '2'
props = copy.copy(rsrc.properties.data)
props['DesiredCapacity'] = '2'
update_snippet = rsrc_defn.ResourceDefinition(rsrc.name,
rsrc.type(),
props)
scheduler.TaskRunner(rsrc.update, update_snippet)()
self.assertEqual(2, len(rsrc.get_instance_names()))
self.assertEqual(2, rsrc.properties['DesiredCapacity'])
@ -674,9 +689,12 @@ class AutoScalingTest(HeatTestCase):
self._stub_delete(1)
self.m.ReplayAll()
update_snippet = copy.deepcopy(rsrc.parsed_template())
update_snippet['Properties']['MinSize'] = '0'
update_snippet['Properties']['DesiredCapacity'] = '0'
props = copy.copy(rsrc.properties.data)
props['MinSize'] = '0'
props['DesiredCapacity'] = '0'
update_snippet = rsrc_defn.ResourceDefinition(rsrc.name,
rsrc.type(),
props)
scheduler.TaskRunner(rsrc.update, update_snippet)()
self.assertEqual(0, len(rsrc.get_instance_names()))
self.assertEqual(0, rsrc.properties['DesiredCapacity'])
@ -701,8 +719,11 @@ class AutoScalingTest(HeatTestCase):
# Remove DesiredCapacity from the updated template, which should
# have no effect, it's an optional parameter
update_snippet = copy.deepcopy(rsrc.parsed_template())
del(update_snippet['Properties']['DesiredCapacity'])
props = copy.copy(rsrc.properties.data)
del props['DesiredCapacity']
update_snippet = rsrc_defn.ResourceDefinition(rsrc.name,
rsrc.type(),
props)
scheduler.TaskRunner(rsrc.update, update_snippet)()
self.assertEqual(instance_names, rsrc.get_instance_names())
self.assertIsNone(rsrc.properties['DesiredCapacity'])
@ -726,8 +747,12 @@ class AutoScalingTest(HeatTestCase):
self.assertEqual(utils.PhysName(stack.name, rsrc.name),
rsrc.FnGetRefId())
self.assertEqual(1, len(rsrc.get_instance_names()))
update_snippet = copy.deepcopy(rsrc.parsed_template())
update_snippet['Properties']['Cooldown'] = '61'
props = copy.copy(rsrc.properties.data)
props['Cooldown'] = '61'
update_snippet = rsrc_defn.ResourceDefinition(rsrc.name,
rsrc.type(),
props)
scheduler.TaskRunner(rsrc.update, update_snippet)()
self.assertEqual(61, rsrc.properties['Cooldown'])
@ -771,8 +796,11 @@ class AutoScalingTest(HeatTestCase):
self.assertEqual(utils.PhysName(stack.name, rsrc.name),
rsrc.FnGetRefId())
self.assertEqual(1, len(rsrc.get_instance_names()))
update_snippet = copy.deepcopy(rsrc.parsed_template())
update_snippet['Properties']['Cooldown'] = '61'
props = copy.copy(rsrc.properties.data)
props['Cooldown'] = '61'
update_snippet = rsrc_defn.ResourceDefinition(rsrc.name,
rsrc.type(),
props)
scheduler.TaskRunner(rsrc.update, update_snippet)()
rsrc.delete()
@ -1557,8 +1585,11 @@ class AutoScalingTest(HeatTestCase):
self.assertEqual(2, len(rsrc.get_instance_names()))
# Update scaling policy
update_snippet = copy.deepcopy(up_policy.parsed_template())
update_snippet['Properties']['ScalingAdjustment'] = '2'
props = copy.copy(up_policy.properties.data)
props['ScalingAdjustment'] = '2'
update_snippet = rsrc_defn.ResourceDefinition(up_policy.name,
up_policy.type(),
props)
scheduler.TaskRunner(up_policy.update, update_snippet)()
self.assertEqual(2, up_policy.properties['ScalingAdjustment'])

View File

@ -25,6 +25,7 @@ from heat.engine import parser
from heat.engine.properties import schemata
from heat.engine import resource
from heat.engine.resources.ceilometer import alarm
from heat.engine import rsrc_defn
from heat.engine import scheduler
from heat.engine import stack_user
from heat.openstack.common.importutils import try_import
@ -193,18 +194,23 @@ class CeilometerAlarmTest(HeatTestCase):
self.stack.create()
rsrc = self.stack['MEMAlarmHigh']
snippet = copy.deepcopy(rsrc.parsed_template())
snippet['Properties']['comparison_operator'] = 'lt'
snippet['Properties']['description'] = 'fruity'
snippet['Properties']['evaluation_periods'] = '2'
snippet['Properties']['period'] = '90'
snippet['Properties']['enabled'] = 'true'
snippet['Properties']['repeat_actions'] = True
snippet['Properties']['statistic'] = 'max'
snippet['Properties']['threshold'] = '39'
snippet['Properties']['insufficient_data_actions'] = []
snippet['Properties']['alarm_actions'] = []
snippet['Properties']['ok_actions'] = ['signal_handler']
props = copy.copy(rsrc.properties.data)
props.update({
'comparison_operator': 'lt',
'description': 'fruity',
'evaluation_periods': '2',
'period': '90',
'enabled': 'true',
'repeat_actions': True,
'statistic': 'max',
'threshold': '39',
'insufficient_data_actions': [],
'alarm_actions': [],
'ok_actions': ['signal_handler'],
})
snippet = rsrc_defn.ResourceDefinition(rsrc.name,
rsrc.type(),
props)
scheduler.TaskRunner(rsrc.update, snippet)()
@ -226,8 +232,11 @@ class CeilometerAlarmTest(HeatTestCase):
self.stack.create()
rsrc = self.stack['MEMAlarmHigh']
snippet = copy.deepcopy(rsrc.parsed_template())
snippet['Properties']['meter_name'] = 'temp'
props = copy.copy(rsrc.properties.data)
props['meter_name'] = 'temp'
snippet = rsrc_defn.ResourceDefinition(rsrc.name,
rsrc.type(),
props)
updater = scheduler.TaskRunner(rsrc.update, snippet)
self.assertRaises(resource.UpdateReplace, updater)

View File

@ -17,6 +17,7 @@ import copy
from heat.common import template_format
from heat.engine import resource
from heat.engine.resources import cloud_watch
from heat.engine import rsrc_defn
from heat.engine import scheduler
from heat.engine import watchrule
from heat.tests.common import HeatTestCase
@ -81,13 +82,18 @@ class CloudWatchAlarmTest(HeatTestCase):
self.m.ReplayAll()
rsrc = self.create_alarm(t, stack, 'MEMAlarmHigh')
snippet = copy.deepcopy(rsrc.parsed_template())
snippet['Properties']['ComparisonOperator'] = 'LessThanThreshold'
snippet['Properties']['AlarmDescription'] = 'fruity'
snippet['Properties']['EvaluationPeriods'] = '2'
snippet['Properties']['Period'] = '90'
snippet['Properties']['Statistic'] = 'Maximum'
snippet['Properties']['Threshold'] = '39'
props = copy.copy(rsrc.properties.data)
props.update({
'ComparisonOperator': 'LessThanThreshold',
'AlarmDescription': 'fruity',
'EvaluationPeriods': '2',
'Period': '90',
'Statistic': 'Maximum',
'Threshold': '39',
})
snippet = rsrc_defn.ResourceDefinition(rsrc.name,
rsrc.type(),
props)
scheduler.TaskRunner(rsrc.update, snippet)()
@ -112,8 +118,11 @@ class CloudWatchAlarmTest(HeatTestCase):
self.m.ReplayAll()
rsrc = self.create_alarm(t, stack, 'MEMAlarmHigh')
snippet = copy.deepcopy(rsrc.parsed_template())
snippet['Properties']['MetricName'] = 'temp'
props = copy.copy(rsrc.properties.data)
props['MetricName'] = 'temp'
snippet = rsrc_defn.ResourceDefinition(rsrc.name,
rsrc.type(),
props)
updater = scheduler.TaskRunner(rsrc.update, snippet)
self.assertRaises(resource.UpdateReplace, updater)

View File

@ -22,6 +22,7 @@ from heat.common import short_id
from heat.common import template_format
from heat.engine import clients
from heat.engine import resource
from heat.engine import rsrc_defn
from heat.engine import scheduler
from heat.engine import stack_resource
from heat.openstack.common import timeutils
@ -82,8 +83,11 @@ class AutoScalingGroupTest(HeatTestCase):
self.assertEqual(1, len(resources))
# Reduce the min size to 0, should complete without adjusting
update_snippet = copy.deepcopy(rsrc.parsed_template())
update_snippet['Properties']['min_size'] = 0
props = copy.copy(rsrc.properties.data)
props['min_size'] = 0
update_snippet = rsrc_defn.ResourceDefinition(rsrc.name,
rsrc.type(),
props)
scheduler.TaskRunner(rsrc.update, update_snippet)()
self.assertEqual(resources, rsrc.get_instances())
@ -132,8 +136,11 @@ class AutoScalingGroupTest(HeatTestCase):
self.assertEqual(1, len(resources))
# Reduce the max size to 2, should complete without adjusting
update_snippet = copy.deepcopy(rsrc.parsed_template())
update_snippet['Properties']['max_size'] = 2
props = copy.copy(rsrc.properties.data)
props['max_size'] = 2
update_snippet = rsrc_defn.ResourceDefinition(rsrc.name,
rsrc.type(),
props)
scheduler.TaskRunner(rsrc.update, update_snippet)()
self.assertEqual(resources, rsrc.get_instances())
self.assertEqual(2, rsrc.properties['max_size'])
@ -146,8 +153,11 @@ class AutoScalingGroupTest(HeatTestCase):
rsrc = self.create_stack(self.parsed)['my-group']
self.assertEqual(1, len(rsrc.get_instances()))
update_snippet = copy.deepcopy(rsrc.parsed_template())
update_snippet['Properties']['min_size'] = 2
props = copy.copy(rsrc.properties.data)
props['min_size'] = 2
update_snippet = rsrc_defn.ResourceDefinition(rsrc.name,
rsrc.type(),
props)
scheduler.TaskRunner(rsrc.update, update_snippet)()
self.assertEqual(2, len(rsrc.get_instances()))
self.assertEqual(2, rsrc.properties['min_size'])
@ -159,8 +169,11 @@ class AutoScalingGroupTest(HeatTestCase):
rsrc = self.create_stack(self.parsed)['my-group']
self.assertEqual(1, len(rsrc.get_instances()))
update_snippet = copy.deepcopy(rsrc.parsed_template())
update_snippet['Properties']['desired_capacity'] = 2
props = copy.copy(rsrc.properties.data)
props['desired_capacity'] = 2
update_snippet = rsrc_defn.ResourceDefinition(rsrc.name,
rsrc.type(),
props)
scheduler.TaskRunner(rsrc.update, update_snippet)()
self.assertEqual(2, len(rsrc.get_instances()))
self.assertEqual(2, rsrc.properties['desired_capacity'])
@ -172,8 +185,11 @@ class AutoScalingGroupTest(HeatTestCase):
resources = rsrc.get_instances()
self.assertEqual(2, len(resources))
update_snippet = copy.deepcopy(rsrc.parsed_template())
update_snippet['Properties'].pop('desired_capacity')
props = copy.copy(rsrc.properties.data)
props.pop('desired_capacity')
update_snippet = rsrc_defn.ResourceDefinition(rsrc.name,
rsrc.type(),
props)
scheduler.TaskRunner(rsrc.update, update_snippet)()
self.assertEqual(resources, rsrc.get_instances())
self.assertIsNone(rsrc.properties['desired_capacity'])
@ -429,14 +445,18 @@ class RollingUpdatesTest(HeatTestCase):
definitions = tmpl.resource_definitions(stack)
templates = [definitions[name] for name in created_order]
batches.append(templates)
patcher = mock.patch.object(
stack_resource.StackResource, 'update_with_template',
side_effect=update_with_template, wraps=rsrc.update_with_template)
patcher.start()
self.addCleanup(patcher.stop)
update_snippet = copy.deepcopy(rsrc.parsed_template())
update_snippet['Properties']['resource']['properties']['Foo'] = 'Hi'
props = copy.deepcopy(rsrc.properties.data)
props['resource']['properties']['Foo'] = 'Hi'
update_snippet = rsrc_defn.ResourceDefinition(rsrc.name,
rsrc.type(),
props)
scheduler.TaskRunner(rsrc.update, update_snippet)()
props_schema = generic_resource.ResourceWithProps.properties_schema

View File

@ -23,6 +23,7 @@ from heat.engine import resources
from heat.engine.resources import image
from heat.engine.resources import instance
from heat.engine.resources import nova_keypair
from heat.engine import rsrc_defn
from heat.engine import scheduler
from heat.tests.common import HeatTestCase
from heat.tests import utils
@ -281,8 +282,11 @@ class InstanceGroupTest(HeatTestCase):
self.m.ReplayAll()
update_snippet = copy.deepcopy(rsrc.parsed_template())
update_snippet['Properties']['Size'] = '2'
props = copy.copy(rsrc.properties.data)
props['Size'] = '2'
update_snippet = rsrc_defn.ResourceDefinition(rsrc.name,
rsrc.type(),
props)
updater = scheduler.TaskRunner(rsrc.update, update_snippet)
self.assertRaises(exception.ResourceFailure, updater)
@ -310,8 +314,11 @@ class InstanceGroupTest(HeatTestCase):
self.m.ReplayAll()
update_snippet = copy.deepcopy(rsrc.parsed_template())
update_snippet['Properties']['AvailabilityZones'] = ['wibble']
props = copy.copy(rsrc.properties.data)
props['AvailabilityZones'] = ['wibble']
update_snippet = rsrc_defn.ResourceDefinition(rsrc.name,
rsrc.type(),
props)
updater = scheduler.TaskRunner(rsrc.update, update_snippet)
self.assertRaises(resource.UpdateReplace, updater)

View File

@ -26,6 +26,7 @@ from heat.engine.resources.neutron import neutron_utils
from heat.engine.resources.neutron import provider_net
from heat.engine.resources.neutron import router
from heat.engine.resources.neutron import subnet
from heat.engine import rsrc_defn
from heat.engine import scheduler
from heat.openstack.common.importutils import try_import
from heat.tests.common import HeatTestCase
@ -2139,27 +2140,34 @@ class NeutronFloatingIPTest(HeatTestCase):
self.assertEqual('%s:%s' % (fip_id, port_id), fipa_id)
# test update FloatingIpAssociation with port_id
update_snippet = copy.deepcopy(fipa.parsed_template())
props = copy.deepcopy(fipa.properties.data)
update_port_id = '2146dfbf-ba77-4083-8e86-d052f671ece5'
update_snippet['Properties']['port_id'] = update_port_id
props['port_id'] = update_port_id
update_snippet = rsrc_defn.ResourceDefinition(fipa.name, fipa.type(),
stack.t.parse(stack,
props))
scheduler.TaskRunner(fipa.update, update_snippet)()
self.assertEqual((fipa.UPDATE, fipa.COMPLETE), fipa.state)
# test update FloatingIpAssociation with floatingip_id
update_snippet = copy.deepcopy(fipa.parsed_template())
props = copy.deepcopy(fipa.properties.data)
update_flip_id = '2146dfbf-ba77-4083-8e86-d052f671ece5'
update_snippet['Properties']['floatingip_id'] = update_flip_id
props['floatingip_id'] = update_flip_id
update_snippet = rsrc_defn.ResourceDefinition(fipa.name, fipa.type(),
props)
scheduler.TaskRunner(fipa.update, update_snippet)()
self.assertEqual((fipa.UPDATE, fipa.COMPLETE), fipa.state)
# test update FloatingIpAssociation with port_id and floatingip_id
update_snippet = copy.deepcopy(fipa.parsed_template())
props = copy.deepcopy(fipa.properties.data)
update_flip_id = 'fc68ea2c-b60b-4b4f-bd82-94ec81110766'
update_port_id = 'ade6fcac-7d47-416e-a3d7-ad12efe445c1'
update_snippet['Properties']['floatingip_id'] = update_flip_id
update_snippet['Properties']['port_id'] = update_port_id
props['floatingip_id'] = update_flip_id
props['port_id'] = update_port_id
update_snippet = rsrc_defn.ResourceDefinition(fipa.name, fipa.type(),
props)
scheduler.TaskRunner(fipa.update, update_snippet)()
self.assertEqual((fipa.UPDATE, fipa.COMPLETE), fipa.state)

View File

@ -21,6 +21,7 @@ from heat.common import template_format
from heat.engine import clients
from heat.engine.resources.nova_floatingip import NovaFloatingIp
from heat.engine.resources.nova_floatingip import NovaFloatingIpAssociation
from heat.engine import rsrc_defn
from heat.engine import scheduler
from heat.tests.common import HeatTestCase
from heat.tests import utils
@ -218,9 +219,11 @@ class NovaFloatingIPTest(HeatTestCase):
scheduler.TaskRunner(rsrc.create)()
self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
# update with the new server_id
update_snippet = copy.deepcopy(rsrc.parsed_template())
props = copy.deepcopy(rsrc.properties.data)
update_server_id = '2146dfbf-ba77-4083-8e86-d052f671ece5'
update_snippet['Properties']['server_id'] = update_server_id
props['server_id'] = update_server_id
update_snippet = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(),
props)
scheduler.TaskRunner(rsrc.update, update_snippet)()
self.assertEqual((rsrc.UPDATE, rsrc.COMPLETE), rsrc.state)
@ -259,9 +262,10 @@ class NovaFloatingIPTest(HeatTestCase):
scheduler.TaskRunner(rsrc.create)()
self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
# update with the new floatingip
update_snippet = copy.deepcopy(rsrc.parsed_template())
update_flip_id = '2'
update_snippet['Properties']['floating_ip'] = update_flip_id
props = copy.deepcopy(rsrc.properties.data)
props['floating_ip'] = '2'
update_snippet = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(),
props)
scheduler.TaskRunner(rsrc.update, update_snippet)()
self.assertEqual((rsrc.UPDATE, rsrc.COMPLETE), rsrc.state)
@ -300,11 +304,12 @@ class NovaFloatingIPTest(HeatTestCase):
scheduler.TaskRunner(rsrc.create)()
self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
# update with the new floatingip
update_snippet = copy.deepcopy(rsrc.parsed_template())
update_flip_id = '2'
props = copy.deepcopy(rsrc.properties.data)
update_server_id = '2146dfbf-ba77-4083-8e86-d052f671ece5'
update_snippet['Properties']['floating_ip'] = update_flip_id
update_snippet['Properties']['server_id'] = update_server_id
props['server_id'] = update_server_id
props['floating_ip'] = '2'
update_snippet = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(),
props)
scheduler.TaskRunner(rsrc.update, update_snippet)()
self.assertEqual((rsrc.UPDATE, rsrc.COMPLETE), rsrc.state)

View File

@ -238,7 +238,8 @@ class ResourceTest(HeatTestCase):
'TestResource')
res = TestResource('test_resource', tmpl, self.stack)
utmpl = {'Type': 'TestResource', 'Properties': {'a_string': 'foo'}}
utmpl = rsrc_defn.ResourceDefinition('test_resource', 'TestResource',
{'a_string': 'foo'})
self.assertRaises(
resource.UpdateReplace, scheduler.TaskRunner(res.update, utmpl))

View File

@ -26,7 +26,9 @@ from heat.engine.resources import glance_utils
from heat.engine.resources import image
from heat.engine.resources import instance
from heat.engine.resources import volume as vol
from heat.engine import rsrc_defn
from heat.engine import scheduler
from heat.engine import template
from heat.openstack.common.importutils import try_import
from heat.tests.common import HeatTestCase
from heat.tests import utils
@ -520,11 +522,14 @@ class VolumeTest(HeatTestCase):
rsrc = self.create_attachment(t, stack, 'MountPoint')
self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
after = copy.deepcopy(t)['Resources']['MountPoint']
after_t = copy.deepcopy(t)
after = after_t['Resources']['MountPoint']
after['Properties']['VolumeId'] = 'vol-123'
after['Properties']['InstanceId'] = 'WikiDatabase'
after['Properties']['Device'] = '/dev/vdd'
scheduler.TaskRunner(rsrc.update, after)()
after_defs = template.Template(after_t).resource_definitions(stack)
scheduler.TaskRunner(rsrc.update, after_defs['MountPoint'])()
self.assertEqual((rsrc.UPDATE, rsrc.COMPLETE), rsrc.state)
self.m.VerifyAll()
@ -586,10 +591,13 @@ class VolumeTest(HeatTestCase):
rsrc = self.create_attachment(t, stack, 'MountPoint')
self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
after = copy.deepcopy(t)['Resources']['MountPoint']
after_t = copy.deepcopy(t)
after = after_t['Resources']['MountPoint']
after['Properties']['VolumeId'] = 'vol-456'
after['Properties']['InstanceId'] = 'WikiDatabase'
scheduler.TaskRunner(rsrc.update, after)()
after_defs = template.Template(after_t).resource_definitions(stack)
scheduler.TaskRunner(rsrc.update, after_defs['MountPoint'])()
self.assertEqual((rsrc.UPDATE, rsrc.COMPLETE), rsrc.state)
self.assertEqual(fv2a.id, rsrc.resource_id)
@ -634,11 +642,14 @@ class VolumeTest(HeatTestCase):
rsrc = self.create_attachment(t, stack, 'MountPoint')
self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
after = copy.deepcopy(t)['Resources']['MountPoint']
after_t = copy.deepcopy(t)
after = after_t['Resources']['MountPoint']
after['Properties']['VolumeId'] = 'vol-123'
after['Properties']['InstanceId'] = 'WikiDatabase2'
#after['Properties']['Device'] = '/dev/vdd'
scheduler.TaskRunner(rsrc.update, after)()
after_defs = template.Template(after_t).resource_definitions(stack)
scheduler.TaskRunner(rsrc.update, after_defs['MountPoint'])()
self.assertEqual((rsrc.UPDATE, rsrc.COMPLETE), rsrc.state)
self.m.VerifyAll()
@ -1051,8 +1062,9 @@ class VolumeTest(HeatTestCase):
rsrc = self.create_volume(t, stack, 'DataVolume')
self.assertEqual('available', fv.status)
after = copy.deepcopy(t)['Resources']['DataVolume']
after['Properties']['Size'] = 1
props = copy.deepcopy(rsrc.properties.data)
props['Size'] = 1
after = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(), props)
update_task = scheduler.TaskRunner(rsrc.update, after)
ex = self.assertRaises(exception.ResourceFailure, update_task)
@ -1084,8 +1096,9 @@ class VolumeTest(HeatTestCase):
rsrc = self.create_volume(t, stack, 'DataVolume')
self.assertEqual('available', fv.status)
after = copy.deepcopy(t)['Resources']['DataVolume']
after['Properties']['Size'] = 2
props = copy.deepcopy(rsrc.properties.data)
props['Size'] = 2
after = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(), props)
update_task = scheduler.TaskRunner(rsrc.update, after)
self.assertIsNone(update_task())
@ -1115,8 +1128,9 @@ class VolumeTest(HeatTestCase):
rsrc = self.create_volume(t, stack, 'DataVolume')
self.assertEqual('available', fv.status)
after = copy.deepcopy(t)['Resources']['DataVolume']
after['Properties']['Size'] = 2
props = copy.deepcopy(rsrc.properties.data)
props['Size'] = 2
after = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(), props)
update_task = scheduler.TaskRunner(rsrc.update, after)
self.assertRaises(exception.ResourceFailure, update_task)
@ -1146,8 +1160,9 @@ class VolumeTest(HeatTestCase):
rsrc = self.create_volume(t, stack, 'DataVolume')
self.assertEqual('available', fv.status)
after = copy.deepcopy(t)['Resources']['DataVolume']
after['Properties']['Size'] = 2
props = copy.deepcopy(rsrc.properties.data)
props['Size'] = 2
after = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(), props)
update_task = scheduler.TaskRunner(rsrc.update, after)
ex = self.assertRaises(exception.ResourceFailure, update_task)
@ -1206,8 +1221,9 @@ class VolumeTest(HeatTestCase):
self.assertEqual('available', fv.status)
self.create_attachment(t, stack, 'MountPoint')
after = copy.deepcopy(t)['Resources']['DataVolume']
after['Properties']['Size'] = 2
props = copy.deepcopy(rsrc.properties.data)
props['Size'] = 2
after = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(), props)
update_task = scheduler.TaskRunner(rsrc.update, after)
self.assertIsNone(update_task())
@ -1247,8 +1263,9 @@ class VolumeTest(HeatTestCase):
self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
self.assertEqual('available', fv.status)
after = copy.deepcopy(t)['Resources']['DataVolume']
after['Properties']['Size'] = 2
props = copy.deepcopy(rsrc.properties.data)
props['Size'] = 2
after = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(), props)
update_task = scheduler.TaskRunner(rsrc.update, after)
self.assertIsNone(update_task())

View File

@ -11,6 +11,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import copy
import datetime
import json
import time
@ -26,6 +27,7 @@ from heat.engine import environment
from heat.engine import parser
from heat.engine import resource
from heat.engine.resources import wait_condition as wc
from heat.engine import rsrc_defn
from heat.engine import scheduler
from heat.tests.common import HeatTestCase
from heat.tests import fakes
@ -611,8 +613,11 @@ class WaitConditionUpdateTest(HeatTestCase):
'Status': 'SUCCESS', 'UniqueId': '1'}
self._metadata_update(wait_condition_handle, test_metadata, 5)
update_snippet = rsrc.parsed_template()
update_snippet['Properties']['Count'] = '5'
uprops = copy.copy(rsrc.properties.data)
uprops['Count'] = '5'
update_snippet = rsrc_defn.ResourceDefinition(rsrc.name,
rsrc.type(),
uprops)
updater = scheduler.TaskRunner(rsrc.update, update_snippet)
updater()