Unit tests: Create resources with ResourceDefinition

Stop creating Resources with dicts that are snippets of templates, and
instead always use ResourceDefinition objects to create Resources.

Change-Id: I1587f1edf9b04f06bd435857d7c1ea2c1cc26058
This commit is contained in:
Zane Bitter 2014-05-30 15:36:29 -04:00
parent fd9506ef83
commit ff76cbd6d8
38 changed files with 763 additions and 522 deletions

View File

@ -16,6 +16,7 @@ import mock
from heat.common import exception
from heat.common import template_format
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
@ -43,10 +44,12 @@ class TestOrder(HeatTestCase):
super(TestOrder, self).setUp()
utils.setup_dummy_db()
self.ctx = utils.dummy_context()
self.stack = utils.parse_stack(template_format.parse(stack_template))
tmpl = template_format.parse(stack_template)
self.stack = utils.parse_stack(tmpl)
self.res_template = self.stack.t['resources']['order']
self.props = self.res_template['Properties']
resource_defns = self.stack.t.resource_definitions(self.stack)
self.res_template = resource_defns['order']
self.props = tmpl['resources']['order']['properties']
self._register_resources()
self.patcher_client = mock.patch.object(order.clients, 'Clients')
@ -118,14 +121,18 @@ class TestOrder(HeatTestCase):
def test_create_order_with_octet_stream(self):
content_type = 'application/octet-stream'
self.props['payload_content_type'] = content_type
res = self._create_resource('foo', self.res_template, self.stack)
defn = rsrc_defn.ResourceDefinition('foo', 'OS::Barbican::Order',
self.props)
res = self._create_resource(defn.name, defn, self.stack)
args = self.barbican.orders.create.call_args[1]
self.assertEqual(content_type, args[res.PAYLOAD_CONTENT_TYPE])
def test_create_order_other_content_types_now_allowed(self):
self.props['payload_content_type'] = 'not/allowed'
res = order.Order('order', self.res_template, self.stack)
defn = rsrc_defn.ResourceDefinition('order', 'OS::Barbican::Order',
self.props)
res = order.Order(defn.name, defn, self.stack)
self.assertRaises(exception.ResourceFailure,
scheduler.TaskRunner(res.create))

View File

@ -16,6 +16,7 @@ import mock
from heat.common import exception
from heat.common import template_format
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
@ -48,7 +49,8 @@ class TestSecret(HeatTestCase):
self._register_resources()
self.stack = utils.parse_stack(template_format.parse(stack_template))
self.stack.validate()
self.res_template = self.stack.t['resources']['secret']
resource_defns = self.stack.t.resource_definitions(self.stack)
self.res_template = resource_defns['secret']
self.res = self._create_resource('foo', self.res_template, self.stack)
def tearDown(self):
@ -93,9 +95,15 @@ class TestSecret(HeatTestCase):
def test_create_secret_with_plain_text(self):
content_type = 'text/plain'
self.res_template['Properties']['payload'] = 'foobar'
self.res_template['Properties']['payload_content_type'] = content_type
res = self._create_resource('secret', self.res_template, self.stack)
props = {
'name': 'secret',
'payload': 'foobar',
'payload_content_type': content_type,
}
defn = rsrc_defn.ResourceDefinition('secret',
'OS::Barbican::Secret',
props)
res = self._create_resource(defn.name, defn, self.stack)
args = self.barbican.secrets.store.call_args[1]
self.assertEqual('foobar', args[res.PAYLOAD])
@ -103,31 +111,45 @@ class TestSecret(HeatTestCase):
def test_create_secret_with_octet_stream(self):
content_type = 'application/octet-stream'
self.res_template['Properties']['payload'] = 'foobar'
self.res_template['Properties']['payload_content_type'] = content_type
res = self._create_resource('secret', self.res_template, self.stack)
props = {
'name': 'secret',
'payload': 'foobar',
'payload_content_type': content_type,
}
defn = rsrc_defn.ResourceDefinition('secret',
'OS::Barbican::Secret',
props)
res = self._create_resource(defn.name, defn, self.stack)
args = self.barbican.secrets.store.call_args[1]
self.assertEqual('foobar', args[res.PAYLOAD])
self.assertEqual(content_type, args[res.PAYLOAD_CONTENT_TYPE])
def test_create_secret_other_content_types_not_allowed(self):
self.res_template['Properties']['payload_content_type'] = 'not/allowed'
props = {
'name': 'secret',
'payload_content_type': 'not/allowed',
}
defn = rsrc_defn.ResourceDefinition('secret',
'OS::Barbican::Secret',
props)
self.assertRaises(exception.ResourceFailure,
self._create_resource, 'secret', self.res_template,
self._create_resource, defn.name, defn,
self.stack)
def test_validate_payload_and_content_type(self):
self.res_template['Properties'] = {}
self.res_template['Properties']['payload_content_type'] = 'text/plain'
res = self._create_resource('nopayload', self.res_template, self.stack)
props = {'payload_content_type': 'text/plain'}
defn = rsrc_defn.ResourceDefinition('nopayload',
'OS::Barbican::Secret',
props)
res = self._create_resource(defn.name, defn, self.stack)
exc = self.assertRaises(exception.StackValidationFailed, res.validate)
self.assertIn('payload', str(exc))
self.assertIn('payload_content_type', str(exc))
self.res_template['Properties'] = {}
self.res_template['Properties']['payload'] = 'foo'
res = self._create_resource('notype', self.res_template, self.stack)
defn = rsrc_defn.ResourceDefinition('notype', 'OS::Barbican::Secret',
{'payload': 'foo'})
res = self._create_resource(defn.name, defn, self.stack)
exc = self.assertRaises(exception.StackValidationFailed, res.validate)
self.assertIn('payload', str(exc))
self.assertIn('payload_content_type', str(exc))

View File

@ -56,7 +56,8 @@ class DockerContainerTest(HeatTestCase):
t = template_format.parse(template)
stack = utils.parse_stack(t)
resource = docker_container.DockerContainer(
resource_name, t['Resources'][resource_name], stack)
resource_name,
stack.t.resource_definitions(stack)[resource_name], stack)
self.m.StubOutWithMock(resource, 'get_client')
resource.get_client().MultipleTimes().AndReturn(FakeDockerClient())
self.assertIsNone(resource.validate())

View File

@ -74,7 +74,7 @@ class NeutronExtraRouteTest(HeatTestCase):
t['Resources'][resource_name]['Properties'] = properties
rsrc = extraroute.ExtraRoute(
resource_name,
t['Resources'][resource_name],
stack.t.resource_definitions(stack)[resource_name],
stack)
scheduler.TaskRunner(rsrc.create)()
self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)

View File

@ -215,9 +215,10 @@ class LoadBalancerTest(HeatTestCase):
.__getattribute__(name))
return super(LoadBalancerTest, self).__getattribute__(name)
def _mock_create(self, t, stack, resource_name, lb_name, lb_body):
def _mock_create(self, tmpl, stack, resource_name, lb_name, lb_body):
resource_defns = tmpl.resource_definitions(stack)
rsrc = LoadBalancerWithFakeClient(resource_name,
t['Resources'][resource_name],
resource_defns[resource_name],
stack)
self.m.StubOutWithMock(rsrc.clb, 'create')
fake_loadbalancer = FakeLoadBalancer(name=lb_name)
@ -231,7 +232,7 @@ class LoadBalancerTest(HeatTestCase):
t = template_format.parse(json.dumps(lb_template))
s = utils.parse_stack(t, stack_name=utils.random_name())
rsrc, fake_loadbalancer = self._mock_create(t, s,
rsrc, fake_loadbalancer = self._mock_create(s.t, s,
self.
_get_first_resource_name(
lb_template),

View File

@ -91,25 +91,27 @@ class CloudServersTest(HeatTestCase):
stack = parser.Stack(utils.dummy_context(), stack_name, template,
environment.Environment({'key_name': 'test'}),
stack_id=uuidutils.generate_uuid())
return (t, stack)
return (template, stack)
def _setup_test_server(self, return_server, name, image_id=None,
override_name=False, stub_create=True, exit_code=0):
stack_name = '%s_s' % name
(t, stack) = self._setup_test_stack(stack_name)
(tmpl, stack) = self._setup_test_stack(stack_name)
t['Resources']['WebServer']['Properties']['image'] = \
tmpl.t['Resources']['WebServer']['Properties']['image'] = \
image_id or 'CentOS 5.2'
t['Resources']['WebServer']['Properties']['flavor'] = \
tmpl.t['Resources']['WebServer']['Properties']['flavor'] = \
'256 MB Server'
server_name = '%s' % name
if override_name:
t['Resources']['WebServer']['Properties']['name'] = \
tmpl.t['Resources']['WebServer']['Properties']['name'] = \
server_name
resource_defns = tmpl.resource_definitions(stack)
server = cloud_server.CloudServer(server_name,
t['Resources']['WebServer'], stack)
resource_defns['WebServer'],
stack)
self._stub_server_validate(server, image_id or 'CentOS 5.2', 1)
if stub_create:
@ -333,9 +335,10 @@ class CloudServersTest(HeatTestCase):
stack_name = 'admin_pass_s'
(t, stack) = self._setup_test_stack(stack_name)
t['Resources']['WebServer']['Properties']['save_admin_pass'] = True
t.t['Resources']['WebServer']['Properties']['save_admin_pass'] = True
resource_defns = t.resource_definitions(stack)
server = cloud_server.CloudServer('WebServer',
t['Resources']['WebServer'], stack)
resource_defns['WebServer'], stack)
mock_nova.return_value = self.fc
self.fc.servers.create = mock.Mock(return_value=return_server)
@ -356,9 +359,10 @@ class CloudServersTest(HeatTestCase):
stack_name = 'admin_pass_s'
(t, stack) = self._setup_test_stack(stack_name)
t['Resources']['WebServer']['Properties']['save_admin_pass'] = False
t.t['Resources']['WebServer']['Properties']['save_admin_pass'] = False
resource_defns = t.resource_definitions(stack)
server = cloud_server.CloudServer('WebServer',
t['Resources']['WebServer'], stack)
resource_defns['WebServer'], stack)
mock_nova.return_value = self.fc
self.fc.servers.create = mock.Mock(return_value=return_server)
@ -379,9 +383,10 @@ class CloudServersTest(HeatTestCase):
stack_name = 'admin_pass_s'
(t, stack) = self._setup_test_stack(stack_name)
t['Resources']['WebServer']['Properties']['save_admin_pass'] = None
t.t['Resources']['WebServer']['Properties']['save_admin_pass'] = None
resource_defns = t.resource_definitions(stack)
server = cloud_server.CloudServer('WebServer',
t['Resources']['WebServer'], stack)
resource_defns['WebServer'], stack)
mock_nova.return_value = self.fc
self.fc.servers.create = mock.Mock(return_value=return_server)
@ -399,10 +404,11 @@ class CloudServersTest(HeatTestCase):
self._mock_metadata_os_distro()
return_server = self.fc.servers.list()[1]
stack_name = 'admin_pass_s'
(t, stack) = self._setup_test_stack(stack_name)
(tmpl, stack) = self._setup_test_stack(stack_name)
resource_defns = tmpl.resource_definitions(stack)
server = cloud_server.CloudServer('WebServer',
t['Resources']['WebServer'], stack)
resource_defns['WebServer'], stack)
mock_nova.return_value = self.fc
self.fc.servers.create = mock.Mock(return_value=return_server)
@ -416,20 +422,22 @@ class CloudServersTest(HeatTestCase):
def test_server_handles_server_without_password(self, mock_data_get):
mock_data_get.return_value = {}
stack_name = 'admin_pass_s'
(t, stack) = self._setup_test_stack(stack_name)
(tmpl, stack) = self._setup_test_stack(stack_name)
resource_defns = tmpl.resource_definitions(stack)
server = cloud_server.CloudServer('WebServer',
t['Resources']['WebServer'], stack)
resource_defns['WebServer'], stack)
self.assertEqual('', server.FnGetAtt('admin_pass'))
@mock.patch.object(resource.Resource, 'data')
def test_server_has_admin_pass_attribute_available(self, mock_data_get):
mock_data_get.return_value = {'admin_pass': 'foo'}
stack_name = 'admin_pass_s'
(t, stack) = self._setup_test_stack(stack_name)
(tmpl, stack) = self._setup_test_stack(stack_name)
resource_defns = tmpl.resource_definitions(stack)
server = cloud_server.CloudServer('WebServer',
t['Resources']['WebServer'], stack)
resource_defns['WebServer'], stack)
self.assertEqual('foo', server.FnGetAtt('admin_pass'))
@mock.patch.object(clients.OpenStackClients, 'nova')
@ -437,12 +445,13 @@ class CloudServersTest(HeatTestCase):
mock_nova):
return_server = self.fc.servers.list()[1]
stack_name = 'no_user_data'
(t, stack) = self._setup_test_stack(stack_name)
properties = t['Resources']['WebServer']['Properties']
(tmpl, stack) = self._setup_test_stack(stack_name)
properties = tmpl.t['Resources']['WebServer']['Properties']
properties['user_data'] = user_data
properties['config_drive'] = config_drive
resource_defns = tmpl.resource_definitions(stack)
server = cloud_server.CloudServer('WebServer',
t['Resources']['WebServer'], stack)
resource_defns['WebServer'], stack)
mock_nova.return_value = self.fc
mock_servers_create = mock.Mock(return_value=return_server)
self.fc.servers.create = mock_servers_create

View File

@ -106,7 +106,7 @@ class RackspaceDnsTest(common.HeatTestCase):
instance = cloud_dns.CloudDns(
'%s_name' % name,
t['Resources']['domain'],
template.resource_definitions(stack)['domain'],
stack)
return instance

View File

@ -95,9 +95,11 @@ class Resource(object):
support_status = support.SupportStatus()
def __new__(cls, name, json, stack):
def __new__(cls, name, definition, stack):
'''Create a new Resource of the appropriate class for its type.'''
assert isinstance(definition, rsrc_defn.ResourceDefinition)
if cls != Resource:
# Call is already for a subclass, so pass it through
ResourceClass = cls
@ -126,7 +128,7 @@ class Resource(object):
return res_info.template_name not in ancestor_list
registry = stack.env.registry
ResourceClass = registry.get_class(json.get('Type'),
ResourceClass = registry.get_class(definition.resource_type,
resource_name=name,
accept_fn=accept_class)
assert issubclass(ResourceClass, Resource)
@ -140,10 +142,7 @@ class Resource(object):
self.stack = stack
self.context = stack.context
self.name = name
if isinstance(definition, rsrc_defn.ResourceDefinition):
self.t = definition
else:
self.t = self.stack.resolve_static_data(definition)
self.t = definition
self.reparse()
self.attributes = Attributes(self.name,
self.attributes_schema,

View File

@ -30,6 +30,7 @@ from heat.engine.resources import image
from heat.engine.resources import instance
from heat.engine.resources import loadbalancer
from heat.engine.resources.neutron import loadbalancer as neutron_lb
from heat.engine import rsrc_defn
from heat.engine import scheduler
from heat.openstack.common.importutils import try_import
from heat.openstack.common import timeutils
@ -1690,11 +1691,13 @@ class TestInstanceGroup(HeatTestCase):
def setUp(self):
super(TestInstanceGroup, self).setUp()
json_snippet = {'Properties':
{'Size': 2, 'LaunchConfigurationName': 'foo'}}
t = template_format.parse(as_template)
stack = utils.parse_stack(t, params=self.params)
self.instance_group = asc.InstanceGroup('ig', json_snippet, stack)
defn = rsrc_defn.ResourceDefinition('ig', 'OS::Heat::InstanceGroup',
{'Size': 2,
'LaunchConfigurationName': 'foo'})
self.instance_group = asc.InstanceGroup('ig', defn, stack)
def test_child_template(self):
self.instance_group._create_template = mock.Mock(return_value='tpl')

View File

@ -280,8 +280,9 @@ class CeilometerAlarmTest(HeatTestCase):
snippet['Resources']['MEMAlarmHigh']['Properties'][p] = '60a'
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
rsrc = alarm.CeilometerAlarm(
'MEMAlarmHigh', snippet['Resources']['MEMAlarmHigh'], stack)
'MEMAlarmHigh', resource_defns['MEMAlarmHigh'], stack)
error = self.assertRaises(exception.StackValidationFailed,
rsrc.validate)
self.assertEqual(
@ -294,8 +295,9 @@ class CeilometerAlarmTest(HeatTestCase):
snippet['Resources']['MEMAlarmHigh']['Properties'][p] = [60]
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
rsrc = alarm.CeilometerAlarm(
'MEMAlarmHigh', snippet['Resources']['MEMAlarmHigh'], stack)
'MEMAlarmHigh', resource_defns['MEMAlarmHigh'], stack)
error = self.assertRaises(exception.StackValidationFailed,
rsrc.validate)
self.assertEqual(
@ -307,8 +309,9 @@ class CeilometerAlarmTest(HeatTestCase):
snippet['Resources']['MEMAlarmHigh']['Properties'].pop('meter_name')
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
rsrc = alarm.CeilometerAlarm(
'MEMAlarmHigh', snippet['Resources']['MEMAlarmHigh'], stack)
'MEMAlarmHigh', resource_defns['MEMAlarmHigh'], stack)
error = self.assertRaises(exception.StackValidationFailed,
rsrc.validate)
self.assertEqual(
@ -321,8 +324,9 @@ class CeilometerAlarmTest(HeatTestCase):
snippet['Resources']['MEMAlarmHigh']['Properties'].pop(p)
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
rsrc = alarm.CeilometerAlarm(
'MEMAlarmHigh', snippet['Resources']['MEMAlarmHigh'], stack)
'MEMAlarmHigh', resource_defns['MEMAlarmHigh'], stack)
self.assertIsNone(rsrc.validate())
def test_delete_alarm_not_found(self):
@ -364,8 +368,9 @@ class CombinationAlarmTest(HeatTestCase):
).AndReturn(FakeCeilometerAlarm())
snippet = template_format.parse(combination_alarm_template)
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
return alarm.CombinationAlarm(
'CombinAlarm', snippet['Resources']['CombinAlarm'], stack)
'CombinAlarm', resource_defns['CombinAlarm'], stack)
def test_create(self):
rsrc = self.create_alarm()
@ -380,8 +385,9 @@ class CombinationAlarmTest(HeatTestCase):
snippet = template_format.parse(combination_alarm_template)
snippet['Resources']['CombinAlarm']['Properties']['alarm_ids'] = []
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
rsrc = alarm.CombinationAlarm(
'CombinAlarm', snippet['Resources']['CombinAlarm'], stack)
'CombinAlarm', resource_defns['CombinAlarm'], stack)
error = self.assertRaises(exception.StackValidationFailed,
rsrc.validate)
self.assertEqual(

View File

@ -54,8 +54,9 @@ class CloudWatchAlarmTest(HeatTestCase):
super(CloudWatchAlarmTest, self).setUp()
def create_alarm(self, t, stack, resource_name):
resource_defns = stack.t.resource_definitions(stack)
rsrc = cloud_watch.CloudWatchAlarm(resource_name,
t['Resources'][resource_name],
resource_defns[resource_name],
stack)
self.assertIsNone(rsrc.validate())
scheduler.TaskRunner(rsrc.create)()

View File

@ -159,8 +159,9 @@ class EIPTest(HeatTestCase):
force_networking('neutron')
def create_eip(self, t, stack, resource_name):
resource_defns = stack.t.resource_definitions(stack)
rsrc = eip.ElasticIp(resource_name,
t['Resources'][resource_name],
resource_defns[resource_name],
stack)
self.assertIsNone(rsrc.validate())
scheduler.TaskRunner(rsrc.create)()
@ -168,8 +169,9 @@ class EIPTest(HeatTestCase):
return rsrc
def create_association(self, t, stack, resource_name):
resource_defns = stack.t.resource_definitions(stack)
rsrc = eip.ElasticIpAssociation(resource_name,
t['Resources'][resource_name],
resource_defns[resource_name],
stack)
self.assertIsNone(rsrc.validate())
scheduler.TaskRunner(rsrc.create)()
@ -245,8 +247,9 @@ class EIPTest(HeatTestCase):
t = template_format.parse(eip_template)
stack = utils.parse_stack(t)
resource_name = 'IPAddress'
resource_defns = stack.t.resource_definitions(stack)
rsrc = eip.ElasticIp(resource_name,
t['Resources'][resource_name],
resource_defns[resource_name],
stack)
self.assertRaises(clients.novaclient.exceptions.NotFound,
@ -264,8 +267,9 @@ class EIPTest(HeatTestCase):
t = template_format.parse(eip_template)
stack = utils.parse_stack(t)
resource_name = 'IPAddress'
resource_defns = stack.t.resource_definitions(stack)
rsrc = eip.ElasticIp(resource_name,
t['Resources'][resource_name],
resource_defns[resource_name],
stack)
rsrc.resource_id = 'fake_id'
rsrc.handle_delete()
@ -318,8 +322,9 @@ class AllocTest(HeatTestCase):
}})
def create_eip(self, t, stack, resource_name):
resource_defns = stack.t.resource_definitions(stack)
rsrc = eip.ElasticIp(resource_name,
t['Resources'][resource_name],
resource_defns[resource_name],
stack)
self.assertIsNone(rsrc.validate())
scheduler.TaskRunner(rsrc.create)()
@ -327,8 +332,9 @@ class AllocTest(HeatTestCase):
return rsrc
def create_association(self, t, stack, resource_name):
resource_defns = stack.t.resource_definitions(stack)
rsrc = eip.ElasticIpAssociation(resource_name,
t['Resources'][resource_name],
resource_defns[resource_name],
stack)
self.assertIsNone(rsrc.validate())
scheduler.TaskRunner(rsrc.create)()

View File

@ -17,6 +17,7 @@ from heat.db import api as db_api
from heat.engine import event
from heat.engine import parser
from heat.engine import resource
from heat.engine import rsrc_defn
from heat.engine import template
from heat.tests.common import HeatTestCase
from heat.tests import generic_resource as generic_rsrc
@ -145,11 +146,12 @@ class EventTest(HeatTestCase):
self.assertIsNone(e.identifier())
def test_badprop(self):
tmpl = {'HeatTemplateFormatVersion': '2012-12-12',
'Type': 'ResourceWithRequiredProps',
'Properties': {'Foo': False}}
rname = 'bad_resource'
res = generic_rsrc.ResourceWithRequiredProps(rname, tmpl, self.stack)
defn = rsrc_defn.ResourceDefinition(rname,
'ResourceWithRequiredProps',
{'Foo': False})
res = generic_rsrc.ResourceWithRequiredProps(rname, defn, self.stack)
e = event.Event(self.ctx, self.stack, 'TEST', 'IN_PROGRESS', 'Testing',
'wibble', res.properties, res.name, res.type())
self.assertIn('Error', e.resource_properties)

View File

@ -76,7 +76,7 @@ class InstancesTest(HeatTestCase):
stack = parser.Stack(utils.dummy_context(), stack_name, template,
environment.Environment({'KeyName': 'test'}),
stack_id=str(uuid.uuid4()))
return (t, stack)
return (template, stack)
def _mock_get_image_id_success(self, imageId_input, imageId):
g_cli_mock = self.m.CreateMockAnything()
@ -95,16 +95,22 @@ class InstancesTest(HeatTestCase):
self.m.StubOutWithMock(glance_utils, 'get_image_id')
glance_utils.get_image_id(g_cli_mock, image_id).AndRaise(exp)
def _get_test_template(self, stack_name, image_id=None):
(tmpl, stack) = self._setup_test_stack(stack_name)
tmpl.t['Resources']['WebServer']['Properties']['ImageId'] = \
image_id or 'CentOS 5.2'
tmpl.t['Resources']['WebServer']['Properties']['InstanceType'] = \
'256 MB Server'
return tmpl, stack
def _setup_test_instance(self, return_server, name, image_id=None,
stub_create=True):
stack_name = '%s_s' % name
(t, stack) = self._setup_test_stack(stack_name)
t['Resources']['WebServer']['Properties']['ImageId'] = \
image_id or 'CentOS 5.2'
t['Resources']['WebServer']['Properties']['InstanceType'] = \
'256 MB Server'
instance = instances.Instance(name, t['Resources']['WebServer'], stack)
tmpl, stack = self._get_test_template(stack_name, image_id)
resource_defns = tmpl.resource_definitions(stack)
instance = instances.Instance(name, resource_defns['WebServer'], stack)
self._mock_get_image_id_success(image_id or 'CentOS 5.2', 1)
@ -173,12 +179,13 @@ class InstancesTest(HeatTestCase):
def test_instance_create_image_name_err(self):
stack_name = 'test_instance_create_image_name_err_stack'
(t, stack) = self._setup_test_stack(stack_name)
(tmpl, stack) = self._setup_test_stack(stack_name)
# create an instance with non exist image name
t['Resources']['WebServer']['Properties']['ImageId'] = 'Slackware'
tmpl.t['Resources']['WebServer']['Properties']['ImageId'] = 'Slackware'
resource_defns = tmpl.resource_definitions(stack)
instance = instances.Instance('instance_create_image_err',
t['Resources']['WebServer'], stack)
resource_defns['WebServer'], stack)
g_cli_moc = self.m.CreateMockAnything()
self.m.StubOutWithMock(clients.OpenStackClients, 'glance')
@ -191,12 +198,14 @@ class InstancesTest(HeatTestCase):
def test_instance_create_duplicate_image_name_err(self):
stack_name = 'test_instance_create_image_name_err_stack'
(t, stack) = self._setup_test_stack(stack_name)
(tmpl, stack) = self._setup_test_stack(stack_name)
# create an instance with a non unique image name
t['Resources']['WebServer']['Properties']['ImageId'] = 'CentOS 5.2'
wsp = tmpl.t['Resources']['WebServer']['Properties']
wsp['ImageId'] = 'CentOS 5.2'
resource_defns = tmpl.resource_definitions(stack)
instance = instances.Instance('instance_create_image_err',
t['Resources']['WebServer'], stack)
resource_defns['WebServer'], stack)
self._mock_get_image_id_fail('CentOS 5.2',
exception.PhysicalResourceNameAmbiguity(
@ -210,12 +219,13 @@ class InstancesTest(HeatTestCase):
def test_instance_create_image_id_err(self):
stack_name = 'test_instance_create_image_id_err_stack'
(t, stack) = self._setup_test_stack(stack_name)
(tmpl, stack) = self._setup_test_stack(stack_name)
# create an instance with non exist image Id
t['Resources']['WebServer']['Properties']['ImageId'] = '1'
tmpl.t['Resources']['WebServer']['Properties']['ImageId'] = '1'
resource_defns = tmpl.resource_definitions(stack)
instance = instances.Instance('instance_create_image_err',
t['Resources']['WebServer'], stack)
resource_defns['WebServer'], stack)
self._mock_get_image_id_fail('1', glance_exceptions.NotFound(404))
@ -280,11 +290,12 @@ class InstancesTest(HeatTestCase):
def test_instance_validate(self):
stack_name = 'test_instance_validate_stack'
(t, stack) = self._setup_test_stack(stack_name)
(tmpl, stack) = self._setup_test_stack(stack_name)
t['Resources']['WebServer']['Properties']['ImageId'] = '1'
tmpl.t['Resources']['WebServer']['Properties']['ImageId'] = '1'
resource_defns = tmpl.resource_definitions(stack)
instance = instances.Instance('instance_create_image',
t['Resources']['WebServer'], stack)
resource_defns['WebServer'], stack)
self.m.StubOutWithMock(clients.OpenStackClients, 'nova')
clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc)
@ -347,9 +358,10 @@ class InstancesTest(HeatTestCase):
instance = self._create_test_instance(return_server,
'ud_md')
update_template = copy.deepcopy(instance.t)
update_template['Metadata'] = {'test': 123}
scheduler.TaskRunner(instance.update, update_template)()
ud_tmpl = self._get_test_template('update_stack')[0]
ud_tmpl.t['Resources']['WebServer']['Metadata'] = {'test': 123}
resource_defns = ud_tmpl.resource_definitions(instance.stack)
scheduler.TaskRunner(instance.update, resource_defns['WebServer'])()
self.assertEqual({'test': 123}, instance.metadata_get())
def test_instance_update_instance_type(self):

View File

@ -171,8 +171,9 @@ class instancesTest(HeatTestCase):
stack_id=str(uuid.uuid4()))
image_id = 'CentOS 5.2'
t['Resources']['WebServer']['Properties']['ImageId'] = image_id
resource_defns = stack.t.resource_definitions(stack)
instance = instances.Instance('%s_name' % name,
t['Resources']['WebServer'], stack)
resource_defns['WebServer'], stack)
self.m.StubOutWithMock(instance, 'nova')
instance.nova().MultipleTimes().AndReturn(self.fc)
@ -222,12 +223,13 @@ class instancesTest(HeatTestCase):
image_id = 'CentOS 5.2'
t['Resources']['WebServer']['Properties']['ImageId'] = image_id
resource_defns = stack.t.resource_definitions(stack)
nic = network_interfaces.NetworkInterface('%s_nic' % name,
t['Resources']['nic1'],
resource_defns['nic1'],
stack)
instance = instances.Instance('%s_name' % name,
t['Resources']['WebServer'], stack)
resource_defns['WebServer'], stack)
self._mock_get_image_id_success(image_id, 1)
self.m.StubOutWithMock(nic, 'neutron')

View File

@ -115,8 +115,9 @@ class LoadBalancerTest(HeatTestCase):
'http://server.test:8000/v1/waitcondition')
def create_loadbalancer(self, t, stack, resource_name):
resource_defns = stack.t.resource_definitions(stack)
rsrc = lb.LoadBalancer(resource_name,
t['Resources'][resource_name],
resource_defns[resource_name],
stack)
self.assertIsNone(rsrc.validate())
scheduler.TaskRunner(rsrc.create)()
@ -193,9 +194,10 @@ class LoadBalancerTest(HeatTestCase):
self.assertRegexpMatches(ha_cfg, 'timeout check 5s')
id_list = []
resource_defns = s.t.resource_definitions(s)
for inst_name in ['WikiServerOne1', 'WikiServerOne2']:
inst = instance.Instance(inst_name,
s.t['Resources']['WikiServerOne'],
resource_defns['WikiServerOne'],
s)
id_list.append(inst.FnGetRefId())
@ -242,8 +244,9 @@ class LoadBalancerTest(HeatTestCase):
s = utils.parse_stack(t)
s.store()
resource_defns = s.t.resource_definitions(s)
rsrc = lb.LoadBalancer('LoadBalancer',
t['Resources']['LoadBalancer'],
resource_defns['LoadBalancer'],
s)
self.assertRaises(exception.StackValidationFailed, rsrc.validate)
@ -254,8 +257,8 @@ class LoadBalancerTest(HeatTestCase):
stack = utils.parse_stack(template)
resource_name = 'LoadBalancer'
lb_json = template['Resources'][resource_name]
return lb.LoadBalancer(resource_name, lb_json, stack)
lb_defn = stack.t.resource_definitions(stack)[resource_name]
return lb.LoadBalancer(resource_name, lb_defn, stack)
def test_child_params_without_key_name(self):
rsrc = self.setup_loadbalancer(False)

View File

@ -534,7 +534,8 @@ class NeutronNetTest(HeatTestCase):
self.m.StubOutWithMock(clients.OpenStackClients, 'keystone')
def create_net(self, t, stack, resource_name):
rsrc = net.Net('test_net', t['Resources'][resource_name], stack)
resource_defns = stack.t.resource_definitions(stack)
rsrc = net.Net('test_net', resource_defns[resource_name], stack)
scheduler.TaskRunner(rsrc.create)()
self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
return rsrc
@ -761,8 +762,9 @@ class NeutronProviderNetTest(HeatTestCase):
t = template_format.parse(provider_network_template)
stack = utils.parse_stack(t)
resource_defns = stack.t.resource_definitions(stack)
rsrc = provider_net.ProviderNet(
'provider_net', t['Resources']['provider_network_vlan'], stack)
'provider_net', resource_defns['provider_network_vlan'], stack)
return rsrc
@ -861,7 +863,8 @@ class NeutronSubnetTest(HeatTestCase):
self.m.StubOutWithMock(clients.OpenStackClients, 'keystone')
def create_subnet(self, t, stack, resource_name):
rsrc = subnet.Subnet('test_subnet', t['Resources'][resource_name],
resource_defns = stack.t.resource_definitions(stack)
rsrc = subnet.Subnet('test_subnet', resource_defns[resource_name],
stack)
return rsrc
@ -1179,16 +1182,18 @@ class NeutronRouterTest(HeatTestCase):
self.m.StubOutWithMock(clients.OpenStackClients, 'keystone')
def create_router(self, t, stack, resource_name):
rsrc = router.Router('router', t['Resources'][resource_name], stack)
resource_defns = stack.t.resource_definitions(stack)
rsrc = router.Router('router', resource_defns[resource_name], stack)
scheduler.TaskRunner(rsrc.create)()
self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
return rsrc
def create_router_interface(self, t, stack, resource_name, properties={}):
t['Resources'][resource_name]['Properties'] = properties
resource_defns = stack.t.resource_definitions(stack)
rsrc = router.RouterInterface(
'router_interface',
t['Resources'][resource_name],
resource_defns[resource_name],
stack)
scheduler.TaskRunner(rsrc.create)()
self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
@ -1196,9 +1201,10 @@ class NeutronRouterTest(HeatTestCase):
def create_gateway_router(self, t, stack, resource_name, properties={}):
t['Resources'][resource_name]['Properties'] = properties
resource_defns = stack.t.resource_definitions(stack)
rsrc = router.RouterGateway(
'gateway',
t['Resources'][resource_name],
resource_defns[resource_name],
stack)
scheduler.TaskRunner(rsrc.create)()
self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
@ -1503,24 +1509,36 @@ class NeutronRouterTest(HeatTestCase):
'subnet_id': '9577cafd-8e98-4059-a2e6-8a771b4d318e',
'port_id': '9577cafd-8e98-4059-a2e6-8a771b4d318e'}
stack = utils.parse_stack(t)
res = router.RouterInterface('router_interface', json, stack)
resource_defns = stack.t.resource_definitions(stack)
res = router.RouterInterface('router_interface',
resource_defns['router_interface'],
stack)
self.assertRaises(exception.ResourcePropertyConflict, res.validate)
json['Properties'] = {
'router_id': 'ae478782-53c0-4434-ab16-49900c88016c',
'port_id': '9577cafd-8e98-4059-a2e6-8a771b4d318e'}
stack = utils.parse_stack(t)
res = router.RouterInterface('router_interface', json, stack)
resource_defns = stack.t.resource_definitions(stack)
res = router.RouterInterface('router_interface',
resource_defns['router_interface'],
stack)
self.assertIsNone(res.validate())
json['Properties'] = {
'router_id': 'ae478782-53c0-4434-ab16-49900c88016c',
'subnet_id': '9577cafd-8e98-4059-a2e6-8a771b4d318e'}
stack = utils.parse_stack(t)
res = router.RouterInterface('router_interface', json, stack)
resource_defns = stack.t.resource_definitions(stack)
res = router.RouterInterface('router_interface',
resource_defns['router_interface'],
stack)
self.assertIsNone(res.validate())
json['Properties'] = {
'router_id': 'ae478782-53c0-4434-ab16-49900c88016c'}
stack = utils.parse_stack(t)
res = router.RouterInterface('router_interface', json, stack)
resource_defns = stack.t.resource_definitions(stack)
res = router.RouterInterface('router_interface',
resource_defns['router_interface'],
stack)
ex = self.assertRaises(exception.StackValidationFailed, res.validate)
self.assertEqual("Either subnet or port_id must be specified.",
str(ex))

View File

@ -108,8 +108,9 @@ class FirewallTest(HeatTestCase):
snippet = template_format.parse(firewall_template)
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
return firewall.Firewall(
'firewall', snippet['Resources']['firewall'], stack)
'firewall', resource_defns['firewall'], stack)
def test_create(self):
rsrc = self.create_firewall()
@ -130,8 +131,9 @@ class FirewallTest(HeatTestCase):
snippet = template_format.parse(firewall_template)
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
rsrc = firewall.Firewall(
'firewall', snippet['Resources']['firewall'], stack)
'firewall', resource_defns['firewall'], stack)
error = self.assertRaises(exception.ResourceFailure,
scheduler.TaskRunner(rsrc.create))
@ -238,8 +240,9 @@ class FirewallPolicyTest(HeatTestCase):
snippet = template_format.parse(firewall_policy_template)
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
return firewall.FirewallPolicy(
'firewall_policy', snippet['Resources']['firewall_policy'], stack)
'firewall_policy', resource_defns['firewall_policy'], stack)
def test_create(self):
rsrc = self.create_firewall_policy()
@ -260,8 +263,9 @@ class FirewallPolicyTest(HeatTestCase):
snippet = template_format.parse(firewall_policy_template)
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
rsrc = firewall.FirewallPolicy(
'firewall_policy', snippet['Resources']['firewall_policy'], stack)
'firewall_policy', resource_defns['firewall_policy'], stack)
error = self.assertRaises(exception.ResourceFailure,
scheduler.TaskRunner(rsrc.create))
@ -368,8 +372,9 @@ class FirewallRuleTest(HeatTestCase):
snippet = template_format.parse(firewall_rule_template)
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
return firewall.FirewallRule(
'firewall_rule', snippet['Resources']['firewall_rule'], stack)
'firewall_rule', resource_defns['firewall_rule'], stack)
def test_create(self):
rsrc = self.create_firewall_rule()
@ -391,8 +396,9 @@ class FirewallRuleTest(HeatTestCase):
snippet = template_format.parse(firewall_rule_template)
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
rsrc = firewall.FirewallRule(
'firewall_rule', snippet['Resources']['firewall_rule'], stack)
'firewall_rule', resource_defns['firewall_rule'], stack)
error = self.assertRaises(exception.ResourceFailure,
scheduler.TaskRunner(rsrc.create))

View File

@ -242,8 +242,9 @@ class HealthMonitorTest(HeatTestCase):
snippet = template_format.parse(health_monitor_template)
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
return loadbalancer.HealthMonitor(
'monitor', snippet['Resources']['monitor'], stack)
'monitor', resource_defns['monitor'], stack)
def test_create(self):
rsrc = self.create_health_monitor()
@ -264,8 +265,9 @@ class HealthMonitorTest(HeatTestCase):
snippet = template_format.parse(health_monitor_template)
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
rsrc = loadbalancer.HealthMonitor(
'monitor', snippet['Resources']['monitor'], stack)
'monitor', resource_defns['monitor'], stack)
error = self.assertRaises(exception.ResourceFailure,
scheduler.TaskRunner(rsrc.create))
self.assertEqual(
@ -420,8 +422,9 @@ class PoolTest(HeatTestCase):
neutronclient.Client.create_vip(stvippsn
).AndReturn({'vip': {'id': 'xyz'}})
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
return loadbalancer.Pool(
'pool', snippet['Resources']['pool'], stack)
'pool', resource_defns['pool'], stack)
def test_create(self):
self._test_create()
@ -475,8 +478,9 @@ class PoolTest(HeatTestCase):
snippet = template_format.parse(pool_template)
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
rsrc = loadbalancer.Pool(
'pool', snippet['Resources']['pool'], stack)
'pool', resource_defns['pool'], stack)
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
@ -508,8 +512,9 @@ class PoolTest(HeatTestCase):
snippet = template_format.parse(pool_template)
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
rsrc = loadbalancer.Pool(
'pool', snippet['Resources']['pool'], stack)
'pool', resource_defns['pool'], stack)
self.m.ReplayAll()
error = self.assertRaises(exception.ResourceFailure,
scheduler.TaskRunner(rsrc.create))
@ -548,8 +553,9 @@ class PoolTest(HeatTestCase):
snippet = template_format.parse(pool_template)
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
rsrc = loadbalancer.Pool(
'pool', snippet['Resources']['pool'], stack)
'pool', resource_defns['pool'], stack)
self.m.ReplayAll()
error = self.assertRaises(exception.ResourceFailure,
scheduler.TaskRunner(rsrc.create))
@ -579,8 +585,9 @@ class PoolTest(HeatTestCase):
snippet = template_format.parse(pool_template)
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
rsrc = loadbalancer.Pool(
'pool', snippet['Resources']['pool'], stack)
'pool', resource_defns['pool'], stack)
error = self.assertRaises(exception.ResourceFailure,
scheduler.TaskRunner(rsrc.create))
self.assertEqual(
@ -619,8 +626,9 @@ class PoolTest(HeatTestCase):
snippet = template_format.parse(pool_with_session_persistence_template)
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
rsrc = loadbalancer.Pool(
'pool', snippet['Resources']['pool'], stack)
'pool', resource_defns['pool'], stack)
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
@ -637,7 +645,9 @@ class PoolTest(HeatTestCase):
persistence['type'] = 'APP_COOKIE'
persistence['cookie_name'] = None
resource = loadbalancer.Pool('pool', pool, utils.parse_stack(snippet))
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
resource = loadbalancer.Pool('pool', resource_defns['pool'], stack)
error = self.assertRaises(exception.StackValidationFailed,
resource.validate)
@ -645,9 +655,10 @@ class PoolTest(HeatTestCase):
def test_validation_not_failing_without_session_persistence(self):
snippet = template_format.parse(pool_template)
pool = snippet['Resources']['pool']
resource = loadbalancer.Pool('pool', pool, utils.parse_stack(snippet))
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
resource = loadbalancer.Pool('pool', resource_defns['pool'], stack)
self.assertIsNone(resource.validate())
@ -685,7 +696,10 @@ class PoolTest(HeatTestCase):
# change persistence type to HTTP_COOKIE that not require cookie_name
persistence['type'] = 'HTTP_COOKIE'
del persistence['cookie_name']
resource = loadbalancer.Pool('pool', pool, utils.parse_stack(snippet))
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
resource = loadbalancer.Pool('pool', resource_defns['pool'], stack)
# assert that properties contain cookie_name property with None value
persistence = resource.properties['vip']['session_persistence']
@ -838,8 +852,8 @@ class PoolTest(HeatTestCase):
stack = utils.parse_stack(snippet)
snippet['Resources']['pool']['Properties']['monitors'] = [
'mon123', 'mon456']
rsrc = loadbalancer.Pool(
'pool', snippet['Resources']['pool'], stack)
resource_defns = stack.t.resource_definitions(stack)
rsrc = loadbalancer.Pool('pool', resource_defns['pool'], stack)
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
@ -872,8 +886,9 @@ class PoolMemberTest(HeatTestCase):
).AndReturn({'member': {'id': 'member5678'}})
snippet = template_format.parse(member_template)
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
return loadbalancer.PoolMember(
'member', snippet['Resources']['member'], stack)
'member', resource_defns['member'], stack)
def test_create(self):
rsrc = self.create_member()
@ -897,8 +912,9 @@ class PoolMemberTest(HeatTestCase):
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)
rsrc = loadbalancer.PoolMember(
'member', snippet['Resources']['member'], stack)
'member', resource_defns['member'], stack)
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
@ -978,8 +994,9 @@ class LoadBalancerTest(HeatTestCase):
).AndReturn({'member': {'id': 'member5678'}})
snippet = template_format.parse(lb_template)
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
return loadbalancer.LoadBalancer(
'lb', snippet['Resources']['lb'], stack)
'lb', resource_defns['lb'], stack)
def test_create(self):
rsrc = self.create_load_balancer()

View File

@ -79,8 +79,9 @@ class MeteringLabelTest(HeatTestCase):
snippet = template_format.parse(metering_template)
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
return metering.MeteringLabel(
'label', snippet['Resources']['label'], stack)
'label', resource_defns['label'], stack)
def test_create(self):
rsrc = self.create_metering_label()
@ -101,8 +102,9 @@ class MeteringLabelTest(HeatTestCase):
snippet = template_format.parse(metering_template)
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
rsrc = metering.MeteringLabel(
'label', snippet['Resources']['label'], stack)
'label', resource_defns['label'], stack)
error = self.assertRaises(exception.ResourceFailure,
scheduler.TaskRunner(rsrc.create))
self.assertEqual(
@ -193,8 +195,9 @@ class MeteringRuleTest(HeatTestCase):
snippet = template_format.parse(metering_template)
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
return metering.MeteringRule(
'rule', snippet['Resources']['rule'], stack)
'rule', resource_defns['rule'], stack)
def test_create(self):
rsrc = self.create_metering_label_rule()
@ -217,8 +220,9 @@ class MeteringRuleTest(HeatTestCase):
snippet = template_format.parse(metering_template)
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
rsrc = metering.MeteringRule(
'rule', snippet['Resources']['rule'], stack)
'rule', resource_defns['rule'], stack)
error = self.assertRaises(exception.ResourceFailure,
scheduler.TaskRunner(rsrc.create))
self.assertEqual(

View File

@ -160,9 +160,10 @@ class NeutronNetworkGatewayTest(HeatTestCase):
t = template_format.parse(gw_template_deprecated)
stack = utils.parse_stack(t)
resource_defns = stack.t.resource_definitions(stack)
rsrc = network_gateway.NetworkGateway(
'test_network_gateway',
t['Resources']['NetworkGateway'], stack)
resource_defns['NetworkGateway'], stack)
return rsrc
def _test_network_gateway_create(self, resolve_neutron=True):
@ -459,8 +460,9 @@ class NeutronNetworkGatewayTest(HeatTestCase):
t = template_format.parse(gw_template)
stack = utils.parse_stack(t)
resource_defns = stack.t.resource_definitions(stack)
rsrc = network_gateway.NetworkGateway(
'network_gateway', t['Resources']['NetworkGateway'], stack)
'network_gateway', resource_defns['NetworkGateway'], stack)
error = self.assertRaises(exception.ResourceFailure,
scheduler.TaskRunner(rsrc.create))
self.assertEqual(
@ -477,9 +479,10 @@ class NeutronNetworkGatewayTest(HeatTestCase):
del t['Resources']['NetworkGateway']['Properties'][
'connections'][0]['segmentation_id']
stack = utils.parse_stack(t)
resource_defns = stack.t.resource_definitions(stack)
rsrc = network_gateway.NetworkGateway(
'test_network_gateway',
t['Resources']['NetworkGateway'], stack)
resource_defns['NetworkGateway'], stack)
self.m.ReplayAll()
@ -497,9 +500,10 @@ class NeutronNetworkGatewayTest(HeatTestCase):
t['Resources']['NetworkGateway']['Properties'][
'connections'][0]['segmentation_type'] = 'flat'
stack = utils.parse_stack(t)
resource_defns = stack.t.resource_definitions(stack)
rsrc = network_gateway.NetworkGateway(
'test_network_gateway',
t['Resources']['NetworkGateway'], stack)
resource_defns['NetworkGateway'], stack)
self.m.ReplayAll()

View File

@ -194,8 +194,9 @@ class VPNServiceTest(HeatTestCase):
self.VPN_SERVICE_CONF).AndReturn({'vpnservice': {'id': 'vpn123'}})
self.stack = utils.parse_stack(snippet)
resource_defns = self.stack.t.resource_definitions(self.stack)
return vpnservice.VPNService('vpnservice',
snippet['Resources']['VPNService'],
resource_defns['VPNService'],
self.stack)
def test_create_deprecated(self):
@ -225,8 +226,9 @@ class VPNServiceTest(HeatTestCase):
self.m.ReplayAll()
snippet = template_format.parse(vpnservice_template)
self.stack = utils.parse_stack(snippet)
resource_defns = self.stack.t.resource_definitions(self.stack)
rsrc = vpnservice.VPNService('vpnservice',
snippet['Resources']['VPNService'],
resource_defns['VPNService'],
self.stack)
error = self.assertRaises(exception.ResourceFailure,
scheduler.TaskRunner(rsrc.create))
@ -353,9 +355,10 @@ class IPsecSiteConnectionTest(HeatTestCase):
{'ipsec_site_connection': {'id': 'con123'}})
snippet = template_format.parse(ipsec_site_connection_template)
self.stack = utils.parse_stack(snippet)
resource_defns = self.stack.t.resource_definitions(self.stack)
return vpnservice.IPsecSiteConnection(
'ipsec_site_connection',
snippet['Resources']['IPsecSiteConnection'],
resource_defns['IPsecSiteConnection'],
self.stack)
def test_create(self):
@ -374,9 +377,10 @@ class IPsecSiteConnectionTest(HeatTestCase):
self.m.ReplayAll()
snippet = template_format.parse(ipsec_site_connection_template)
self.stack = utils.parse_stack(snippet)
resource_defns = self.stack.t.resource_definitions(self.stack)
rsrc = vpnservice.IPsecSiteConnection(
'ipsec_site_connection',
snippet['Resources']['IPsecSiteConnection'],
resource_defns['IPsecSiteConnection'],
self.stack)
error = self.assertRaises(exception.ResourceFailure,
scheduler.TaskRunner(rsrc.create))
@ -503,8 +507,9 @@ class IKEPolicyTest(HeatTestCase):
{'ikepolicy': {'id': 'ike123'}})
snippet = template_format.parse(ikepolicy_template)
self.stack = utils.parse_stack(snippet)
resource_defns = self.stack.t.resource_definitions(self.stack)
return vpnservice.IKEPolicy('ikepolicy',
snippet['Resources']['IKEPolicy'],
resource_defns['IKEPolicy'],
self.stack)
def test_create(self):
@ -523,9 +528,10 @@ class IKEPolicyTest(HeatTestCase):
self.m.ReplayAll()
snippet = template_format.parse(ikepolicy_template)
self.stack = utils.parse_stack(snippet)
resource_defns = self.stack.t.resource_definitions(self.stack)
rsrc = vpnservice.IKEPolicy(
'ikepolicy',
snippet['Resources']['IKEPolicy'],
resource_defns['IKEPolicy'],
self.stack)
error = self.assertRaises(exception.ResourceFailure,
scheduler.TaskRunner(rsrc.create))
@ -647,8 +653,9 @@ class IPsecPolicyTest(HeatTestCase):
{'ipsecpolicy': {'id': 'ips123'}})
snippet = template_format.parse(ipsecpolicy_template)
self.stack = utils.parse_stack(snippet)
resource_defns = self.stack.t.resource_definitions(self.stack)
return vpnservice.IPsecPolicy('ipsecpolicy',
snippet['Resources']['IPsecPolicy'],
resource_defns['IPsecPolicy'],
self.stack)
def test_create(self):
@ -667,9 +674,10 @@ class IPsecPolicyTest(HeatTestCase):
self.m.ReplayAll()
snippet = template_format.parse(ipsecpolicy_template)
self.stack = utils.parse_stack(snippet)
resource_defns = self.stack.t.resource_definitions(self.stack)
rsrc = vpnservice.IPsecPolicy(
'ipsecpolicy',
snippet['Resources']['IPsecPolicy'],
resource_defns['IPsecPolicy'],
self.stack)
error = self.assertRaises(exception.ResourceFailure,
scheduler.TaskRunner(rsrc.create))

View File

@ -55,8 +55,9 @@ class nokeyTest(HeatTestCase):
t['Resources']['WebServer']['Properties']['ImageId'] = 'CentOS 5.2'
t['Resources']['WebServer']['Properties']['InstanceType'] = \
'256 MB Server'
resource_defns = stack.t.resource_definitions(stack)
instance = instances.Instance('create_instance_name',
t['Resources']['WebServer'], stack)
resource_defns['WebServer'], stack)
self.m.StubOutWithMock(instance, 'nova')
instance.nova().MultipleTimes().AndReturn(self.fc)

View File

@ -27,10 +27,10 @@ from heat.tests import utils
floating_ip_template = '''
{
"heat_template_version": "2013-05-23",
"Resources": {
"resources": {
"MyFloatingIP": {
"Type": "OS::Nova::FloatingIP",
"Properties": {
"type": "OS::Nova::FloatingIP",
"properties": {
"pool": "public"
}
}
@ -41,10 +41,10 @@ floating_ip_template = '''
floating_ip_template_with_assoc = '''
{
"heat_template_version": "2013-05-23",
"Resources": {
"resources": {
"MyFloatingIPAssociation": {
"Type": "OS::Nova::FloatingIPAssociation",
"Properties": {
"type": "OS::Nova::FloatingIPAssociation",
"properties": {
"server_id": "67dc62f9-efde-4c8b-94af-013e00f5dc57",
"floating_ip": "1"
}
@ -87,7 +87,7 @@ class NovaFloatingIPTest(HeatTestCase):
template = template_format.parse(floating_ip_template)
stack = utils.parse_stack(template)
floating_ip = template['Resources']['MyFloatingIP']
floating_ip = stack.t.resource_definitions(stack)['MyFloatingIP']
return NovaFloatingIp('MyFloatingIP', floating_ip, stack)
@ -105,7 +105,8 @@ class NovaFloatingIPTest(HeatTestCase):
template = template_format.parse(floating_ip_template_with_assoc)
stack = utils.parse_stack(template)
floating_ip_assoc = template['Resources']['MyFloatingIPAssociation']
resource_defns = stack.t.resource_definitions(stack)
floating_ip_assoc = resource_defns['MyFloatingIPAssociation']
return NovaFloatingIpAssociation('MyFloatingIPAssociation',
floating_ip_assoc, stack)

View File

@ -56,8 +56,8 @@ class NovaKeyPairTest(HeatTestCase):
def _get_test_resource(self, template):
stack = utils.parse_stack(template)
snippet = stack.t['Resources']['kp']
kp_res = nova_keypair.KeyPair('kp', snippet, stack)
definition = stack.t.resource_definitions(stack)['kp']
kp_res = nova_keypair.KeyPair('kp', definition, stack)
self.m.StubOutWithMock(kp_res, "nova")
kp_res.nova().MultipleTimes().AndReturn(self.fake_nova)
return kp_res

View File

@ -103,7 +103,7 @@ class OSDBInstanceTest(HeatTestCase):
instance = os_database.OSDBInstance(
'%s_name' % name,
t['Resources']['MySqlCloudDB'],
template.resource_definitions(stack)['MySqlCloudDB'],
stack)
return instance

View File

@ -26,6 +26,7 @@ from heat.engine import properties
from heat.engine import resource
from heat.engine import resources
from heat.engine.resources import template_resource
from heat.engine import rsrc_defn
from heat.tests.common import HeatTestCase
from heat.tests import generic_resource as generic_rsrc
from heat.tests import utils
@ -130,18 +131,18 @@ class ProviderTemplateTest(HeatTestCase):
"key5": False
}
}
json_snippet = {
"Type": "DummyResource",
"Properties": {
"Foo": "Bar",
"AList": ["one", "two", "three"],
"ListEmpty": [],
"ANum": 5,
"AMap": map_prop_val
}
prop_vals = {
"Foo": "Bar",
"AList": ["one", "two", "three"],
"ListEmpty": [],
"ANum": 5,
"AMap": map_prop_val,
}
definition = rsrc_defn.ResourceDefinition('test_t_res',
'DummyResource',
prop_vals)
temp_res = template_resource.TemplateResource('test_t_res',
json_snippet, stack)
definition, stack)
temp_res.validate()
converted_params = temp_res.child_params()
self.assertTrue(converted_params)
@ -150,10 +151,7 @@ class ProviderTemplateTest(HeatTestCase):
# verify String conversion
self.assertEqual("Bar", converted_params.get("Foo"))
# verify List conversion
self.assertEqual(",".join(json_snippet.get("Properties",
{}).get("AList",
[])),
converted_params.get("AList"))
self.assertEqual("one,two,three", converted_params.get("AList"))
# verify Number conversion
self.assertEqual(5, converted_params.get("ANum"))
# verify Map conversion
@ -182,12 +180,10 @@ class ProviderTemplateTest(HeatTestCase):
env=env,
stack_id=str(uuid.uuid4()))
json_snippet = {
"Type": "DummyResource",
}
definition = rsrc_defn.ResourceDefinition('test_t_res',
"DummyResource")
temp_res = template_resource.TemplateResource('test_t_res',
json_snippet, stack)
definition, stack)
self.assertIsNone(temp_res.validate())
def test_attributes_missing(self):
@ -203,10 +199,6 @@ class ProviderTemplateTest(HeatTestCase):
properties_schema = {}
attributes_schema = {"Foo": attributes.Schema("A test attribute")}
json_snippet = {
"Type": "DummyResource",
}
env = environment.Environment()
resource._register_class('DummyResource', DummyResource)
env.load({'resource_registry':
@ -216,8 +208,10 @@ class ProviderTemplateTest(HeatTestCase):
env=env,
stack_id=str(uuid.uuid4()))
definition = rsrc_defn.ResourceDefinition('test_t_res',
"DummyResource")
temp_res = template_resource.TemplateResource('test_t_res',
json_snippet, stack)
definition, stack)
self.assertRaises(exception.StackValidationFailed,
temp_res.validate)
@ -237,13 +231,6 @@ class ProviderTemplateTest(HeatTestCase):
required=True)}
attributes_schema = {}
json_snippet = {
"Type": "DummyResource",
"Properties": {
"Foo": "bar",
},
}
env = environment.Environment()
resource._register_class('DummyResource', DummyResource)
env.load({'resource_registry':
@ -253,8 +240,11 @@ class ProviderTemplateTest(HeatTestCase):
env=env,
stack_id=str(uuid.uuid4()))
definition = rsrc_defn.ResourceDefinition('test_t_res',
"DummyResource",
{"Foo": "bar"})
temp_res = template_resource.TemplateResource('test_t_res',
json_snippet, stack)
definition, stack)
self.assertIsNone(temp_res.validate())
def test_properties_missing(self):
@ -272,10 +262,6 @@ class ProviderTemplateTest(HeatTestCase):
required=True)}
attributes_schema = {}
json_snippet = {
"Type": "DummyResource",
}
env = environment.Environment()
resource._register_class('DummyResource', DummyResource)
env.load({'resource_registry':
@ -285,8 +271,10 @@ class ProviderTemplateTest(HeatTestCase):
env=env,
stack_id=str(uuid.uuid4()))
definition = rsrc_defn.ResourceDefinition('test_t_res',
"DummyResource")
temp_res = template_resource.TemplateResource('test_t_res',
json_snippet, stack)
definition, stack)
self.assertRaises(exception.StackValidationFailed,
temp_res.validate)
@ -303,13 +291,6 @@ class ProviderTemplateTest(HeatTestCase):
properties_schema = {}
attributes_schema = {}
json_snippet = {
"Type": "DummyResource",
"Properties": {
"Blarg": "wibble",
},
}
env = environment.Environment()
resource._register_class('DummyResource', DummyResource)
env.load({'resource_registry':
@ -319,8 +300,11 @@ class ProviderTemplateTest(HeatTestCase):
env=env,
stack_id=str(uuid.uuid4()))
definition = rsrc_defn.ResourceDefinition('test_t_res',
"DummyResource",
{"Blarg": "wibble"})
temp_res = template_resource.TemplateResource('test_t_res',
json_snippet, stack)
definition, stack)
self.assertRaises(exception.StackValidationFailed,
temp_res.validate)
@ -337,13 +321,6 @@ class ProviderTemplateTest(HeatTestCase):
properties.Schema(properties.Schema.MAP)}
attributes_schema = {}
json_snippet = {
"Type": "DummyResource",
"Properties": {
"Foo": "bar",
},
}
env = environment.Environment()
resource._register_class('DummyResource', DummyResource)
env.load({'resource_registry':
@ -354,8 +331,11 @@ class ProviderTemplateTest(HeatTestCase):
files=files), env=env,
stack_id=str(uuid.uuid4()))
definition = rsrc_defn.ResourceDefinition('test_t_res',
"DummyResource",
{"Foo": "bar"})
temp_res = template_resource.TemplateResource('test_t_res',
json_snippet, stack)
definition, stack)
self.assertRaises(exception.StackValidationFailed,
temp_res.validate)
@ -413,21 +393,23 @@ class ProviderTemplateTest(HeatTestCase):
allowed_schemes=('http', 'https')).AndReturn(test_templ)
parsed_test_templ = template_format.parse(test_templ)
self.m.ReplayAll()
json_snippet = {
"Type": test_templ_name,
"Properties": {
"KeyName": "mykeyname",
"DBName": "wordpress1",
"DBUsername": "wpdbuser",
"DBPassword": "wpdbpass",
"DBRootPassword": "wpdbrootpass",
"LinuxDistribution": "U10"
}
}
stack = parser.Stack(utils.dummy_context(), 'test_stack',
parser.Template(empty_template),
stack_id=str(uuid.uuid4()))
templ_resource = resource.Resource("test_templ_resource", json_snippet,
properties = {
"KeyName": "mykeyname",
"DBName": "wordpress1",
"DBUsername": "wpdbuser",
"DBPassword": "wpdbpass",
"DBRootPassword": "wpdbrootpass",
"LinuxDistribution": "U10"
}
definition = rsrc_defn.ResourceDefinition("test_templ_resource",
test_templ_name,
properties)
templ_resource = resource.Resource("test_templ_resource", definition,
stack)
self.m.VerifyAll()
self.assertIsInstance(templ_resource,
@ -436,7 +418,7 @@ class ProviderTemplateTest(HeatTestCase):
self.assertIn(prop, templ_resource.properties)
for attrib in parsed_test_templ.get("Outputs", {}):
self.assertIn(attrib, templ_resource.attributes)
for k, v in json_snippet.get("Properties").items():
for k, v in properties.items():
self.assertEqual(v, templ_resource.properties[k])
self.assertEqual(
{'WordPress_Single_Instance.yaml':
@ -476,8 +458,10 @@ class ProviderTemplateTest(HeatTestCase):
'file')).AndReturn(minimal_temp)
self.m.ReplayAll()
definition = rsrc_defn.ResourceDefinition('test_t_res',
'Test::Frodo')
temp_res = template_resource.TemplateResource('test_t_res',
{"Type": 'Test::Frodo'},
definition,
stack)
self.assertIsNone(temp_res.validate())
self.m.VerifyAll()
@ -493,8 +477,10 @@ class ProviderTemplateTest(HeatTestCase):
parser.Template(empty_template), env=env,
stack_id=str(uuid.uuid4()))
definition = rsrc_defn.ResourceDefinition('test_t_res',
'Test::Flippy')
temp_res = template_resource.TemplateResource('test_t_res',
{"Type": 'Test::Flippy'},
definition,
stack)
self.assertRaises(exception.StackValidationFailed, temp_res.validate)
@ -520,8 +506,10 @@ class ProviderTemplateTest(HeatTestCase):
.AndRaise(urlfetch.URLFetchError(_('Failed to retrieve template')))
self.m.ReplayAll()
definition = rsrc_defn.ResourceDefinition('test_t_res',
'Test::Frodo')
temp_res = template_resource.TemplateResource('test_t_res',
{"Type": 'Test::Frodo'},
definition,
stack)
self.assertRaises(exception.StackValidationFailed, temp_res.validate)
self.m.VerifyAll()
@ -546,8 +534,10 @@ class ProviderTemplateTest(HeatTestCase):
.AndRaise(urlfetch.URLFetchError(_('Failed to retrieve template')))
self.m.ReplayAll()
definition = rsrc_defn.ResourceDefinition('test_t_res',
'Test::Flippy')
temp_res = template_resource.TemplateResource('test_t_res',
{"Type": 'Test::Flippy'},
definition,
stack)
self.assertRaises(exception.StackValidationFailed, temp_res.validate)
self.m.VerifyAll()
@ -568,8 +558,10 @@ class ProviderTemplateTest(HeatTestCase):
self.m.ReplayAll()
definition = rsrc_defn.ResourceDefinition('test_t_res',
'Test::Flippy')
temp_res = template_resource.TemplateResource('test_t_res',
{"Type": 'Test::Flippy'},
definition,
stack)
self.assertRaises(exception.StackValidationFailed, temp_res.validate)
self.m.VerifyAll()

View File

@ -21,10 +21,12 @@ import six
from heat.common import exception
from heat.db import api as db_api
from heat.engine import attributes
from heat.engine.cfn import functions as cfn_funcs
from heat.engine import dependencies
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.engine import template
from heat.openstack.common.gettextutils import _
@ -60,13 +62,15 @@ class ResourceTest(HeatTestCase):
'NoExistResourceType')
def test_resource_new_ok(self):
snippet = {'Type': 'GenericResourceType'}
snippet = rsrc_defn.ResourceDefinition('aresource',
'GenericResourceType')
res = resource.Resource('aresource', snippet, self.stack)
self.assertIsInstance(res, generic_rsrc.GenericResource)
self.assertEqual("INIT", res.action)
def test_resource_new_stack_not_stored(self):
snippet = {'Type': 'GenericResourceType'}
snippet = rsrc_defn.ResourceDefinition('aresource',
'GenericResourceType')
self.stack.id = None
db_method = 'resource_get_by_name_and_stack'
with mock.patch.object(db_api, db_method) as resource_get:
@ -75,44 +79,27 @@ class ResourceTest(HeatTestCase):
self.assertIs(False, resource_get.called)
def test_resource_new_err(self):
snippet = {'Type': 'NoExistResourceType'}
snippet = rsrc_defn.ResourceDefinition('aresource',
'NoExistResourceType')
self.assertRaises(exception.StackValidationFailed,
resource.Resource, 'aresource', snippet, self.stack)
def test_resource_non_type(self):
snippet = {'Type': ''}
resource_name = 'aresource'
snippet = rsrc_defn.ResourceDefinition(resource_name, '')
ex = self.assertRaises(exception.StackValidationFailed,
resource.Resource, resource_name,
snippet, self.stack)
self.assertIn(_('Resource "%s" has no type') % resource_name, str(ex))
def test_resource_wrong_type(self):
snippet = {'Type': {}}
resource_name = 'aresource'
ex = self.assertRaises(exception.StackValidationFailed,
resource.Resource, resource_name,
snippet, self.stack)
self.assertIn(_('Resource "%s" type is not a string') % resource_name,
str(ex))
def test_resource_missed_type(self):
snippet = {'not-a-Type': 'GenericResourceType'}
resource_name = 'aresource'
ex = self.assertRaises(exception.StackValidationFailed,
resource.Resource, resource_name,
snippet, self.stack)
self.assertIn(_('Non-empty resource type is required '
'for resource "%s"') % resource_name, str(ex))
def test_state_defaults(self):
tmpl = {'Type': 'Foo'}
tmpl = rsrc_defn.ResourceDefinition('test_res_def', 'Foo')
res = generic_rsrc.GenericResource('test_res_def', tmpl, self.stack)
self.assertEqual((res.INIT, res.COMPLETE), res.state)
self.assertEqual('', res.status_reason)
def test_resource_str_repr_stack_id_resource_id(self):
tmpl = {'Type': 'Foo'}
tmpl = rsrc_defn.ResourceDefinition('test_res_str_repr', 'Foo')
res = generic_rsrc.GenericResource('test_res_str_repr', tmpl,
self.stack)
res.stack.id = "123"
@ -123,7 +110,7 @@ class ResourceTest(HeatTestCase):
self.assertEqual(expected, observed)
def test_resource_str_repr_stack_id_no_resource_id(self):
tmpl = {'Type': 'Foo'}
tmpl = rsrc_defn.ResourceDefinition('test_res_str_repr', 'Foo')
res = generic_rsrc.GenericResource('test_res_str_repr', tmpl,
self.stack)
res.stack.id = "123"
@ -134,7 +121,7 @@ class ResourceTest(HeatTestCase):
self.assertEqual(expected, observed)
def test_resource_str_repr_no_stack_id(self):
tmpl = {'Type': 'Foo'}
tmpl = rsrc_defn.ResourceDefinition('test_res_str_repr', 'Foo')
res = generic_rsrc.GenericResource('test_res_str_repr', tmpl,
self.stack)
res.stack.id = None
@ -143,7 +130,7 @@ class ResourceTest(HeatTestCase):
self.assertEqual(expected, observed)
def test_state_set(self):
tmpl = {'Type': 'Foo'}
tmpl = rsrc_defn.ResourceDefinition('test_resource', 'Foo')
res = generic_rsrc.GenericResource('test_resource', tmpl, self.stack)
res.state_set(res.CREATE, res.COMPLETE, 'wibble')
self.assertEqual(res.CREATE, res.action)
@ -152,7 +139,7 @@ class ResourceTest(HeatTestCase):
self.assertEqual('wibble', res.status_reason)
def test_prepare_abandon(self):
tmpl = {'Type': 'Foo'}
tmpl = rsrc_defn.ResourceDefinition('test_resource', 'Foo')
res = generic_rsrc.GenericResource('test_resource', tmpl, self.stack)
expected = {
'action': 'INIT',
@ -167,7 +154,7 @@ class ResourceTest(HeatTestCase):
self.assertEqual(expected, actual)
def test_abandon_with_resource_data(self):
tmpl = {'Type': 'Foo'}
tmpl = rsrc_defn.ResourceDefinition('test_resource', 'Foo')
res = generic_rsrc.GenericResource('test_resource', tmpl, self.stack)
res._data = {"test-key": "test-value"}
@ -184,14 +171,14 @@ class ResourceTest(HeatTestCase):
self.assertEqual(expected, actual)
def test_state_set_invalid(self):
tmpl = {'Type': 'Foo'}
tmpl = rsrc_defn.ResourceDefinition('test_resource', 'Foo')
res = generic_rsrc.GenericResource('test_resource', tmpl, self.stack)
self.assertRaises(ValueError, res.state_set, 'foo', 'bla')
self.assertRaises(ValueError, res.state_set, 'foo', res.COMPLETE)
self.assertRaises(ValueError, res.state_set, res.CREATE, 'bla')
def test_state_del_stack(self):
tmpl = {'Type': 'Foo'}
tmpl = rsrc_defn.ResourceDefinition('test_resource', 'Foo')
self.stack.action = self.stack.DELETE
self.stack.status = self.stack.IN_PROGRESS
res = generic_rsrc.GenericResource('test_resource', tmpl, self.stack)
@ -199,39 +186,43 @@ class ResourceTest(HeatTestCase):
self.assertEqual(res.COMPLETE, res.status)
def test_type(self):
tmpl = {'Type': 'Foo'}
tmpl = rsrc_defn.ResourceDefinition('test_resource', 'Foo')
res = generic_rsrc.GenericResource('test_resource', tmpl, self.stack)
self.assertEqual('Foo', res.type())
def test_has_interface_direct_match(self):
tmpl = {'Type': 'GenericResourceType'}
tmpl = rsrc_defn.ResourceDefinition('test_resource',
'GenericResourceType')
res = generic_rsrc.GenericResource('test_resource', tmpl, self.stack)
self.assertTrue(res.has_interface('GenericResourceType'))
def test_has_interface_no_match(self):
tmpl = {'Type': 'GenericResourceType'}
tmpl = rsrc_defn.ResourceDefinition('test_resource',
'GenericResourceType')
res = generic_rsrc.GenericResource('test_resource', tmpl, self.stack)
self.assertFalse(res.has_interface('LookingForAnotherType'))
def test_has_interface_mapping(self):
tmpl = {'Type': 'OS::Test::GenericResource'}
tmpl = rsrc_defn.ResourceDefinition('test_resource',
'OS::Test::GenericResource')
res = generic_rsrc.GenericResource('test_resource', tmpl, self.stack)
self.assertTrue(res.has_interface('GenericResourceType'))
def test_created_time(self):
tmpl = {'Type': 'Foo'}
tmpl = rsrc_defn.ResourceDefinition('test_resource', 'Foo')
res = generic_rsrc.GenericResource('test_res_new', tmpl, self.stack)
self.assertIsNone(res.created_time)
res._store()
self.assertIsNotNone(res.created_time)
def test_updated_time(self):
tmpl = {'Type': 'GenericResourceType'}
tmpl = rsrc_defn.ResourceDefinition('test_resource',
'GenericResourceType')
res = generic_rsrc.GenericResource('test_resource', tmpl, self.stack)
res._store()
stored_time = res.updated_time
utmpl = {'Type': 'Foo'}
utmpl = rsrc_defn.ResourceDefinition('test_resource', 'Foo')
scheduler.TaskRunner(res.update, utmpl)()
self.assertIsNotNone(res.updated_time)
self.assertNotEqual(res.updated_time, stored_time)
@ -243,7 +234,8 @@ class ResourceTest(HeatTestCase):
resource._register_class('TestResource', TestResource)
tmpl = {'Type': 'TestResource'}
tmpl = rsrc_defn.ResourceDefinition('test_resource',
'TestResource')
res = TestResource('test_resource', tmpl, self.stack)
utmpl = {'Type': 'TestResource', 'Properties': {'a_string': 'foo'}}
@ -251,7 +243,8 @@ class ResourceTest(HeatTestCase):
resource.UpdateReplace, scheduler.TaskRunner(res.update, utmpl))
def test_updated_time_changes_only_on_update_calls(self):
tmpl = {'Type': 'GenericResourceType'}
tmpl = rsrc_defn.ResourceDefinition('test_resource',
'GenericResourceType')
res = generic_rsrc.GenericResource('test_resource', tmpl, self.stack)
res._store()
self.assertIsNone(res.updated_time)
@ -260,7 +253,7 @@ class ResourceTest(HeatTestCase):
self.assertIsNone(res.updated_time)
def test_store_or_update(self):
tmpl = {'Type': 'Foo'}
tmpl = rsrc_defn.ResourceDefinition('test_resource', 'Foo')
res = generic_rsrc.GenericResource('test_res_upd', tmpl, self.stack)
res._store_or_update(res.CREATE, res.IN_PROGRESS, 'test_store')
self.assertIsNotNone(res.id)
@ -282,34 +275,37 @@ class ResourceTest(HeatTestCase):
self.assertEqual('test_update', db_res.status_reason)
def test_parsed_template(self):
tmpl = {
'Type': 'Foo',
'foo': {'Fn::Join': [' ', ['bar', 'baz', 'quux']]}
}
join_func = cfn_funcs.Join(None,
'Fn::Join', [' ', ['bar', 'baz', 'quux']])
tmpl = rsrc_defn.ResourceDefinition('test_resource', 'Foo',
metadata={'foo': join_func})
res = generic_rsrc.GenericResource('test_resource', tmpl, self.stack)
parsed_tmpl = res.parsed_template()
self.assertEqual('Foo', parsed_tmpl['Type'])
self.assertEqual('bar baz quux', parsed_tmpl['foo'])
self.assertEqual('bar baz quux', parsed_tmpl['Metadata']['foo'])
self.assertEqual('bar baz quux', res.parsed_template('foo'))
self.assertEqual('bar baz quux', res.parsed_template('foo', 'bar'))
self.assertEqual({'foo': 'bar baz quux'},
res.parsed_template('Metadata'))
self.assertEqual({'foo': 'bar baz quux'},
res.parsed_template('Metadata', {'foo': 'bar'}))
def test_parsed_template_default(self):
tmpl = {'Type': 'Foo'}
tmpl = rsrc_defn.ResourceDefinition('test_resource', 'Foo')
res = generic_rsrc.GenericResource('test_resource', tmpl, self.stack)
self.assertEqual({}, res.parsed_template('foo'))
self.assertEqual('bar', res.parsed_template('foo', 'bar'))
self.assertEqual({}, res.parsed_template('Metadata'))
self.assertEqual({'foo': 'bar'},
res.parsed_template('Metadata', {'foo': 'bar'}))
def test_metadata_default(self):
tmpl = {'Type': 'Foo'}
tmpl = rsrc_defn.ResourceDefinition('test_resource', 'Foo')
res = generic_rsrc.GenericResource('test_resource', tmpl, self.stack)
self.assertEqual({}, res.metadata_get())
def test_equals_different_stacks(self):
tmpl1 = {'Type': 'Foo'}
tmpl2 = {'Type': 'Foo'}
tmpl3 = {'Type': 'Bar'}
tmpl1 = rsrc_defn.ResourceDefinition('test_resource', 'Foo')
tmpl2 = rsrc_defn.ResourceDefinition('test_resource', 'Foo')
tmpl3 = rsrc_defn.ResourceDefinition('test_resource2', 'Bar')
stack2 = parser.Stack(utils.dummy_context(), 'test_stack',
parser.Template(empty_template), stack_id=-1)
res1 = generic_rsrc.GenericResource('test_resource', tmpl1, self.stack)
@ -320,8 +316,8 @@ class ResourceTest(HeatTestCase):
self.assertNotEqual(res1, res3)
def test_equals_names(self):
tmpl1 = {'Type': 'Foo'}
tmpl2 = {'Type': 'Foo'}
tmpl1 = rsrc_defn.ResourceDefinition('test_resource1', 'Foo')
tmpl2 = rsrc_defn.ResourceDefinition('test_resource2', 'Foo')
res1 = generic_rsrc.GenericResource('test_resource1',
tmpl1, self.stack)
res2 = generic_rsrc.GenericResource('test_resource2', tmpl2,
@ -330,29 +326,33 @@ class ResourceTest(HeatTestCase):
self.assertNotEqual(res1, res2)
def test_update_template_diff_changed_modified(self):
tmpl = {'Type': 'Foo', 'Metadata': {'foo': 123}}
update_snippet = {'Type': 'Foo', 'Metadata': {'foo': 456}}
tmpl = rsrc_defn.ResourceDefinition('test_resource', 'Foo',
metadata={'foo': 123})
update_snippet = rsrc_defn.ResourceDefinition('test_resource', 'Foo',
metadata={'foo': 456})
res = generic_rsrc.GenericResource('test_resource', tmpl, self.stack)
diff = res.update_template_diff(update_snippet, tmpl)
self.assertEqual({'Metadata': {'foo': 456}}, diff)
def test_update_template_diff_changed_add(self):
tmpl = {'Type': 'Foo'}
update_snippet = {'Type': 'Foo', 'Metadata': {'foo': 123}}
tmpl = rsrc_defn.ResourceDefinition('test_resource', 'Foo')
update_snippet = rsrc_defn.ResourceDefinition('test_resource', 'Foo',
metadata={'foo': 123})
res = generic_rsrc.GenericResource('test_resource', tmpl, self.stack)
diff = res.update_template_diff(update_snippet, tmpl)
self.assertEqual({'Metadata': {'foo': 123}}, diff)
def test_update_template_diff_changed_remove(self):
tmpl = {'Type': 'Foo', 'Metadata': {'foo': 123}}
update_snippet = {'Type': 'Foo'}
tmpl = rsrc_defn.ResourceDefinition('test_resource', 'Foo',
metadata={'foo': 123})
update_snippet = rsrc_defn.ResourceDefinition('test_resource', 'Foo')
res = generic_rsrc.GenericResource('test_resource', tmpl, self.stack)
diff = res.update_template_diff(update_snippet, tmpl)
self.assertEqual({'Metadata': None}, diff)
def test_update_template_diff_properties_none(self):
before_props = {}
tmpl = {'Type': 'Foo'}
tmpl = rsrc_defn.ResourceDefinition('test_resource', 'Foo')
after_props = {}
res = generic_rsrc.ResourceWithProps('test_resource', tmpl, self.stack)
diff = res.update_template_diff_properties(after_props, before_props)
@ -360,7 +360,7 @@ class ResourceTest(HeatTestCase):
def test_update_template_diff_properties_added(self):
before_props = {}
tmpl = {'Type': 'Foo'}
tmpl = rsrc_defn.ResourceDefinition('test_resource', 'Foo')
after_props = {'Foo': '123'}
res = generic_rsrc.ResourceWithProps('test_resource', tmpl, self.stack)
res.update_allowed_properties = ('Foo',)
@ -369,9 +369,10 @@ class ResourceTest(HeatTestCase):
def test_update_template_diff_properties_removed_no_default_value(self):
before_props = {'Foo': '123'}
tmpl = {'Type': 'Foo', 'Properties': before_props}
tmpl = rsrc_defn.ResourceDefinition('test_resource', 'Foo',
before_props)
# Here should be used real property to get default value
new_t = {'Type': 'Foo'}
new_t = rsrc_defn.ResourceDefinition('test_resource', 'Foo')
new_res = generic_rsrc.ResourceWithProps('new_res', new_t, self.stack)
after_props = new_res.properties
@ -382,11 +383,12 @@ class ResourceTest(HeatTestCase):
def test_update_template_diff_properties_removed_with_default_value(self):
before_props = {'Foo': '123'}
tmpl = {'Type': 'Foo', 'Properties': before_props}
tmpl = rsrc_defn.ResourceDefinition('test_resource', 'Foo',
before_props)
generic_rsrc.ResourceWithProps.properties_schema = \
{'Foo': {'Type': 'String', 'Default': '567'}}
# Here should be used real property to get default value
new_t = {'Type': 'Foo'}
new_t = rsrc_defn.ResourceDefinition('test_resource', 'Foo')
new_res = generic_rsrc.ResourceWithProps('new_res', new_t, self.stack)
after_props = new_res.properties
@ -397,7 +399,8 @@ class ResourceTest(HeatTestCase):
def test_update_template_diff_properties_changed(self):
before_props = {'Foo': '123'}
tmpl = {'Type': 'Foo', 'Properties': before_props}
tmpl = rsrc_defn.ResourceDefinition('test_resource', 'Foo',
before_props)
after_props = {'Foo': '456'}
res = generic_rsrc.ResourceWithProps('test_resource', tmpl, self.stack)
res.update_allowed_properties = ('Foo',)
@ -406,7 +409,8 @@ class ResourceTest(HeatTestCase):
def test_update_template_diff_properties_notallowed(self):
before_props = {'Foo': '123'}
tmpl = {'Type': 'Foo', 'Properties': before_props}
tmpl = rsrc_defn.ResourceDefinition('test_resource', 'Foo',
before_props)
after_props = {'Bar': '456'}
res = generic_rsrc.ResourceWithProps('test_resource', tmpl, self.stack)
res.update_allowed_properties = ('Cat',)
@ -415,14 +419,15 @@ class ResourceTest(HeatTestCase):
after_props, before_props)
def test_resource(self):
tmpl = {'Type': 'GenericResourceType', 'Properties': {'Foo': 'abc'}}
tmpl = rsrc_defn.ResourceDefinition('test_resource', 'Foo',
{'Foo': 'abc'})
res = generic_rsrc.ResourceWithProps('test_resource', tmpl, self.stack)
scheduler.TaskRunner(res.create)()
self.assertEqual((res.CREATE, res.COMPLETE), res.state)
def test_create_fail_missing_req_prop(self):
tmpl = {'Type': 'GenericResourceType', 'Properties': {}}
rname = 'test_resource'
tmpl = rsrc_defn.ResourceDefinition(rname, 'Foo', {})
res = generic_rsrc.ResourceWithRequiredProps(rname, tmpl, self.stack)
estr = 'Property error : test_resource: Property Foo not assigned'
@ -432,8 +437,9 @@ class ResourceTest(HeatTestCase):
self.assertEqual((res.CREATE, res.FAILED), res.state)
def test_create_fail_prop_typo(self):
tmpl = {'Type': 'GenericResourceType', 'Properties': {'Food': 'abc'}}
rname = 'test_resource'
tmpl = rsrc_defn.ResourceDefinition(rname, 'GenericResourceType',
{'Food': 'abc'})
res = generic_rsrc.ResourceWithProps(rname, tmpl, self.stack)
estr = 'StackValidationFailed: Unknown Property Food'
@ -443,9 +449,12 @@ class ResourceTest(HeatTestCase):
self.assertEqual((res.CREATE, res.FAILED), res.state)
def test_create_fail_metadata_parse_error(self):
tmpl = {'Type': 'GenericResourceType', 'Properties': {},
'Metadata': {"Fn::GetAtt": ["ResourceA", "abc"]}}
rname = 'test_resource'
get_att = cfn_funcs.GetAtt(self.stack, 'Fn::GetAtt',
["ResourceA", "abc"])
tmpl = rsrc_defn.ResourceDefinition(rname, 'GenericResourceType',
properties={},
metadata={'foo': get_att})
res = generic_rsrc.ResourceWithProps(rname, tmpl, self.stack)
create = scheduler.TaskRunner(res.create)
@ -453,8 +462,8 @@ class ResourceTest(HeatTestCase):
self.assertEqual((res.CREATE, res.FAILED), res.state)
def test_create_resource_after_destroy(self):
tmpl = {'Type': 'GenericResourceType'}
rname = 'test_res_id_none'
tmpl = rsrc_defn.ResourceDefinition(rname, 'GenericResourceType')
res = generic_rsrc.ResourceWithProps(rname, tmpl, self.stack)
res.id = 'test_res_id'
(res.action, res.status) = (res.INIT, res.DELETE)
@ -465,18 +474,23 @@ class ResourceTest(HeatTestCase):
self.assertEqual((res.CREATE, res.COMPLETE), res.state)
def test_preview(self):
tmpl = {'Type': 'GenericResourceType'}
tmpl = rsrc_defn.ResourceDefinition('test_resource',
'GenericResourceType')
res = generic_rsrc.ResourceWithProps('test_resource', tmpl, self.stack)
self.assertEqual(res, res.preview())
def test_update_ok(self):
tmpl = {'Type': 'GenericResourceType', 'Properties': {'Foo': 'abc'}}
tmpl = rsrc_defn.ResourceDefinition('test_resource',
'GenericResourceType',
{'Foo': 'abc'})
res = generic_rsrc.ResourceWithProps('test_resource', tmpl, self.stack)
res.update_allowed_properties = ('Foo',)
scheduler.TaskRunner(res.create)()
self.assertEqual((res.CREATE, res.COMPLETE), res.state)
utmpl = {'Type': 'GenericResourceType', 'Properties': {'Foo': 'xyz'}}
utmpl = rsrc_defn.ResourceDefinition('test_resource',
'GenericResourceType',
{'Foo': 'xyz'})
tmpl_diff = {'Properties': {'Foo': 'xyz'}}
prop_diff = {'Foo': 'xyz'}
self.m.StubOutWithMock(generic_rsrc.ResourceWithProps, 'handle_update')
@ -489,13 +503,17 @@ class ResourceTest(HeatTestCase):
self.m.VerifyAll()
def test_update_replace_with_resource_name(self):
tmpl = {'Type': 'GenericResourceType', 'Properties': {'Foo': 'abc'}}
tmpl = rsrc_defn.ResourceDefinition('test_resource',
'GenericResourceType',
{'Foo': 'abc'})
res = generic_rsrc.ResourceWithProps('test_resource', tmpl, self.stack)
res.update_allowed_properties = ('Foo',)
scheduler.TaskRunner(res.create)()
self.assertEqual((res.CREATE, res.COMPLETE), res.state)
utmpl = {'Type': 'GenericResourceType', 'Properties': {'Foo': 'xyz'}}
utmpl = rsrc_defn.ResourceDefinition('test_resource',
'GenericResourceType',
{'Foo': 'xyz'})
self.m.StubOutWithMock(generic_rsrc.ResourceWithProps, 'handle_update')
tmpl_diff = {'Properties': {'Foo': 'xyz'}}
prop_diff = {'Foo': 'xyz'}
@ -511,13 +529,17 @@ class ResourceTest(HeatTestCase):
self.m.VerifyAll()
def test_update_replace_without_resource_name(self):
tmpl = {'Type': 'GenericResourceType', 'Properties': {'Foo': 'abc'}}
tmpl = rsrc_defn.ResourceDefinition('test_resource',
'GenericResourceType',
{'Foo': 'abc'})
res = generic_rsrc.ResourceWithProps('test_resource', tmpl, self.stack)
res.update_allowed_properties = ('Foo',)
scheduler.TaskRunner(res.create)()
self.assertEqual((res.CREATE, res.COMPLETE), res.state)
utmpl = {'Type': 'GenericResourceType', 'Properties': {'Foo': 'xyz'}}
utmpl = rsrc_defn.ResourceDefinition('test_resource',
'GenericResourceType',
{'Foo': 'xyz'})
self.m.StubOutWithMock(generic_rsrc.ResourceWithProps, 'handle_update')
tmpl_diff = {'Properties': {'Foo': 'xyz'}}
prop_diff = {'Foo': 'xyz'}
@ -532,40 +554,52 @@ class ResourceTest(HeatTestCase):
self.m.VerifyAll()
def test_update_fail_missing_req_prop(self):
tmpl = {'Type': 'GenericResourceType', 'Properties': {'Foo': 'abc'}}
tmpl = rsrc_defn.ResourceDefinition('test_resource',
'GenericResourceType',
{'Foo': 'abc'})
res = generic_rsrc.ResourceWithRequiredProps('test_resource',
tmpl, self.stack)
res.update_allowed_properties = ('Foo',)
scheduler.TaskRunner(res.create)()
self.assertEqual((res.CREATE, res.COMPLETE), res.state)
utmpl = {'Type': 'GenericResourceType', 'Properties': {}}
utmpl = rsrc_defn.ResourceDefinition('test_resource',
'GenericResourceType',
{})
updater = scheduler.TaskRunner(res.update, utmpl)
self.assertRaises(exception.ResourceFailure, updater)
self.assertEqual((res.UPDATE, res.FAILED), res.state)
def test_update_fail_prop_typo(self):
tmpl = {'Type': 'GenericResourceType', 'Properties': {'Foo': 'abc'}}
tmpl = rsrc_defn.ResourceDefinition('test_resource',
'GenericResourceType',
{'Foo': 'abc'})
res = generic_rsrc.ResourceWithProps('test_resource', tmpl, self.stack)
res.update_allowed_properties = ('Foo',)
scheduler.TaskRunner(res.create)()
self.assertEqual((res.CREATE, res.COMPLETE), res.state)
utmpl = {'Type': 'GenericResourceType', 'Properties': {'Food': 'xyz'}}
utmpl = rsrc_defn.ResourceDefinition('test_resource',
'GenericResourceType',
{'Food': 'xyz'})
updater = scheduler.TaskRunner(res.update, utmpl)
self.assertRaises(exception.ResourceFailure, updater)
self.assertEqual((res.UPDATE, res.FAILED), res.state)
def test_update_not_implemented(self):
tmpl = {'Type': 'GenericResourceType', 'Properties': {'Foo': 'abc'}}
tmpl = rsrc_defn.ResourceDefinition('test_resource',
'GenericResourceType',
{'Foo': 'abc'})
res = generic_rsrc.ResourceWithProps('test_resource', tmpl, self.stack)
res.update_allowed_properties = ('Foo',)
scheduler.TaskRunner(res.create)()
self.assertEqual((res.CREATE, res.COMPLETE), res.state)
utmpl = {'Type': 'GenericResourceType', 'Properties': {'Foo': 'xyz'}}
utmpl = rsrc_defn.ResourceDefinition('test_resource',
'GenericResourceType',
{'Foo': 'xyz'})
tmpl_diff = {'Properties': {'Foo': 'xyz'}}
prop_diff = {'Foo': 'xyz'}
self.m.StubOutWithMock(generic_rsrc.ResourceWithProps, 'handle_update')
@ -578,7 +612,9 @@ class ResourceTest(HeatTestCase):
self.m.VerifyAll()
def test_suspend_resume_ok(self):
tmpl = {'Type': 'GenericResourceType', 'Properties': {'Foo': 'abc'}}
tmpl = rsrc_defn.ResourceDefinition('test_resource',
'GenericResourceType',
{'Foo': 'abc'})
res = generic_rsrc.ResourceWithProps('test_resource', tmpl, self.stack)
res.update_allowed_properties = ('Foo',)
scheduler.TaskRunner(res.create)()
@ -589,7 +625,9 @@ class ResourceTest(HeatTestCase):
self.assertEqual((res.RESUME, res.COMPLETE), res.state)
def test_suspend_fail_inprogress(self):
tmpl = {'Type': 'GenericResourceType', 'Properties': {'Foo': 'abc'}}
tmpl = rsrc_defn.ResourceDefinition('test_resource',
'GenericResourceType',
{'Foo': 'abc'})
res = generic_rsrc.ResourceWithProps('test_resource', tmpl, self.stack)
scheduler.TaskRunner(res.create)()
self.assertEqual((res.CREATE, res.COMPLETE), res.state)
@ -607,7 +645,9 @@ class ResourceTest(HeatTestCase):
self.assertRaises(exception.ResourceFailure, suspend)
def test_resume_fail_not_suspend_complete(self):
tmpl = {'Type': 'GenericResourceType', 'Properties': {'Foo': 'abc'}}
tmpl = rsrc_defn.ResourceDefinition('test_resource',
'GenericResourceType',
{'Foo': 'abc'})
res = generic_rsrc.ResourceWithProps('test_resource', tmpl, self.stack)
scheduler.TaskRunner(res.create)()
self.assertEqual((res.CREATE, res.COMPLETE), res.state)
@ -621,7 +661,9 @@ class ResourceTest(HeatTestCase):
self.assertRaises(exception.ResourceFailure, resume)
def test_suspend_fail_exception(self):
tmpl = {'Type': 'GenericResourceType', 'Properties': {'Foo': 'abc'}}
tmpl = rsrc_defn.ResourceDefinition('test_resource',
'GenericResourceType',
{'Foo': 'abc'})
res = generic_rsrc.ResourceWithProps('test_resource', tmpl, self.stack)
scheduler.TaskRunner(res.create)()
self.assertEqual((res.CREATE, res.COMPLETE), res.state)
@ -636,7 +678,9 @@ class ResourceTest(HeatTestCase):
self.assertEqual((res.SUSPEND, res.FAILED), res.state)
def test_resume_fail_exception(self):
tmpl = {'Type': 'GenericResourceType', 'Properties': {'Foo': 'abc'}}
tmpl = rsrc_defn.ResourceDefinition('test_resource',
'GenericResourceType',
{'Foo': 'abc'})
res = generic_rsrc.ResourceWithProps('test_resource', tmpl, self.stack)
scheduler.TaskRunner(res.create)()
self.assertEqual((res.CREATE, res.COMPLETE), res.state)
@ -1293,16 +1337,17 @@ class ResourceDependenciesTest(HeatTestCase):
class MetadataTest(HeatTestCase):
def setUp(self):
super(MetadataTest, self).setUp()
tmpl = {
'Type': 'Foo',
'Metadata': {'Test': 'Initial metadata'}
}
self.stack = parser.Stack(utils.dummy_context(),
'test_stack',
parser.Template(empty_template))
self.stack.store()
metadata = {'Test': 'Initial metadata'}
tmpl = rsrc_defn.ResourceDefinition('metadata_resource', 'Foo',
metadata=metadata)
self.res = generic_rsrc.GenericResource('metadata_resource',
tmpl, self.stack)
scheduler.TaskRunner(self.res.create)()
self.addCleanup(self.stack.delete)

View File

@ -84,7 +84,7 @@ class ResourceGroupTest(common.HeatTestCase):
appropriately based on properties.
"""
stack = utils.parse_stack(template)
snip = stack.t['Resources']['group1']
snip = stack.t.resource_definitions(stack)['group1']
resg = resource_group.ResourceGroup('test', snip, stack)
templ = {
"heat_template_version": "2013-05-23",
@ -117,7 +117,7 @@ class ResourceGroupTest(common.HeatTestCase):
res_def = templ["resources"]["group1"]["properties"]['resource_def']
res_def['properties']['Foo'] = None
stack = utils.parse_stack(templ)
snip = stack.t['Resources']['group1']
snip = stack.t.resource_definitions(stack)['group1']
resg = resource_group.ResourceGroup('test', snip, stack)
expect = {
"heat_template_version": "2013-05-23",
@ -146,7 +146,7 @@ class ResourceGroupTest(common.HeatTestCase):
grp_props = tmp['resources']['group1']['properties']
grp_props['resource_def']['type'] = "idontexist"
stack = utils.parse_stack(tmp)
snip = stack.t['Resources']['group1']
snip = stack.t.resource_definitions(stack)['group1']
resg = resource_group.ResourceGroup('test', snip, stack)
exc = self.assertRaises(exception.StackValidationFailed,
resg.validate)
@ -154,7 +154,7 @@ class ResourceGroupTest(common.HeatTestCase):
def test_reference_attr(self):
stack = utils.parse_stack(template2)
snip = stack.t['Resources']['group1']
snip = stack.t.resource_definitions(stack)['group1']
resgrp = resource_group.ResourceGroup('test', snip, stack)
self.assertIsNone(resgrp.validate())
@ -205,7 +205,7 @@ class ResourceGroupTest(common.HeatTestCase):
def _create_dummy_stack(self):
stack = utils.parse_stack(template)
snip = stack.t['Resources']['group1']
snip = stack.t.resource_definitions(stack)['group1']
resg = resource_group.ResourceGroup('test', snip, stack)
scheduler.TaskRunner(resg.create)()
self.stack = resg.nested()
@ -215,7 +215,7 @@ class ResourceGroupTest(common.HeatTestCase):
def test_child_template(self):
stack = utils.parse_stack(template2)
snip = stack.t['Resources']['group1']
snip = stack.t.resource_definitions(stack)['group1']
resgrp = resource_group.ResourceGroup('test', snip, stack)
resgrp._assemble_nested = mock.Mock(return_value='tmpl')
resgrp.properties.data[resgrp.COUNT] = 2
@ -225,6 +225,6 @@ class ResourceGroupTest(common.HeatTestCase):
def test_child_params(self):
stack = utils.parse_stack(template2)
snip = stack.t['Resources']['group1']
snip = stack.t.resource_definitions(stack)['group1']
resgrp = resource_group.ResourceGroup('test', snip, stack)
self.assertEqual({}, resgrp.child_params())

View File

@ -44,8 +44,9 @@ class RestarterTest(common.HeatTestCase):
def create_restarter(self):
snippet = template_format.parse(restarter_template)
stack = utils.parse_stack(snippet)
resource_defns = stack.t.resource_definitions(stack)
restarter = instance.Restarter(
'restarter', snippet['Resources']['restarter'], stack)
'restarter', resource_defns['restarter'], stack)
restarter.handle_create = mock.Mock(return_value=None)
return restarter

View File

@ -77,8 +77,9 @@ class s3Test(HeatTestCase):
self.m.StubOutWithMock(clients.OpenStackClients, 'keystone')
def create_resource(self, t, stack, resource_name):
resource_defns = stack.t.resource_definitions(stack)
rsrc = s3.S3Bucket('test_resource',
t['Resources'][resource_name],
resource_defns[resource_name],
stack)
scheduler.TaskRunner(rsrc.create)()
self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)

View File

@ -94,26 +94,33 @@ class ServersTest(HeatTestCase):
environment.Environment({'key_name': 'test'}),
stack_id=str(uuid.uuid4()),
stack_user_project_id='8888')
return (t, stack)
return (template, stack)
def _get_test_template(self, stack_name, server_name=None,
image_id=None):
(tmpl, stack) = self._setup_test_stack(stack_name)
tmpl.t['Resources']['WebServer']['Properties']['image'] = \
image_id or 'CentOS 5.2'
tmpl.t['Resources']['WebServer']['Properties']['flavor'] = \
'256 MB Server'
if server_name is not None:
tmpl.t['Resources']['WebServer']['Properties']['name'] = \
server_name
return tmpl, stack
def _setup_test_server(self, return_server, name, image_id=None,
override_name=False, stub_create=True,
server_rebuild=False):
stack_name = '%s_s' % name
(t, stack) = self._setup_test_stack(stack_name)
t['Resources']['WebServer']['Properties']['image'] = \
image_id or 'CentOS 5.2'
t['Resources']['WebServer']['Properties']['flavor'] = \
'256 MB Server'
server_name = '%s' % name
if override_name:
t['Resources']['WebServer']['Properties']['name'] = \
server_name
server = servers.Server(server_name,
t['Resources']['WebServer'], stack)
server_name = str(name) if override_name else None
tmpl, stack = self._get_test_template(stack_name, server_name,
image_id)
resource_defns = tmpl.resource_definitions(stack)
server = servers.Server(str(name), resource_defns['WebServer'],
stack)
self._mock_get_image_id_success(image_id or 'CentOS 5.2', 1,
server_rebuild=server_rebuild)
@ -235,12 +242,13 @@ class ServersTest(HeatTestCase):
def test_server_create_metadata(self):
return_server = self.fc.servers.list()[1]
stack_name = 'create_metadata_test_stack'
(t, stack) = self._setup_test_stack(stack_name)
(tmpl, stack) = self._setup_test_stack(stack_name)
t['Resources']['WebServer']['Properties']['metadata'] = \
tmpl['Resources']['WebServer']['Properties']['metadata'] = \
{'a': 1}
resource_defns = tmpl.resource_definitions(stack)
server = servers.Server('create_metadata_test_server',
t['Resources']['WebServer'], stack)
resource_defns['WebServer'], stack)
instance_meta = {'a': "1"}
image_id = mox.IgnoreArg()
@ -313,12 +321,13 @@ class ServersTest(HeatTestCase):
def test_server_create_image_name_err(self):
stack_name = 'img_name_err'
(t, stack) = self._setup_test_stack(stack_name)
(tmpl, stack) = self._setup_test_stack(stack_name)
# create an server with non exist image name
t['Resources']['WebServer']['Properties']['image'] = 'Slackware'
tmpl['Resources']['WebServer']['Properties']['image'] = 'Slackware'
resource_defns = tmpl.resource_definitions(stack)
server = servers.Server('server_create_image_err',
t['Resources']['WebServer'], stack)
resource_defns['WebServer'], stack)
self._mock_get_image_id_fail('Slackware',
exception.ImageNotFound(
@ -335,12 +344,13 @@ class ServersTest(HeatTestCase):
def test_server_create_duplicate_image_name_err(self):
stack_name = 'img_dup_err'
(t, stack) = self._setup_test_stack(stack_name)
(tmpl, stack) = self._setup_test_stack(stack_name)
# create an server with a non unique image name
t['Resources']['WebServer']['Properties']['image'] = 'CentOS 5.2'
tmpl['Resources']['WebServer']['Properties']['image'] = 'CentOS 5.2'
resource_defns = tmpl.resource_definitions(stack)
server = servers.Server('server_create_image_err',
t['Resources']['WebServer'], stack)
resource_defns['WebServer'], stack)
self._mock_get_image_id_fail('CentOS 5.2',
exception.PhysicalResourceNameAmbiguity(
@ -357,12 +367,13 @@ class ServersTest(HeatTestCase):
def test_server_create_image_id_err(self):
stack_name = 'img_id_err'
(t, stack) = self._setup_test_stack(stack_name)
(tmpl, stack) = self._setup_test_stack(stack_name)
# create an server with non exist image Id
t['Resources']['WebServer']['Properties']['image'] = '1'
tmpl['Resources']['WebServer']['Properties']['image'] = '1'
resource_defns = tmpl.resource_definitions(stack)
server = servers.Server('server_create_image_err',
t['Resources']['WebServer'], stack)
resource_defns['WebServer'], stack)
self._mock_get_image_id_fail('1',
exception.ImageNotFound(image_name='1'))
@ -410,13 +421,14 @@ class ServersTest(HeatTestCase):
def test_server_create_raw_userdata(self):
return_server = self.fc.servers.list()[1]
stack_name = 'raw_userdata_s'
(t, stack) = self._setup_test_stack(stack_name)
(tmpl, stack) = self._setup_test_stack(stack_name)
t['Resources']['WebServer']['Properties']['user_data_format'] = \
tmpl['Resources']['WebServer']['Properties']['user_data_format'] = \
'RAW'
resource_defns = tmpl.resource_definitions(stack)
server = servers.Server('WebServer',
t['Resources']['WebServer'], stack)
resource_defns['WebServer'], stack)
self.m.StubOutWithMock(server, 'nova')
server.nova().MultipleTimes().AndReturn(self.fc)
@ -443,15 +455,16 @@ class ServersTest(HeatTestCase):
def test_server_create_raw_config_userdata(self):
return_server = self.fc.servers.list()[1]
stack_name = 'raw_userdata_s'
(t, stack) = self._setup_test_stack(stack_name)
(tmpl, stack) = self._setup_test_stack(stack_name)
t['Resources']['WebServer']['Properties']['user_data_format'] = \
tmpl['Resources']['WebServer']['Properties']['user_data_format'] = \
'RAW'
t['Resources']['WebServer']['Properties']['user_data'] = \
tmpl['Resources']['WebServer']['Properties']['user_data'] = \
'8c813873-f6ee-4809-8eec-959ef39acb55'
resource_defns = tmpl.resource_definitions(stack)
server = servers.Server('WebServer',
t['Resources']['WebServer'], stack)
resource_defns['WebServer'], stack)
self.m.StubOutWithMock(server, 'nova')
self.m.StubOutWithMock(server, 'heat')
@ -485,15 +498,16 @@ class ServersTest(HeatTestCase):
def test_server_create_raw_config_userdata_None(self):
return_server = self.fc.servers.list()[1]
stack_name = 'raw_userdata_s'
(t, stack) = self._setup_test_stack(stack_name)
(tmpl, stack) = self._setup_test_stack(stack_name)
sc_id = '8c813873-f6ee-4809-8eec-959ef39acb55'
t['Resources']['WebServer']['Properties']['user_data_format'] = \
tmpl['Resources']['WebServer']['Properties']['user_data_format'] = \
'RAW'
t['Resources']['WebServer']['Properties']['user_data'] = sc_id
tmpl['Resources']['WebServer']['Properties']['user_data'] = sc_id
resource_defns = tmpl.resource_definitions(stack)
server = servers.Server('WebServer',
t['Resources']['WebServer'], stack)
resource_defns['WebServer'], stack)
self.m.StubOutWithMock(server, 'nova')
self.m.StubOutWithMock(server, 'heat')
@ -527,14 +541,15 @@ class ServersTest(HeatTestCase):
def test_server_create_software_config(self):
return_server = self.fc.servers.list()[1]
stack_name = 'software_config_s'
(t, stack) = self._setup_test_stack(stack_name)
(tmpl, stack) = self._setup_test_stack(stack_name)
t['Resources']['WebServer']['Properties']['user_data_format'] = \
tmpl['Resources']['WebServer']['Properties']['user_data_format'] = \
'SOFTWARE_CONFIG'
stack.stack_user_project_id = '8888'
resource_defns = tmpl.resource_definitions(stack)
server = servers.Server('WebServer',
t['Resources']['WebServer'], stack)
resource_defns['WebServer'], stack)
self.m.StubOutWithMock(server, 'nova')
self.m.StubOutWithMock(server, 'keystone')
@ -583,8 +598,9 @@ class ServersTest(HeatTestCase):
'deployments': []
}, server.metadata_get())
resource_defns = tmpl.resource_definitions(stack)
created_server = servers.Server('WebServer',
t['Resources']['WebServer'], stack)
resource_defns['WebServer'], stack)
self.assertEqual('4567', created_server.access_key)
self.assertTrue(stack.access_allowed('4567', 'WebServer'))
@ -593,14 +609,15 @@ class ServersTest(HeatTestCase):
def test_server_create_software_config_poll_heat(self):
return_server = self.fc.servers.list()[1]
stack_name = 'software_config_s'
(t, stack) = self._setup_test_stack(stack_name)
(tmpl, stack) = self._setup_test_stack(stack_name)
props = t['Resources']['WebServer']['Properties']
props = tmpl.t['Resources']['WebServer']['Properties']
props['user_data_format'] = 'SOFTWARE_CONFIG'
props['software_config_transport'] = 'POLL_SERVER_HEAT'
resource_defns = tmpl.resource_definitions(stack)
server = servers.Server('WebServer',
t['Resources']['WebServer'], stack)
resource_defns['WebServer'], stack)
self.m.StubOutWithMock(server, 'nova')
self.m.StubOutWithMock(server, 'keystone')
@ -648,8 +665,9 @@ class ServersTest(HeatTestCase):
'deployments': []
}, server.metadata_get())
resource_defns = tmpl.resource_definitions(stack)
created_server = servers.Server('WebServer',
t['Resources']['WebServer'], stack)
resource_defns['WebServer'], stack)
self.assertEqual('1234', created_server._get_user_id())
self.assertTrue(stack.access_allowed('1234', 'WebServer'))
@ -660,10 +678,11 @@ class ServersTest(HeatTestCase):
return_server = self.fc.servers.list()[1]
return_server.adminPass = 'autogenerated'
stack_name = 'admin_pass_s'
(t, stack) = self._setup_test_stack(stack_name)
(tmpl, stack) = self._setup_test_stack(stack_name)
resource_defns = tmpl.resource_definitions(stack)
server = servers.Server('WebServer',
t['Resources']['WebServer'], stack)
resource_defns['WebServer'], stack)
mock_nova.return_value = self.fc
self.fc.servers.create = mock.Mock(return_value=return_server)
@ -685,11 +704,12 @@ class ServersTest(HeatTestCase):
return_server = self.fc.servers.list()[1]
return_server.adminPass = 'foo'
stack_name = 'admin_pass_s'
(t, stack) = self._setup_test_stack(stack_name)
(tmpl, stack) = self._setup_test_stack(stack_name)
t['Resources']['WebServer']['Properties']['admin_pass'] = 'foo'
tmpl.t['Resources']['WebServer']['Properties']['admin_pass'] = 'foo'
resource_defns = tmpl.resource_definitions(stack)
server = servers.Server('WebServer',
t['Resources']['WebServer'], stack)
resource_defns['WebServer'], stack)
mock_nova.return_value = self.fc
self.fc.servers.create = mock.Mock(return_value=return_server)
@ -717,11 +737,12 @@ class ServersTest(HeatTestCase):
def test_server_validate(self):
stack_name = 'srv_val'
(t, stack) = self._setup_test_stack(stack_name)
(tmpl, stack) = self._setup_test_stack(stack_name)
t['Resources']['WebServer']['Properties']['image'] = '1'
tmpl.t['Resources']['WebServer']['Properties']['image'] = '1'
resource_defns = tmpl.resource_definitions(stack)
server = servers.Server('server_create_image',
t['Resources']['WebServer'], stack)
resource_defns['WebServer'], stack)
self.m.StubOutWithMock(clients.OpenStackClients, 'nova')
clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc)
@ -737,10 +758,10 @@ class ServersTest(HeatTestCase):
def test_server_validate_with_bootable_vol(self):
stack_name = 'srv_val_bootvol'
(t, stack) = self._setup_test_stack(stack_name)
(tmpl, stack) = self._setup_test_stack(stack_name)
# create an server with bootable volume
web_server = t['Resources']['WebServer']
web_server = tmpl.t['Resources']['WebServer']
del web_server['Properties']['image']
def create_server(device_name, mock_nova=True):
@ -750,8 +771,9 @@ class ServersTest(HeatTestCase):
"volume_id": "5d7e27da-6703-4f7e-9f94-1f67abef734c",
"delete_on_termination": False
}]
resource_defns = tmpl.resource_definitions(stack)
server = servers.Server('server_with_bootable_volume',
web_server, stack)
resource_defns['WebServer'], stack)
if mock_nova:
self.m.StubOutWithMock(server, 'nova')
server.nova().MultipleTimes().AndReturn(self.fc)
@ -801,8 +823,9 @@ class ServersTest(HeatTestCase):
stack = parser.Stack(utils.dummy_context(), stack_name, template,
stack_id=str(uuid.uuid4()))
resource_defns = template.resource_definitions(stack)
server = servers.Server('server_validate_test',
t['Resources']['WebServer'], stack)
resource_defns['WebServer'], stack)
self.m.StubOutWithMock(server, 'nova')
server.nova().MultipleTimes().AndReturn(self.fc)
@ -817,15 +840,16 @@ class ServersTest(HeatTestCase):
def test_server_validate_with_invalid_ssh_key(self):
stack_name = 'srv_val_test'
(t, stack) = self._setup_test_stack(stack_name)
(tmpl, stack) = self._setup_test_stack(stack_name)
web_server = t['Resources']['WebServer']
web_server = tmpl['Resources']['WebServer']
# Make the ssh key have an invalid name
web_server['Properties']['key_name'] = 'test2'
resource_defns = tmpl.resource_definitions(stack)
server = servers.Server('server_validate_test',
t['Resources']['WebServer'], stack)
resource_defns['WebServer'], stack)
self.m.StubOutWithMock(clients.OpenStackClients, 'nova')
clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc)
@ -839,36 +863,19 @@ class ServersTest(HeatTestCase):
str(error))
self.m.VerifyAll()
def test_server_validate_delete_policy(self):
stack_name = 'srv_val_delpol'
(t, stack) = self._setup_test_stack(stack_name)
# create an server with non exist image Id
t['Resources']['WebServer']['DeletionPolicy'] = 'SelfDestruct'
server = servers.Server('server_create_image_err',
t['Resources']['WebServer'], stack)
self.m.ReplayAll()
ex = self.assertRaises(exception.StackValidationFailed,
server.validate)
self.assertEqual('Invalid DeletionPolicy SelfDestruct',
str(ex))
self.m.VerifyAll()
def test_server_validate_with_networks(self):
stack_name = 'srv_net'
(t, stack) = self._setup_test_stack(stack_name)
(tmpl, stack) = self._setup_test_stack(stack_name)
network_name = 'public'
# create an server with 'uuid' and 'network' properties
t['Resources']['WebServer']['Properties']['networks'] = (
tmpl['Resources']['WebServer']['Properties']['networks'] = (
[{'uuid': 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa',
'network': network_name}])
resource_defns = tmpl.resource_definitions(stack)
server = servers.Server('server_validate_with_networks',
t['Resources']['WebServer'], stack)
resource_defns['WebServer'], stack)
self.m.StubOutWithMock(clients.OpenStackClients, 'nova')
clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc)
@ -890,15 +897,16 @@ class ServersTest(HeatTestCase):
# Test that if network 'ports' are assigned security groups are
# not, because they'll be ignored
stack_name = 'srv_net_secgroups'
(t, stack) = self._setup_test_stack(stack_name)
(tmpl, stack) = self._setup_test_stack(stack_name)
t['Resources']['WebServer']['Properties']['networks'] = [
tmpl['Resources']['WebServer']['Properties']['networks'] = [
{'port': 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'}]
t['Resources']['WebServer']['Properties']['security_groups'] = \
tmpl['Resources']['WebServer']['Properties']['security_groups'] = \
['my_security_group']
resource_defns = tmpl.resource_definitions(stack)
server = servers.Server('server_validate_net_security_groups',
t['Resources']['WebServer'], stack)
resource_defns['WebServer'], stack)
self.m.StubOutWithMock(server, 'nova')
server.nova().MultipleTimes().AndReturn(self.fc)
@ -966,12 +974,16 @@ class ServersTest(HeatTestCase):
server = self._create_test_server(return_server,
'md_update')
update_template = copy.deepcopy(server.t)
update_template['Metadata'] = {'test': 123}
scheduler.TaskRunner(server.update, update_template)()
ud_tmpl = self._get_test_template('update_stack')[0]
ud_tmpl.t['Resources']['WebServer']['Metadata'] = {'test': 123}
resource_defns = ud_tmpl.resource_definitions(server.stack)
scheduler.TaskRunner(server.update, resource_defns['WebServer'])()
self.assertEqual({'test': 123}, server.metadata_get())
server.t['Metadata'] = {'test': 456}
ud_tmpl.t['Resources']['WebServer']['Metadata'] = {'test': 456}
server.t = ud_tmpl.resource_definitions(server.stack)['WebServer']
self.assertEqual({'test': 123}, server.metadata_get())
server.metadata_update()
self.assertEqual({'test': 456}, server.metadata_get())
@ -1151,16 +1163,17 @@ class ServersTest(HeatTestCase):
def test_server_update_server_flavor_replace(self):
stack_name = 'update_flvrep'
(t, stack) = self._setup_test_stack(stack_name)
(tmpl, stack) = self._setup_test_stack(stack_name)
self.m.StubOutWithMock(clients.OpenStackClients, 'nova')
clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc)
self._mock_get_image_id_success('F17-x86_64-gold', 'image_id')
self.m.ReplayAll()
t['Resources']['WebServer']['Properties'][
tmpl['Resources']['WebServer']['Properties'][
'flavor_update_policy'] = 'REPLACE'
resource_defns = tmpl.resource_definitions(stack)
server = servers.Server('server_server_update_flavor_replace',
t['Resources']['WebServer'], stack)
resource_defns['WebServer'], stack)
update_template = copy.deepcopy(server.t)
update_template['Properties']['flavor'] = 'm1.smigish'
@ -1169,14 +1182,15 @@ class ServersTest(HeatTestCase):
def test_server_update_server_flavor_policy_update(self):
stack_name = 'update_flvpol'
(t, stack) = self._setup_test_stack(stack_name)
(tmpl, stack) = self._setup_test_stack(stack_name)
self.m.StubOutWithMock(clients.OpenStackClients, 'nova')
clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc)
self._mock_get_image_id_success('F17-x86_64-gold', 'image_id')
self.m.ReplayAll()
resource_defns = tmpl.resource_definitions(stack)
server = servers.Server('server_server_update_flavor_replace',
t['Resources']['WebServer'], stack)
resource_defns['WebServer'], stack)
update_template = copy.deepcopy(server.t)
# confirm that when flavor_update_policy is changed during
@ -1189,12 +1203,13 @@ class ServersTest(HeatTestCase):
def test_server_update_image_replace(self):
stack_name = 'update_imgrep'
(t, stack) = self._setup_test_stack(stack_name)
(tmpl, stack) = self._setup_test_stack(stack_name)
t['Resources']['WebServer']['Properties'][
tmpl.t['Resources']['WebServer']['Properties'][
'image_update_policy'] = 'REPLACE'
resource_defns = tmpl.resource_definitions(stack)
server = servers.Server('server_update_image_replace',
t['Resources']['WebServer'], stack)
resource_defns['WebServer'], stack)
image_id = self.getUniqueString()
self.m.StubOutWithMock(clients.OpenStackClients, 'nova')
clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc)
@ -1670,12 +1685,14 @@ class ServersTest(HeatTestCase):
def test_validate_block_device_mapping_volume_size_valid_int(self):
stack_name = 'val_vsize_valid'
t, stack = self._setup_test_stack(stack_name)
tmpl, stack = self._setup_test_stack(stack_name)
bdm = [{'device_name': 'vda', 'volume_id': '1234',
'volume_size': 10}]
t['Resources']['WebServer']['Properties']['block_device_mapping'] = bdm
wsp = tmpl.t['Resources']['WebServer']['Properties']
wsp['block_device_mapping'] = bdm
resource_defns = tmpl.resource_definitions(stack)
server = servers.Server('server_create_image_err',
t['Resources']['WebServer'], stack)
resource_defns['WebServer'], stack)
self._server_validate_mock(server)
self.m.ReplayAll()
@ -1685,12 +1702,14 @@ class ServersTest(HeatTestCase):
def test_validate_block_device_mapping_volume_size_valid_str(self):
stack_name = 'val_vsize_valid'
t, stack = self._setup_test_stack(stack_name)
tmpl, stack = self._setup_test_stack(stack_name)
bdm = [{'device_name': 'vda', 'volume_id': '1234',
'volume_size': '10'}]
t['Resources']['WebServer']['Properties']['block_device_mapping'] = bdm
wsp = tmpl.t['Resources']['WebServer']['Properties']
wsp['block_device_mapping'] = bdm
resource_defns = tmpl.resource_definitions(stack)
server = servers.Server('server_create_image_err',
t['Resources']['WebServer'], stack)
resource_defns['WebServer'], stack)
self._server_validate_mock(server)
@ -1701,12 +1720,14 @@ class ServersTest(HeatTestCase):
def test_validate_block_device_mapping_volume_size_invalid_str(self):
stack_name = 'val_vsize_invalid'
t, stack = self._setup_test_stack(stack_name)
tmpl, stack = self._setup_test_stack(stack_name)
bdm = [{'device_name': 'vda', 'volume_id': '1234',
'volume_size': '10a'}]
t['Resources']['WebServer']['Properties']['block_device_mapping'] = bdm
wsp = tmpl.t['Resources']['WebServer']['Properties']
wsp['block_device_mapping'] = bdm
resource_defns = tmpl.resource_definitions(stack)
server = servers.Server('server_create_image_err',
t['Resources']['WebServer'], stack)
resource_defns['WebServer'], stack)
exc = self.assertRaises(exception.StackValidationFailed,
server.validate)
@ -1714,13 +1735,15 @@ class ServersTest(HeatTestCase):
def test_validate_conflict_block_device_mapping_props(self):
stack_name = 'val_blkdev1'
(t, stack) = self._setup_test_stack(stack_name)
(tmpl, stack) = self._setup_test_stack(stack_name)
bdm = [{'device_name': 'vdb', 'snapshot_id': '1234',
'volume_id': '1234'}]
t['Resources']['WebServer']['Properties']['block_device_mapping'] = bdm
wsp = tmpl.t['Resources']['WebServer']['Properties']
wsp['block_device_mapping'] = bdm
resource_defns = tmpl.resource_definitions(stack)
server = servers.Server('server_create_image_err',
t['Resources']['WebServer'], stack)
resource_defns['WebServer'], stack)
self.m.StubOutWithMock(clients.OpenStackClients, 'nova')
clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc)
self._mock_get_image_id_success('F17-x86_64-gold', 'image_id')
@ -1731,13 +1754,15 @@ class ServersTest(HeatTestCase):
def test_validate_insufficient_block_device_mapping_props(self):
stack_name = 'val_blkdev2'
(t, stack) = self._setup_test_stack(stack_name)
(tmpl, stack) = self._setup_test_stack(stack_name)
bdm = [{'device_name': 'vdb', 'volume_size': 1,
'delete_on_termination': True}]
t['Resources']['WebServer']['Properties']['block_device_mapping'] = bdm
wsp = tmpl.t['Resources']['WebServer']['Properties']
wsp['block_device_mapping'] = bdm
resource_defns = tmpl.resource_definitions(stack)
server = servers.Server('server_create_image_err',
t['Resources']['WebServer'], stack)
resource_defns['WebServer'], stack)
self.m.StubOutWithMock(clients.OpenStackClients, 'nova')
clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc)
self._mock_get_image_id_success('F17-x86_64-gold', 'image_id')
@ -1753,13 +1778,15 @@ class ServersTest(HeatTestCase):
def test_validate_without_image_or_bootable_volume(self):
stack_name = 'val_imgvol'
(t, stack) = self._setup_test_stack(stack_name)
(tmpl, stack) = self._setup_test_stack(stack_name)
del t['Resources']['WebServer']['Properties']['image']
del tmpl['Resources']['WebServer']['Properties']['image']
bdm = [{'device_name': 'vdb', 'volume_id': '1234'}]
t['Resources']['WebServer']['Properties']['block_device_mapping'] = bdm
wsp = tmpl.t['Resources']['WebServer']['Properties']
wsp['block_device_mapping'] = bdm
resource_defns = tmpl.resource_definitions(stack)
server = servers.Server('server_create_image_err',
t['Resources']['WebServer'], stack)
resource_defns['WebServer'], stack)
self.m.StubOutWithMock(clients.OpenStackClients, 'nova')
clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc)
self.m.ReplayAll()
@ -1774,14 +1801,15 @@ class ServersTest(HeatTestCase):
def test_validate_metadata_too_many(self):
stack_name = 'srv_val_metadata'
(t, stack) = self._setup_test_stack(stack_name)
(tmpl, stack) = self._setup_test_stack(stack_name)
t['Resources']['WebServer']['Properties']['metadata'] = {'a': 1,
'b': 2,
'c': 3,
'd': 4}
tmpl.t['Resources']['WebServer']['Properties']['metadata'] = {'a': 1,
'b': 2,
'c': 3,
'd': 4}
resource_defns = tmpl.resource_definitions(stack)
server = servers.Server('server_create_image_err',
t['Resources']['WebServer'], stack)
resource_defns['WebServer'], stack)
self.m.StubOutWithMock(self.fc.limits, 'get')
self.fc.limits.get().MultipleTimes().AndReturn(self.limits)
@ -1801,13 +1829,14 @@ class ServersTest(HeatTestCase):
def test_validate_metadata_okay(self):
stack_name = 'srv_val_metadata'
(t, stack) = self._setup_test_stack(stack_name)
(tmpl, stack) = self._setup_test_stack(stack_name)
t['Resources']['WebServer']['Properties']['metadata'] = {'a': 1,
'b': 2,
'c': 3}
tmpl.t['Resources']['WebServer']['Properties']['metadata'] = {'a': 1,
'b': 2,
'c': 3}
resource_defns = tmpl.resource_definitions(stack)
server = servers.Server('server_create_image_err',
t['Resources']['WebServer'], stack)
resource_defns['WebServer'], stack)
self.m.StubOutWithMock(self.fc.limits, 'get')
self.fc.limits.get().MultipleTimes().AndReturn(self.limits)
@ -1823,17 +1852,18 @@ class ServersTest(HeatTestCase):
def test_server_validate_too_many_personality(self):
stack_name = 'srv_val'
(t, stack) = self._setup_test_stack(stack_name)
(tmpl, stack) = self._setup_test_stack(stack_name)
t['Resources']['WebServer']['Properties']['personality'] = \
tmpl.t['Resources']['WebServer']['Properties']['personality'] = \
{"/fake/path1": "fake contents1",
"/fake/path2": "fake_contents2",
"/fake/path3": "fake_contents3",
"/fake/path4": "fake_contents4",
"/fake/path5": "fake_contents5",
"/fake/path6": "fake_contents6"}
resource_defns = tmpl.resource_definitions(stack)
server = servers.Server('server_create_image_err',
t['Resources']['WebServer'], stack)
resource_defns['WebServer'], stack)
self.m.StubOutWithMock(self.fc.limits, 'get')
self.fc.limits.get().MultipleTimes().AndReturn(self.limits)
@ -1853,16 +1883,17 @@ class ServersTest(HeatTestCase):
def test_server_validate_personality_okay(self):
stack_name = 'srv_val'
(t, stack) = self._setup_test_stack(stack_name)
(tmpl, stack) = self._setup_test_stack(stack_name)
t['Resources']['WebServer']['Properties']['personality'] = \
tmpl.t['Resources']['WebServer']['Properties']['personality'] = \
{"/fake/path1": "fake contents1",
"/fake/path2": "fake_contents2",
"/fake/path3": "fake_contents3",
"/fake/path4": "fake_contents4",
"/fake/path5": "fake_contents5"}
resource_defns = tmpl.resource_definitions(stack)
server = servers.Server('server_create_image_err',
t['Resources']['WebServer'], stack)
resource_defns['WebServer'], stack)
self.m.StubOutWithMock(self.fc.limits, 'get')
self.fc.limits.get().MultipleTimes().AndReturn(self.limits)
@ -1879,12 +1910,13 @@ class ServersTest(HeatTestCase):
def test_server_validate_personality_file_size_okay(self):
stack_name = 'srv_val'
(t, stack) = self._setup_test_stack(stack_name)
(tmpl, stack) = self._setup_test_stack(stack_name)
t['Resources']['WebServer']['Properties']['personality'] = \
tmpl.t['Resources']['WebServer']['Properties']['personality'] = \
{"/fake/path1": "a" * 10240}
resource_defns = tmpl.resource_definitions(stack)
server = servers.Server('server_create_image_err',
t['Resources']['WebServer'], stack)
resource_defns['WebServer'], stack)
self.m.StubOutWithMock(self.fc.limits, 'get')
self.fc.limits.get().MultipleTimes().AndReturn(self.limits)
@ -1901,12 +1933,13 @@ class ServersTest(HeatTestCase):
def test_server_validate_personality_file_size_too_big(self):
stack_name = 'srv_val'
(t, stack) = self._setup_test_stack(stack_name)
(tmpl, stack) = self._setup_test_stack(stack_name)
t['Resources']['WebServer']['Properties']['personality'] = \
tmpl.t['Resources']['WebServer']['Properties']['personality'] = \
{"/fake/path1": "a" * 10241}
resource_defns = tmpl.resource_definitions(stack)
server = servers.Server('server_create_image_err',
t['Resources']['WebServer'], stack)
resource_defns['WebServer'], stack)
self.m.StubOutWithMock(self.fc.limits, 'get')
self.fc.limits.get().MultipleTimes().AndReturn(self.limits)
@ -1962,11 +1995,13 @@ class ServersTest(HeatTestCase):
"""
return_server = self.fc.servers.list()[1]
stack_name = 'stack_with_custom_admin_user_server'
(t, stack) = self._setup_test_stack(stack_name)
(tmpl, stack) = self._setup_test_stack(stack_name)
t['Resources']['WebServer']['Properties']['admin_user'] = 'custom_user'
wsp = tmpl.t['Resources']['WebServer']['Properties']
wsp['admin_user'] = 'custom_user'
resource_defns = tmpl.resource_definitions(stack)
server = servers.Server('create_metadata_test_server',
t['Resources']['WebServer'], stack)
resource_defns['WebServer'], stack)
self.m.StubOutWithMock(self.fc.servers, 'create')
image_id = mox.IgnoreArg()
self.fc.servers.create(

View File

@ -148,8 +148,9 @@ class ServerTagsTest(HeatTestCase):
stack_id=str(uuid.uuid4()))
t['Resources']['WebServer']['Properties']['Tags'] = intags
resource_defns = template.resource_definitions(stack)
instance = instances.Instance(stack_name,
t['Resources']['WebServer'], stack)
resource_defns['WebServer'], stack)
self.m.StubOutWithMock(instance, 'nova')
instance.nova().MultipleTimes().AndReturn(self.fc)

View File

@ -115,7 +115,7 @@ class SqlAlchemyTest(HeatTestCase):
stack_user_project_id=stack_user_project_id)
with utils.UUIDStub(stack_id):
stack.store()
return (t, stack)
return (template, stack)
def _mock_create(self, mocks):
fc = fakes.FakeClient()
@ -253,9 +253,10 @@ class SqlAlchemyTest(HeatTestCase):
def test_encryption(self):
stack_name = 'test_encryption'
(t, stack) = self._setup_test_stack(stack_name)
(tmpl, stack) = self._setup_test_stack(stack_name)
resource_defns = tmpl.resource_definitions(stack)
cs = MyResource('cs_encryption',
t['Resources']['WebServer'],
resource_defns['WebServer'],
stack)
# This gives the fake cloud server an id and created_time attribute

View File

@ -106,13 +106,15 @@ class StackResourceTest(HeatTestCase):
MyStackResource)
resource._register_class('GenericResource',
generic_rsrc.GenericResource)
self.ws_resname = "provider_resource"
t = parser.Template({'HeatTemplateFormatVersion': '2012-12-12',
'Resources':
{"provider_resource": ws_res_snippet}})
{self.ws_resname: ws_res_snippet}})
self.parent_stack = parser.Stack(utils.dummy_context(), 'test_stack',
t, stack_id=str(uuid.uuid4()))
resource_defns = t.resource_definitions(self.parent_stack)
self.parent_resource = MyStackResource('test',
ws_res_snippet,
resource_defns[self.ws_resname],
self.parent_stack)
self.templ = template_format.parse(param_template)
self.simple_template = template_format.parse(simple_template)
@ -148,9 +150,12 @@ class StackResourceTest(HeatTestCase):
mock_template_class.return_value = 'parsed_template'
mock_env_class.return_value = 'environment'
template = template_format.parse(param_template)
parent_resource = MyImplementedStackResource('test',
ws_res_snippet,
self.parent_stack)
parent_t = self.parent_stack.t
resource_defns = parent_t.resource_definitions(self.parent_stack)
parent_resource = MyImplementedStackResource(
'test',
resource_defns[self.ws_resname],
self.parent_stack)
params = {'KeyName': 'test'}
parent_resource.set_template(template, params)
validation_mock = mock.Mock(return_value=None)
@ -171,9 +176,12 @@ class StackResourceTest(HeatTestCase):
)
def test_preview_validates_nested_resources(self):
stack_resource = MyImplementedStackResource('test',
ws_res_snippet,
self.parent_stack)
parent_t = self.parent_stack.t
resource_defns = parent_t.resource_definitions(self.parent_stack)
stack_resource = MyImplementedStackResource(
'test',
resource_defns[self.ws_resname],
self.parent_stack)
stack_resource.child_template = \
mock.Mock(return_value={'HeatTemplateFormatVersion': '2012-12-12'})
stack_resource.child_params = mock.Mock()

View File

@ -80,9 +80,10 @@ class swiftTest(HeatTestCase):
self.m.StubOutWithMock(clients.OpenStackClients, 'keystone')
def create_resource(self, t, stack, resource_name):
resource_defns = stack.t.resource_definitions(stack)
rsrc = swift.SwiftContainer(
'test_resource',
t['Resources'][resource_name],
resource_defns[resource_name],
stack)
scheduler.TaskRunner(rsrc.create)()
self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
@ -93,9 +94,10 @@ class swiftTest(HeatTestCase):
t = template_format.parse(swift_template)
t['Resources']['SwiftContainer']['Properties']['name'] = 'the_name'
stack = utils.parse_stack(t)
resource_defns = stack.t.resource_definitions(stack)
rsrc = swift.SwiftContainer(
'test_resource',
t['Resources']['SwiftContainer'],
resource_defns['SwiftContainer'],
stack)
self.assertEqual('the_name', rsrc.physical_resource_name())

View File

@ -118,8 +118,9 @@ class UserTest(HeatTestCase):
fakes.FakeKeystoneClient.create_stack_domain_project(
stack.id).AndReturn(project_id)
resource_defns = stack.t.resource_definitions(stack)
rsrc = user.User(resource_name,
t['Resources'][resource_name],
resource_defns[resource_name],
stack)
rsrc._store()
@ -222,8 +223,9 @@ class UserTest(HeatTestCase):
t['Resources']['CfnUser']['Properties']['Policies'] = ['NoExistBad']
stack = utils.parse_stack(t)
resource_name = 'CfnUser'
resource_defns = stack.t.resource_definitions(stack)
rsrc = user.User(resource_name,
t['Resources'][resource_name],
resource_defns[resource_name],
stack)
self.assertRaises(exception.InvalidTemplateAttribute,
rsrc.handle_create)
@ -293,8 +295,9 @@ class AccessKeyTest(HeatTestCase):
return rsrc
def create_access_key(self, t, stack, resource_name):
resource_defns = stack.t.resource_definitions(stack)
rsrc = user.AccessKey(resource_name,
t['Resources'][resource_name],
resource_defns[resource_name],
stack)
self.assertIsNone(rsrc.validate())
scheduler.TaskRunner(rsrc.create)()
@ -372,8 +375,9 @@ class AccessKeyTest(HeatTestCase):
stack = utils.parse_stack(t)
stack['CfnUser'].resource_id = self.fc.user_id
resource_defns = stack.t.resource_definitions(stack)
rsrc = user.AccessKey('HostKeys',
t['Resources']['HostKeys'],
resource_defns['HostKeys'],
stack)
create = scheduler.TaskRunner(rsrc.create)
self.assertRaises(exception.ResourceFailure, create)
@ -392,8 +396,9 @@ class AccessPolicyTest(HeatTestCase):
stack = utils.parse_stack(t)
resource_name = 'WebServerAccessPolicy'
resource_defns = stack.t.resource_definitions(stack)
rsrc = user.AccessPolicy(resource_name,
t['Resources'][resource_name],
resource_defns[resource_name],
stack)
scheduler.TaskRunner(rsrc.create)()
self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
@ -404,8 +409,9 @@ class AccessPolicyTest(HeatTestCase):
t['Resources'][resource_name]['Properties']['AllowedResources'] = []
stack = utils.parse_stack(t)
resource_defns = stack.t.resource_definitions(stack)
rsrc = user.AccessPolicy(resource_name,
t['Resources'][resource_name],
resource_defns[resource_name],
stack)
scheduler.TaskRunner(rsrc.create)()
self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
@ -424,8 +430,9 @@ class AccessPolicyTest(HeatTestCase):
resource_name = 'WebServerAccessPolicy'
stack = utils.parse_stack(t)
resource_defns = stack.t.resource_definitions(stack)
rsrc = user.AccessPolicy(resource_name,
t['Resources'][resource_name],
resource_defns[resource_name],
stack)
self.assertTrue(rsrc.access_allowed('WikiDatabase'))
self.assertFalse(rsrc.access_allowed('NotWikiDatabase'))

View File

@ -97,15 +97,18 @@ class VolumeTest(HeatTestCase):
def create_volume(self, t, stack, resource_name):
data = t['Resources'][resource_name]
data['Properties']['AvailabilityZone'] = 'nova'
rsrc = vol.Volume(resource_name, data, stack)
rsrc = vol.Volume(resource_name,
stack.t.resource_definitions(stack)[resource_name],
stack)
self.assertIsNone(rsrc.validate())
scheduler.TaskRunner(rsrc.create)()
self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
return rsrc
def create_attachment(self, t, stack, resource_name):
resource_defns = stack.t.resource_definitions(stack)
rsrc = vol.VolumeAttachment(resource_name,
t['Resources'][resource_name],
resource_defns[resource_name],
stack)
self.assertIsNone(rsrc.validate())
scheduler.TaskRunner(rsrc.create)()
@ -235,8 +238,9 @@ class VolumeTest(HeatTestCase):
t['Resources']['DataVolume']['Properties']['AvailabilityZone'] = 'nova'
stack = utils.parse_stack(t, stack_name=stack_name)
resource_defns = stack.t.resource_definitions(stack)
rsrc = vol.Volume('DataVolume',
t['Resources']['DataVolume'],
resource_defns['DataVolume'],
stack)
create = scheduler.TaskRunner(rsrc.create)
self.assertRaises(exception.ResourceFailure, create)
@ -248,8 +252,9 @@ class VolumeTest(HeatTestCase):
t['Resources']['DataVolume']['Properties']['Tags'] = [{'Foo': 'bar'}]
stack = utils.parse_stack(t, stack_name='test_volume_bad_tags_stack')
resource_defns = stack.t.resource_definitions(stack)
rsrc = vol.Volume('DataVolume',
t['Resources']['DataVolume'],
resource_defns['DataVolume'],
stack)
self.assertRaises(exception.StackValidationFailed, rsrc.validate)
@ -272,8 +277,9 @@ class VolumeTest(HeatTestCase):
scheduler.TaskRunner(stack['DataVolume'].create)()
self.assertEqual('available', fv.status)
resource_defns = stack.t.resource_definitions(stack)
rsrc = vol.VolumeAttachment('MountPoint',
t['Resources']['MountPoint'],
resource_defns['MountPoint'],
stack)
create = scheduler.TaskRunner(rsrc.create)
self.assertRaises(exception.ResourceFailure, create)
@ -701,8 +707,9 @@ class VolumeTest(HeatTestCase):
t['Resources']['DataVolume']['DeletionPolicy'] = 'Snapshot'
t['Resources']['DataVolume']['Properties']['AvailabilityZone'] = 'nova'
stack = utils.parse_stack(t, stack_name=stack_name)
resource_defns = stack.t.resource_definitions(stack)
rsrc = vol.Volume('DataVolume',
t['Resources']['DataVolume'],
resource_defns['DataVolume'],
stack)
create = scheduler.TaskRunner(rsrc.create)
@ -767,8 +774,9 @@ class VolumeTest(HeatTestCase):
t['Resources']['DataVolume']['Properties']['AvailabilityZone'] = 'nova'
stack = utils.parse_stack(t, stack_name=stack_name)
resource_defns = stack.t.resource_definitions(stack)
rsrc = vol.Volume('DataVolume',
t['Resources']['DataVolume'],
resource_defns['DataVolume'],
stack)
create = scheduler.TaskRunner(rsrc.create)
self.assertRaises(exception.ResourceFailure, create)
@ -810,8 +818,9 @@ class VolumeTest(HeatTestCase):
}
stack = utils.parse_stack(t, stack_name=stack_name)
resource_defns = stack.t.resource_definitions(stack)
rsrc = vol.CinderVolume('DataVolume',
t['Resources']['DataVolume'],
resource_defns['DataVolume'],
stack)
self.assertIsNone(rsrc.validate())
scheduler.TaskRunner(rsrc.create)()
@ -824,8 +833,9 @@ class VolumeTest(HeatTestCase):
t = template_format.parse(volume_template)
t['Resources']['DataVolume']['Properties'] = {'size': '0'}
stack = utils.parse_stack(t)
resource_defns = stack.t.resource_definitions(stack)
rsrc = vol.CinderVolume(
'DataVolume', t['Resources']['DataVolume'], stack)
'DataVolume', resource_defns['DataVolume'], stack)
error = self.assertRaises(exception.StackValidationFailed,
rsrc.validate)
self.assertEqual(
@ -836,8 +846,9 @@ class VolumeTest(HeatTestCase):
t = template_format.parse(volume_template)
t['Resources']['DataVolume']['Properties']['Size'] = '0'
stack = utils.parse_stack(t)
resource_defns = stack.t.resource_definitions(stack)
rsrc = vol.Volume(
'DataVolume', t['Resources']['DataVolume'], stack)
'DataVolume', resource_defns['DataVolume'], stack)
error = self.assertRaises(exception.StackValidationFailed,
rsrc.validate)
self.assertEqual(
@ -876,8 +887,9 @@ class VolumeTest(HeatTestCase):
}
stack = utils.parse_stack(t, stack_name=stack_name)
resource_defns = stack.t.resource_definitions(stack)
rsrc = vol.CinderVolume('DataVolume',
t['Resources']['DataVolume'],
resource_defns['DataVolume'],
stack)
self.assertIsNone(rsrc.validate())
scheduler.TaskRunner(rsrc.create)()
@ -907,8 +919,9 @@ class VolumeTest(HeatTestCase):
}
stack = utils.parse_stack(t, stack_name=stack_name)
resource_defns = stack.t.resource_definitions(stack)
rsrc = vol.CinderVolume('DataVolume',
t['Resources']['DataVolume'],
resource_defns['DataVolume'],
stack)
self.assertIsNone(rsrc.validate())
scheduler.TaskRunner(rsrc.create)()
@ -945,8 +958,9 @@ class VolumeTest(HeatTestCase):
}
stack = utils.parse_stack(t, stack_name=stack_name)
resource_defns = stack.t.resource_definitions(stack)
rsrc = vol.CinderVolume('DataVolume',
t['Resources']['DataVolume'],
resource_defns['DataVolume'],
stack)
scheduler.TaskRunner(rsrc.create)()
self.assertEqual(u'zone1', rsrc.FnGetAtt('availability_zone'))
@ -1005,8 +1019,9 @@ class VolumeTest(HeatTestCase):
scheduler.TaskRunner(stack['DataVolume'].create)()
self.assertEqual('available', fv.status)
resource_defns = stack.t.resource_definitions(stack)
rsrc = vol.CinderVolumeAttachment('MountPoint',
t['Resources']['MountPoint'],
resource_defns['MountPoint'],
stack)
self.assertIsNone(rsrc.validate())
scheduler.TaskRunner(rsrc.create)()