Adding stack-adopt support to python-heatclient
Closes-Bug: #1262267 Change-Id: I7c337b90ad58e17f0c24fc4664fc37f642296566
This commit is contained in:
parent
448d303790
commit
4cc5dc95cb
|
@ -739,6 +739,50 @@ class ShellTestUserPass(ShellBase):
|
|||
for r in required:
|
||||
self.assertRegexpMatches(create_text, r)
|
||||
|
||||
def test_stack_adopt(self):
|
||||
self._script_keystone_client()
|
||||
resp = fakes.FakeHTTPResponse(
|
||||
201,
|
||||
'Created',
|
||||
{'location': 'http://no.where/v1/tenant_id/stacks/teststack/1'},
|
||||
None)
|
||||
http.HTTPClient.json_request(
|
||||
'POST', '/stacks', data=mox.IgnoreArg(),
|
||||
headers={'X-Auth-Key': 'password', 'X-Auth-User': 'username'}
|
||||
).AndReturn((resp, None))
|
||||
fakes.script_heat_list()
|
||||
|
||||
self.m.ReplayAll()
|
||||
|
||||
template_file = os.path.join(TEST_VAR_DIR, 'minimal.template')
|
||||
adopt_data_file = os.path.join(TEST_VAR_DIR, 'adopt_stack_data.json')
|
||||
adopt_text = self.shell(
|
||||
'stack-adopt teststack '
|
||||
'--template-file=%s '
|
||||
'--adopt-file=%s '
|
||||
'--parameters="InstanceType=m1.large;DBUsername=wp;'
|
||||
'DBPassword=verybadpassword;KeyName=heat_key;'
|
||||
'LinuxDistribution=F17"' % (template_file, adopt_data_file))
|
||||
|
||||
required = [
|
||||
'stack_name',
|
||||
'id',
|
||||
'teststack',
|
||||
'1'
|
||||
]
|
||||
|
||||
for r in required:
|
||||
self.assertRegexpMatches(adopt_text, r)
|
||||
|
||||
def test_stack_adopt_without_data(self):
|
||||
failed_msg = 'Need to specify --adopt-file'
|
||||
self._script_keystone_client()
|
||||
self.m.ReplayAll()
|
||||
template_file = os.path.join(TEST_VAR_DIR, 'minimal.template')
|
||||
self.shell_error(
|
||||
'stack-adopt teststack '
|
||||
'--template-file=%s ' % template_file, failed_msg)
|
||||
|
||||
def test_stack_update(self):
|
||||
self._script_keystone_client()
|
||||
resp = fakes.FakeHTTPResponse(
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"action": "CREATE",
|
||||
"status": "COMPLETE",
|
||||
"name": "teststack",
|
||||
"resources": {}
|
||||
}
|
|
@ -18,6 +18,7 @@ import yaml
|
|||
from heatclient.common import template_utils
|
||||
from heatclient.common import utils
|
||||
from heatclient.openstack.common import jsonutils
|
||||
from heatclient.openstack.common.py3kcompat import urlutils
|
||||
|
||||
import heatclient.exc as exc
|
||||
|
||||
|
@ -91,6 +92,59 @@ def do_stack_create(hc, args):
|
|||
do_stack_list(hc)
|
||||
|
||||
|
||||
@utils.arg('-f', '--template-file', metavar='<FILE>',
|
||||
help='Path to the template.')
|
||||
@utils.arg('-e', '--environment-file', metavar='<FILE or URL>',
|
||||
help='Path to the environment.')
|
||||
@utils.arg('-u', '--template-url', metavar='<URL>',
|
||||
help='URL of template.')
|
||||
@utils.arg('-o', '--template-object', metavar='<URL>',
|
||||
help='URL to retrieve template object (e.g from swift)')
|
||||
@utils.arg('-c', '--create-timeout', metavar='<TIMEOUT>',
|
||||
default=60, type=int,
|
||||
help='Stack creation timeout in minutes. Default: 60')
|
||||
@utils.arg('-a', '--adopt-file', metavar='<FILE or URL>',
|
||||
help='Path to adopt stack data file.')
|
||||
@utils.arg('-r', '--enable-rollback', default=False, action="store_true",
|
||||
help='Enable rollback on create/update failure')
|
||||
@utils.arg('-P', '--parameters', metavar='<KEY1=VALUE1;KEY2=VALUE2...>',
|
||||
help='Parameter values used to create the stack. '
|
||||
'This can be specified multiple times, or once with parameters '
|
||||
'separated by semicolon.',
|
||||
action='append')
|
||||
@utils.arg('name', metavar='<STACK_NAME>',
|
||||
help='Name of the stack to adopt.')
|
||||
def do_stack_adopt(hc, args):
|
||||
'''Adopt a stack.'''
|
||||
tpl_files, template = template_utils.get_template_contents(
|
||||
args.template_file,
|
||||
args.template_url,
|
||||
args.template_object,
|
||||
hc.http_client.raw_request)
|
||||
env_files, env = template_utils.process_environment_and_files(
|
||||
env_path=args.environment_file)
|
||||
|
||||
if not args.adopt_file:
|
||||
raise exc.CommandError('Need to specify --adopt-file')
|
||||
|
||||
adopt_url = template_utils.normalise_file_path_to_url(args.adopt_file)
|
||||
adopt_data = urlutils.urlopen(adopt_url).read()
|
||||
|
||||
fields = {
|
||||
'stack_name': args.name,
|
||||
'timeout_mins': args.create_timeout,
|
||||
'disable_rollback': not(args.enable_rollback),
|
||||
'adopt_stack_data': adopt_data,
|
||||
'parameters': utils.format_parameters(args.parameters),
|
||||
'template': template,
|
||||
'files': dict(tpl_files.items() + env_files.items()),
|
||||
'environment': env
|
||||
}
|
||||
|
||||
hc.stacks.create(**fields)
|
||||
do_stack_list(hc)
|
||||
|
||||
|
||||
@utils.arg('id', metavar='<NAME or ID>', nargs='+',
|
||||
help='Name or ID of stack(s) to delete.')
|
||||
def do_delete(hc, args):
|
||||
|
|
Loading…
Reference in New Issue