stack-update -x tolerate no template
Replacement for the approach outlined in https://review.openstack.org/#/c/154692/ This works with the following heat changes to enable full PATCH update functionality, including omitting the template or environment: https://review.openstack.org/#/c/205754/ https://review.openstack.org/#/c/154619/ Closes-Bug: #1224828 Change-Id: I2a82936743badb69f0de5a6ca64f95ae63a35358
This commit is contained in:
committed by
Steve Baker
parent
8eb188457d
commit
8ee2fc1b3d
@@ -28,7 +28,7 @@ from heatclient.openstack.common._i18n import _
|
||||
|
||||
def get_template_contents(template_file=None, template_url=None,
|
||||
template_object=None, object_request=None,
|
||||
files=None):
|
||||
files=None, existing=False):
|
||||
|
||||
# Transform a bare file path to a file:// URL.
|
||||
if template_file:
|
||||
@@ -41,6 +41,8 @@ def get_template_contents(template_file=None, template_url=None,
|
||||
template_url = template_object
|
||||
tpl = object_request and object_request('GET',
|
||||
template_object)
|
||||
elif existing:
|
||||
return {}, None
|
||||
else:
|
||||
raise exc.CommandError(_('Need to specify exactly one of '
|
||||
'%(arg1)s, %(arg2)s or %(arg3)s') %
|
||||
|
||||
@@ -2223,6 +2223,51 @@ class ShellTestUserPass(ShellBase):
|
||||
for r in required:
|
||||
self.assertRegexpMatches(update_text, r)
|
||||
|
||||
def test_stack_update_with_existing_template(self):
|
||||
self.register_keystone_auth_fixture()
|
||||
resp = fakes.FakeHTTPResponse(
|
||||
202,
|
||||
'Accepted',
|
||||
{},
|
||||
'The request is accepted for processing.')
|
||||
expected_data = {
|
||||
'files': {},
|
||||
'environment': {},
|
||||
'template': None,
|
||||
'parameters': {}}
|
||||
if self.client is http.HTTPClient:
|
||||
headers = {'X-Auth-Key': 'password', 'X-Auth-User': 'username'}
|
||||
else:
|
||||
headers = {}
|
||||
if self.client == http.SessionClient:
|
||||
self.client.request(
|
||||
'/stacks/teststack2/2', 'PATCH',
|
||||
data=expected_data,
|
||||
headers=headers
|
||||
).AndReturn(resp)
|
||||
else:
|
||||
self.client.json_request(
|
||||
'PATCH', '/stacks/teststack2/2',
|
||||
data=expected_data,
|
||||
headers=headers
|
||||
).AndReturn((resp, None))
|
||||
fakes.script_heat_list(client=self.client)
|
||||
|
||||
self.m.ReplayAll()
|
||||
|
||||
update_text = self.shell(
|
||||
'stack-update teststack2/2 '
|
||||
'--existing')
|
||||
|
||||
required = [
|
||||
'stack_name',
|
||||
'id',
|
||||
'teststack2',
|
||||
'1'
|
||||
]
|
||||
for r in required:
|
||||
self.assertRegexpMatches(update_text, r)
|
||||
|
||||
def test_stack_update_with_tags(self):
|
||||
self.register_keystone_auth_fixture()
|
||||
template_file = os.path.join(TEST_VAR_DIR, 'minimal.template')
|
||||
|
||||
@@ -436,6 +436,12 @@ class TestGetTemplateContents(testtools.TestCase):
|
||||
'--template-url or --template-object'),
|
||||
str(ex))
|
||||
|
||||
def test_get_template_contents_file_none_existing(self):
|
||||
files, tmpl_parsed = template_utils.get_template_contents(
|
||||
existing=True)
|
||||
self.assertEqual(None, tmpl_parsed)
|
||||
self.assertEqual({}, files)
|
||||
|
||||
def test_get_template_contents_parse_error(self):
|
||||
with tempfile.NamedTemporaryFile() as tmpl_file:
|
||||
|
||||
|
||||
@@ -442,11 +442,14 @@ def do_stack_show(hc, args):
|
||||
'would be the content of the file'),
|
||||
action='append')
|
||||
@utils.arg('-x', '--existing', default=False, action="store_true",
|
||||
help=_('Re-use the set of parameters of the current stack. '
|
||||
help=_('Re-use the template, parameters and environment of the '
|
||||
'current stack. If the template argument is omitted then the '
|
||||
'existing template is used. If no %(env_arg)s is specified then '
|
||||
'the existing environment is used. '
|
||||
'Parameters specified in %(arg)s will patch over the existing '
|
||||
'values in the current stack. Parameters omitted will keep '
|
||||
'the existing values.')
|
||||
% {'arg': '--parameters'})
|
||||
% {'arg': '--parameters', 'env_arg': '--environment-file'})
|
||||
@utils.arg('-c', '--clear-parameter', metavar='<PARAMETER>',
|
||||
help=_('Remove the parameters from the set of parameters of '
|
||||
'current stack for the %(cmd)s. The default value in the '
|
||||
@@ -464,7 +467,8 @@ def do_stack_update(hc, args):
|
||||
args.template_file,
|
||||
args.template_url,
|
||||
args.template_object,
|
||||
_authenticated_fetcher(hc))
|
||||
_authenticated_fetcher(hc),
|
||||
existing=args.existing)
|
||||
|
||||
env_files, env = template_utils.process_multiple_environments_and_files(
|
||||
env_paths=args.environment_file)
|
||||
|
||||
Reference in New Issue
Block a user