diff --git a/openstackclient/compute/v2/server.py b/openstackclient/compute/v2/server.py index fa27f68c88..aa4f237208 100644 --- a/openstackclient/compute/v2/server.py +++ b/openstackclient/compute/v2/server.py @@ -1317,6 +1317,11 @@ class DeleteServer(command.Command): nargs="+", help=_('Server(s) to delete (name or ID)'), ) + parser.add_argument( + '--force', + action='store_true', + help=_('Force delete server(s)'), + ) parser.add_argument( '--wait', action='store_true', @@ -1335,7 +1340,12 @@ class DeleteServer(command.Command): for server in parsed_args.server: server_obj = utils.find_resource( compute_client.servers, server) - compute_client.servers.delete(server_obj.id) + + if parsed_args.force: + compute_client.servers.force_delete(server_obj.id) + else: + compute_client.servers.delete(server_obj.id) + if parsed_args.wait: if not utils.wait_for_delete(compute_client.servers, server_obj.id, diff --git a/openstackclient/tests/unit/compute/v2/test_server.py b/openstackclient/tests/unit/compute/v2/test_server.py index 0f33dd7047..bde0699b06 100644 --- a/openstackclient/tests/unit/compute/v2/test_server.py +++ b/openstackclient/tests/unit/compute/v2/test_server.py @@ -2850,6 +2850,7 @@ class TestServerDelete(TestServer): super(TestServerDelete, self).setUp() self.servers_mock.delete.return_value = None + self.servers_mock.force_delete.return_value = None # Get the command object to test self.cmd = server.DeleteServer(self.app, None) @@ -2868,6 +2869,26 @@ class TestServerDelete(TestServer): result = self.cmd.take_action(parsed_args) self.servers_mock.delete.assert_called_with(servers[0].id) + self.servers_mock.force_delete.assert_not_called() + self.assertIsNone(result) + + def test_server_delete_with_force(self): + servers = self.setup_servers_mock(count=1) + + arglist = [ + servers[0].id, + '--force', + ] + verifylist = [ + ('server', [servers[0].id]), + ('force', True), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + result = self.cmd.take_action(parsed_args) + + self.servers_mock.force_delete.assert_called_with(servers[0].id) + self.servers_mock.delete.assert_not_called() self.assertIsNone(result) def test_server_delete_multi_servers(self): diff --git a/releasenotes/notes/add-missing-server-delete-opts-071c3e054e3ce674.yaml b/releasenotes/notes/add-missing-server-delete-opts-071c3e054e3ce674.yaml new file mode 100644 index 0000000000..2c1fc46ed2 --- /dev/null +++ b/releasenotes/notes/add-missing-server-delete-opts-071c3e054e3ce674.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + Add ``--force`` option to ``server delete`` command, allowing users to + force delete a server. This is admin-only by default.