Add preview for NestedStack
Override ``child_template`` and ``child_params`` to allow previewing of NestedStack as a group of resources. Implements: blueprint preview-stack (partial) Change-Id: I3acde4ccc31731aee1209c747fdbcc4446be63bc
This commit is contained in:
parent
8a42e1baf0
commit
faf6034989
@ -61,13 +61,7 @@ class NestedStack(stack_resource.StackResource):
|
||||
|
||||
update_allowed_keys = ('Properties',)
|
||||
|
||||
def handle_adopt(self, resource_data=None):
|
||||
return self._create_with_template(resource_adopt_data=resource_data)
|
||||
|
||||
def handle_create(self):
|
||||
return self._create_with_template()
|
||||
|
||||
def _create_with_template(self, resource_adopt_data=None):
|
||||
def child_template(self):
|
||||
try:
|
||||
template_data = urlfetch.get(self.properties[self.TEMPLATE_URL])
|
||||
except (exceptions.RequestException, IOError) as r_exc:
|
||||
@ -76,10 +70,21 @@ class NestedStack(stack_resource.StackResource):
|
||||
{'url': self.properties[self.TEMPLATE_URL],
|
||||
'exc': str(r_exc)})
|
||||
|
||||
template = template_format.parse(template_data)
|
||||
return template_format.parse(template_data)
|
||||
|
||||
def child_params(self):
|
||||
return self.properties[self.PARAMETERS]
|
||||
|
||||
def handle_adopt(self, resource_data=None):
|
||||
return self._create_with_template(resource_adopt_data=resource_data)
|
||||
|
||||
def handle_create(self):
|
||||
return self._create_with_template()
|
||||
|
||||
def _create_with_template(self, resource_adopt_data=None):
|
||||
template = self.child_template()
|
||||
return self.create_with_template(template,
|
||||
self.properties[self.PARAMETERS],
|
||||
self.child_params(),
|
||||
self.properties[self.TIMEOUT_IN_MINS],
|
||||
adopt_data=resource_adopt_data)
|
||||
|
||||
|
@ -15,6 +15,8 @@
|
||||
|
||||
import copy
|
||||
import json
|
||||
import mock
|
||||
from requests import exceptions
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
@ -598,6 +600,42 @@ Resources:
|
||||
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_child_params(self):
|
||||
t = template_format.parse(self.test_template)
|
||||
stack = self.parse_stack(t)
|
||||
nested_stack = stack['the_nested']
|
||||
nested_stack.properties.data[nested_stack.PARAMETERS] = {'foo': 'bar'}
|
||||
|
||||
self.assertEqual({'foo': 'bar'}, nested_stack.child_params())
|
||||
|
||||
@mock.patch.object(urlfetch, 'get')
|
||||
def test_child_template_when_file_is_fetched(self, mock_get):
|
||||
mock_get.return_value = 'template_file'
|
||||
t = template_format.parse(self.test_template)
|
||||
stack = self.parse_stack(t)
|
||||
nested_stack = stack['the_nested']
|
||||
|
||||
with mock.patch('heat.common.template_format.parse') as mock_parse:
|
||||
mock_parse.return_value = 'child_template'
|
||||
self.assertEqual('child_template', nested_stack.child_template())
|
||||
mock_parse.assert_called_once_with('template_file')
|
||||
|
||||
@mock.patch.object(urlfetch, 'get')
|
||||
def test_child_template_when_fetching_file_fails(self, mock_get):
|
||||
mock_get.side_effect = exceptions.RequestException()
|
||||
t = template_format.parse(self.test_template)
|
||||
stack = self.parse_stack(t)
|
||||
nested_stack = stack['the_nested']
|
||||
self.assertRaises(ValueError, nested_stack.child_template)
|
||||
|
||||
@mock.patch.object(urlfetch, 'get')
|
||||
def test_child_template_when_io_error(self, mock_get):
|
||||
mock_get.side_effect = IOError()
|
||||
t = template_format.parse(self.test_template)
|
||||
stack = self.parse_stack(t)
|
||||
nested_stack = stack['the_nested']
|
||||
self.assertRaises(ValueError, nested_stack.child_template)
|
||||
|
||||
|
||||
class ResDataResource(generic_rsrc.GenericResource):
|
||||
def handle_create(self):
|
||||
|
Loading…
Reference in New Issue
Block a user