Browse Source

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
tags/5.6.0
Adriano Petrich 2 years ago
parent
commit
a3012ca424

+ 26
- 0
tripleoclient/tests/v1/overcloud_node/test_overcloud_node.py View File

@@ -44,6 +44,8 @@ class TestDeleteNode(fakes.TestDeleteNode):
44 44
         self.app.client_manager.tripleoclient = self.tripleoclient
45 45
 
46 46
         self.workflow = self.app.client_manager.workflow_engine
47
+        self.stack_name = self.app.client_manager.orchestration.stacks.get
48
+        self.stack_name.return_value = mock.Mock(stack_name="overcloud")
47 49
 
48 50
         # Mock UUID4 generation for every test
49 51
         uuid4_patcher = mock.patch('uuid.uuid4', return_value="UUID4")
@@ -65,6 +67,8 @@ class TestDeleteNode(fakes.TestDeleteNode):
65 67
             "status": "SUCCESS"
66 68
         }
67 69
 
70
+        self.stack_name.return_value = mock.Mock(stack_name="overcast")
71
+
68 72
         self.cmd.take_action(parsed_args)
69 73
 
70 74
         # Verify
@@ -76,6 +80,28 @@ class TestDeleteNode(fakes.TestDeleteNode):
76 80
                 'nodes': ['instance1', 'instance2']
77 81
             })
78 82
 
83
+    def test_node_wrong_stack(self):
84
+        argslist = ['instance1', '--templates',
85
+                    '--stack', 'overcast']
86
+        verifylist = [
87
+            ('stack', 'overcast'),
88
+            ('nodes', ['instance1', ])
89
+        ]
90
+        parsed_args = self.check_parser(self.cmd, argslist, verifylist)
91
+
92
+        self.websocket.wait_for_message.return_value = {
93
+            "status": "SUCCESS"
94
+        }
95
+
96
+        self.stack_name.return_value = None
97
+
98
+        self.assertRaises(exceptions.InvalidConfiguration,
99
+                          self.cmd.take_action,
100
+                          parsed_args)
101
+
102
+        # Verify
103
+        self.workflow.executions.create.assert_not_called()
104
+
79 105
     def test_node_delete_without_stack(self):
80 106
 
81 107
         arglist = ['instance1', ]

+ 10
- 2
tripleoclient/v1/overcloud_node.py View File

@@ -22,6 +22,7 @@ from osc_lib.i18n import _
22 22
 from osc_lib import utils
23 23
 
24 24
 from tripleoclient import constants
25
+from tripleoclient.exceptions import InvalidConfiguration
25 26
 from tripleoclient import utils as oooutils
26 27
 from tripleoclient.workflows import baremetal
27 28
 from tripleoclient.workflows import scale
@@ -65,12 +66,19 @@ class DeleteNode(command.Command):
65 66
     def take_action(self, parsed_args):
66 67
         self.log.debug("take_action(%s)" % parsed_args)
67 68
         clients = self.app.client_manager
69
+        orchestration_client = clients.orchestration
70
+
71
+        stack = oooutils.get_stack(orchestration_client, parsed_args.stack)
72
+
73
+        if not stack:
74
+            raise InvalidConfiguration("stack {} not found".format(
75
+                parsed_args.stack))
68 76
 
69 77
         nodes = '\n'.join('- %s' % node for node in parsed_args.nodes)
70 78
         print("Deleting the following nodes from stack {stack}:\n{nodes}"
71
-              .format(stack=parsed_args.stack, nodes=nodes))
79
+              .format(stack=stack.stack_name, nodes=nodes))
72 80
 
73
-        scale.scale_down(clients, parsed_args.stack, parsed_args.nodes)
81
+        scale.scale_down(clients, stack.stack_name, parsed_args.nodes)
74 82
 
75 83
 
76 84
 class ProvideNode(command.Command):

Loading…
Cancel
Save