Move aws nested stack tests to functional tests
- use swift to post templates to. - move limit tests to test_stack_resource Part of blueprint decouple-nested Change-Id: Id11e86835addc21301b3534a559d1754a802425e
This commit is contained in:
@@ -12,13 +12,8 @@
|
||||
# under the License.
|
||||
|
||||
|
||||
import copy
|
||||
import json
|
||||
|
||||
import mock
|
||||
from oslo.config import cfg
|
||||
from requests import exceptions
|
||||
import six
|
||||
import yaml
|
||||
|
||||
from heat.common import exception
|
||||
@@ -29,13 +24,10 @@ from heat.engine import parser
|
||||
from heat.engine import resource
|
||||
from heat.engine.resources import stack as stack_res
|
||||
from heat.engine import rsrc_defn
|
||||
from heat.engine import scheduler
|
||||
from heat.tests import common
|
||||
from heat.tests import generic_resource as generic_rsrc
|
||||
from heat.tests import utils
|
||||
|
||||
cfg.CONF.import_opt('max_resources_per_stack', 'heat.common.config')
|
||||
|
||||
|
||||
class NestedStackTest(common.HeatTestCase):
|
||||
test_template = '''
|
||||
@@ -80,13 +72,6 @@ Outputs:
|
||||
self.assertEqual((stack.CREATE, stack.COMPLETE), stack.state)
|
||||
return stack
|
||||
|
||||
def adopt_stack(self, template, adopt_data):
|
||||
t = template_format.parse(template)
|
||||
stack = self.parse_stack(t, adopt_data)
|
||||
stack.adopt()
|
||||
self.assertEqual((stack.ADOPT, stack.COMPLETE), stack.state)
|
||||
return stack
|
||||
|
||||
def parse_stack(self, t, data=None):
|
||||
ctx = utils.dummy_context('test_username', 'aaaa', 'password')
|
||||
stack_name = 'test_stack'
|
||||
@@ -95,324 +80,6 @@ Outputs:
|
||||
stack.store()
|
||||
return stack
|
||||
|
||||
def test_nested_stack_create(self):
|
||||
urlfetch.get('https://server.test/the.template'
|
||||
).MultipleTimes().AndReturn(self.nested_template)
|
||||
self.m.ReplayAll()
|
||||
|
||||
stack = self.create_stack(self.test_template)
|
||||
rsrc = stack['the_nested']
|
||||
nested_name = utils.PhysName(stack.name, 'the_nested')
|
||||
self.assertEqual(nested_name, rsrc.physical_resource_name())
|
||||
arn_prefix = ('arn:openstack:heat::aaaa:stacks/%s/' %
|
||||
rsrc.physical_resource_name())
|
||||
self.assertTrue(rsrc.FnGetRefId().startswith(arn_prefix))
|
||||
|
||||
self.assertEqual('bar', rsrc.FnGetAtt('Outputs.Foo'))
|
||||
self.assertRaises(
|
||||
exception.InvalidTemplateAttribute, rsrc.FnGetAtt, 'Foo')
|
||||
self.assertRaises(
|
||||
exception.InvalidTemplateAttribute, rsrc.FnGetAtt, 'Outputs.Bar')
|
||||
self.assertRaises(
|
||||
exception.InvalidTemplateAttribute, rsrc.FnGetAtt, 'Bar')
|
||||
|
||||
rsrc.delete()
|
||||
self.assertTrue(rsrc.FnGetRefId().startswith(arn_prefix))
|
||||
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_nested_stack_adopt(self):
|
||||
resource._register_class('GenericResource',
|
||||
generic_rsrc.GenericResource)
|
||||
urlfetch.get('https://server.test/the.template'
|
||||
).MultipleTimes().AndReturn(
|
||||
'''
|
||||
HeatTemplateFormatVersion: '2012-12-12'
|
||||
Parameters:
|
||||
KeyName:
|
||||
Type: String
|
||||
Resources:
|
||||
NestedResource:
|
||||
Type: GenericResource
|
||||
Outputs:
|
||||
Foo:
|
||||
Value: bar
|
||||
''')
|
||||
self.m.ReplayAll()
|
||||
|
||||
adopt_data = {
|
||||
"resources": {
|
||||
"the_nested": {
|
||||
"resource_id": "test-res-id",
|
||||
"resources": {
|
||||
"NestedResource": {
|
||||
"resource_id": "test-nested-res-id"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stack = self.adopt_stack(self.test_template, adopt_data)
|
||||
self.assertEqual((stack.ADOPT, stack.COMPLETE), stack.state)
|
||||
rsrc = stack['the_nested']
|
||||
self.assertEqual((rsrc.ADOPT, rsrc.COMPLETE), rsrc.state)
|
||||
nested_name = utils.PhysName(stack.name, 'the_nested')
|
||||
self.assertEqual(nested_name, rsrc.physical_resource_name())
|
||||
self.assertEqual('test-nested-res-id',
|
||||
rsrc.nested()['NestedResource'].resource_id)
|
||||
rsrc.delete()
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_nested_stack_adopt_fail(self):
|
||||
resource._register_class('GenericResource',
|
||||
generic_rsrc.GenericResource)
|
||||
urlfetch.get('https://server.test/the.template'
|
||||
).MultipleTimes().AndReturn(
|
||||
'''
|
||||
HeatTemplateFormatVersion: '2012-12-12'
|
||||
Parameters:
|
||||
KeyName:
|
||||
Type: String
|
||||
Resources:
|
||||
NestedResource:
|
||||
Type: GenericResource
|
||||
Outputs:
|
||||
Foo:
|
||||
Value: bar
|
||||
''')
|
||||
self.m.ReplayAll()
|
||||
|
||||
adopt_data = {
|
||||
"resources": {
|
||||
"the_nested": {
|
||||
"resource_id": "test-res-id",
|
||||
"resources": {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
t = template_format.parse(self.test_template)
|
||||
stack = self.parse_stack(t, adopt_data)
|
||||
stack.adopt()
|
||||
self.assertEqual((stack.ADOPT, stack.FAILED), stack.state)
|
||||
rsrc = stack['the_nested']
|
||||
self.assertEqual((rsrc.ADOPT, rsrc.FAILED), rsrc.nested().state)
|
||||
nested_name = utils.PhysName(stack.name, 'the_nested')
|
||||
self.assertEqual(nested_name, rsrc.physical_resource_name())
|
||||
rsrc.delete()
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_nested_stack_create_with_timeout(self):
|
||||
urlfetch.get('https://server.test/the.template'
|
||||
).MultipleTimes().AndReturn(self.nested_template)
|
||||
self.m.ReplayAll()
|
||||
|
||||
timeout_template = template_format.parse(
|
||||
copy.deepcopy(self.test_template))
|
||||
props = timeout_template['Resources']['the_nested']['Properties']
|
||||
props['TimeoutInMinutes'] = '50'
|
||||
|
||||
stack = self.create_stack(json.dumps(timeout_template))
|
||||
self.assertEqual((stack.CREATE, stack.COMPLETE), stack.state)
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_nested_stack_create_exceeds_resource_limit(self):
|
||||
cfg.CONF.set_override('max_resources_per_stack', 1)
|
||||
resource._register_class('GenericResource',
|
||||
generic_rsrc.GenericResource)
|
||||
urlfetch.get('https://server.test/the.template'
|
||||
).MultipleTimes().AndReturn(
|
||||
'''
|
||||
HeatTemplateFormatVersion: '2012-12-12'
|
||||
Parameters:
|
||||
KeyName:
|
||||
Type: String
|
||||
Resources:
|
||||
NestedResource:
|
||||
Type: GenericResource
|
||||
Outputs:
|
||||
Foo:
|
||||
Value: bar
|
||||
''')
|
||||
self.m.ReplayAll()
|
||||
|
||||
t = template_format.parse(self.test_template)
|
||||
stack = self.parse_stack(t)
|
||||
stack.create()
|
||||
self.assertEqual((stack.CREATE, stack.FAILED), stack.state)
|
||||
self.assertIn('Maximum resources per stack exceeded',
|
||||
stack.status_reason)
|
||||
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_nested_stack_create_equals_resource_limit(self):
|
||||
cfg.CONF.set_override('max_resources_per_stack', 2)
|
||||
resource._register_class('GenericResource',
|
||||
generic_rsrc.GenericResource)
|
||||
urlfetch.get('https://server.test/the.template'
|
||||
).MultipleTimes().AndReturn(
|
||||
'''
|
||||
HeatTemplateFormatVersion: '2012-12-12'
|
||||
Parameters:
|
||||
KeyName:
|
||||
Type: String
|
||||
Resources:
|
||||
NestedResource:
|
||||
Type: GenericResource
|
||||
Outputs:
|
||||
Foo:
|
||||
Value: bar
|
||||
''')
|
||||
self.m.ReplayAll()
|
||||
|
||||
t = template_format.parse(self.test_template)
|
||||
stack = self.parse_stack(t)
|
||||
stack.create()
|
||||
self.assertEqual((stack.CREATE, stack.COMPLETE), stack.state)
|
||||
self.assertIn('NestedResource',
|
||||
stack['the_nested'].nested())
|
||||
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_nested_stack_update(self):
|
||||
urlfetch.get('https://server.test/the.template'
|
||||
).MultipleTimes().AndReturn(self.nested_template)
|
||||
urlfetch.get('https://server.test/new.template'
|
||||
).MultipleTimes().AndReturn(self.update_template)
|
||||
|
||||
self.m.ReplayAll()
|
||||
|
||||
stack = self.create_stack(self.test_template)
|
||||
rsrc = stack['the_nested']
|
||||
|
||||
original_nested_id = rsrc.resource_id
|
||||
prop_diff = {'TemplateURL': 'https://server.test/new.template'}
|
||||
props = copy.copy(rsrc.properties.data)
|
||||
props.update(prop_diff)
|
||||
new_res = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(), props)
|
||||
updater = rsrc.handle_update(new_res, {}, prop_diff)
|
||||
updater.run_to_completion()
|
||||
self.assertIs(True, rsrc.check_update_complete(updater))
|
||||
|
||||
# Expect the physical resource name staying the same after update,
|
||||
# so that the nested was actually updated instead of replaced.
|
||||
self.assertEqual(original_nested_id, rsrc.resource_id)
|
||||
db_nested = db_api.stack_get(stack.context,
|
||||
rsrc.resource_id)
|
||||
# Owner_id should be preserved during the update process.
|
||||
self.assertEqual(stack.id, db_nested.owner_id)
|
||||
|
||||
self.assertEqual('foo', rsrc.FnGetAtt('Outputs.Bar'))
|
||||
self.assertRaises(
|
||||
exception.InvalidTemplateAttribute, rsrc.FnGetAtt, 'Foo')
|
||||
self.assertRaises(
|
||||
exception.InvalidTemplateAttribute, rsrc.FnGetAtt, 'Outputs.Foo')
|
||||
self.assertRaises(
|
||||
exception.InvalidTemplateAttribute, rsrc.FnGetAtt, 'Bar')
|
||||
|
||||
rsrc.delete()
|
||||
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_nested_stack_update_equals_resource_limit(self):
|
||||
resource._register_class('GenericResource',
|
||||
generic_rsrc.GenericResource)
|
||||
urlfetch.get('https://server.test/the.template'
|
||||
).MultipleTimes().AndReturn(self.nested_template)
|
||||
urlfetch.get('https://server.test/new.template'
|
||||
).MultipleTimes().AndReturn(
|
||||
'''
|
||||
HeatTemplateFormatVersion: '2012-12-12'
|
||||
Parameters:
|
||||
KeyName:
|
||||
Type: String
|
||||
Resources:
|
||||
NestedResource:
|
||||
Type: GenericResource
|
||||
Outputs:
|
||||
Bar:
|
||||
Value: foo
|
||||
''')
|
||||
self.m.ReplayAll()
|
||||
|
||||
stack = self.create_stack(self.test_template)
|
||||
|
||||
cfg.CONF.set_override('max_resources_per_stack', 2)
|
||||
|
||||
rsrc = stack['the_nested']
|
||||
|
||||
prop_diff = {'TemplateURL': 'https://server.test/new.template'}
|
||||
props = copy.copy(rsrc.properties.data)
|
||||
props.update(prop_diff)
|
||||
new_res = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(), props)
|
||||
updater = rsrc.handle_update(new_res, {}, prop_diff)
|
||||
updater.run_to_completion()
|
||||
self.assertIs(True, rsrc.check_update_complete(updater))
|
||||
|
||||
self.assertEqual('foo', rsrc.FnGetAtt('Outputs.Bar'))
|
||||
|
||||
rsrc.delete()
|
||||
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_nested_stack_update_exceeds_limit(self):
|
||||
resource._register_class('GenericResource',
|
||||
generic_rsrc.GenericResource)
|
||||
urlfetch.get('https://server.test/the.template'
|
||||
).MultipleTimes().AndReturn(self.nested_template)
|
||||
urlfetch.get('https://server.test/new.template'
|
||||
).MultipleTimes().AndReturn(
|
||||
'''
|
||||
HeatTemplateFormatVersion: '2012-12-12'
|
||||
Parameters:
|
||||
KeyName:
|
||||
Type: String
|
||||
Resources:
|
||||
NestedResource:
|
||||
Type: GenericResource
|
||||
Outputs:
|
||||
Bar:
|
||||
Value: foo
|
||||
''')
|
||||
self.m.ReplayAll()
|
||||
|
||||
stack = self.create_stack(self.test_template)
|
||||
|
||||
cfg.CONF.set_override('max_resources_per_stack', 1)
|
||||
|
||||
rsrc = stack['the_nested']
|
||||
|
||||
prop_diff = {'TemplateURL': 'https://server.test/new.template'}
|
||||
props = copy.copy(rsrc.properties.data)
|
||||
props.update(prop_diff)
|
||||
new_res = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(), props)
|
||||
ex = self.assertRaises(exception.RequestLimitExceeded,
|
||||
rsrc.handle_update, new_res, {}, prop_diff)
|
||||
self.assertIn(exception.StackResourceLimitExceeded.msg_fmt,
|
||||
six.text_type(ex))
|
||||
rsrc.delete()
|
||||
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_nested_stack_suspend_resume(self):
|
||||
urlfetch.get('https://server.test/the.template').AndReturn(
|
||||
self.nested_template)
|
||||
self.m.ReplayAll()
|
||||
|
||||
stack = self.create_stack(self.test_template)
|
||||
rsrc = stack['the_nested']
|
||||
|
||||
scheduler.TaskRunner(rsrc.suspend)()
|
||||
self.assertEqual((rsrc.SUSPEND, rsrc.COMPLETE), rsrc.state)
|
||||
|
||||
scheduler.TaskRunner(rsrc.resume)()
|
||||
self.assertEqual((rsrc.RESUME, rsrc.COMPLETE), rsrc.state)
|
||||
|
||||
rsrc.delete()
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_nested_stack_three_deep(self):
|
||||
root_template = '''
|
||||
HeatTemplateFormatVersion: 2012-12-12
|
||||
@@ -575,22 +242,6 @@ Resources:
|
||||
self.assertIn('Recursion depth exceeds', stack.status_reason)
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_nested_stack_delete(self):
|
||||
urlfetch.get('https://server.test/the.template'
|
||||
).MultipleTimes().AndReturn(self.nested_template)
|
||||
self.m.ReplayAll()
|
||||
|
||||
stack = self.create_stack(self.test_template)
|
||||
rsrc = stack['the_nested']
|
||||
scheduler.TaskRunner(rsrc.delete)()
|
||||
self.assertEqual((stack.DELETE, stack.COMPLETE), rsrc.state)
|
||||
|
||||
nested_stack = parser.Stack.load(utils.dummy_context(
|
||||
'test_username', 'aaaa', 'password'), rsrc.resource_id)
|
||||
self.assertEqual((stack.DELETE, stack.COMPLETE), nested_stack.state)
|
||||
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_nested_stack_delete_then_delete_parent_stack(self):
|
||||
urlfetch.get('https://server.test/the.template'
|
||||
).MultipleTimes().AndReturn(self.nested_template)
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
import uuid
|
||||
|
||||
import mock
|
||||
from oslo.config import cfg
|
||||
import six
|
||||
|
||||
from heat.common import exception
|
||||
@@ -567,6 +568,55 @@ class StackResourceTest(common.HeatTestCase):
|
||||
for res in nested.resources.values()]
|
||||
|
||||
|
||||
class StackResourceLimitTest(common.HeatTestCase):
|
||||
scenarios = [
|
||||
('1', dict(root=3, templ=4, nested=0, max=10, error=False)),
|
||||
('2', dict(root=3, templ=8, nested=0, max=10, error=True)),
|
||||
('3', dict(root=3, templ=8, nested=2, max=10, error=False)),
|
||||
('4', dict(root=3, templ=12, nested=2, max=10, error=True))]
|
||||
|
||||
def setUp(self):
|
||||
super(StackResourceLimitTest, self).setUp()
|
||||
resource._register_class('some_magic_type',
|
||||
MyStackResource)
|
||||
ws_resname = "provider_resource"
|
||||
t = templatem.Template(
|
||||
{'HeatTemplateFormatVersion': '2012-12-12',
|
||||
'Resources': {ws_resname: ws_res_snippet}})
|
||||
self.ctx = utils.dummy_context()
|
||||
self.parent_stack = parser.Stack(self.ctx, 'test_stack',
|
||||
t, stack_id=str(uuid.uuid4()),
|
||||
user_creds_id='uc123',
|
||||
stack_user_project_id='aprojectid')
|
||||
resource_defns = t.resource_definitions(self.parent_stack)
|
||||
self.res = MyStackResource('test',
|
||||
resource_defns[ws_resname],
|
||||
self.parent_stack)
|
||||
|
||||
def test_resource_limit(self):
|
||||
# mock nested resources
|
||||
nested = mock.MagicMock()
|
||||
nested.resources = range(self.nested)
|
||||
self.res.nested = mock.MagicMock(return_value=nested)
|
||||
|
||||
# mock root total_resources
|
||||
self.res.stack.root_stack.total_resources = mock.Mock(
|
||||
return_value=self.root)
|
||||
|
||||
# setup the config max
|
||||
cfg.CONF.set_default('max_resources_per_stack', self.max)
|
||||
|
||||
# fake the template
|
||||
templ = mock.MagicMock()
|
||||
templ.__getitem__.return_value = range(self.templ)
|
||||
templ.RESOURCES = 'Resources'
|
||||
if self.error:
|
||||
self.assertRaises(exception.RequestLimitExceeded,
|
||||
self.res._validate_nested_resources, templ)
|
||||
else:
|
||||
self.assertIsNone(self.res._validate_nested_resources(templ))
|
||||
|
||||
|
||||
class StackResourceAttrTest(common.HeatTestCase):
|
||||
def setUp(self):
|
||||
super(StackResourceAttrTest, self).setUp()
|
||||
|
||||
@@ -18,6 +18,7 @@ import keystoneclient.exceptions
|
||||
import keystoneclient.v2_0.client
|
||||
import neutronclient.v2_0.client
|
||||
import novaclient.client
|
||||
import swiftclient
|
||||
|
||||
import logging
|
||||
|
||||
@@ -41,6 +42,7 @@ class ClientManager(object):
|
||||
self.compute_client = self._get_compute_client()
|
||||
self.network_client = self._get_network_client()
|
||||
self.volume_client = self._get_volume_client()
|
||||
self.object_client = self._get_object_client()
|
||||
|
||||
def _get_orchestration_client(self):
|
||||
region = self.conf.region
|
||||
@@ -125,3 +127,16 @@ class ClientManager(object):
|
||||
endpoint_type=endpoint_type,
|
||||
insecure=dscv,
|
||||
http_log_debug=True)
|
||||
|
||||
def _get_object_client(self):
|
||||
dscv = self.conf.disable_ssl_certificate_validation
|
||||
args = {
|
||||
'auth_version': '2.0',
|
||||
'tenant_name': self.conf.tenant_name,
|
||||
'user': self.conf.username,
|
||||
'key': self.conf.password,
|
||||
'authurl': self.conf.auth_url,
|
||||
'os_options': {'endpoint_type': 'publicURL'},
|
||||
'insecure': dscv,
|
||||
}
|
||||
return swiftclient.client.Connection(**args)
|
||||
|
||||
@@ -85,6 +85,7 @@ class HeatIntegrationTest(testscenarios.WithScenarios,
|
||||
self.compute_client = self.manager.compute_client
|
||||
self.network_client = self.manager.network_client
|
||||
self.volume_client = self.manager.volume_client
|
||||
self.object_client = self.manager.object_client
|
||||
self.useFixture(fixtures.FakeLogger(format=_LOG_FORMAT))
|
||||
|
||||
def status_timeout(self, things, thing_id, expected_status,
|
||||
|
||||
213
heat_integrationtests/functional/test_aws_stack.py
Normal file
213
heat_integrationtests/functional/test_aws_stack.py
Normal file
@@ -0,0 +1,213 @@
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import hashlib
|
||||
import json
|
||||
import logging
|
||||
import random
|
||||
import urlparse
|
||||
|
||||
from swiftclient import utils as swiftclient_utils
|
||||
import yaml
|
||||
|
||||
from heat_integrationtests.common import test
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class AwsStackTest(test.HeatIntegrationTest):
|
||||
test_template = '''
|
||||
HeatTemplateFormatVersion: '2012-12-12'
|
||||
Resources:
|
||||
the_nested:
|
||||
Type: AWS::CloudFormation::Stack
|
||||
Properties:
|
||||
TemplateURL: the.yaml
|
||||
Parameters:
|
||||
KeyName: foo
|
||||
Outputs:
|
||||
output_foo:
|
||||
Value: {"Fn::GetAtt": [the_nested, Outputs.Foo]}
|
||||
'''
|
||||
|
||||
nested_template = '''
|
||||
HeatTemplateFormatVersion: '2012-12-12'
|
||||
Parameters:
|
||||
KeyName:
|
||||
Type: String
|
||||
Outputs:
|
||||
Foo:
|
||||
Value: bar
|
||||
'''
|
||||
|
||||
update_template = '''
|
||||
HeatTemplateFormatVersion: '2012-12-12'
|
||||
Parameters:
|
||||
KeyName:
|
||||
Type: String
|
||||
Outputs:
|
||||
Foo:
|
||||
Value: foo
|
||||
'''
|
||||
|
||||
nested_with_res_template = '''
|
||||
HeatTemplateFormatVersion: '2012-12-12'
|
||||
Parameters:
|
||||
KeyName:
|
||||
Type: String
|
||||
Resources:
|
||||
NestedResource:
|
||||
Type: OS::Heat::RandomString
|
||||
Outputs:
|
||||
Foo:
|
||||
Value: {"Fn::GetAtt": [NestedResource, value]}
|
||||
'''
|
||||
|
||||
def setUp(self):
|
||||
super(AwsStackTest, self).setUp()
|
||||
self.client = self.orchestration_client
|
||||
self.object_container_name = AwsStackTest.__name__
|
||||
self.project_id = self.identity_client.auth_ref.project_id
|
||||
self.object_client.put_container(self.object_container_name)
|
||||
self.nested_name = '%s.yaml' % test.rand_name()
|
||||
|
||||
def publish_template(self, name, contents):
|
||||
oc = self.object_client
|
||||
|
||||
# post the object
|
||||
oc.put_object(self.object_container_name, name, contents)
|
||||
# TODO(asalkeld) see if this is causing problems.
|
||||
# self.addCleanup(self.object_client.delete_object,
|
||||
# self.object_container_name, name)
|
||||
|
||||
# make the tempurl
|
||||
key_header = 'x-account-meta-temp-url-key'
|
||||
if key_header not in oc.head_account():
|
||||
swift_key = hashlib.sha224(
|
||||
str(random.getrandbits(256))).hexdigest()[:32]
|
||||
LOG.warn('setting swift key to %s' % swift_key)
|
||||
oc.post_account({key_header: swift_key})
|
||||
key = oc.head_account()[key_header]
|
||||
path = '/v1/AUTH_%s/%s/%s' % (self.project_id,
|
||||
self.object_container_name, name)
|
||||
timeout = self.conf.build_timeout * 10
|
||||
tempurl = swiftclient_utils.generate_temp_url(path, timeout,
|
||||
key, 'GET')
|
||||
sw_url = urlparse.urlparse(oc.url)
|
||||
return '%s://%s%s' % (sw_url.scheme, sw_url.netloc, tempurl)
|
||||
|
||||
def test_nested_stack_create(self):
|
||||
url = self.publish_template(self.nested_name, self.nested_template)
|
||||
self.template = self.test_template.replace('the.yaml', url)
|
||||
stack_identifier = self.stack_create(template=self.template)
|
||||
stack = self.client.stacks.get(stack_identifier)
|
||||
self.assert_resource_is_a_stack(stack_identifier, 'the_nested')
|
||||
self.assertEqual('bar', self._stack_output(stack, 'output_foo'))
|
||||
|
||||
def test_nested_stack_create_with_timeout(self):
|
||||
url = self.publish_template(self.nested_name, self.nested_template)
|
||||
self.template = self.test_template.replace('the.yaml', url)
|
||||
timeout_template = yaml.load(self.template)
|
||||
props = timeout_template['Resources']['the_nested']['Properties']
|
||||
props['TimeoutInMinutes'] = '50'
|
||||
|
||||
stack_identifier = self.stack_create(
|
||||
template=timeout_template)
|
||||
stack = self.client.stacks.get(stack_identifier)
|
||||
self.assert_resource_is_a_stack(stack_identifier, 'the_nested')
|
||||
self.assertEqual('bar', self._stack_output(stack, 'output_foo'))
|
||||
|
||||
def test_nested_stack_adopt_ok(self):
|
||||
url = self.publish_template(self.nested_name,
|
||||
self.nested_with_res_template)
|
||||
self.template = self.test_template.replace('the.yaml', url)
|
||||
adopt_data = {
|
||||
"resources": {
|
||||
"the_nested": {
|
||||
"resource_id": "test-res-id",
|
||||
"resources": {
|
||||
"NestedResource": {
|
||||
"type": "OS::Heat::RandomString",
|
||||
"resource_id": "test-nested-res-id",
|
||||
"resource_data": {"value": "goopie"}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"environment": {"parameters": {}},
|
||||
"template": yaml.load(self.template)
|
||||
}
|
||||
|
||||
stack_identifier = self.stack_adopt(adopt_data=json.dumps(adopt_data))
|
||||
|
||||
self.assert_resource_is_a_stack(stack_identifier, 'the_nested')
|
||||
stack = self.client.stacks.get(stack_identifier)
|
||||
self.assertEqual('goopie', self._stack_output(stack, 'output_foo'))
|
||||
|
||||
def test_nested_stack_adopt_fail(self):
|
||||
url = self.publish_template(self.nested_name,
|
||||
self.nested_with_res_template)
|
||||
self.template = self.test_template.replace('the.yaml', url)
|
||||
adopt_data = {
|
||||
"resources": {
|
||||
"the_nested": {
|
||||
"resource_id": "test-res-id",
|
||||
"resources": {
|
||||
}
|
||||
}
|
||||
},
|
||||
"environment": {"parameters": {}},
|
||||
"template": yaml.load(self.template)
|
||||
}
|
||||
|
||||
stack_identifier = self.stack_adopt(adopt_data=json.dumps(adopt_data),
|
||||
wait_for_status='ADOPT_FAILED')
|
||||
rsrc = self.client.resources.get(stack_identifier, 'the_nested')
|
||||
self.assertEqual('ADOPT_FAILED', rsrc.resource_status)
|
||||
|
||||
def test_nested_stack_update(self):
|
||||
url = self.publish_template(self.nested_name, self.nested_template)
|
||||
self.template = self.test_template.replace('the.yaml', url)
|
||||
stack_identifier = self.stack_create(template=self.template)
|
||||
original_nested_id = self.assert_resource_is_a_stack(
|
||||
stack_identifier, 'the_nested')
|
||||
stack = self.client.stacks.get(stack_identifier)
|
||||
self.assertEqual('bar', self._stack_output(stack, 'output_foo'))
|
||||
|
||||
new_template = yaml.load(self.template)
|
||||
props = new_template['Resources']['the_nested']['Properties']
|
||||
props['TemplateURL'] = self.publish_template(self.nested_name,
|
||||
self.update_template)
|
||||
|
||||
self.update_stack(stack_identifier, new_template)
|
||||
|
||||
# Expect the physical resource name staying the same after update,
|
||||
# so that the nested was actually updated instead of replaced.
|
||||
new_nested_id = self.assert_resource_is_a_stack(
|
||||
stack_identifier, 'the_nested')
|
||||
self.assertEqual(original_nested_id, new_nested_id)
|
||||
updt_stack = self.client.stacks.get(stack_identifier)
|
||||
self.assertEqual('foo', self._stack_output(updt_stack, 'output_foo'))
|
||||
|
||||
def test_nested_stack_suspend_resume(self):
|
||||
url = self.publish_template(self.nested_name, self.nested_template)
|
||||
self.template = self.test_template.replace('the.yaml', url)
|
||||
stack_identifier = self.stack_create(template=self.template)
|
||||
|
||||
self.client.actions.suspend(stack_id=stack_identifier)
|
||||
self._wait_for_resource_status(
|
||||
stack_identifier, 'the_nested', 'SUSPEND_COMPLETE')
|
||||
|
||||
self.client.actions.resume(stack_id=stack_identifier)
|
||||
self._wait_for_resource_status(
|
||||
stack_identifier, 'the_nested', 'RESUME_COMPLETE')
|
||||
Reference in New Issue
Block a user