Merge "compute: Fix bug with start/stop server"

This commit is contained in:
Zuul 2023-05-17 23:20:17 +00:00 committed by Gerrit Code Review
commit d0a17d48a9
3 changed files with 50 additions and 10 deletions
openstackclient
compute/v2
tests
functional/compute/v2
unit/compute/v2

@ -4731,10 +4731,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:
@ -4771,10 +4771,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:

@ -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.

@ -8634,10 +8634,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,
)
@ -8669,10 +8669,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,
)