Merge "Pass the environment into the Template class and not Stack"

This commit is contained in:
Jenkins 2015-03-18 03:28:34 +00:00 committed by Gerrit Code Review
commit ead3f0acf2
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):
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,
environment.Environment({'key_name': 'test'}),
stack_id=uuidutils.generate_uuid())
return (templ, stack)

View File

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

View File

@ -16,6 +16,7 @@ from heat.common import grouputils
from heat.common.i18n import _
from heat.common import timeutils as iso8601utils
from heat.engine import attributes
from heat.engine import environment
from heat.engine import function
from heat.engine import properties
from heat.engine.resources import stack_resource
@ -264,7 +265,12 @@ class InstanceGroup(stack_resource.StackResource):
definitions = template.resource_templates(
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):
if (self.update_policy[self.ROLLING_UPDATE] and

View File

@ -73,7 +73,7 @@ class Stack(collections.Mapping):
_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,
status_reason='', timeout_mins=None, resolve_data=True,
disable_rollback=True, parent_resource=None, owner_id=None,
@ -138,7 +138,6 @@ class Stack(collections.Mapping):
resources.initialise()
self.env = env or self.t.env
self.parameters = self.t.parameters(
self.identifier(),
user_params=self.env.params,
@ -150,6 +149,11 @@ class Stack(collections.Mapping):
else:
self.outputs = {}
@property
def env(self):
"""This is a helper to allow resources to access stack.env."""
return self.t.env
@property
def parent_resource(self):
"""Dynamically load up the parent_resource.
@ -327,10 +331,15 @@ class Stack(collections.Mapping):
use_stored_context=False):
template = tmpl.Template.load(
context, stack.raw_template_id, stack.raw_template)
return cls(context, stack.name, template, template.env,
stack.id, stack.action, stack.status, stack.status_reason,
stack.timeout, resolve_data, stack.disable_rollback,
parent_resource, owner_id=stack.owner_id,
return cls(context, stack.name, template,
stack_id=stack.id,
action=stack.action, status=stack.status,
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,
created_time=stack.created_at,
updated_time=stack.updated_at,
@ -729,7 +738,7 @@ class Stack(collections.Mapping):
return self.load(self.context, stack=s)
elif create_if_missing:
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,
convergence=self.convergence)
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
# need to build it, this can avoid some unexpected errors.
oldstack = Stack(self.context, self.name, copy.deepcopy(self.t),
self.env, convergence=self.convergence)
convergence=self.convergence)
backup_stack = self._backup_stack()
try:
update_task = update.StackUpdate(
@ -815,7 +824,6 @@ class Stack(collections.Mapping):
error_wait_time=cfg.CONF.error_wait_time)
updater = scheduler.TaskRunner(update_task)
self.env = newstack.env
self.parameters = newstack.parameters
self.t.files = newstack.t.files
self.t.env = newstack.t.env
@ -1152,7 +1160,7 @@ class Stack(collections.Mapping):
return
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)):
rsrc = resource.Resource(name, defn, self)
@ -1162,7 +1170,7 @@ class Stack(collections.Mapping):
defn = handle_restore(defn, data)
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,
disable_rollback=self.disable_rollback)
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())
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
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,
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.
@ -48,7 +49,7 @@ def make_template(resource_definitions,
can be specified by passing a (version_type, version_string) tuple matching
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:
tmpl.add_resource(defn, name)

View File

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

View File

@ -80,10 +80,10 @@ class HeatWaitConditionTest(common.HeatTestCase):
params={},
stub=True, stub_status=True):
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)
stack = parser.Stack(ctx, 'test_stack', template,
environment.Environment(params),
disable_rollback=True)
# Stub out the stack ID so we have a known value

View File

@ -734,8 +734,7 @@ class StackServiceCreateUpdateDeleteTest(common.HeatTestCase):
'C': {'Type': 'GenericResourceType'}}}
template = templatem.Template(tpl)
stack = parser.Stack(self.ctx, stack_name, template,
environment.Environment({}))
stack = parser.Stack(self.ctx, stack_name, template)
self.m.StubOutWithMock(templatem, 'Template')
self.m.StubOutWithMock(environment, 'Environment')
@ -1059,10 +1058,10 @@ class StackServiceCreateUpdateDeleteTest(common.HeatTestCase):
s = stack_object.Stack.get_by_id(self.ctx, sid)
t = template_format.parse(wp_template_no_default)
template = templatem.Template(t)
env = environment.Environment({'parameters': with_params,
'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)
@ -3003,8 +3002,7 @@ class StackServiceTest(common.HeatTestCase):
}
}
templ = templatem.Template(lazy_load_template)
stack = parser.Stack(self.ctx, stack_name, templ,
environment.Environment({}))
stack = parser.Stack(self.ctx, stack_name, templ)
self.assertIsNone(stack._resources)
self.assertIsNone(stack._dependencies)

View File

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

View File

@ -1053,16 +1053,18 @@ class HotStackTest(common.HeatTestCase):
'update_template_diff')
self.stack = parser.Stack(self.ctx, 'update_test_stack',
template.Template(tmpl),
environment.Environment({'foo': 'abc'}))
template.Template(
tmpl, env=environment.Environment(
{'foo': 'abc'})))
self.stack.store()
self.stack.create()
self.assertEqual((parser.Stack.CREATE, parser.Stack.COMPLETE),
self.stack.state)
updated_stack = parser.Stack(self.ctx, 'updated_stack',
template.Template(tmpl),
environment.Environment({'foo': 'xyz'}))
template.Template(
tmpl, env=environment.Environment(
{'foo': 'xyz'})))
def check_props(*args):
self.assertEqual('abc', self.stack['AResource'].properties['Foo'])
@ -1307,9 +1309,9 @@ class StackParametersTest(common.HeatTestCase):
def test_param_refs(self):
"""Test if parameter references work."""
tmpl = parser.Template(self.props_template)
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',
tenant_id='9913ef0a-b8be-4b33-b574-9061441bd373')
self.assertEqual(self.expected,

View File

@ -79,9 +79,9 @@ class InstancesTest(common.HeatTestCase):
def _setup_test_stack(self, stack_name):
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,
environment.Environment({'KeyName': 'test'}),
stack_id=str(uuid.uuid4()))
return (template, stack)

View File

@ -198,12 +198,12 @@ class instancesTest(common.HeatTestCase):
def _create_test_instance(self, return_server, name):
stack_name = '%s_s' % name
t = template_format.parse(wp_template)
template = parser.Template(t)
kwargs = {'KeyName': 'test',
'InstanceType': 'm1.large',
'SubnetId': '4156c7a5-e8c4-4aff-a6e1-8f3c7bc83861'}
template = parser.Template(t,
env=environment.Environment(kwargs))
stack = parser.Stack(utils.dummy_context(), stack_name, template,
environment.Environment(kwargs),
stack_id=str(uuid.uuid4()))
image_id = 'CentOS 5.2'
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):
stack_name = '%s_s' % name
t = template_format.parse(wp_template_with_nic)
template = parser.Template(t)
kwargs = {'KeyName': 'test',
'InstanceType': 'm1.large',
'SubnetId': '4156c7a5-e8c4-4aff-a6e1-8f3c7bc83861'}
template = parser.Template(t,
env=environment.Environment(kwargs))
stack = parser.Stack(utils.dummy_context(), stack_name, template,
environment.Environment(kwargs),
stack_id=str(uuid.uuid4()))
image_id = 'CentOS 5.2'
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):
params = params or {}
temp = template_format.parse(test_template_metadata)
template = parser.Template(temp)
template = parser.Template(temp,
env=environment.Environment(params))
ctx = utils.dummy_context()
stack = parser.Stack(ctx, stack_name, template,
environment.Environment(params),
disable_rollback=True)
self.stack_id = stack.store()
@ -314,10 +314,10 @@ class MetadataRefreshTestServer(common.HeatTestCase):
def create_stack(self, stack_name='test_stack_native', params=None):
params = params or {}
temp = template_format.parse(test_template_server)
template = parser.Template(temp)
template = parser.Template(temp,
env=environment.Environment(params))
ctx = utils.dummy_context()
stack = parser.Stack(ctx, stack_name, template,
environment.Environment(params),
disable_rollback=True)
self.stack_id = stack.store()

View File

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

View File

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

View File

@ -119,9 +119,10 @@ class ServersTest(common.HeatTestCase):
def _setup_test_stack(self, stack_name, test_templ=wp_template):
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,
environment.Environment({'key_name': 'test'}),
stack_id=uuidutils.generate_uuid(),
stack_user_project_id='8888')
return (templ, stack)

View File

@ -65,9 +65,10 @@ class ServerTagsTest(common.HeatTestCase):
def _setup_test_instance(self, intags=None, nova_tags=None):
stack_name = 'tag_test'
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,
environment.Environment({'KeyName': 'test'}),
stack_id=str(uuid.uuid4()))
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,
stack_user_project_id=None, backup=False):
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 = parser.Stack(self.ctx, stack_name, template,
environment.Environment({'KeyName': 'test'}),
owner_id=owner_id,
stack_user_project_id=stack_user_project_id)
with utils.UUIDStub(stack_id):

View File

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

View File

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

View File

@ -26,7 +26,6 @@ from testtools import matchers
from heat.common import exception
from heat.common import template_format
from heat.engine.clients.os import swift
from heat.engine import environment
from heat.engine import resource
from heat.engine import rsrc_defn
from heat.engine import scheduler
@ -88,7 +87,6 @@ def create_stack(template, stack_id=None):
template = templatem.Template(tmpl)
ctx = utils.dummy_context(tenant_id='test_tenant')
st = stack.Stack(ctx, 'test_st', template,
environment.Environment(),
disable_rollback=True)
# 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)
def test_param_refs(self):
tmpl = template.Template(parameter_template)
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"}
self.assertEqual("bar", self.resolve(p_snippet, tmpl, stk))
def test_param_ref_missing(self):
tmpl = template.Template(parameter_template)
env = environment.Environment({'foo': 'bar'})
stk = stack.Stack(self.ctx, 'test', tmpl, env)
stk.env = environment.Environment({})
tmpl = template.Template(parameter_template, env=env)
stk = stack.Stack(self.ctx, 'test', tmpl)
tmpl.env = environment.Environment({})
stk.parameters = parameters.Parameters(stk.identifier(), tmpl)
snippet = {"Ref": "foo"}
self.assertRaises(exception.UserParameterMissing,
@ -728,9 +728,9 @@ Mappings:
self.assertEqual('"foo" is "${var3}"', self.resolve(snippet, tmpl))
def test_replace_param_values(self):
tmpl = template.Template(parameter_template)
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": [
{'$var1': {'Ref': 'foo'}, '%var2%': {'Ref': 'blarg'}},
'$var1 is %var2%'
@ -1007,8 +1007,7 @@ class ResolveDataTest(common.HeatTestCase):
self.ctx = utils.dummy_context()
self.stack = stack.Stack(self.ctx, 'resolve_test_stack',
template.Template(empty_template),
environment.Environment({}))
template.Template(empty_template))
def resolve(self, 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):
t = template_format.parse(test_unregistered_key)
template = parser.Template(t)
params = {'KeyName': 'not_registered'}
stack = parser.Stack(self.ctx, 'test_stack', template,
environment.Environment(params))
template = parser.Template(t, env=environment.Environment(params))
stack = parser.Stack(self.ctx, 'test_stack', template)
self._mock_get_image_id_success('image_name', 'image_id')
self.m.ReplayAll()
@ -1259,10 +1258,11 @@ class validateTest(common.HeatTestCase):
def test_unregistered_image(self):
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,
environment.Environment({'KeyName': 'test'}))
stack = parser.Stack(self.ctx, 'test_stack', template)
self._mock_get_image_id_fail('image_name',
exception.ImageNotFound(
@ -1276,10 +1276,11 @@ class validateTest(common.HeatTestCase):
def test_duplicated_image(self):
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,
environment.Environment({'KeyName': 'test'}))
stack = parser.Stack(self.ctx, 'test_stack', template)
self._mock_get_image_id_fail('image_name',
exception.PhysicalResourceNameAmbiguity(
@ -1295,9 +1296,10 @@ class validateTest(common.HeatTestCase):
def test_invalid_security_groups_with_nics(self):
t = template_format.parse(test_template_invalid_secgroups)
template = parser.Template(t)
stack = parser.Stack(self.ctx, 'test_stack', template,
environment.Environment({'KeyName': 'test'}))
template = parser.Template(t,
env=environment.Environment(
{'KeyName': 'test'}))
stack = parser.Stack(self.ctx, 'test_stack', template)
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):
t = template_format.parse(test_template_invalid_secgroupids)
template = parser.Template(t)
stack = parser.Stack(self.ctx, 'test_stack', template,
environment.Environment({'KeyName': 'test'}))
template = parser.Template(
t, env=environment.Environment({'KeyName': 'test'}))
stack = parser.Stack(self.ctx, 'test_stack', template)
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):
t = template_format.parse(test_template_unique_logical_name)
template = parser.Template(t)
stack = parser.Stack(self.ctx, 'test_stack', template,
environment.Environment({'AName': 'test',
'KeyName': 'test'}))
template = parser.Template(
t, env=environment.Environment(
{'AName': 'test', 'KeyName': 'test'}))
stack = parser.Stack(self.ctx, 'test_stack', template)
self.assertRaises(exception.StackValidationFailed, stack.validate)
def test_validate_duplicate_parameters_in_group(self):
t = template_format.parse(test_template_duplicate_parameters)
template = tmpl.HOTemplate20130523(t)
stack = parser.Stack(self.ctx, 'test_stack', template,
environment.Environment({
'KeyName': 'test',
'ImageId': 'sometestid',
'db_password': 'Pass123'
}))
template = tmpl.HOTemplate20130523(
t, env=environment.Environment({
'KeyName': 'test',
'ImageId': 'sometestid',
'db_password': 'Pass123'
}))
stack = parser.Stack(self.ctx, 'test_stack', template)
exc = self.assertRaises(exception.StackValidationFailed,
stack.validate)
@ -1368,12 +1370,12 @@ class validateTest(common.HeatTestCase):
def test_validate_invalid_parameter_in_group(self):
t = template_format.parse(test_template_invalid_parameter_name)
template = tmpl.HOTemplate20130523(t)
stack = parser.Stack(self.ctx, 'test_stack', template,
environment.Environment({
'KeyName': 'test',
'ImageId': 'sometestid',
'db_password': 'Pass123'}))
template = tmpl.HOTemplate20130523(t,
env=environment.Environment({
'KeyName': 'test',
'ImageId': 'sometestid',
'db_password': 'Pass123'}))
stack = parser.Stack(self.ctx, 'test_stack', template)
exc = self.assertRaises(exception.StackValidationFailed,
stack.validate)
@ -1394,47 +1396,46 @@ class validateTest(common.HeatTestCase):
def test_validate_allowed_values_integer(self):
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
stack = parser.Stack(self.ctx, 'test_stack', template,
environment.Environment({'size': '4'}))
stack = parser.Stack(self.ctx, 'test_stack', template)
self.assertIsNone(stack.validate())
# test with size parameter provided as number
stack = parser.Stack(self.ctx, 'test_stack', template,
environment.Environment({'size': 4}))
template.env = environment.Environment({'size': 4})
stack = parser.Stack(self.ctx, 'test_stack', template)
self.assertIsNone(stack.validate())
def test_validate_allowed_values_integer_str(self):
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
stack = parser.Stack(self.ctx, 'test_stack', template,
environment.Environment({'size': '4'}))
stack = parser.Stack(self.ctx, 'test_stack', template)
self.assertIsNone(stack.validate())
# test with size parameter provided as number
stack = parser.Stack(self.ctx, 'test_stack', template,
environment.Environment({'size': 4}))
template.env = environment.Environment({'size': 4})
stack = parser.Stack(self.ctx, 'test_stack', template)
self.assertIsNone(stack.validate())
def test_validate_not_allowed_values_integer(self):
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
stack = parser.Stack(self.ctx, 'test_stack', template,
environment.Environment({'size': '3'}))
stack = parser.Stack(self.ctx, 'test_stack', template)
err = self.assertRaises(exception.StackValidationFailed,
stack.validate)
self.assertIn('"3" is not an allowed value [1, 4, 8]',
six.text_type(err))
# test with size parameter provided as number
stack = parser.Stack(self.ctx, 'test_stack', template,
environment.Environment({'size': 3}))
template.env = environment.Environment({'size': 3})
stack = parser.Stack(self.ctx, 'test_stack', template)
err = self.assertRaises(exception.StackValidationFailed,
stack.validate)
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):
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
stack = parser.Stack(self.ctx, 'test_stack', template,
environment.Environment({'size': '3'}))
stack = parser.Stack(self.ctx, 'test_stack', template)
err = self.assertRaises(exception.StackValidationFailed,
stack.validate)
self.assertIn('"3" is not an allowed value [1, 4, 8]',
six.text_type(err))
# test with size parameter provided as number
stack = parser.Stack(self.ctx, 'test_stack', template,
environment.Environment({'size': 3}))
template.env = environment.Environment({'size': 3})
stack = parser.Stack(self.ctx, 'test_stack', template)
err = self.assertRaises(exception.StackValidationFailed,
stack.validate)
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()
if stack_name is None:
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)
stk.store()
return stk