Use stack name or id for backwards compatibility

Heat used to accept either stack name or id

Scale nodes in the documentation and in the argparse usage
states that stacks can be identified by name or id but mistral
only accepts stack names.

This makes the client accept names or ids and pass names for the
mistral workflow

Change-Id: If7527e36c1e5d2214dc155392a2e3750b38ec365
Closes-Bug: #1640933
(cherry picked from commit a3012ca424)
This commit is contained in:
Adriano Petrich 2016-11-16 10:56:36 +00:00 committed by Julie Pichon
parent 0955bc5731
commit 6097c132c7
2 changed files with 36 additions and 2 deletions

View File

@ -44,6 +44,8 @@ class TestDeleteNode(fakes.TestDeleteNode):
self.app.client_manager.tripleoclient = self.tripleoclient self.app.client_manager.tripleoclient = self.tripleoclient
self.workflow = self.app.client_manager.workflow_engine self.workflow = self.app.client_manager.workflow_engine
self.stack_name = self.app.client_manager.orchestration.stacks.get
self.stack_name.return_value = mock.Mock(stack_name="overcloud")
# Mock UUID4 generation for every test # Mock UUID4 generation for every test
uuid4_patcher = mock.patch('uuid.uuid4', return_value="UUID4") uuid4_patcher = mock.patch('uuid.uuid4', return_value="UUID4")
@ -65,6 +67,8 @@ class TestDeleteNode(fakes.TestDeleteNode):
"status": "SUCCESS" "status": "SUCCESS"
} }
self.stack_name.return_value = mock.Mock(stack_name="overcast")
self.cmd.take_action(parsed_args) self.cmd.take_action(parsed_args)
# Verify # Verify
@ -76,6 +80,28 @@ class TestDeleteNode(fakes.TestDeleteNode):
'nodes': ['instance1', 'instance2'] 'nodes': ['instance1', 'instance2']
}) })
def test_node_wrong_stack(self):
argslist = ['instance1', '--templates',
'--stack', 'overcast']
verifylist = [
('stack', 'overcast'),
('nodes', ['instance1', ])
]
parsed_args = self.check_parser(self.cmd, argslist, verifylist)
self.websocket.wait_for_message.return_value = {
"status": "SUCCESS"
}
self.stack_name.return_value = None
self.assertRaises(exceptions.InvalidConfiguration,
self.cmd.take_action,
parsed_args)
# Verify
self.workflow.executions.create.assert_not_called()
def test_node_delete_without_stack(self): def test_node_delete_without_stack(self):
arglist = ['instance1', ] arglist = ['instance1', ]

View File

@ -22,6 +22,7 @@ from osc_lib.i18n import _
from osc_lib import utils from osc_lib import utils
from tripleoclient import constants from tripleoclient import constants
from tripleoclient.exceptions import InvalidConfiguration
from tripleoclient import utils as oooutils from tripleoclient import utils as oooutils
from tripleoclient.workflows import baremetal from tripleoclient.workflows import baremetal
from tripleoclient.workflows import scale from tripleoclient.workflows import scale
@ -65,12 +66,19 @@ class DeleteNode(command.Command):
def take_action(self, parsed_args): def take_action(self, parsed_args):
self.log.debug("take_action(%s)" % parsed_args) self.log.debug("take_action(%s)" % parsed_args)
clients = self.app.client_manager clients = self.app.client_manager
orchestration_client = clients.orchestration
stack = oooutils.get_stack(orchestration_client, parsed_args.stack)
if not stack:
raise InvalidConfiguration("stack {} not found".format(
parsed_args.stack))
nodes = '\n'.join('- %s' % node for node in parsed_args.nodes) nodes = '\n'.join('- %s' % node for node in parsed_args.nodes)
print("Deleting the following nodes from stack {stack}:\n{nodes}" print("Deleting the following nodes from stack {stack}:\n{nodes}"
.format(stack=parsed_args.stack, nodes=nodes)) .format(stack=stack.stack_name, nodes=nodes))
scale.scale_down(clients, parsed_args.stack, parsed_args.nodes) scale.scale_down(clients, stack.stack_name, parsed_args.nodes)
class ProvideNode(command.Command): class ProvideNode(command.Command):