Pass the environment into the Template class and not Stack

When we moved parameters from the stack table to the template table
we did it in a "flexible" way, but this led to some difficult to
diagnose problems. So this patch totally removes "env" as an argument
to the Stack class to make absolutely sure that we are doing this
correctly. I came across these bugs when rebasing decouple-nested.

- env was not getting passed into instance group make_templates()
- template deepcopy was not working correctly (causing some problems
  when deleting backup stacks)

Change-Id: I85cfb01c68ff5a44e2ff4f6e446870efb7205933
This commit is contained in:
Angus Salkeld 2015-03-16 14:07:38 +10:00
parent 831f4beaf4
commit e3950a4e72
25 changed files with 194 additions and 179 deletions

View File

@ -90,9 +90,10 @@ class CloudServersTest(common.HeatTestCase):
def _setup_test_stack(self, stack_name): def _setup_test_stack(self, stack_name):
t = template_format.parse(wp_template) t = template_format.parse(wp_template)
templ = template.Template(t) templ = template.Template(
t, env=environment.Environment({'key_name': 'test'}))
stack = parser.Stack(self.ctx, stack_name, templ, stack = parser.Stack(self.ctx, stack_name, templ,
environment.Environment({'key_name': 'test'}),
stack_id=uuidutils.generate_uuid()) stack_id=uuidutils.generate_uuid())
return (templ, stack) return (templ, stack)

View File

@ -101,11 +101,11 @@ class RackspaceDnsTest(common.HeatTestCase):
def _setup_test_cloud_dns_instance(self, name, parsed_t): def _setup_test_cloud_dns_instance(self, name, parsed_t):
stack_name = '%s_stack' % name stack_name = '%s_stack' % name
t = parsed_t t = parsed_t
templ = template.Template(t) templ = template.Template(
t, env=environment.Environment({'name': 'test'}))
stack = parser.Stack(utils.dummy_context(), stack = parser.Stack(utils.dummy_context(),
stack_name, stack_name,
templ, templ,
environment.Environment({'name': 'test'}),
stack_id=str(uuid.uuid4())) stack_id=str(uuid.uuid4()))
instance = cloud_dns.CloudDns( instance = cloud_dns.CloudDns(

View File

@ -16,6 +16,7 @@ from heat.common import grouputils
from heat.common.i18n import _ from heat.common.i18n import _
from heat.common import timeutils as iso8601utils from heat.common import timeutils as iso8601utils
from heat.engine import attributes from heat.engine import attributes
from heat.engine import environment
from heat.engine import function from heat.engine import function
from heat.engine import properties from heat.engine import properties
from heat.engine.resources import stack_resource from heat.engine.resources import stack_resource
@ -264,7 +265,12 @@ class InstanceGroup(stack_resource.StackResource):
definitions = template.resource_templates( definitions = template.resource_templates(
old_resources, instance_definition, num_instances, num_replace) old_resources, instance_definition, num_instances, num_replace)
return template.make_template(definitions, version=template_version) child_env = environment.get_child_environment(
self.stack.env,
self.child_params(), item_to_remove=self.resource_info)
return template.make_template(definitions, version=template_version,
child_env=child_env)
def _try_rolling_update(self, prop_diff): def _try_rolling_update(self, prop_diff):
if (self.update_policy[self.ROLLING_UPDATE] and if (self.update_policy[self.ROLLING_UPDATE] and

View File

@ -73,7 +73,7 @@ class Stack(collections.Mapping):
_zones = None _zones = None
def __init__(self, context, stack_name, tmpl, env=None, def __init__(self, context, stack_name, tmpl,
stack_id=None, action=None, status=None, stack_id=None, action=None, status=None,
status_reason='', timeout_mins=None, resolve_data=True, status_reason='', timeout_mins=None, resolve_data=True,
disable_rollback=True, parent_resource=None, owner_id=None, disable_rollback=True, parent_resource=None, owner_id=None,
@ -138,7 +138,6 @@ class Stack(collections.Mapping):
resources.initialise() resources.initialise()
self.env = env or self.t.env
self.parameters = self.t.parameters( self.parameters = self.t.parameters(
self.identifier(), self.identifier(),
user_params=self.env.params, user_params=self.env.params,
@ -150,6 +149,11 @@ class Stack(collections.Mapping):
else: else:
self.outputs = {} self.outputs = {}
@property
def env(self):
"""This is a helper to allow resources to access stack.env."""
return self.t.env
@property @property
def parent_resource(self): def parent_resource(self):
"""Dynamically load up the parent_resource. """Dynamically load up the parent_resource.
@ -327,10 +331,15 @@ class Stack(collections.Mapping):
use_stored_context=False): use_stored_context=False):
template = tmpl.Template.load( template = tmpl.Template.load(
context, stack.raw_template_id, stack.raw_template) context, stack.raw_template_id, stack.raw_template)
return cls(context, stack.name, template, template.env, return cls(context, stack.name, template,
stack.id, stack.action, stack.status, stack.status_reason, stack_id=stack.id,
stack.timeout, resolve_data, stack.disable_rollback, action=stack.action, status=stack.status,
parent_resource, owner_id=stack.owner_id, status_reason=stack.status_reason,
timeout_mins=stack.timeout,
resolve_data=resolve_data,
disable_rollback=stack.disable_rollback,
parent_resource=parent_resource,
owner_id=stack.owner_id,
stack_user_project_id=stack.stack_user_project_id, stack_user_project_id=stack.stack_user_project_id,
created_time=stack.created_at, created_time=stack.created_at,
updated_time=stack.updated_at, updated_time=stack.updated_at,
@ -729,7 +738,7 @@ class Stack(collections.Mapping):
return self.load(self.context, stack=s) return self.load(self.context, stack=s)
elif create_if_missing: elif create_if_missing:
prev = type(self)(self.context, self.name, copy.deepcopy(self.t), prev = type(self)(self.context, self.name, copy.deepcopy(self.t),
self.env, owner_id=self.id, owner_id=self.id,
user_creds_id=self.user_creds_id, user_creds_id=self.user_creds_id,
convergence=self.convergence) convergence=self.convergence)
prev.store(backup=True) prev.store(backup=True)
@ -806,7 +815,7 @@ class Stack(collections.Mapping):
# Oldstack is useless when the action is not UPDATE , so we don't # Oldstack is useless when the action is not UPDATE , so we don't
# need to build it, this can avoid some unexpected errors. # need to build it, this can avoid some unexpected errors.
oldstack = Stack(self.context, self.name, copy.deepcopy(self.t), oldstack = Stack(self.context, self.name, copy.deepcopy(self.t),
self.env, convergence=self.convergence) convergence=self.convergence)
backup_stack = self._backup_stack() backup_stack = self._backup_stack()
try: try:
update_task = update.StackUpdate( update_task = update.StackUpdate(
@ -815,7 +824,6 @@ class Stack(collections.Mapping):
error_wait_time=cfg.CONF.error_wait_time) error_wait_time=cfg.CONF.error_wait_time)
updater = scheduler.TaskRunner(update_task) updater = scheduler.TaskRunner(update_task)
self.env = newstack.env
self.parameters = newstack.parameters self.parameters = newstack.parameters
self.t.files = newstack.t.files self.t.files = newstack.t.files
self.t.env = newstack.t.env self.t.env = newstack.t.env
@ -1152,7 +1160,7 @@ class Stack(collections.Mapping):
return return
self.updated_time = datetime.datetime.utcnow() self.updated_time = datetime.datetime.utcnow()
template = tmpl.Template(snapshot.data['template']) template = tmpl.Template(snapshot.data['template'], env=self.env)
for name, defn in six.iteritems(template.resource_definitions(self)): for name, defn in six.iteritems(template.resource_definitions(self)):
rsrc = resource.Resource(name, defn, self) rsrc = resource.Resource(name, defn, self)
@ -1162,7 +1170,7 @@ class Stack(collections.Mapping):
defn = handle_restore(defn, data) defn = handle_restore(defn, data)
template.add_resource(defn, name) template.add_resource(defn, name)
newstack = self.__class__(self.context, self.name, template, self.env, newstack = self.__class__(self.context, self.name, template,
timeout_mins=self.timeout_mins, timeout_mins=self.timeout_mins,
disable_rollback=self.disable_rollback) disable_rollback=self.disable_rollback)
newstack.parameters.set_stack_id(self.identifier()) newstack.parameters.set_stack_id(self.identifier())

View File

@ -119,7 +119,8 @@ class Template(collections.Mapping):
self.version = get_version(self.t, _template_classes.keys()) self.version = get_version(self.t, _template_classes.keys())
def __deepcopy__(self, memo): def __deepcopy__(self, memo):
return Template(copy.deepcopy(self.t, memo), files=self.files) return Template(copy.deepcopy(self.t, memo), files=self.files,
env=self.env)
@classmethod @classmethod
def load(cls, context, template_id, t=None): def load(cls, context, template_id, t=None):

View File

@ -40,7 +40,8 @@ def resource_templates(old_resources, resource_definition,
def make_template(resource_definitions, def make_template(resource_definitions,
version=('heat_template_version', '2013-05-23')): version=('heat_template_version', '2013-05-23'),
child_env=None):
""" """
Return a Template object containing the given resource definitions. Return a Template object containing the given resource definitions.
@ -48,7 +49,7 @@ def make_template(resource_definitions,
can be specified by passing a (version_type, version_string) tuple matching can be specified by passing a (version_type, version_string) tuple matching
any of the available template format plugins. any of the available template format plugins.
""" """
tmpl = template.Template(dict([version])) tmpl = template.Template(dict([version]), env=child_env)
for name, defn in resource_definitions: for name, defn in resource_definitions:
tmpl.add_resource(defn, name) tmpl.add_resource(defn, name)

View File

@ -87,10 +87,10 @@ class WaitConditionTest(common.HeatTestCase):
stub=True, stub_status=True): stub=True, stub_status=True):
params = params or {} params = params or {}
temp = template_format.parse(template) temp = template_format.parse(template)
template = parser.Template(temp) template = parser.Template(temp,
env=environment.Environment(params))
ctx = utils.dummy_context(tenant_id='test_tenant') ctx = utils.dummy_context(tenant_id='test_tenant')
stack = parser.Stack(ctx, 'test_stack', template, stack = parser.Stack(ctx, 'test_stack', template,
environment.Environment(params),
disable_rollback=True) disable_rollback=True)
# Stub out the stack ID so we have a known value # Stub out the stack ID so we have a known value
@ -533,7 +533,6 @@ class WaitConditionUpdateTest(common.HeatTestCase):
template = parser.Template(temp) template = parser.Template(temp)
ctx = utils.dummy_context(tenant_id='test_tenant') ctx = utils.dummy_context(tenant_id='test_tenant')
stack = parser.Stack(ctx, 'test_stack', template, stack = parser.Stack(ctx, 'test_stack', template,
environment.Environment({}),
disable_rollback=True) disable_rollback=True)
stack_id = str(uuid.uuid4()) stack_id = str(uuid.uuid4())

View File

@ -80,10 +80,10 @@ class HeatWaitConditionTest(common.HeatTestCase):
params={}, params={},
stub=True, stub_status=True): stub=True, stub_status=True):
temp = template_format.parse(template) temp = template_format.parse(template)
template = parser.Template(temp) template = parser.Template(temp,
env=environment.Environment(params))
ctx = utils.dummy_context(tenant_id=self.tenant_id) ctx = utils.dummy_context(tenant_id=self.tenant_id)
stack = parser.Stack(ctx, 'test_stack', template, stack = parser.Stack(ctx, 'test_stack', template,
environment.Environment(params),
disable_rollback=True) disable_rollback=True)
# Stub out the stack ID so we have a known value # Stub out the stack ID so we have a known value

View File

@ -733,8 +733,7 @@ class StackServiceCreateUpdateDeleteTest(common.HeatTestCase):
'C': {'Type': 'GenericResourceType'}}} 'C': {'Type': 'GenericResourceType'}}}
template = templatem.Template(tpl) template = templatem.Template(tpl)
stack = parser.Stack(self.ctx, stack_name, template, stack = parser.Stack(self.ctx, stack_name, template)
environment.Environment({}))
self.m.StubOutWithMock(templatem, 'Template') self.m.StubOutWithMock(templatem, 'Template')
self.m.StubOutWithMock(environment, 'Environment') self.m.StubOutWithMock(environment, 'Environment')
@ -1058,10 +1057,10 @@ class StackServiceCreateUpdateDeleteTest(common.HeatTestCase):
s = stack_object.Stack.get_by_id(self.ctx, sid) s = stack_object.Stack.get_by_id(self.ctx, sid)
t = template_format.parse(wp_template_no_default) t = template_format.parse(wp_template_no_default)
template = templatem.Template(t)
env = environment.Environment({'parameters': with_params, env = environment.Environment({'parameters': with_params,
'resource_registry': {'rsc': 'test'}}) 'resource_registry': {'rsc': 'test'}})
stack = parser.Stack(self.ctx, stack_name, template, env) template = templatem.Template(t, env=env)
stack = parser.Stack(self.ctx, stack_name, template)
self._stub_update_mocks(s, old_stack) self._stub_update_mocks(s, old_stack)
@ -3002,8 +3001,7 @@ class StackServiceTest(common.HeatTestCase):
} }
} }
templ = templatem.Template(lazy_load_template) templ = templatem.Template(lazy_load_template)
stack = parser.Stack(self.ctx, stack_name, templ, stack = parser.Stack(self.ctx, stack_name, templ)
environment.Environment({}))
self.assertIsNone(stack._resources) self.assertIsNone(stack._resources)
self.assertIsNone(stack._dependencies) self.assertIsNone(stack._dependencies)

View File

@ -177,8 +177,9 @@ class ValidateGetAttTest(common.HeatTestCase):
self.stack = parser.Stack( self.stack = parser.Stack(
utils.dummy_context(), 'test_stack', utils.dummy_context(), 'test_stack',
parser.Template({"HeatTemplateFormatVersion": "2012-12-12"}), parser.Template({"HeatTemplateFormatVersion": "2012-12-12"},
env=env, stack_id=str(uuid.uuid4())) env=env),
stack_id=str(uuid.uuid4()))
res_defn = rsrc_defn.ResourceDefinition('test_rsrc', res_defn = rsrc_defn.ResourceDefinition('test_rsrc',
'OS::Test::GenericResource') 'OS::Test::GenericResource')
self.rsrc = resource.Resource('test_rsrc', res_defn, self.stack) self.rsrc = resource.Resource('test_rsrc', res_defn, self.stack)

View File

@ -1053,16 +1053,18 @@ class HotStackTest(common.HeatTestCase):
'update_template_diff') 'update_template_diff')
self.stack = parser.Stack(self.ctx, 'update_test_stack', self.stack = parser.Stack(self.ctx, 'update_test_stack',
template.Template(tmpl), template.Template(
environment.Environment({'foo': 'abc'})) tmpl, env=environment.Environment(
{'foo': 'abc'})))
self.stack.store() self.stack.store()
self.stack.create() self.stack.create()
self.assertEqual((parser.Stack.CREATE, parser.Stack.COMPLETE), self.assertEqual((parser.Stack.CREATE, parser.Stack.COMPLETE),
self.stack.state) self.stack.state)
updated_stack = parser.Stack(self.ctx, 'updated_stack', updated_stack = parser.Stack(self.ctx, 'updated_stack',
template.Template(tmpl), template.Template(
environment.Environment({'foo': 'xyz'})) tmpl, env=environment.Environment(
{'foo': 'xyz'})))
def check_props(*args): def check_props(*args):
self.assertEqual('abc', self.stack['AResource'].properties['Foo']) self.assertEqual('abc', self.stack['AResource'].properties['Foo'])
@ -1307,9 +1309,9 @@ class StackParametersTest(common.HeatTestCase):
def test_param_refs(self): def test_param_refs(self):
"""Test if parameter references work.""" """Test if parameter references work."""
tmpl = parser.Template(self.props_template)
env = environment.Environment(self.params) env = environment.Environment(self.params)
stack = parser.Stack(utils.dummy_context(), 'test', tmpl, env, tmpl = parser.Template(self.props_template, env=env)
stack = parser.Stack(utils.dummy_context(), 'test', tmpl,
stack_id='1ba8c334-2297-4312-8c7c-43763a988ced', stack_id='1ba8c334-2297-4312-8c7c-43763a988ced',
tenant_id='9913ef0a-b8be-4b33-b574-9061441bd373') tenant_id='9913ef0a-b8be-4b33-b574-9061441bd373')
self.assertEqual(self.expected, self.assertEqual(self.expected,

View File

@ -79,9 +79,9 @@ class InstancesTest(common.HeatTestCase):
def _setup_test_stack(self, stack_name): def _setup_test_stack(self, stack_name):
t = template_format.parse(wp_template) t = template_format.parse(wp_template)
template = parser.Template(t) template = parser.Template(
t, env=environment.Environment({'KeyName': 'test'}))
stack = parser.Stack(utils.dummy_context(), stack_name, template, stack = parser.Stack(utils.dummy_context(), stack_name, template,
environment.Environment({'KeyName': 'test'}),
stack_id=str(uuid.uuid4())) stack_id=str(uuid.uuid4()))
return (template, stack) return (template, stack)

View File

@ -198,12 +198,12 @@ class instancesTest(common.HeatTestCase):
def _create_test_instance(self, return_server, name): def _create_test_instance(self, return_server, name):
stack_name = '%s_s' % name stack_name = '%s_s' % name
t = template_format.parse(wp_template) t = template_format.parse(wp_template)
template = parser.Template(t)
kwargs = {'KeyName': 'test', kwargs = {'KeyName': 'test',
'InstanceType': 'm1.large', 'InstanceType': 'm1.large',
'SubnetId': '4156c7a5-e8c4-4aff-a6e1-8f3c7bc83861'} 'SubnetId': '4156c7a5-e8c4-4aff-a6e1-8f3c7bc83861'}
template = parser.Template(t,
env=environment.Environment(kwargs))
stack = parser.Stack(utils.dummy_context(), stack_name, template, stack = parser.Stack(utils.dummy_context(), stack_name, template,
environment.Environment(kwargs),
stack_id=str(uuid.uuid4())) stack_id=str(uuid.uuid4()))
image_id = 'CentOS 5.2' image_id = 'CentOS 5.2'
t['Resources']['WebServer']['Properties']['ImageId'] = image_id t['Resources']['WebServer']['Properties']['ImageId'] = image_id
@ -253,12 +253,12 @@ class instancesTest(common.HeatTestCase):
def _create_test_instance_with_nic(self, return_server, name): def _create_test_instance_with_nic(self, return_server, name):
stack_name = '%s_s' % name stack_name = '%s_s' % name
t = template_format.parse(wp_template_with_nic) t = template_format.parse(wp_template_with_nic)
template = parser.Template(t)
kwargs = {'KeyName': 'test', kwargs = {'KeyName': 'test',
'InstanceType': 'm1.large', 'InstanceType': 'm1.large',
'SubnetId': '4156c7a5-e8c4-4aff-a6e1-8f3c7bc83861'} 'SubnetId': '4156c7a5-e8c4-4aff-a6e1-8f3c7bc83861'}
template = parser.Template(t,
env=environment.Environment(kwargs))
stack = parser.Stack(utils.dummy_context(), stack_name, template, stack = parser.Stack(utils.dummy_context(), stack_name, template,
environment.Environment(kwargs),
stack_id=str(uuid.uuid4())) stack_id=str(uuid.uuid4()))
image_id = 'CentOS 5.2' image_id = 'CentOS 5.2'
t['Resources']['WebServer']['Properties']['ImageId'] = image_id t['Resources']['WebServer']['Properties']['ImageId'] = image_id

View File

@ -154,10 +154,10 @@ class MetadataRefreshTest(common.HeatTestCase):
def create_stack(self, stack_name='test_stack', params=None): def create_stack(self, stack_name='test_stack', params=None):
params = params or {} params = params or {}
temp = template_format.parse(test_template_metadata) temp = template_format.parse(test_template_metadata)
template = parser.Template(temp) template = parser.Template(temp,
env=environment.Environment(params))
ctx = utils.dummy_context() ctx = utils.dummy_context()
stack = parser.Stack(ctx, stack_name, template, stack = parser.Stack(ctx, stack_name, template,
environment.Environment(params),
disable_rollback=True) disable_rollback=True)
self.stack_id = stack.store() self.stack_id = stack.store()
@ -314,10 +314,10 @@ class MetadataRefreshTestServer(common.HeatTestCase):
def create_stack(self, stack_name='test_stack_native', params=None): def create_stack(self, stack_name='test_stack_native', params=None):
params = params or {} params = params or {}
temp = template_format.parse(test_template_server) temp = template_format.parse(test_template_server)
template = parser.Template(temp) template = parser.Template(temp,
env=environment.Environment(params))
ctx = utils.dummy_context() ctx = utils.dummy_context()
stack = parser.Stack(ctx, stack_name, template, stack = parser.Stack(ctx, stack_name, template,
environment.Environment(params),
disable_rollback=True) disable_rollback=True)
self.stack_id = stack.store() self.stack_id = stack.store()

View File

@ -127,8 +127,8 @@ class ProviderTemplateTest(common.HeatTestCase):
env.load({'resource_registry': env.load({'resource_registry':
{'DummyResource': 'test_resource.template'}}) {'DummyResource': 'test_resource.template'}})
stack = parser.Stack(utils.dummy_context(), 'test_stack', stack = parser.Stack(utils.dummy_context(), 'test_stack',
parser.Template(empty_template, files=files), parser.Template(empty_template, files=files,
env=env, env=env),
stack_id=str(uuid.uuid4())) stack_id=str(uuid.uuid4()))
map_prop_val = { map_prop_val = {
@ -208,8 +208,8 @@ class ProviderTemplateTest(common.HeatTestCase):
env.load({'resource_registry': env.load({'resource_registry':
{'DummyResource': 'test_resource.template'}}) {'DummyResource': 'test_resource.template'}})
stack = parser.Stack(utils.dummy_context(), 'test_stack', stack = parser.Stack(utils.dummy_context(), 'test_stack',
parser.Template(empty_template, files=files), parser.Template(empty_template, files=files,
env=env, env=env),
stack_id=str(uuid.uuid4())) stack_id=str(uuid.uuid4()))
definition = rsrc_defn.ResourceDefinition('test_t_res', definition = rsrc_defn.ResourceDefinition('test_t_res',
@ -237,8 +237,8 @@ class ProviderTemplateTest(common.HeatTestCase):
env.load({'resource_registry': env.load({'resource_registry':
{'DummyResource': 'test_resource.template'}}) {'DummyResource': 'test_resource.template'}})
stack = parser.Stack(utils.dummy_context(), 'test_stack', stack = parser.Stack(utils.dummy_context(), 'test_stack',
parser.Template(empty_template, files=files), parser.Template(empty_template, files=files,
env=env, env=env),
stack_id=str(uuid.uuid4())) stack_id=str(uuid.uuid4()))
definition = rsrc_defn.ResourceDefinition('test_t_res', definition = rsrc_defn.ResourceDefinition('test_t_res',
@ -270,8 +270,8 @@ class ProviderTemplateTest(common.HeatTestCase):
env.load({'resource_registry': env.load({'resource_registry':
{'DummyResource': 'test_resource.template'}}) {'DummyResource': 'test_resource.template'}})
stack = parser.Stack(utils.dummy_context(), 'test_stack', stack = parser.Stack(utils.dummy_context(), 'test_stack',
parser.Template(empty_template, files=files), parser.Template(empty_template, files=files,
env=env, env=env),
stack_id=str(uuid.uuid4())) stack_id=str(uuid.uuid4()))
definition = rsrc_defn.ResourceDefinition('test_t_res', definition = rsrc_defn.ResourceDefinition('test_t_res',
@ -302,8 +302,8 @@ class ProviderTemplateTest(common.HeatTestCase):
env.load({'resource_registry': env.load({'resource_registry':
{'DummyResource': 'test_resource.template'}}) {'DummyResource': 'test_resource.template'}})
stack = parser.Stack(utils.dummy_context(), 'test_stack', stack = parser.Stack(utils.dummy_context(), 'test_stack',
parser.Template(empty_template, files=files), parser.Template(empty_template, files=files,
env=env, env=env),
stack_id=str(uuid.uuid4())) stack_id=str(uuid.uuid4()))
definition = rsrc_defn.ResourceDefinition('test_t_res', definition = rsrc_defn.ResourceDefinition('test_t_res',
@ -332,8 +332,8 @@ class ProviderTemplateTest(common.HeatTestCase):
env.load({'resource_registry': env.load({'resource_registry':
{'DummyResource': 'test_resource.template'}}) {'DummyResource': 'test_resource.template'}})
stack = parser.Stack(utils.dummy_context(), 'test_stack', stack = parser.Stack(utils.dummy_context(), 'test_stack',
parser.Template(empty_template, files=files), parser.Template(empty_template, files=files,
env=env, env=env),
stack_id=str(uuid.uuid4())) stack_id=str(uuid.uuid4()))
definition = rsrc_defn.ResourceDefinition('test_t_res', definition = rsrc_defn.ResourceDefinition('test_t_res',
@ -366,7 +366,7 @@ class ProviderTemplateTest(common.HeatTestCase):
stack = parser.Stack(utils.dummy_context(), 'test_stack', stack = parser.Stack(utils.dummy_context(), 'test_stack',
parser.Template( parser.Template(
{'HeatTemplateFormatVersion': '2012-12-12'}, {'HeatTemplateFormatVersion': '2012-12-12'},
files=files), env=env, files=files, env=env),
stack_id=str(uuid.uuid4())) stack_id=str(uuid.uuid4()))
definition = rsrc_defn.ResourceDefinition('test_t_res', definition = rsrc_defn.ResourceDefinition('test_t_res',
@ -402,7 +402,7 @@ class ProviderTemplateTest(common.HeatTestCase):
stack = parser.Stack(utils.dummy_context(), 'test_stack', stack = parser.Stack(utils.dummy_context(), 'test_stack',
parser.Template( parser.Template(
{'HeatTemplateFormatVersion': '2012-12-12'}, {'HeatTemplateFormatVersion': '2012-12-12'},
files=files), env=env, files=files, env=env),
stack_id=str(uuid.uuid4())) stack_id=str(uuid.uuid4()))
definition = rsrc_defn.ResourceDefinition('test_t_res', definition = rsrc_defn.ResourceDefinition('test_t_res',
@ -434,7 +434,7 @@ class ProviderTemplateTest(common.HeatTestCase):
stack = parser.Stack(utils.dummy_context(), 'test_stack', stack = parser.Stack(utils.dummy_context(), 'test_stack',
parser.Template( parser.Template(
{'HeatTemplateFormatVersion': '2012-12-12'}, {'HeatTemplateFormatVersion': '2012-12-12'},
files=files), env=env, files=files, env=env),
stack_id=str(uuid.uuid4())) stack_id=str(uuid.uuid4()))
definition = rsrc_defn.ResourceDefinition('test_t_res', definition = rsrc_defn.ResourceDefinition('test_t_res',
@ -468,7 +468,7 @@ class ProviderTemplateTest(common.HeatTestCase):
stack = parser.Stack(utils.dummy_context(), 'test_stack', stack = parser.Stack(utils.dummy_context(), 'test_stack',
parser.Template( parser.Template(
{'HeatTemplateFormatVersion': '2012-12-12'}, {'HeatTemplateFormatVersion': '2012-12-12'},
files=files), env=env, files=files, env=env),
stack_id=str(uuid.uuid4())) stack_id=str(uuid.uuid4()))
definition = rsrc_defn.ResourceDefinition('test_t_res', definition = rsrc_defn.ResourceDefinition('test_t_res',
@ -503,7 +503,7 @@ class ProviderTemplateTest(common.HeatTestCase):
stack = parser.Stack(utils.dummy_context(), 'test_stack', stack = parser.Stack(utils.dummy_context(), 'test_stack',
parser.Template( parser.Template(
{'HeatTemplateFormatVersion': '2012-12-12'}, {'HeatTemplateFormatVersion': '2012-12-12'},
files=files), env=env, files=files, env=env),
stack_id=str(uuid.uuid4())) stack_id=str(uuid.uuid4()))
definition = rsrc_defn.ResourceDefinition('foo', definition = rsrc_defn.ResourceDefinition('foo',
@ -547,7 +547,7 @@ class ProviderTemplateTest(common.HeatTestCase):
stack = parser.Stack(utils.dummy_context(), 'test_stack', stack = parser.Stack(utils.dummy_context(), 'test_stack',
parser.Template( parser.Template(
{'HeatTemplateFormatVersion': '2012-12-12'}, {'HeatTemplateFormatVersion': '2012-12-12'},
files=files), env=env, files=files, env=env),
stack_id=str(uuid.uuid4())) stack_id=str(uuid.uuid4()))
definition = rsrc_defn.ResourceDefinition('test_t_res', definition = rsrc_defn.ResourceDefinition('test_t_res',
@ -686,7 +686,7 @@ class ProviderTemplateTest(common.HeatTestCase):
env.load({'resource_registry': env.load({'resource_registry':
{'Test::Flippy': test_templ_name}}) {'Test::Flippy': test_templ_name}})
stack = parser.Stack(utils.dummy_context(), 'test_stack', stack = parser.Stack(utils.dummy_context(), 'test_stack',
parser.Template(empty_template), env=env, parser.Template(empty_template, env=env),
stack_id=str(uuid.uuid4())) stack_id=str(uuid.uuid4()))
definition = rsrc_defn.ResourceDefinition('test_t_res', definition = rsrc_defn.ResourceDefinition('test_t_res',
@ -738,7 +738,7 @@ class ProviderTemplateTest(common.HeatTestCase):
env.load({'resource_registry': env.load({'resource_registry':
{'Test::Flippy': test_templ_name}}) {'Test::Flippy': test_templ_name}})
stack = parser.Stack(utils.dummy_context(), 'test_stack', stack = parser.Stack(utils.dummy_context(), 'test_stack',
parser.Template(empty_template), env=env, parser.Template(empty_template, env=env),
stack_id=str(uuid.uuid4())) stack_id=str(uuid.uuid4()))
self.m.StubOutWithMock(urlfetch, "get") self.m.StubOutWithMock(urlfetch, "get")
@ -767,7 +767,7 @@ class ProviderTemplateTest(common.HeatTestCase):
env.load({'resource_registry': env.load({'resource_registry':
{'Test::Flippy': test_templ_name}}) {'Test::Flippy': test_templ_name}})
stack = parser.Stack(utils.dummy_context(), 'test_stack', stack = parser.Stack(utils.dummy_context(), 'test_stack',
parser.Template(empty_template), env=env, parser.Template(empty_template, env=env),
stack_id=str(uuid.uuid4())) stack_id=str(uuid.uuid4()))
self.m.ReplayAll() self.m.ReplayAll()
@ -790,7 +790,7 @@ class ProviderTemplateTest(common.HeatTestCase):
env.load({'resource_registry': env.load({'resource_registry':
{'Test::Tmpl': test_templ_name}}) {'Test::Tmpl': test_templ_name}})
stack = parser.Stack(utils.dummy_context(), 'test_stack', stack = parser.Stack(utils.dummy_context(), 'test_stack',
parser.Template(empty_template), env=env, parser.Template(empty_template, env=env),
stack_id=str(uuid.uuid4())) stack_id=str(uuid.uuid4()))
self.m.StubOutWithMock(urlfetch, "get") self.m.StubOutWithMock(urlfetch, "get")
@ -836,8 +836,8 @@ class TemplateResourceCrudTest(common.HeatTestCase):
env.load({'resource_registry': env.load({'resource_registry':
{'DummyResource': 'test_resource.template'}}) {'DummyResource': 'test_resource.template'}})
stack = parser.Stack(utils.dummy_context(), 'test_stack', stack = parser.Stack(utils.dummy_context(), 'test_stack',
parser.Template(empty_template, files=files), parser.Template(empty_template, files=files,
env=env, env=env),
stack_id=str(uuid.uuid4())) stack_id=str(uuid.uuid4()))
self.defn = rsrc_defn.ResourceDefinition('test_t_res', self.defn = rsrc_defn.ResourceDefinition('test_t_res',

View File

@ -62,8 +62,9 @@ class ResourceTest(common.HeatTestCase):
u'ResourceWithCustomConstraint'}}) u'ResourceWithCustomConstraint'}})
self.stack = parser.Stack(utils.dummy_context(), 'test_stack', self.stack = parser.Stack(utils.dummy_context(), 'test_stack',
parser.Template(empty_template), parser.Template(empty_template,
env=self.env, stack_id=str(uuid.uuid4())) env=self.env),
stack_id=str(uuid.uuid4()))
self.patch('heat.engine.resource.warnings') self.patch('heat.engine.resource.warnings')
def test_get_class_ok(self): def test_get_class_ok(self):
@ -1083,7 +1084,7 @@ class ResourceTest(common.HeatTestCase):
self.assertFalse(res.is_using_neutron()) self.assertFalse(res.is_using_neutron())
def _test_skip_validation_if_custom_constraint(self, tmpl): def _test_skip_validation_if_custom_constraint(self, tmpl):
stack = parser.Stack(utils.dummy_context(), 'test', tmpl, env=self.env) stack = parser.Stack(utils.dummy_context(), 'test', tmpl)
stack.store() stack.store()
path = ('heat.engine.clients.os.neutron.NetworkConstraint.' path = ('heat.engine.clients.os.neutron.NetworkConstraint.'
'validate_with_client') 'validate_with_client')
@ -1104,7 +1105,7 @@ class ResourceTest(common.HeatTestCase):
} }
} }
} }
}) }, env=self.env)
self._test_skip_validation_if_custom_constraint(tmpl) self._test_skip_validation_if_custom_constraint(tmpl)
def test_hot_ref_skip_validation_if_custom_constraint(self): def test_hot_ref_skip_validation_if_custom_constraint(self):
@ -1119,7 +1120,7 @@ class ResourceTest(common.HeatTestCase):
} }
} }
} }
}) }, env=self.env)
self._test_skip_validation_if_custom_constraint(tmpl) self._test_skip_validation_if_custom_constraint(tmpl)

View File

@ -119,9 +119,10 @@ class ServersTest(common.HeatTestCase):
def _setup_test_stack(self, stack_name, test_templ=wp_template): def _setup_test_stack(self, stack_name, test_templ=wp_template):
t = template_format.parse(test_templ) t = template_format.parse(test_templ)
templ = template.Template(t) templ = template.Template(t,
env=environment.Environment(
{'key_name': 'test'}))
stack = parser.Stack(utils.dummy_context(), stack_name, templ, stack = parser.Stack(utils.dummy_context(), stack_name, templ,
environment.Environment({'key_name': 'test'}),
stack_id=uuidutils.generate_uuid(), stack_id=uuidutils.generate_uuid(),
stack_user_project_id='8888') stack_user_project_id='8888')
return (templ, stack) return (templ, stack)

View File

@ -65,9 +65,10 @@ class ServerTagsTest(common.HeatTestCase):
def _setup_test_instance(self, intags=None, nova_tags=None): def _setup_test_instance(self, intags=None, nova_tags=None):
stack_name = 'tag_test' stack_name = 'tag_test'
t = template_format.parse(instance_template) t = template_format.parse(instance_template)
template = parser.Template(t) template = parser.Template(t,
env=environment.Environment(
{'KeyName': 'test'}))
stack = parser.Stack(utils.dummy_context(), stack_name, template, stack = parser.Stack(utils.dummy_context(), stack_name, template,
environment.Environment({'KeyName': 'test'}),
stack_id=str(uuid.uuid4())) stack_id=str(uuid.uuid4()))
t['Resources']['WebServer']['Properties']['Tags'] = intags t['Resources']['WebServer']['Properties']['Tags'] = intags

View File

@ -100,10 +100,10 @@ class SqlAlchemyTest(common.HeatTestCase):
def _setup_test_stack(self, stack_name, stack_id=None, owner_id=None, def _setup_test_stack(self, stack_name, stack_id=None, owner_id=None,
stack_user_project_id=None, backup=False): stack_user_project_id=None, backup=False):
t = template_format.parse(wp_template) t = template_format.parse(wp_template)
template = parser.Template(t) template = parser.Template(
t, env=environment.Environment({'KeyName': 'test'}))
stack_id = stack_id or str(uuid.uuid4()) stack_id = stack_id or str(uuid.uuid4())
stack = parser.Stack(self.ctx, stack_name, template, stack = parser.Stack(self.ctx, stack_name, template,
environment.Environment({'KeyName': 'test'}),
owner_id=owner_id, owner_id=owner_id,
stack_user_project_id=stack_user_project_id) stack_user_project_id=stack_user_project_id)
with utils.UUIDStub(stack_id): with utils.UUIDStub(stack_id):

View File

@ -276,10 +276,12 @@ class StackTest(common.HeatTestCase):
).AndReturn(t) ).AndReturn(t)
self.m.StubOutWithMock(stack.Stack, '__init__') self.m.StubOutWithMock(stack.Stack, '__init__')
stack.Stack.__init__(self.ctx, stk.name, t, t.env, stk.id, stack.Stack.__init__(self.ctx, stk.name, t, stack_id=stk.id,
stk.action, stk.status, stk.status_reason, action=stk.action, status=stk.status,
stk.timeout, True, stk.disable_rollback, status_reason=stk.status_reason,
'parent', owner_id=None, timeout_mins=stk.timeout, resolve_data=True,
disable_rollback=stk.disable_rollback,
parent_resource='parent', owner_id=None,
stack_user_project_id=None, stack_user_project_id=None,
created_time=mox.IgnoreArg(), created_time=mox.IgnoreArg(),
updated_time=None, updated_time=None,
@ -319,10 +321,9 @@ class StackTest(common.HeatTestCase):
"metadata": {}}}''' "metadata": {}}}'''
env = environment.Environment({'parameters': {'param1': 'test'}}) env = environment.Environment({'parameters': {'param1': 'test'}})
self.stack = stack.Stack(self.ctx, 'stack_details_test', self.stack = stack.Stack(self.ctx, 'stack_details_test',
template.Template(tpl), template.Template(tpl, env=env),
tenant_id='123', tenant_id='123',
stack_user_project_id='234', stack_user_project_id='234')
env=env)
self.stack.store() self.stack.store()
info = self.stack.prepare_abandon() info = self.stack.prepare_abandon()
self.assertEqual('CREATE', info['action']) self.assertEqual('CREATE', info['action'])
@ -1459,9 +1460,9 @@ class StackTest(common.HeatTestCase):
self.m.ReplayAll() self.m.ReplayAll()
test_env = environment.Environment({'flavor': 'dummy'})
self.stack = stack.Stack(self.ctx, 'stack_with_custom_constraint', self.stack = stack.Stack(self.ctx, 'stack_with_custom_constraint',
template.Template(tmpl), template.Template(tmpl, env=test_env))
environment.Environment({'flavor': 'dummy'}))
self.stack.validate() self.stack.validate()
self.stack.store() self.stack.store()
@ -1627,10 +1628,9 @@ class StackTest(common.HeatTestCase):
Type: Number Type: Number
""") """)
env1 = {'parameters': {'foo': 'abc'}} env1 = environment.Environment({'parameters': {'foo': 'abc'}})
self.stack = stack.Stack(self.ctx, 'stack_with_bad_param', self.stack = stack.Stack(self.ctx, 'stack_with_bad_param',
template.Template(tmpl), template.Template(tmpl, env=env1))
env=environment.Environment(env1))
ex = self.assertRaises(exception.StackValidationFailed, ex = self.assertRaises(exception.StackValidationFailed,
self.stack.validate) self.stack.validate)

View File

@ -261,17 +261,18 @@ class StackUpdateTest(common.HeatTestCase):
} }
} }
self.stack = stack.Stack(self.ctx, 'update_test_stack', self.stack = stack.Stack(
template.Template(tmpl), self.ctx, 'update_test_stack',
environment.Environment({'foo': 'abc'})) template.Template(
tmpl, env=environment.Environment({'foo': 'abc'})))
self.stack.store() self.stack.store()
self.stack.create() self.stack.create()
self.assertEqual((stack.Stack.CREATE, stack.Stack.COMPLETE), self.assertEqual((stack.Stack.CREATE, stack.Stack.COMPLETE),
self.stack.state) self.stack.state)
env2 = environment.Environment({'foo': 'xyz'})
updated_stack = stack.Stack(self.ctx, 'updated_stack', updated_stack = stack.Stack(self.ctx, 'updated_stack',
template.Template(tmpl), template.Template(tmpl, env=env2))
environment.Environment({'foo': 'xyz'}))
def check_and_raise(*args): def check_and_raise(*args):
self.assertEqual('abc', self.stack['AResource'].properties['Foo']) self.assertEqual('abc', self.stack['AResource'].properties['Foo'])
@ -800,11 +801,10 @@ class StackUpdateTest(common.HeatTestCase):
'Resources': {'AResource': {'Type': 'ResourceWithPropsType', 'Resources': {'AResource': {'Type': 'ResourceWithPropsType',
'Properties': {'Foo': 'abc'}}}} 'Properties': {'Foo': 'abc'}}}}
env1 = {'parameters': {'AParam': 'abc'}} env1 = environment.Environment({'parameters': {'AParam': 'abc'}})
self.stack = stack.Stack(self.ctx, 'update_test_stack', self.stack = stack.Stack(self.ctx, 'update_test_stack',
template.Template(tmpl), template.Template(tmpl, env=env1),
disable_rollback=False, disable_rollback=False)
env=environment.Environment(env1))
self.stack.store() self.stack.store()
self.stack.create() self.stack.create()
self.assertEqual((stack.Stack.CREATE, stack.Stack.COMPLETE), self.assertEqual((stack.Stack.CREATE, stack.Stack.COMPLETE),
@ -815,11 +815,10 @@ class StackUpdateTest(common.HeatTestCase):
'Resources': {'AResource': {'Type': 'ResourceWithPropsType', 'Resources': {'AResource': {'Type': 'ResourceWithPropsType',
'Properties': {'Foo': 'xyz'}}}} 'Properties': {'Foo': 'xyz'}}}}
env2 = {'parameters': {'BParam': 'smelly'}} env2 = environment.Environment({'parameters': {'BParam': 'smelly'}})
updated_stack = stack.Stack(self.ctx, 'updated_stack', updated_stack = stack.Stack(self.ctx, 'updated_stack',
template.Template(tmpl2), template.Template(tmpl2, env=env2),
disable_rollback=False, disable_rollback=False)
env=environment.Environment(env2))
# patch in a dummy handle_create making the replace fail when creating # patch in a dummy handle_create making the replace fail when creating
# the replacement rsrc, and again on the second call (rollback) # the replacement rsrc, and again on the second call (rollback)
@ -1344,11 +1343,10 @@ class StackUpdateTest(common.HeatTestCase):
'AResource': {'Type': 'ResourceWithPropsType', 'AResource': {'Type': 'ResourceWithPropsType',
'Properties': {'Foo': {'Ref': 'AParam'}}}}} 'Properties': {'Foo': {'Ref': 'AParam'}}}}}
env1 = {'parameters': {'AParam': 'abc'}} env1 = environment.Environment({'parameters': {'AParam': 'abc'}})
env2 = {'parameters': {'AParam': 'smelly'}} env2 = environment.Environment({'parameters': {'AParam': 'smelly'}})
self.stack = stack.Stack(self.ctx, 'update_test_stack', self.stack = stack.Stack(self.ctx, 'update_test_stack',
template.Template(tmpl), template.Template(tmpl, env=env1))
environment.Environment(env1))
self.stack.store() self.stack.store()
self.stack.create() self.stack.create()
@ -1357,8 +1355,7 @@ class StackUpdateTest(common.HeatTestCase):
self.assertEqual('abc', self.stack['AResource'].properties['Foo']) self.assertEqual('abc', self.stack['AResource'].properties['Foo'])
updated_stack = stack.Stack(self.ctx, 'updated_stack', updated_stack = stack.Stack(self.ctx, 'updated_stack',
template.Template(tmpl), template.Template(tmpl, env=env2))
environment.Environment(env2))
self.stack.update(updated_stack) self.stack.update(updated_stack)
self.assertEqual((stack.Stack.UPDATE, stack.Stack.COMPLETE), self.assertEqual((stack.Stack.UPDATE, stack.Stack.COMPLETE),
self.stack.state) self.stack.state)

View File

@ -26,7 +26,6 @@ from testtools import matchers
from heat.common import exception from heat.common import exception
from heat.common import template_format from heat.common import template_format
from heat.engine.clients.os import swift from heat.engine.clients.os import swift
from heat.engine import environment
from heat.engine import resource from heat.engine import resource
from heat.engine import rsrc_defn from heat.engine import rsrc_defn
from heat.engine import scheduler from heat.engine import scheduler
@ -88,7 +87,6 @@ def create_stack(template, stack_id=None):
template = templatem.Template(tmpl) template = templatem.Template(tmpl)
ctx = utils.dummy_context(tenant_id='test_tenant') ctx = utils.dummy_context(tenant_id='test_tenant')
st = stack.Stack(ctx, 'test_st', template, st = stack.Stack(ctx, 'test_st', template,
environment.Environment(),
disable_rollback=True) disable_rollback=True)
# Stub out the stack ID so we have a known value # Stub out the stack ID so we have a known value

View File

@ -559,17 +559,17 @@ Mappings:
self.assertRaises(KeyError, self.resolve, find, tmpl, stk) self.assertRaises(KeyError, self.resolve, find, tmpl, stk)
def test_param_refs(self): def test_param_refs(self):
tmpl = template.Template(parameter_template)
env = environment.Environment({'foo': 'bar', 'blarg': 'wibble'}) env = environment.Environment({'foo': 'bar', 'blarg': 'wibble'})
stk = stack.Stack(self.ctx, 'test', tmpl, env) tmpl = template.Template(parameter_template, env=env)
stk = stack.Stack(self.ctx, 'test', tmpl)
p_snippet = {"Ref": "foo"} p_snippet = {"Ref": "foo"}
self.assertEqual("bar", self.resolve(p_snippet, tmpl, stk)) self.assertEqual("bar", self.resolve(p_snippet, tmpl, stk))
def test_param_ref_missing(self): def test_param_ref_missing(self):
tmpl = template.Template(parameter_template)
env = environment.Environment({'foo': 'bar'}) env = environment.Environment({'foo': 'bar'})
stk = stack.Stack(self.ctx, 'test', tmpl, env) tmpl = template.Template(parameter_template, env=env)
stk.env = environment.Environment({}) stk = stack.Stack(self.ctx, 'test', tmpl)
tmpl.env = environment.Environment({})
stk.parameters = parameters.Parameters(stk.identifier(), tmpl) stk.parameters = parameters.Parameters(stk.identifier(), tmpl)
snippet = {"Ref": "foo"} snippet = {"Ref": "foo"}
self.assertRaises(exception.UserParameterMissing, self.assertRaises(exception.UserParameterMissing,
@ -728,9 +728,9 @@ Mappings:
self.assertEqual('"foo" is "${var3}"', self.resolve(snippet, tmpl)) self.assertEqual('"foo" is "${var3}"', self.resolve(snippet, tmpl))
def test_replace_param_values(self): def test_replace_param_values(self):
tmpl = template.Template(parameter_template)
env = environment.Environment({'foo': 'wibble'}) env = environment.Environment({'foo': 'wibble'})
stk = stack.Stack(self.ctx, 'test_stack', tmpl, env) tmpl = template.Template(parameter_template, env=env)
stk = stack.Stack(self.ctx, 'test_stack', tmpl)
snippet = {"Fn::Replace": [ snippet = {"Fn::Replace": [
{'$var1': {'Ref': 'foo'}, '%var2%': {'Ref': 'blarg'}}, {'$var1': {'Ref': 'foo'}, '%var2%': {'Ref': 'blarg'}},
'$var1 is %var2%' '$var1 is %var2%'
@ -1007,8 +1007,7 @@ class ResolveDataTest(common.HeatTestCase):
self.ctx = utils.dummy_context() self.ctx = utils.dummy_context()
self.stack = stack.Stack(self.ctx, 'resolve_test_stack', self.stack = stack.Stack(self.ctx, 'resolve_test_stack',
template.Template(empty_template), template.Template(empty_template))
environment.Environment({}))
def resolve(self, snippet): def resolve(self, snippet):
return function.resolve(self.stack.t.parse(self.stack, snippet)) return function.resolve(self.stack.t.parse(self.stack, snippet))

View File

@ -1245,10 +1245,9 @@ class validateTest(common.HeatTestCase):
def test_unregistered_key(self): def test_unregistered_key(self):
t = template_format.parse(test_unregistered_key) t = template_format.parse(test_unregistered_key)
template = parser.Template(t)
params = {'KeyName': 'not_registered'} params = {'KeyName': 'not_registered'}
stack = parser.Stack(self.ctx, 'test_stack', template, template = parser.Template(t, env=environment.Environment(params))
environment.Environment(params)) stack = parser.Stack(self.ctx, 'test_stack', template)
self._mock_get_image_id_success('image_name', 'image_id') self._mock_get_image_id_success('image_name', 'image_id')
self.m.ReplayAll() self.m.ReplayAll()
@ -1259,10 +1258,11 @@ class validateTest(common.HeatTestCase):
def test_unregistered_image(self): def test_unregistered_image(self):
t = template_format.parse(test_template_image) t = template_format.parse(test_template_image)
template = parser.Template(t) template = parser.Template(t,
env=environment.Environment(
{'KeyName': 'test'}))
stack = parser.Stack(self.ctx, 'test_stack', template, stack = parser.Stack(self.ctx, 'test_stack', template)
environment.Environment({'KeyName': 'test'}))
self._mock_get_image_id_fail('image_name', self._mock_get_image_id_fail('image_name',
exception.ImageNotFound( exception.ImageNotFound(
@ -1276,10 +1276,11 @@ class validateTest(common.HeatTestCase):
def test_duplicated_image(self): def test_duplicated_image(self):
t = template_format.parse(test_template_image) t = template_format.parse(test_template_image)
template = parser.Template(t) template = parser.Template(t,
env=environment.Environment(
{'KeyName': 'test'}))
stack = parser.Stack(self.ctx, 'test_stack', template, stack = parser.Stack(self.ctx, 'test_stack', template)
environment.Environment({'KeyName': 'test'}))
self._mock_get_image_id_fail('image_name', self._mock_get_image_id_fail('image_name',
exception.PhysicalResourceNameAmbiguity( exception.PhysicalResourceNameAmbiguity(
@ -1295,9 +1296,10 @@ class validateTest(common.HeatTestCase):
def test_invalid_security_groups_with_nics(self): def test_invalid_security_groups_with_nics(self):
t = template_format.parse(test_template_invalid_secgroups) t = template_format.parse(test_template_invalid_secgroups)
template = parser.Template(t) template = parser.Template(t,
stack = parser.Stack(self.ctx, 'test_stack', template, env=environment.Environment(
environment.Environment({'KeyName': 'test'})) {'KeyName': 'test'}))
stack = parser.Stack(self.ctx, 'test_stack', template)
self._mock_get_image_id_success('image_name', 'image_id') self._mock_get_image_id_success('image_name', 'image_id')
@ -1312,9 +1314,9 @@ class validateTest(common.HeatTestCase):
def test_invalid_security_group_ids_with_nics(self): def test_invalid_security_group_ids_with_nics(self):
t = template_format.parse(test_template_invalid_secgroupids) t = template_format.parse(test_template_invalid_secgroupids)
template = parser.Template(t) template = parser.Template(
stack = parser.Stack(self.ctx, 'test_stack', template, t, env=environment.Environment({'KeyName': 'test'}))
environment.Environment({'KeyName': 'test'})) stack = parser.Stack(self.ctx, 'test_stack', template)
self._mock_get_image_id_success('image_name', 'image_id') self._mock_get_image_id_success('image_name', 'image_id')
@ -1344,22 +1346,22 @@ class validateTest(common.HeatTestCase):
def test_validate_unique_logical_name(self): def test_validate_unique_logical_name(self):
t = template_format.parse(test_template_unique_logical_name) t = template_format.parse(test_template_unique_logical_name)
template = parser.Template(t) template = parser.Template(
stack = parser.Stack(self.ctx, 'test_stack', template, t, env=environment.Environment(
environment.Environment({'AName': 'test', {'AName': 'test', 'KeyName': 'test'}))
'KeyName': 'test'})) stack = parser.Stack(self.ctx, 'test_stack', template)
self.assertRaises(exception.StackValidationFailed, stack.validate) self.assertRaises(exception.StackValidationFailed, stack.validate)
def test_validate_duplicate_parameters_in_group(self): def test_validate_duplicate_parameters_in_group(self):
t = template_format.parse(test_template_duplicate_parameters) t = template_format.parse(test_template_duplicate_parameters)
template = tmpl.HOTemplate20130523(t) template = tmpl.HOTemplate20130523(
stack = parser.Stack(self.ctx, 'test_stack', template, t, env=environment.Environment({
environment.Environment({
'KeyName': 'test', 'KeyName': 'test',
'ImageId': 'sometestid', 'ImageId': 'sometestid',
'db_password': 'Pass123' 'db_password': 'Pass123'
})) }))
stack = parser.Stack(self.ctx, 'test_stack', template)
exc = self.assertRaises(exception.StackValidationFailed, exc = self.assertRaises(exception.StackValidationFailed,
stack.validate) stack.validate)
@ -1368,12 +1370,12 @@ class validateTest(common.HeatTestCase):
def test_validate_invalid_parameter_in_group(self): def test_validate_invalid_parameter_in_group(self):
t = template_format.parse(test_template_invalid_parameter_name) t = template_format.parse(test_template_invalid_parameter_name)
template = tmpl.HOTemplate20130523(t) template = tmpl.HOTemplate20130523(t,
stack = parser.Stack(self.ctx, 'test_stack', template, env=environment.Environment({
environment.Environment({
'KeyName': 'test', 'KeyName': 'test',
'ImageId': 'sometestid', 'ImageId': 'sometestid',
'db_password': 'Pass123'})) 'db_password': 'Pass123'}))
stack = parser.Stack(self.ctx, 'test_stack', template)
exc = self.assertRaises(exception.StackValidationFailed, exc = self.assertRaises(exception.StackValidationFailed,
stack.validate) stack.validate)
@ -1394,47 +1396,46 @@ class validateTest(common.HeatTestCase):
def test_validate_allowed_values_integer(self): def test_validate_allowed_values_integer(self):
t = template_format.parse(test_template_allowed_integers) t = template_format.parse(test_template_allowed_integers)
template = parser.Template(t) template = parser.Template(t,
env=environment.Environment({'size': '4'}))
# test with size parameter provided as string # test with size parameter provided as string
stack = parser.Stack(self.ctx, 'test_stack', template, stack = parser.Stack(self.ctx, 'test_stack', template)
environment.Environment({'size': '4'}))
self.assertIsNone(stack.validate()) self.assertIsNone(stack.validate())
# test with size parameter provided as number # test with size parameter provided as number
stack = parser.Stack(self.ctx, 'test_stack', template, template.env = environment.Environment({'size': 4})
environment.Environment({'size': 4})) stack = parser.Stack(self.ctx, 'test_stack', template)
self.assertIsNone(stack.validate()) self.assertIsNone(stack.validate())
def test_validate_allowed_values_integer_str(self): def test_validate_allowed_values_integer_str(self):
t = template_format.parse(test_template_allowed_integers_str) t = template_format.parse(test_template_allowed_integers_str)
template = parser.Template(t) template = parser.Template(t,
env=environment.Environment({'size': '4'}))
# test with size parameter provided as string # test with size parameter provided as string
stack = parser.Stack(self.ctx, 'test_stack', template, stack = parser.Stack(self.ctx, 'test_stack', template)
environment.Environment({'size': '4'}))
self.assertIsNone(stack.validate()) self.assertIsNone(stack.validate())
# test with size parameter provided as number # test with size parameter provided as number
stack = parser.Stack(self.ctx, 'test_stack', template, template.env = environment.Environment({'size': 4})
environment.Environment({'size': 4})) stack = parser.Stack(self.ctx, 'test_stack', template)
self.assertIsNone(stack.validate()) self.assertIsNone(stack.validate())
def test_validate_not_allowed_values_integer(self): def test_validate_not_allowed_values_integer(self):
t = template_format.parse(test_template_allowed_integers) t = template_format.parse(test_template_allowed_integers)
template = parser.Template(t) template = parser.Template(t,
env=environment.Environment({'size': '3'}))
# test with size parameter provided as string # test with size parameter provided as string
stack = parser.Stack(self.ctx, 'test_stack', template, stack = parser.Stack(self.ctx, 'test_stack', template)
environment.Environment({'size': '3'}))
err = self.assertRaises(exception.StackValidationFailed, err = self.assertRaises(exception.StackValidationFailed,
stack.validate) stack.validate)
self.assertIn('"3" is not an allowed value [1, 4, 8]', self.assertIn('"3" is not an allowed value [1, 4, 8]',
six.text_type(err)) six.text_type(err))
# test with size parameter provided as number # test with size parameter provided as number
stack = parser.Stack(self.ctx, 'test_stack', template, template.env = environment.Environment({'size': 3})
environment.Environment({'size': 3})) stack = parser.Stack(self.ctx, 'test_stack', template)
err = self.assertRaises(exception.StackValidationFailed, err = self.assertRaises(exception.StackValidationFailed,
stack.validate) stack.validate)
self.assertIn('"3" is not an allowed value [1, 4, 8]', self.assertIn('"3" is not an allowed value [1, 4, 8]',
@ -1442,19 +1443,19 @@ class validateTest(common.HeatTestCase):
def test_validate_not_allowed_values_integer_str(self): def test_validate_not_allowed_values_integer_str(self):
t = template_format.parse(test_template_allowed_integers_str) t = template_format.parse(test_template_allowed_integers_str)
template = parser.Template(t) template = parser.Template(t,
env=environment.Environment({'size': '3'}))
# test with size parameter provided as string # test with size parameter provided as string
stack = parser.Stack(self.ctx, 'test_stack', template, stack = parser.Stack(self.ctx, 'test_stack', template)
environment.Environment({'size': '3'}))
err = self.assertRaises(exception.StackValidationFailed, err = self.assertRaises(exception.StackValidationFailed,
stack.validate) stack.validate)
self.assertIn('"3" is not an allowed value [1, 4, 8]', self.assertIn('"3" is not an allowed value [1, 4, 8]',
six.text_type(err)) six.text_type(err))
# test with size parameter provided as number # test with size parameter provided as number
stack = parser.Stack(self.ctx, 'test_stack', template, template.env = environment.Environment({'size': 3})
environment.Environment({'size': 3})) stack = parser.Stack(self.ctx, 'test_stack', template)
err = self.assertRaises(exception.StackValidationFailed, err = self.assertRaises(exception.StackValidationFailed,
stack.validate) stack.validate)
self.assertIn('"3" is not an allowed value [1, 4, 8]', self.assertIn('"3" is not an allowed value [1, 4, 8]',

View File

@ -96,7 +96,7 @@ def parse_stack(t, params=None, files=None, stack_name=None,
templ.store() templ.store()
if stack_name is None: if stack_name is None:
stack_name = random_name() stack_name = random_name()
stk = stack.Stack(ctx, stack_name, templ, stack_id, stk = stack.Stack(ctx, stack_name, templ, stack_id=stack_id,
timeout_mins=timeout_mins) timeout_mins=timeout_mins)
stk.store() stk.store()
return stk return stk