Merge "Use the template module to access the Template class"

This commit is contained in:
Jenkins 2014-08-28 13:24:04 +00:00 committed by Gerrit Code Review
commit b630251b28
18 changed files with 109 additions and 97 deletions

View File

@ -80,7 +80,7 @@ class MarconiMessageQueueTest(HeatTestCase):
def parse_stack(self, t): def parse_stack(self, t):
stack_name = 'test_stack' stack_name = 'test_stack'
tmpl = parser.Template(t) tmpl = template.Template(t)
self.stack = parser.Stack(self.ctx, stack_name, tmpl) self.stack = parser.Stack(self.ctx, stack_name, tmpl)
self.stack.validate() self.stack.validate()
self.stack.store() self.stack.store()

View File

@ -22,6 +22,7 @@ from heat.engine import environment
from heat.engine import parser from heat.engine import parser
from heat.engine import resource from heat.engine import resource
from heat.engine import scheduler from heat.engine import scheduler
from heat.engine import template
from heat.openstack.common import uuidutils from heat.openstack.common import uuidutils
from heat.tests import common from heat.tests import common
from heat.tests import utils from heat.tests import utils
@ -89,11 +90,11 @@ 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)
template = parser.Template(t) templ = template.Template(t)
stack = parser.Stack(self.ctx, stack_name, template, stack = parser.Stack(self.ctx, stack_name, templ,
environment.Environment({'key_name': 'test'}), environment.Environment({'key_name': 'test'}),
stack_id=uuidutils.generate_uuid()) stack_id=uuidutils.generate_uuid())
return (template, stack) return (templ, stack)
def _setup_test_server(self, return_server, name, image_id=None, def _setup_test_server(self, return_server, name, image_id=None,
override_name=False, stub_create=True, exit_code=0): override_name=False, stub_create=True, exit_code=0):

View File

@ -19,6 +19,7 @@ from heat.engine import parser
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
from heat.engine import template
from heat.tests import common from heat.tests import common
from heat.tests import utils from heat.tests import utils
@ -97,16 +98,16 @@ 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
template = parser.Template(t) templ = template.Template(t)
stack = parser.Stack(utils.dummy_context(), stack = parser.Stack(utils.dummy_context(),
stack_name, stack_name,
template, templ,
environment.Environment({'name': 'test'}), environment.Environment({'name': 'test'}),
stack_id=str(uuid.uuid4())) stack_id=str(uuid.uuid4()))
instance = cloud_dns.CloudDns( instance = cloud_dns.CloudDns(
'%s_name' % name, '%s_name' % name,
template.resource_definitions(stack)['domain'], templ.resource_definitions(stack)['domain'],
stack) stack)
return instance return instance

View File

@ -17,9 +17,9 @@ import copy
from heat.common import exception from heat.common import exception
from heat.engine import attributes from heat.engine import attributes
from heat.engine import constraints from heat.engine import constraints
from heat.engine import parser
from heat.engine import properties from heat.engine import properties
from heat.engine import stack_resource from heat.engine import stack_resource
from heat.engine import template
from heat.openstack.common.gettextutils import _ from heat.openstack.common.gettextutils import _
template_template = { template_template = {
@ -136,7 +136,7 @@ class ResourceGroup(stack_resource.StackResource):
super(ResourceGroup, self).validate() super(ResourceGroup, self).validate()
# make sure the nested resource is valid # make sure the nested resource is valid
test_tmpl = self._assemble_nested(1, include_all=True) test_tmpl = self._assemble_nested(1, include_all=True)
val_templ = parser.Template(test_tmpl) val_templ = template.Template(test_tmpl)
res_def = val_templ.resource_definitions(self.stack)["0"] res_def = val_templ.resource_definitions(self.stack)["0"]
res_class = self.stack.env.get_class(res_def.resource_type) res_class = self.stack.env.get_class(res_def.resource_type)
res_inst = res_class("%s:resource_def" % self.name, res_def, res_inst = res_class("%s:resource_def" % self.name, res_def,

View File

@ -38,6 +38,7 @@ from heat.engine import properties
from heat.engine import resource from heat.engine import resource
from heat.engine import resources from heat.engine import resources
from heat.engine import stack_lock from heat.engine import stack_lock
from heat.engine import template as templatem
from heat.engine import watchrule from heat.engine import watchrule
from heat.openstack.common.gettextutils import _ from heat.openstack.common.gettextutils import _
from heat.openstack.common import log as logging from heat.openstack.common import log as logging
@ -501,7 +502,7 @@ class EngineService(service.Service):
def _parse_template_and_validate_stack(self, cnxt, stack_name, template, def _parse_template_and_validate_stack(self, cnxt, stack_name, template,
params, files, args, owner_id=None): params, files, args, owner_id=None):
tmpl = parser.Template(template, files=files) tmpl = templatem.Template(template, files=files)
self._validate_new_stack(cnxt, stack_name, tmpl) self._validate_new_stack(cnxt, stack_name, tmpl)
common_params = api.extract_args(args) common_params = api.extract_args(args)
@ -618,7 +619,7 @@ class EngineService(service.Service):
# Now parse the template and any parameters for the updated # Now parse the template and any parameters for the updated
# stack definition. # stack definition.
tmpl = parser.Template(template, files=files) tmpl = templatem.Template(template, files=files)
if len(tmpl[tmpl.RESOURCES]) > cfg.CONF.max_resources_per_stack: if len(tmpl[tmpl.RESOURCES]) > cfg.CONF.max_resources_per_stack:
raise exception.RequestLimitExceeded( raise exception.RequestLimitExceeded(
message=exception.StackResourceLimitExceeded.msg_fmt) message=exception.StackResourceLimitExceeded.msg_fmt)
@ -656,7 +657,7 @@ class EngineService(service.Service):
msg = _("No Template provided.") msg = _("No Template provided.")
return webob.exc.HTTPBadRequest(explanation=msg) return webob.exc.HTTPBadRequest(explanation=msg)
tmpl = parser.Template(template) tmpl = templatem.Template(template)
# validate overall template # validate overall template
try: try:

View File

@ -19,6 +19,7 @@ from heat.engine import environment
from heat.engine import parser from heat.engine import parser
from heat.engine import resource from heat.engine import resource
from heat.engine import scheduler from heat.engine import scheduler
from heat.engine import template
from heat.openstack.common.gettextutils import _ from heat.openstack.common.gettextutils import _
from heat.openstack.common import log as logging from heat.openstack.common import log as logging
@ -99,21 +100,21 @@ class StackResource(resource.Resource):
StackResource will be returned as if it were a regular Resource. StackResource will be returned as if it were a regular Resource.
''' '''
try: try:
if isinstance(self.child_template(), parser.Template): if isinstance(self.child_template(), template.Template):
template = parser.Template(self.child_template().t) templ = template.Template(self.child_template().t)
else: else:
template = parser.Template(self.child_template()) templ = template.Template(self.child_template())
params = self.child_params() params = self.child_params()
except NotImplementedError: except NotImplementedError:
not_implemented_msg = _("Preview of '%s' not yet implemented") not_implemented_msg = _("Preview of '%s' not yet implemented")
LOG.warning(not_implemented_msg % self.__class__.__name__) LOG.warning(not_implemented_msg % self.__class__.__name__)
return self return self
self._validate_nested_resources(template) self._validate_nested_resources(templ)
name = "%s-%s" % (self.stack.name, self.name) name = "%s-%s" % (self.stack.name, self.name)
nested = parser.Stack(self.context, nested = parser.Stack(self.context,
name, name,
template, templ,
self._nested_environment(params), self._nested_environment(params),
disable_rollback=True, disable_rollback=True,
parent_resource=self, parent_resource=self,
@ -122,8 +123,8 @@ class StackResource(resource.Resource):
return nested.preview_resources() return nested.preview_resources()
def _validate_nested_resources(self, template): def _validate_nested_resources(self, templ):
total_resources = (len(template[template.RESOURCES]) + total_resources = (len(templ[templ.RESOURCES]) +
self.stack.root_stack.total_resources()) self.stack.root_stack.total_resources())
if (total_resources > cfg.CONF.max_resources_per_stack): if (total_resources > cfg.CONF.max_resources_per_stack):
message = exception.StackResourceLimitExceeded.msg_fmt message = exception.StackResourceLimitExceeded.msg_fmt
@ -155,14 +156,14 @@ class StackResource(resource.Resource):
msg = _("Recursion depth exceeds %d.") % \ msg = _("Recursion depth exceeds %d.") % \
cfg.CONF.max_nested_stack_depth cfg.CONF.max_nested_stack_depth
raise exception.RequestLimitExceeded(message=msg) raise exception.RequestLimitExceeded(message=msg)
if isinstance(child_template, parser.Template): if isinstance(child_template, template.Template):
template = child_template templ = child_template
template.files = self.stack.t.files templ.files = self.stack.t.files
else: else:
template = parser.Template(child_template, templ = template.Template(child_template,
files=self.stack.t.files) files=self.stack.t.files)
self._validate_nested_resources(template) self._validate_nested_resources(templ)
self._outputs_to_attribs(template) self._outputs_to_attribs(templ)
if timeout_mins is None: if timeout_mins is None:
timeout_mins = self.stack.timeout_mins timeout_mins = self.stack.timeout_mins
@ -171,7 +172,7 @@ class StackResource(resource.Resource):
# should be rolled back by the parent stack on failure # should be rolled back by the parent stack on failure
nested = parser.Stack(self.context, nested = parser.Stack(self.context,
self.physical_resource_name(), self.physical_resource_name(),
template, templ,
self._nested_environment(user_params), self._nested_environment(user_params),
timeout_mins=timeout_mins, timeout_mins=timeout_mins,
disable_rollback=True, disable_rollback=True,
@ -205,18 +206,18 @@ class StackResource(resource.Resource):
def update_with_template(self, child_template, user_params, def update_with_template(self, child_template, user_params,
timeout_mins=None): timeout_mins=None):
"""Update the nested stack with the new template.""" """Update the nested stack with the new template."""
if isinstance(child_template, parser.Template): if isinstance(child_template, template.Template):
template = child_template templ = child_template
template.files = self.stack.t.files templ.files = self.stack.t.files
else: else:
template = parser.Template(child_template, templ = template.Template(child_template,
files=self.stack.t.files) files=self.stack.t.files)
nested_stack = self.nested() nested_stack = self.nested()
if nested_stack is None: if nested_stack is None:
raise exception.Error(_('Cannot update %s, stack not created') raise exception.Error(_('Cannot update %s, stack not created')
% self.name) % self.name)
res_diff = ( res_diff = (
len(template[template.RESOURCES]) - len(nested_stack.resources)) len(templ[templ.RESOURCES]) - len(nested_stack.resources))
new_size = nested_stack.root_stack.total_resources() + res_diff new_size = nested_stack.root_stack.total_resources() + res_diff
if new_size > cfg.CONF.max_resources_per_stack: if new_size > cfg.CONF.max_resources_per_stack:
raise exception.RequestLimitExceeded( raise exception.RequestLimitExceeded(
@ -229,7 +230,7 @@ class StackResource(resource.Resource):
# should be rolled back by the parent stack on failure # should be rolled back by the parent stack on failure
stack = parser.Stack(self.context, stack = parser.Stack(self.context,
self.physical_resource_name(), self.physical_resource_name(),
template, templ,
self._nested_environment(user_params), self._nested_environment(user_params),
timeout_mins=timeout_mins, timeout_mins=timeout_mins,
disable_rollback=True, disable_rollback=True,
@ -243,7 +244,7 @@ class StackResource(resource.Resource):
# define their own attributes_schema. # define their own attributes_schema.
if not hasattr(type(self), 'attributes_schema'): if not hasattr(type(self), 'attributes_schema'):
self.attributes = None self.attributes = None
self._outputs_to_attribs(template) self._outputs_to_attribs(templ)
updater = scheduler.TaskRunner(nested_stack.update_task, stack) updater = scheduler.TaskRunner(nested_stack.update_task, stack)
updater.start() updater.start()

View File

@ -17,6 +17,7 @@ from heat.engine import constraints
from heat.engine import parser from heat.engine import parser
from heat.engine import properties from heat.engine import properties
from heat.engine import resource from heat.engine import resource
from heat.engine import template
from heat.tests.common import HeatTestCase from heat.tests.common import HeatTestCase
from heat.tests import utils from heat.tests import utils
@ -154,7 +155,7 @@ class DBInstanceTest(HeatTestCase):
"""test that the Template is parsable and """test that the Template is parsable and
publishes the correct properties. publishes the correct properties.
""" """
templ = parser.Template(template_format.parse(rds_template)) templ = template.Template(template_format.parse(rds_template))
stack = parser.Stack(utils.dummy_context(), 'test_stack', stack = parser.Stack(utils.dummy_context(), 'test_stack',
templ) templ)

View File

@ -42,6 +42,7 @@ from heat.engine import resource as res
from heat.engine.resources import instance as instances from heat.engine.resources import instance as instances
from heat.engine import service from heat.engine import service
from heat.engine import stack_lock from heat.engine import stack_lock
from heat.engine import template as templatem
from heat.engine import watchrule from heat.engine import watchrule
from heat.openstack.common import threadgroup from heat.openstack.common import threadgroup
from heat.rpc import api as engine_api from heat.rpc import api as engine_api
@ -175,7 +176,7 @@ resources:
def get_wordpress_stack(stack_name, ctx): def get_wordpress_stack(stack_name, ctx):
t = template_format.parse(wp_template) t = template_format.parse(wp_template)
template = parser.Template(t) template = templatem.Template(t)
stack = parser.Stack(ctx, stack_name, template, stack = parser.Stack(ctx, stack_name, template,
environment.Environment({'KeyName': 'test'})) environment.Environment({'KeyName': 'test'}))
return stack return stack
@ -183,7 +184,7 @@ def get_wordpress_stack(stack_name, ctx):
def get_stack(stack_name, ctx, template): def get_stack(stack_name, ctx, template):
t = template_format.parse(template) t = template_format.parse(template)
template = parser.Template(t) template = templatem.Template(t)
stack = parser.Stack(ctx, stack_name, template) stack = parser.Stack(ctx, stack_name, template)
return stack return stack
@ -344,7 +345,7 @@ class StackCreateTest(HeatTestCase):
def test_wordpress_single_instance_stack_adopt(self): def test_wordpress_single_instance_stack_adopt(self):
t = template_format.parse(wp_template) t = template_format.parse(wp_template)
template = parser.Template(t) template = templatem.Template(t)
ctx = utils.dummy_context() ctx = utils.dummy_context()
adopt_data = { adopt_data = {
'resources': { 'resources': {
@ -369,7 +370,7 @@ class StackCreateTest(HeatTestCase):
def test_wordpress_single_instance_stack_adopt_fail(self): def test_wordpress_single_instance_stack_adopt_fail(self):
t = template_format.parse(wp_template) t = template_format.parse(wp_template)
template = parser.Template(t) template = templatem.Template(t)
ctx = utils.dummy_context() ctx = utils.dummy_context()
adopt_data = { adopt_data = {
'resources': { 'resources': {
@ -436,11 +437,11 @@ class StackServiceCreateUpdateDeleteTest(HeatTestCase):
stack = get_wordpress_stack(stack_name, self.ctx) stack = get_wordpress_stack(stack_name, self.ctx)
self.m.StubOutWithMock(parser, 'Template') self.m.StubOutWithMock(templatem, 'Template')
self.m.StubOutWithMock(environment, 'Environment') self.m.StubOutWithMock(environment, 'Environment')
self.m.StubOutWithMock(parser, 'Stack') self.m.StubOutWithMock(parser, 'Stack')
parser.Template(template, files=None).AndReturn(stack.t) templatem.Template(template, files=None).AndReturn(stack.t)
environment.Environment(params).AndReturn(stack.env) environment.Environment(params).AndReturn(stack.env)
parser.Stack(self.ctx, stack.name, parser.Stack(self.ctx, stack.name,
stack.t, stack.env, owner_id=None).AndReturn(stack) stack.t, stack.env, owner_id=None).AndReturn(stack)
@ -485,11 +486,11 @@ class StackServiceCreateUpdateDeleteTest(HeatTestCase):
stack = get_wordpress_stack(stack_name, self.ctx) stack = get_wordpress_stack(stack_name, self.ctx)
self.m.StubOutWithMock(parser, 'Template') self.m.StubOutWithMock(templatem, 'Template')
self.m.StubOutWithMock(environment, 'Environment') self.m.StubOutWithMock(environment, 'Environment')
self.m.StubOutWithMock(parser, 'Stack') self.m.StubOutWithMock(parser, 'Stack')
parser.Template(template, files=None).AndReturn(stack.t) templatem.Template(template, files=None).AndReturn(stack.t)
environment.Environment(params).AndReturn(stack.env) environment.Environment(params).AndReturn(stack.env)
parser.Stack(self.ctx, stack.name, parser.Stack(self.ctx, stack.name,
stack.t, stack.t,
@ -539,19 +540,19 @@ class StackServiceCreateUpdateDeleteTest(HeatTestCase):
# force check for credentials on create # force check for credentials on create
stack['WebServer'].requires_deferred_auth = True stack['WebServer'].requires_deferred_auth = True
self.m.StubOutWithMock(parser, 'Template') self.m.StubOutWithMock(templatem, 'Template')
self.m.StubOutWithMock(environment, 'Environment') self.m.StubOutWithMock(environment, 'Environment')
self.m.StubOutWithMock(parser, 'Stack') self.m.StubOutWithMock(parser, 'Stack')
ctx_no_pwd = utils.dummy_context(password=None) ctx_no_pwd = utils.dummy_context(password=None)
ctx_no_user = utils.dummy_context(user=None) ctx_no_user = utils.dummy_context(user=None)
parser.Template(template, files=None).AndReturn(stack.t) templatem.Template(template, files=None).AndReturn(stack.t)
environment.Environment(params).AndReturn(stack.env) environment.Environment(params).AndReturn(stack.env)
parser.Stack(ctx_no_pwd, stack.name, parser.Stack(ctx_no_pwd, stack.name,
stack.t, stack.env, owner_id=None).AndReturn(stack) stack.t, stack.env, owner_id=None).AndReturn(stack)
parser.Template(template, files=None).AndReturn(stack.t) templatem.Template(template, files=None).AndReturn(stack.t)
environment.Environment(params).AndReturn(stack.env) environment.Environment(params).AndReturn(stack.env)
parser.Stack(ctx_no_user, stack.name, parser.Stack(ctx_no_user, stack.name,
stack.t, stack.env, owner_id=None).AndReturn(stack) stack.t, stack.env, owner_id=None).AndReturn(stack)
@ -587,15 +588,15 @@ class StackServiceCreateUpdateDeleteTest(HeatTestCase):
'B': {'Type': 'GenericResourceType'}, 'B': {'Type': 'GenericResourceType'},
'C': {'Type': 'GenericResourceType'}}} 'C': {'Type': 'GenericResourceType'}}}
template = parser.Template(tpl) template = templatem.Template(tpl)
stack = parser.Stack(self.ctx, stack_name, template, stack = parser.Stack(self.ctx, stack_name, template,
environment.Environment({})) environment.Environment({}))
self.m.StubOutWithMock(parser, 'Template') self.m.StubOutWithMock(templatem, 'Template')
self.m.StubOutWithMock(environment, 'Environment') self.m.StubOutWithMock(environment, 'Environment')
self.m.StubOutWithMock(parser, 'Stack') self.m.StubOutWithMock(parser, 'Stack')
parser.Template(template, files=None).AndReturn(stack.t) templatem.Template(template, files=None).AndReturn(stack.t)
environment.Environment(params).AndReturn(stack.env) environment.Environment(params).AndReturn(stack.env)
parser.Stack(self.ctx, stack.name, parser.Stack(self.ctx, stack.name,
stack.t, stack.t,
@ -861,10 +862,10 @@ class StackServiceCreateUpdateDeleteTest(HeatTestCase):
self.m.StubOutWithMock(parser.Stack, 'load') self.m.StubOutWithMock(parser.Stack, 'load')
parser.Stack.load(self.ctx, stack=s).AndReturn(old_stack) parser.Stack.load(self.ctx, stack=s).AndReturn(old_stack)
self.m.StubOutWithMock(parser, 'Template') self.m.StubOutWithMock(templatem, 'Template')
self.m.StubOutWithMock(environment, 'Environment') self.m.StubOutWithMock(environment, 'Environment')
parser.Template(template, files=None).AndReturn(stack.t) templatem.Template(template, files=None).AndReturn(stack.t)
environment.Environment(params).AndReturn(stack.env) environment.Environment(params).AndReturn(stack.env)
parser.Stack(self.ctx, stack.name, parser.Stack(self.ctx, stack.name,
stack.t, stack.env, timeout_mins=60).AndReturn(stack) stack.t, stack.env, timeout_mins=60).AndReturn(stack)
@ -896,7 +897,7 @@ class StackServiceCreateUpdateDeleteTest(HeatTestCase):
'B': {'Type': 'GenericResourceType'}, 'B': {'Type': 'GenericResourceType'},
'C': {'Type': 'GenericResourceType'}}} 'C': {'Type': 'GenericResourceType'}}}
template = parser.Template(tpl) template = templatem.Template(tpl)
old_stack = parser.Stack(self.ctx, stack_name, template) old_stack = parser.Stack(self.ctx, stack_name, template)
sid = old_stack.store() sid = old_stack.store()
@ -908,10 +909,10 @@ class StackServiceCreateUpdateDeleteTest(HeatTestCase):
self.m.StubOutWithMock(parser.Stack, 'load') self.m.StubOutWithMock(parser.Stack, 'load')
parser.Stack.load(self.ctx, stack=s).AndReturn(old_stack) parser.Stack.load(self.ctx, stack=s).AndReturn(old_stack)
self.m.StubOutWithMock(parser, 'Template') self.m.StubOutWithMock(templatem, 'Template')
self.m.StubOutWithMock(environment, 'Environment') self.m.StubOutWithMock(environment, 'Environment')
parser.Template(template, files=None).AndReturn(stack.t) templatem.Template(template, files=None).AndReturn(stack.t)
environment.Environment(params).AndReturn(stack.env) environment.Environment(params).AndReturn(stack.env)
parser.Stack(self.ctx, stack.name, parser.Stack(self.ctx, stack.name,
stack.t, stack.env, timeout_mins=60).AndReturn(stack) stack.t, stack.env, timeout_mins=60).AndReturn(stack)
@ -951,7 +952,7 @@ class StackServiceCreateUpdateDeleteTest(HeatTestCase):
} }
} }
template = parser.Template(tpl) template = templatem.Template(tpl)
create_stack = parser.Stack(self.ctx, stack_name, template) create_stack = parser.Stack(self.ctx, stack_name, template)
sid = create_stack.store() sid = create_stack.store()
@ -1029,7 +1030,7 @@ class StackServiceCreateUpdateDeleteTest(HeatTestCase):
AndReturn(json.dumps(nested_tpl)) AndReturn(json.dumps(nested_tpl))
mox.Replay(urlfetch.get) mox.Replay(urlfetch.get)
template = parser.Template(tpl) template = templatem.Template(tpl)
create_env = environment.Environment({'some_param': 'foo'}) create_env = environment.Environment({'some_param': 'foo'})
create_stack = parser.Stack(self.ctx, stack_name, template, create_env) create_stack = parser.Stack(self.ctx, stack_name, template, create_env)
@ -1081,7 +1082,7 @@ class StackServiceCreateUpdateDeleteTest(HeatTestCase):
'B': {'Type': 'GenericResourceType'}, 'B': {'Type': 'GenericResourceType'},
'C': {'Type': 'GenericResourceType'}}} 'C': {'Type': 'GenericResourceType'}}}
template = parser.Template(tpl) template = templatem.Template(tpl)
old_stack = parser.Stack(self.ctx, stack_name, template) old_stack = parser.Stack(self.ctx, stack_name, template)
sid = old_stack.store() sid = old_stack.store()
self.assertIsNotNone(sid) self.assertIsNotNone(sid)
@ -1112,10 +1113,10 @@ class StackServiceCreateUpdateDeleteTest(HeatTestCase):
self.m.StubOutWithMock(parser.Stack, 'load') self.m.StubOutWithMock(parser.Stack, 'load')
parser.Stack.load(self.ctx, stack=s).AndReturn(old_stack) parser.Stack.load(self.ctx, stack=s).AndReturn(old_stack)
self.m.StubOutWithMock(parser, 'Template') self.m.StubOutWithMock(templatem, 'Template')
self.m.StubOutWithMock(environment, 'Environment') self.m.StubOutWithMock(environment, 'Environment')
parser.Template(template, files=None).AndReturn(stack.t) templatem.Template(template, files=None).AndReturn(stack.t)
environment.Environment(params).AndReturn(stack.env) environment.Environment(params).AndReturn(stack.env)
parser.Stack(self.ctx, stack.name, parser.Stack(self.ctx, stack.name,
stack.t, stack.env, timeout_mins=60).AndReturn(stack) stack.t, stack.env, timeout_mins=60).AndReturn(stack)
@ -1166,7 +1167,7 @@ class StackServiceCreateUpdateDeleteTest(HeatTestCase):
self.m.StubOutWithMock(parser, 'Stack') self.m.StubOutWithMock(parser, 'Stack')
self.m.StubOutWithMock(parser.Stack, 'load') self.m.StubOutWithMock(parser.Stack, 'load')
self.m.StubOutWithMock(parser, 'Template') self.m.StubOutWithMock(templatem, 'Template')
self.m.StubOutWithMock(environment, 'Environment') self.m.StubOutWithMock(environment, 'Environment')
self.m.StubOutWithMock(self.man, '_get_stack') self.m.StubOutWithMock(self.man, '_get_stack')
@ -1174,7 +1175,7 @@ class StackServiceCreateUpdateDeleteTest(HeatTestCase):
parser.Stack.load(self.ctx, stack=s).AndReturn(old_stack) parser.Stack.load(self.ctx, stack=s).AndReturn(old_stack)
parser.Template(template, files=None).AndReturn(old_stack.t) templatem.Template(template, files=None).AndReturn(old_stack.t)
environment.Environment(params).AndReturn(old_stack.env) environment.Environment(params).AndReturn(old_stack.env)
parser.Stack(self.ctx, old_stack.name, parser.Stack(self.ctx, old_stack.name,
old_stack.t, old_stack.env, old_stack.t, old_stack.env,
@ -2664,7 +2665,7 @@ class StackServiceTest(HeatTestCase):
} }
} }
} }
templ = parser.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({})) environment.Environment({}))
@ -2751,7 +2752,7 @@ class StackServiceTest(HeatTestCase):
def test_validate_new_stack_checks_stack_limit(self, mock_db_count): def test_validate_new_stack_checks_stack_limit(self, mock_db_count):
cfg.CONF.set_override('max_stacks_per_tenant', 99) cfg.CONF.set_override('max_stacks_per_tenant', 99)
mock_db_count.return_value = 99 mock_db_count.return_value = 99
template = service.parser.Template( template = service.templatem.Template(
{'HeatTemplateFormatVersion': '2012-12-12'}) {'HeatTemplateFormatVersion': '2012-12-12'})
self.assertRaises(exception.RequestLimitExceeded, self.assertRaises(exception.RequestLimitExceeded,
self.eng._validate_new_stack, self.eng._validate_new_stack,
@ -2761,7 +2762,7 @@ class StackServiceTest(HeatTestCase):
cfg.CONF.set_override('max_resources_per_stack', 5) cfg.CONF.set_override('max_resources_per_stack', 5)
template = {'HeatTemplateFormatVersion': '2012-12-12', template = {'HeatTemplateFormatVersion': '2012-12-12',
'Resources': [1, 2, 3, 4, 5, 6]} 'Resources': [1, 2, 3, 4, 5, 6]}
parsed_template = service.parser.Template(template) parsed_template = service.templatem.Template(template)
self.assertRaises(exception.RequestLimitExceeded, self.assertRaises(exception.RequestLimitExceeded,
self.eng._validate_new_stack, self.eng._validate_new_stack,
self.ctx, 'test_existing_stack', parsed_template) self.ctx, 'test_existing_stack', parsed_template)

View File

@ -20,6 +20,7 @@ from heat.common import exception
from heat.common import template_format from heat.common import template_format
from heat.engine import parser from heat.engine import parser
from heat.engine import scheduler from heat.engine import scheduler
from heat.engine import template
from heat.tests.common import HeatTestCase from heat.tests.common import HeatTestCase
from heat.tests import utils from heat.tests import utils
from heat.tests.v1_1 import fakes from heat.tests.v1_1 import fakes
@ -101,15 +102,15 @@ Resources:
self.m.StubOutWithMock(neutronclient.Client, 'delete_security_group') self.m.StubOutWithMock(neutronclient.Client, 'delete_security_group')
self.m.StubOutWithMock(neutronclient.Client, 'update_security_group') self.m.StubOutWithMock(neutronclient.Client, 'update_security_group')
def create_stack(self, template): def create_stack(self, templ):
t = template_format.parse(template) t = template_format.parse(templ)
self.stack = self.parse_stack(t) self.stack = self.parse_stack(t)
self.assertIsNone(self.stack.create()) self.assertIsNone(self.stack.create())
return self.stack return self.stack
def parse_stack(self, t): def parse_stack(self, t):
stack_name = 'test_stack' stack_name = 'test_stack'
tmpl = parser.Template(t) tmpl = template.Template(t)
stack = parser.Stack(utils.dummy_context(), stack_name, tmpl) stack = parser.Stack(utils.dummy_context(), stack_name, tmpl)
stack.store() stack.store()
return stack return stack

View File

@ -50,7 +50,7 @@ from heat.tests.v1_1 import fakes
def join(raw): def join(raw):
tmpl = parser.Template(mapping_template) tmpl = template.Template(mapping_template)
return function.resolve(tmpl.parse(None, raw)) return function.resolve(tmpl.parse(None, raw))

View File

@ -21,6 +21,7 @@ from heat.common import exception
from heat.common import template_format from heat.common import template_format
from heat.engine import parser from heat.engine import parser
from heat.engine.resources.random_string import RandomString from heat.engine.resources.random_string import RandomString
from heat.engine import template
from heat.tests.common import HeatTestCase from heat.tests.common import HeatTestCase
from heat.tests import utils from heat.tests import utils
@ -87,15 +88,14 @@ Resources:
super(TestRandomString, self).setUp() super(TestRandomString, self).setUp()
self.ctx = utils.dummy_context() self.ctx = utils.dummy_context()
def create_stack(self, template): def create_stack(self, templ):
t = template_format.parse(template) self.stack = self.parse_stack(template_format.parse(templ))
self.stack = self.parse_stack(t)
self.assertIsNone(self.stack.create()) self.assertIsNone(self.stack.create())
return self.stack return self.stack
def parse_stack(self, t): def parse_stack(self, t):
stack_name = 'test_stack' stack_name = 'test_stack'
tmpl = parser.Template(t) tmpl = template.Template(t)
stack = parser.Stack(utils.dummy_context(), stack_name, tmpl) stack = parser.Stack(utils.dummy_context(), stack_name, tmpl)
stack.validate() stack.validate()
stack.store() stack.store()

View File

@ -23,6 +23,7 @@ from heat.common import template_format
from heat.engine.clients.os import nova from heat.engine.clients.os import nova
from heat.engine import parser from heat.engine import parser
from heat.engine import scheduler from heat.engine import scheduler
from heat.engine import template
from heat.tests.common import HeatTestCase from heat.tests.common import HeatTestCase
from heat.tests import utils from heat.tests import utils
from heat.tests.v1_1 import fakes from heat.tests.v1_1 import fakes
@ -143,15 +144,14 @@ Resources:
neutronclient.Client, 'delete_security_group_rule') neutronclient.Client, 'delete_security_group_rule')
self.m.StubOutWithMock(neutronclient.Client, 'delete_security_group') self.m.StubOutWithMock(neutronclient.Client, 'delete_security_group')
def create_stack(self, template): def create_stack(self, templ):
t = template_format.parse(template) self.stack = self.parse_stack(template_format.parse(templ))
self.stack = self.parse_stack(t)
self.assertIsNone(self.stack.create()) self.assertIsNone(self.stack.create())
return self.stack return self.stack
def parse_stack(self, t): def parse_stack(self, t):
stack_name = 'test_stack' stack_name = 'test_stack'
tmpl = parser.Template(t) tmpl = template.Template(t)
stack = parser.Stack(utils.dummy_context(), stack_name, tmpl) stack = parser.Stack(utils.dummy_context(), stack_name, tmpl)
stack.store() stack.store()
return stack return stack

View File

@ -31,6 +31,7 @@ from heat.engine import parser
from heat.engine import resource from heat.engine import resource
from heat.engine.resources import server as servers from heat.engine.resources import server as servers
from heat.engine import scheduler from heat.engine import scheduler
from heat.engine import template
from heat.openstack.common.gettextutils import _ from heat.openstack.common.gettextutils import _
from heat.tests.common import HeatTestCase from heat.tests.common import HeatTestCase
from heat.tests import fakes from heat.tests import fakes
@ -88,12 +89,12 @@ class ServersTest(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) templ = template.Template(t)
stack = parser.Stack(utils.dummy_context(), stack_name, template, stack = parser.Stack(utils.dummy_context(), stack_name, templ,
environment.Environment({'key_name': 'test'}), environment.Environment({'key_name': 'test'}),
stack_id=str(uuid.uuid4()), stack_id=str(uuid.uuid4()),
stack_user_project_id='8888') stack_user_project_id='8888')
return (template, stack) return (templ, stack)
def _get_test_template(self, stack_name, server_name=None, def _get_test_template(self, stack_name, server_name=None,
image_id=None): image_id=None):
@ -812,11 +813,11 @@ class ServersTest(HeatTestCase):
} }
''' '''
t = template_format.parse(nova_keypair_template) t = template_format.parse(nova_keypair_template)
template = parser.Template(t) templ = template.Template(t)
stack = parser.Stack(utils.dummy_context(), stack_name, template, stack = parser.Stack(utils.dummy_context(), stack_name, templ,
stack_id=str(uuid.uuid4())) stack_id=str(uuid.uuid4()))
resource_defns = template.resource_definitions(stack) resource_defns = templ.resource_definitions(stack)
server = servers.Server('server_validate_test', server = servers.Server('server_validate_test',
resource_defns['WebServer'], stack) resource_defns['WebServer'], stack)

View File

@ -23,6 +23,7 @@ from heat.engine import parser
from heat.engine import resource from heat.engine import resource
from heat.engine import scheduler from heat.engine import scheduler
from heat.engine import stack_user from heat.engine import stack_user
from heat.engine import template
from heat.tests.common import HeatTestCase from heat.tests.common import HeatTestCase
from heat.tests import fakes from heat.tests import fakes
from heat.tests import generic_resource from heat.tests import generic_resource
@ -61,11 +62,10 @@ class SignalTest(HeatTestCase):
super(SignalTest, self).tearDown() super(SignalTest, self).tearDown()
def create_stack(self, stack_name='test_stack', stub=True): def create_stack(self, stack_name='test_stack', stub=True):
temp = template_format.parse(test_template_signal) templ = template.Template(template_format.parse(test_template_signal))
template = parser.Template(temp)
ctx = utils.dummy_context() ctx = utils.dummy_context()
ctx.tenant_id = 'test_tenant' ctx.tenant_id = 'test_tenant'
stack = parser.Stack(ctx, stack_name, template, stack = parser.Stack(ctx, stack_name, templ,
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

@ -24,6 +24,7 @@ from heat.engine import parser
from heat.engine import resource from heat.engine import resource
from heat.engine import scheduler from heat.engine import scheduler
from heat.engine import stack_resource from heat.engine import stack_resource
from heat.engine import template as templatem
from heat.tests.common import HeatTestCase from heat.tests.common import HeatTestCase
from heat.tests import generic_resource as generic_rsrc from heat.tests import generic_resource as generic_rsrc
from heat.tests import utils from heat.tests import utils
@ -147,7 +148,7 @@ class StackResourceTest(HeatTestCase):
mock_stack_class.return_value = nested_stack mock_stack_class.return_value = nested_stack
nested_stack.preview_resources.return_value = 'preview_nested_stack' nested_stack.preview_resources.return_value = 'preview_nested_stack'
mock_env_class.return_value = 'environment' mock_env_class.return_value = 'environment'
template = parser.Template(template_format.parse(param_template)) template = templatem.Template(template_format.parse(param_template))
parent_t = self.parent_stack.t parent_t = self.parent_stack.t
resource_defns = parent_t.resource_definitions(self.parent_stack) resource_defns = parent_t.resource_definitions(self.parent_stack)
parent_resource = MyImplementedStackResource( parent_resource = MyImplementedStackResource(
@ -183,7 +184,7 @@ class StackResourceTest(HeatTestCase):
nested_stack.preview_resources.return_value = 'preview_nested_stack' nested_stack.preview_resources.return_value = 'preview_nested_stack'
mock_env_class.return_value = 'environment' mock_env_class.return_value = 'environment'
template_dict = template_format.parse(param_template) template_dict = template_format.parse(param_template)
template = parser.Template(template_dict) template = templatem.Template(template_dict)
parent_t = self.parent_stack.t parent_t = self.parent_stack.t
resource_defns = parent_t.resource_definitions(self.parent_stack) resource_defns = parent_t.resource_definitions(self.parent_stack)
parent_resource = MyImplementedStackResource( parent_resource = MyImplementedStackResource(
@ -217,7 +218,7 @@ class StackResourceTest(HeatTestCase):
resource_defns[self.ws_resname], resource_defns[self.ws_resname],
self.parent_stack) self.parent_stack)
stk_resource.child_template = \ stk_resource.child_template = \
mock.Mock(return_value=parser.Template(self.simple_template)) mock.Mock(return_value=templatem.Template(self.simple_template))
stk_resource.child_params = mock.Mock() stk_resource.child_params = mock.Mock()
exc = exception.RequestLimitExceeded(message='Validation Failed') exc = exception.RequestLimitExceeded(message='Validation Failed')
validation_mock = mock.Mock(side_effect=exc) validation_mock = mock.Mock(side_effect=exc)
@ -247,7 +248,7 @@ class StackResourceTest(HeatTestCase):
stack_resource.cfg.CONF.set_override('max_resources_per_stack', 2) stack_resource.cfg.CONF.set_override('max_resources_per_stack', 2)
tmpl = {'HeatTemplateFormatVersion': '2012-12-12', tmpl = {'HeatTemplateFormatVersion': '2012-12-12',
'Resources': [1]} 'Resources': [1]}
template = stack_resource.parser.Template(tmpl) template = stack_resource.template.Template(tmpl)
root_resources = mock.Mock(return_value=2) root_resources = mock.Mock(return_value=2)
self.parent_resource.stack.root_stack.total_resources = root_resources self.parent_resource.stack.root_stack.total_resources = root_resources
@ -578,7 +579,7 @@ class StackResourceTest(HeatTestCase):
ctx = self.parent_resource.context ctx = self.parent_resource.context
phy_id = "cb2f2b28-a663-4683-802c-4b40c916e1ff" phy_id = "cb2f2b28-a663-4683-802c-4b40c916e1ff"
templ = parser.Template(self.templ) templ = templatem.Template(self.templ)
env = environment.Environment({"KeyName": "test"}) env = environment.Environment({"KeyName": "test"})
self.stack = parser.Stack(ctx, phy_id, templ, env, timeout_mins=None, self.stack = parser.Stack(ctx, phy_id, templ, env, timeout_mins=None,
disable_rollback=True, disable_rollback=True,

View File

@ -15,6 +15,7 @@ from heat.common import exception
from heat.common import template_format from heat.common import template_format
from heat.engine import parser from heat.engine import parser
from heat.engine import scheduler from heat.engine import scheduler
from heat.engine import template
from heat.tests.common import HeatTestCase from heat.tests.common import HeatTestCase
from heat.tests import utils from heat.tests import utils
@ -57,8 +58,8 @@ class VPCTestBase(HeatTestCase):
neutronclient.Client, 'delete_security_group_rule') neutronclient.Client, 'delete_security_group_rule')
self.stub_keystoneclient() self.stub_keystoneclient()
def create_stack(self, template): def create_stack(self, templ):
t = template_format.parse(template) t = template_format.parse(templ)
stack = self.parse_stack(t) stack = self.parse_stack(t)
self.assertIsNone(stack.validate()) self.assertIsNone(stack.validate())
self.assertIsNone(stack.create()) self.assertIsNone(stack.create())
@ -66,7 +67,7 @@ class VPCTestBase(HeatTestCase):
def parse_stack(self, t): def parse_stack(self, t):
stack_name = 'test_stack' stack_name = 'test_stack'
tmpl = parser.Template(t) tmpl = template.Template(t)
stack = parser.Stack(utils.dummy_context(), stack_name, tmpl) stack = parser.Stack(utils.dummy_context(), stack_name, tmpl)
stack.store() stack.store()
return stack return stack

View File

@ -19,6 +19,7 @@ import mox
from heat.common import exception from heat.common import exception
from heat.db import api as db_api from heat.db import api as db_api
from heat.engine import parser from heat.engine import parser
from heat.engine import template
from heat.engine import watchrule from heat.engine import watchrule
from heat.openstack.common import timeutils from heat.openstack.common import timeutils
from heat.tests.common import HeatTestCase from heat.tests.common import HeatTestCase
@ -47,7 +48,7 @@ class WatchRuleTest(HeatTestCase):
ctx = utils.dummy_context() ctx = utils.dummy_context()
ctx.auth_token = 'abcd1234' ctx.auth_token = 'abcd1234'
empty_tmpl = {'HeatTemplateFormatVersion': '2012-12-12'} empty_tmpl = {'HeatTemplateFormatVersion': '2012-12-12'}
tmpl = parser.Template(empty_tmpl) tmpl = template.Template(empty_tmpl)
stack_name = 'dummystack' stack_name = 'dummystack'
dummy_stack = parser.Stack(ctx, stack_name, tmpl) dummy_stack = parser.Stack(ctx, stack_name, tmpl)
dummy_stack.state_set(dummy_stack.CREATE, dummy_stack.COMPLETE, dummy_stack.state_set(dummy_stack.CREATE, dummy_stack.COMPLETE,

View File

@ -24,6 +24,7 @@ from heat.db import api as db_api
from heat.engine import environment from heat.engine import environment
from heat.engine import parser from heat.engine import parser
from heat.engine import resource from heat.engine import resource
from heat.engine import template
get_engine = db_api.get_engine get_engine = db_api.get_engine
@ -85,8 +86,8 @@ def parse_stack(t, params=None, stack_name='test_stack', stack_id=None,
timeout_mins=None): timeout_mins=None):
params = params or {} params = params or {}
ctx = dummy_context() ctx = dummy_context()
template = parser.Template(t) templ = template.Template(t)
stack = parser.Stack(ctx, stack_name, template, stack = parser.Stack(ctx, stack_name, templ,
environment.Environment(params), stack_id, environment.Environment(params), stack_id,
timeout_mins=timeout_mins) timeout_mins=timeout_mins)
stack.store() stack.store()