Switch server dump create to using sdk

Change-Id: I8e2a4651bff1f739fa98533cd47074b143b2e3d6
Co-authored-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
Diwei Zhu 2021-11-02 04:52:25 +00:00 committed by Stephen Finucane
parent b52ae93cd2
commit c47998c59a
4 changed files with 34 additions and 16 deletions

View File

@ -1874,12 +1874,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
@ -605,7 +605,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

@ -4464,21 +4464,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):

View File

@ -6,7 +6,7 @@ pbr!=2.1.0,>=2.0.0 # Apache-2.0
cliff>=3.5.0 # Apache-2.0
iso8601>=0.1.11 # MIT
openstacksdk>=0.102.0 # Apache-2.0
openstacksdk>=0.103.0 # Apache-2.0
osc-lib>=2.3.0 # Apache-2.0
oslo.i18n>=3.15.3 # Apache-2.0
oslo.utils>=3.33.0 # Apache-2.0