From 0a63f8603e37542a9758db4ed2db73c781b48e4f Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Wed, 17 May 2023 11:58:39 +0100 Subject: [PATCH] compute: Fix bug with start/stop server A mistake was introduced during the conversion from novaclient to SDK in change I5ebfa6b2468d5f20b99ea0eab1aea9377be09b8c. Fix the issue and add functional tests to prevent it being reintroduced. Change-Id: I6b314eab31bcf452e88b8b6a239ac2e296497cb9 Signed-off-by: Stephen Finucane Story: 2010750 Task: 48004 --- openstackclient/compute/v2/server.py | 8 ++-- .../functional/compute/v2/test_server.py | 44 ++++++++++++++++++- .../tests/unit/compute/v2/test_server.py | 8 ++-- 3 files changed, 50 insertions(+), 10 deletions(-) diff --git a/openstackclient/compute/v2/server.py b/openstackclient/compute/v2/server.py index cde4ab058b..644fee5186 100644 --- a/openstackclient/compute/v2/server.py +++ b/openstackclient/compute/v2/server.py @@ -4721,10 +4721,10 @@ class StartServer(command.Command): for server in parsed_args.server: try: server_id = compute_client.find_server( - name=server, + server, + ignore_missing=False, details=False, all_projects=parsed_args.all_projects, - ignore_missing=False, ).id except sdk_exceptions.HttpException as exc: if exc.status_code == 403: @@ -4761,10 +4761,10 @@ class StopServer(command.Command): for server in parsed_args.server: try: server_id = compute_client.find_server( - name=server, + server, + ignore_missing=False, details=False, all_projects=parsed_args.all_projects, - ignore_missing=False, ).id except sdk_exceptions.HttpException as exc: if exc.status_code == 403: diff --git a/openstackclient/tests/functional/compute/v2/test_server.py b/openstackclient/tests/functional/compute/v2/test_server.py index 7ce1ddcbca..d04fe31d65 100644 --- a/openstackclient/tests/functional/compute/v2/test_server.py +++ b/openstackclient/tests/functional/compute/v2/test_server.py @@ -27,11 +27,11 @@ class ServerTests(common.ComputeTestCase): @classmethod def setUpClass(cls): - super(ServerTests, cls).setUpClass() + super().setUpClass() cls.haz_network = cls.is_service_enabled('network') def test_server_list(self): - """Test server list, set""" + """Test server list""" cmd_output = self.server_create() name1 = cmd_output['name'] cmd_output = self.server_create() @@ -1447,6 +1447,46 @@ class ServerTests(common.ComputeTestCase): raw_output = self.openstack('server volume list ' + server_name) self.assertEqual('\n', raw_output) + def test_server_stop_start(self): + """Test server stop, start""" + server_name = uuid.uuid4().hex + cmd_output = self.openstack( + 'server create ' + + '--network private ' + + '--flavor ' + + self.flavor_name + + ' ' + + '--image ' + + self.image_name + + ' ' + + '--wait ' + + server_name, + parse_output=True, + ) + + self.assertIsNotNone(cmd_output['id']) + self.assertEqual(server_name, cmd_output['name']) + self.addCleanup(self.openstack, 'server delete --wait ' + server_name) + server_id = cmd_output['id'] + + cmd_output = self.openstack( + 'server stop ' + server_name, + ) + self.assertEqual("", cmd_output) + + # This is our test that the request succeeded. If it doesn't transition + # to SHUTOFF then it didn't work. + self.wait_for_status(server_id, "SHUTOFF") + + cmd_output = self.openstack( + 'server start ' + server_name, + ) + self.assertEqual("", cmd_output) + + # As above, this is our test that the request succeeded. If it doesn't + # transition to ACTIVE then it didn't work. + self.wait_for_status(server_id, "ACTIVE") + def test_server_migration_list(self): # Verify that the command does not raise an exception when we list # migrations, including when we specify a query. diff --git a/openstackclient/tests/unit/compute/v2/test_server.py b/openstackclient/tests/unit/compute/v2/test_server.py index 235e24c665..4971629554 100644 --- a/openstackclient/tests/unit/compute/v2/test_server.py +++ b/openstackclient/tests/unit/compute/v2/test_server.py @@ -8577,10 +8577,10 @@ class TestServerStart(TestServer): self.cmd.take_action(parsed_args) self.sdk_client.find_server.assert_called_once_with( - name=servers[0].id, + servers[0].id, + ignore_missing=False, details=False, all_projects=True, - ignore_missing=False, ) @@ -8612,10 +8612,10 @@ class TestServerStop(TestServer): self.cmd.take_action(parsed_args) self.sdk_client.find_server.assert_called_once_with( - name=servers[0].id, + servers[0].id, + ignore_missing=False, details=False, all_projects=True, - ignore_missing=False, )