Merge "Add force parameter for cluster and node deletion"

This commit is contained in:
Zuul 2017-09-30 03:30:31 +00:00 committed by Gerrit Code Review
commit 95df530538
7 changed files with 88 additions and 29 deletions

View File

@ -23,7 +23,7 @@ LOG = logging.getLogger(__name__)
DEFAULT_CLUSTERING_API_VERSION = '1'
API_VERSION_OPTION = 'os_clustering_api_version'
API_NAME = 'clustering'
CURRENT_API_VERSION = '1.7'
CURRENT_API_VERSION = '1.8'
def make_client(instance):

View File

@ -343,8 +343,9 @@ class TestClusterDelete(TestCluster):
parsed_args = self.check_parser(self.cmd, arglist, [])
self.cmd.take_action(parsed_args)
self.mock_client.delete_cluster.assert_has_calls(
[mock.call('cluster1', False), mock.call('cluster2', False),
mock.call('cluster3', False)]
[mock.call('cluster1', False, False),
mock.call('cluster2', False, False),
mock.call('cluster3', False, False)]
)
def test_cluster_delete_force(self):
@ -352,8 +353,19 @@ class TestClusterDelete(TestCluster):
parsed_args = self.check_parser(self.cmd, arglist, [])
self.cmd.take_action(parsed_args)
self.mock_client.delete_cluster.assert_has_calls(
[mock.call('cluster1', False), mock.call('cluster2', False),
mock.call('cluster3', False)]
[mock.call('cluster1', False, False),
mock.call('cluster2', False, False),
mock.call('cluster3', False, False)]
)
def test_cluster_delete_force_delete(self):
arglist = ['cluster1', 'cluster2', 'cluster3', '--force-delete']
parsed_args = self.check_parser(self.cmd, arglist, [])
self.cmd.take_action(parsed_args)
self.mock_client.delete_cluster.assert_has_calls(
[mock.call('cluster1', True, False),
mock.call('cluster2', True, False),
mock.call('cluster3', True, False)]
)
def test_cluster_delete_not_found(self):
@ -364,7 +376,7 @@ class TestClusterDelete(TestCluster):
self.cmd.take_action(parsed_args)
self.mock_client.delete_cluster.assert_has_calls(
[mock.call('my_cluster', False)]
[mock.call('my_cluster', False, False)]
)
def test_cluster_delete_one_found_one_not_found(self):
@ -377,7 +389,8 @@ class TestClusterDelete(TestCluster):
self.cmd.take_action(parsed_args)
self.mock_client.delete_cluster.assert_has_calls(
[mock.call('cluster1', False), mock.call('cluster2', False)]
[mock.call('cluster1', False, False),
mock.call('cluster2', False, False)]
)
@mock.patch('sys.stdin', spec=six.StringIO)
@ -390,8 +403,8 @@ class TestClusterDelete(TestCluster):
self.cmd.take_action(parsed_args)
mock_stdin.readline.assert_called_with()
self.mock_client.delete_cluster.assert_called_with('my_cluster',
False)
self.mock_client.delete_cluster.assert_called_with(
'my_cluster', False, False)
@mock.patch('sys.stdin', spec=six.StringIO)
def test_cluster_delete_prompt_no(self, mock_stdin):

View File

@ -339,8 +339,9 @@ class TestNodeDelete(TestNode):
parsed_args = self.check_parser(self.cmd, arglist, [])
self.cmd.take_action(parsed_args)
self.mock_client.delete_node.assert_has_calls(
[mock.call('node1', False), mock.call('node2', False),
mock.call('node3', False)]
[mock.call('node1', False, False),
mock.call('node2', False, False),
mock.call('node3', False, False)]
)
def test_node_delete_force(self):
@ -348,8 +349,19 @@ class TestNodeDelete(TestNode):
parsed_args = self.check_parser(self.cmd, arglist, [])
self.cmd.take_action(parsed_args)
self.mock_client.delete_node.assert_has_calls(
[mock.call('node1', False), mock.call('node2', False),
mock.call('node3', False)]
[mock.call('node1', False, False),
mock.call('node2', False, False),
mock.call('node3', False, False)]
)
def test_node_delete_force_delete(self):
arglist = ['node1', 'node2', 'node3', '--force-delete']
parsed_args = self.check_parser(self.cmd, arglist, [])
self.cmd.take_action(parsed_args)
self.mock_client.delete_node.assert_has_calls(
[mock.call('node1', True, False),
mock.call('node2', True, False),
mock.call('node3', True, False)]
)
def test_node_delete_not_found(self):
@ -360,7 +372,7 @@ class TestNodeDelete(TestNode):
self.cmd.take_action(parsed_args)
self.mock_client.delete_node.assert_has_calls(
[mock.call('my_node', False)]
[mock.call('my_node', False, False)]
)
def test_node_delete_one_found_one_not_found(self):
@ -373,7 +385,8 @@ class TestNodeDelete(TestNode):
self.cmd.take_action(parsed_args)
self.mock_client.delete_node.assert_has_calls(
[mock.call('node1', False), mock.call('node2', False)]
[mock.call('node1', False, False),
mock.call('node2', False, False)]
)
@mock.patch('sys.stdin', spec=six.StringIO)
@ -386,8 +399,8 @@ class TestNodeDelete(TestNode):
self.cmd.take_action(parsed_args)
mock_stdin.readline.assert_called_with()
self.mock_client.delete_node.assert_called_with('my_node',
False)
self.mock_client.delete_node.assert_called_with(
'my_node', False, False)
@mock.patch('sys.stdin', spec=six.StringIO)
def test_node_delete_prompt_no(self, mock_stdin):

View File

@ -867,11 +867,19 @@ class ShellTest(testtools.TestCase):
def test_do_cluster_delete(self):
service = mock.Mock()
args = {'id': ['CID']}
args = {'id': ['CID'], 'force_delete': False}
args = self._make_args(args)
service.delete_cluster = mock.Mock()
sh.do_cluster_delete(service, args)
service.delete_cluster.assert_called_once_with('CID', False)
service.delete_cluster.assert_called_once_with('CID', False, False)
def test_do_cluster_delete_force(self):
service = mock.Mock()
args = {'id': ['CID'], 'force_delete': True}
args = self._make_args(args)
service.delete_cluster = mock.Mock()
sh.do_cluster_delete(service, args)
service.delete_cluster.assert_called_once_with('CID', True, False)
@mock.patch('subprocess.Popen')
def test__run_script(self, mock_proc):
@ -1702,12 +1710,21 @@ class ShellTest(testtools.TestCase):
def test_do_node_delete(self):
service = mock.Mock()
args = self._make_args({'id': ['node1']})
args = self._make_args({'id': ['node1'], 'force_delete': False})
service.delete_node = mock.Mock()
sh.do_node_delete(service, args)
service.delete_node.assert_called_once_with('node1', False)
service.delete_node.assert_called_once_with('node1', False, False)
def test_do_node_delete_force(self):
service = mock.Mock()
args = self._make_args({'id': ['node1'], 'force_delete': True})
service.delete_node = mock.Mock()
sh.do_node_delete(service, args)
service.delete_node.assert_called_once_with('node1', True, False)
def test_do_node_check(self):
service = mock.Mock()

View File

@ -322,12 +322,17 @@ class DeleteCluster(command.Command):
'cluster',
metavar='<cluster>',
nargs='+',
help=_('Name or ID of cluster(s) to delete')
help=_('Name or ID of cluster(s) to delete.')
)
parser.add_argument(
'--force-delete',
action='store_true',
help=_('Force to delete cluster(s).')
)
parser.add_argument(
'--force',
action='store_true',
help=_('Skip yes/no prompt (assume yes)')
help=_('Skip yes/no prompt (assume yes).')
)
return parser
@ -353,7 +358,8 @@ class DeleteCluster(command.Command):
result = {}
for cid in parsed_args.cluster:
try:
cluster = senlin_client.delete_cluster(cid, False)
cluster = senlin_client.delete_cluster(
cid, parsed_args.force_delete, False)
result[cid] = ('OK', cluster.location.split('/')[-1])
except Exception as ex:
result[cid] = ('ERROR', six.text_type(ex))

View File

@ -293,12 +293,17 @@ class DeleteNode(command.Command):
'node',
metavar='<node>',
nargs='+',
help=_('Name or ID of node(s) to delete')
help=_('Name or ID of node(s) to delete.')
)
parser.add_argument(
'--force-delete',
action='store_true',
help=_('Force to delete node(s).')
)
parser.add_argument(
'--force',
action='store_true',
help=_('Skip yes/no prompt (assume yes)')
help=_('Skip yes/no prompt (assume yes).')
)
return parser
@ -324,7 +329,8 @@ class DeleteNode(command.Command):
result = {}
for nid in parsed_args.node:
try:
node = senlin_client.delete_node(nid, False)
node = senlin_client.delete_node(
nid, parsed_args.force_delete, False)
result[nid] = ('OK', node.location.split('/')[-1])
except Exception as ex:
result[nid] = ('ERROR', six.text_type(ex))

View File

@ -653,6 +653,8 @@ def do_cluster_collect(service, args):
@utils.arg('id', metavar='<CLUSTER>', nargs='+',
help=_('Name or ID of cluster(s) to delete.'))
@utils.arg('-f', '--force-delete', default=False, action="store_true",
help=_('Force to delete cluster(s).'))
def do_cluster_delete(service, args):
"""Delete the cluster(s)."""
show_deprecated('senlin cluster-delete', 'openstack cluster delete')
@ -660,7 +662,7 @@ def do_cluster_delete(service, args):
result = {}
for cid in args.id:
try:
cluster = service.delete_cluster(cid, False)
cluster = service.delete_cluster(cid, args.force_delete, False)
result[cid] = ('OK', cluster.location.split('/')[-1])
except Exception as ex:
result[cid] = ('ERROR', six.text_type(ex))
@ -1428,6 +1430,8 @@ def do_node_show(service, args):
@utils.arg('id', metavar='<NODE>', nargs='+',
help=_('Name or ID of node(s) to delete.'))
@utils.arg('-f', '--force-delete', default=False, action="store_true",
help=_('Force to delete the node(s).'))
def do_node_delete(service, args):
"""Delete the node(s)."""
show_deprecated('senlin node-delete', 'openstack cluster node delete')
@ -1435,7 +1439,7 @@ def do_node_delete(service, args):
result = {}
for nid in args.id:
try:
node = service.delete_node(nid, False)
node = service.delete_node(nid, args.force_delete, False)
result[nid] = ('OK', node.location.split('/')[-1])
except Exception as ex:
result[nid] = ('ERROR', six.text_type(ex))