Switch server pause and server unpause to SDK

Switch the server pause and server unpause commands from novaclient to
SDK. Use the SDK versions of test fakes to support fake Server
resources.

Change-Id: Id626f06f3d7edd44b306b7fc7b9b00d04af09621
This commit is contained in:
Thrivikram Mudunuri 2021-11-13 02:37:44 -05:00
parent fae293dd52
commit b515fe61b2
No known key found for this signature in database
GPG Key ID: 62A420BADBFB4875
3 changed files with 36 additions and 15 deletions

View File

@ -3130,12 +3130,13 @@ class PauseServer(command.Command):
return parser return parser
def take_action(self, parsed_args): def take_action(self, parsed_args):
compute_client = self.app.client_manager.compute compute_client = self.app.client_manager.sdk_connection.compute
for server in parsed_args.server: for server in parsed_args.server:
utils.find_resource( server_id = compute_client.find_server(
compute_client.servers, server,
server ignore_missing=False,
).pause() ).id
compute_client.pause_server(server_id)
class RebootServer(command.Command): class RebootServer(command.Command):
@ -4674,7 +4675,6 @@ class UnlockServer(command.Command):
return parser return parser
def take_action(self, parsed_args): def take_action(self, parsed_args):
compute_client = self.app.client_manager.compute compute_client = self.app.client_manager.compute
for server in parsed_args.server: for server in parsed_args.server:
utils.find_resource( utils.find_resource(
@ -4697,13 +4697,13 @@ class UnpauseServer(command.Command):
return parser return parser
def take_action(self, parsed_args): def take_action(self, parsed_args):
compute_client = self.app.client_manager.sdk_connection.compute
compute_client = self.app.client_manager.compute
for server in parsed_args.server: for server in parsed_args.server:
utils.find_resource( server_id = compute_client.find_server(
compute_client.servers,
server, server,
).unpause() ignore_missing=False,
).id
compute_client.unpause_server(server_id)
class UnrescueServer(command.Command): class UnrescueServer(command.Command):

View File

@ -192,6 +192,22 @@ class TestServer(compute_fakes.TestComputev2):
method.assert_called_with() method.assert_called_with()
self.assertIsNone(result) self.assertIsNone(result)
def run_method_with_sdk_servers(self, method_name, server_count):
servers = self.setup_sdk_servers_mock(count=server_count)
arglist = [s.id for s in servers]
verifylist = [
('server', arglist),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.take_action(parsed_args)
calls = [call(s.id) for s in servers]
method = getattr(self.sdk_client, method_name)
method.assert_has_calls(calls)
self.assertIsNone(result)
class TestServerAddFixedIP(TestServer): class TestServerAddFixedIP(TestServer):
@ -6062,10 +6078,10 @@ class TestServerPause(TestServer):
} }
def test_server_pause_one_server(self): def test_server_pause_one_server(self):
self.run_method_with_servers('pause', 1) self.run_method_with_sdk_servers('pause_server', 1)
def test_server_pause_multi_servers(self): def test_server_pause_multi_servers(self):
self.run_method_with_servers('pause', 3) self.run_method_with_sdk_servers('pause_server', 3)
class TestServerRebuild(TestServer): class TestServerRebuild(TestServer):
@ -8308,10 +8324,10 @@ class TestServerUnpause(TestServer):
} }
def test_server_unpause_one_server(self): def test_server_unpause_one_server(self):
self.run_method_with_servers('unpause', 1) self.run_method_with_sdk_servers('unpause_server', 1)
def test_server_unpause_multi_servers(self): def test_server_unpause_multi_servers(self):
self.run_method_with_servers('unpause', 3) self.run_method_with_sdk_servers('unpause_server', 3)
class TestServerUnset(TestServer): class TestServerUnset(TestServer):

View File

@ -0,0 +1,5 @@
---
features:
- |
Migrate ``server pause`` and ``server unpause`` commands from novaclient
to sdk.