Merge "Switch server dump create to using sdk"

This commit is contained in:
Zuul 2022-12-15 20:14:43 +00:00 committed by Gerrit Code Review
commit b2c9a4cd40
3 changed files with 33 additions and 15 deletions

View File

@ -1927,12 +1927,10 @@ class CreateServerDump(command.Command):
return parser
def take_action(self, parsed_args):
compute_client = self.app.client_manager.compute
for server in parsed_args.server:
utils.find_resource(
compute_client.servers,
server,
).trigger_crash_dump()
compute_client = self.app.client_manager.sdk_connection.compute
for name_or_id in parsed_args.server:
server = compute_client.find_server(name_or_id)
server.trigger_crash_dump(compute_client)
class DeleteServer(command.Command):

View File

@ -21,7 +21,7 @@ import uuid
from novaclient import api_versions
from openstack.compute.v2 import flavor as _flavor
from openstack.compute.v2 import hypervisor as _hypervisor
from openstack.compute.v2 import server
from openstack.compute.v2 import server as _server
from openstack.compute.v2 import server_group as _server_group
from openstack.compute.v2 import server_interface as _server_interface
from openstack.compute.v2 import service
@ -544,7 +544,12 @@ class FakeServer(object):
# Overwrite default attributes.
server_info.update(attrs)
return server.Server(**server_info)
server = _server.Server(**server_info)
# Override methods
server.trigger_crash_dump = mock.MagicMock()
return server
@staticmethod
def create_sdk_servers(attrs=None, methods=None, count=2):

View File

@ -4461,21 +4461,36 @@ class TestServerDelete(TestServer):
class TestServerDumpCreate(TestServer):
def setUp(self):
super(TestServerDumpCreate, self).setUp()
super().setUp()
# Get the command object to test
self.cmd = server.CreateServerDump(self.app, None)
# Set methods to be tested.
self.methods = {
'trigger_crash_dump': None,
}
def run_test_server_dump(self, server_count):
servers = self.setup_sdk_servers_mock(server_count)
arglist = []
verifylist = []
for s in servers:
arglist.append(s.id)
verifylist = [
('server', arglist),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.take_action(parsed_args)
self.assertIsNone(result)
for s in servers:
s.trigger_crash_dump.assert_called_once_with(self.sdk_client)
def test_server_dump_one_server(self):
self.run_method_with_servers('trigger_crash_dump', 1)
self.run_test_server_dump(1)
def test_server_dump_multi_servers(self):
self.run_method_with_servers('trigger_crash_dump', 3)
self.run_test_server_dump(3)
class _TestServerList(TestServer):