compute: Add support for triggering crash dumps

Add support for compute API microversion 2.17, which allowed admins to
trigger a crash dump in a running server.

Change-Id: Ie0409f11f2a2b03044dfb504748e0177cae0d6b0
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
Stephen Finucane 2021-12-09 17:34:41 +00:00
parent 9fa6603d4e
commit 013795500c
5 changed files with 54 additions and 8 deletions

View File

@ -1011,6 +1011,23 @@ class Proxy(proxy.Proxy):
server = self._get_resource(_server.Server, server) server = self._get_resource(_server.Server, server)
server.unshelve(self) server.unshelve(self)
def trigger_server_crash_dump(self, server):
"""Trigger a crash dump in a server.
When a server starts behaving oddly at a fundamental level, it maybe be
useful to get a kernel level crash dump to debug further. The crash
dump action forces a crash dump followed by a system reboot of the
server. Once the server comes back online, you can find a Kernel Crash
Dump file in a certain location of the filesystem. For example, for
Ubuntu you can find it in the /var/crash directory.
:param server: Either the ID of a server or a
:class:`~openstack.compute.v2.server.Server` instance.
:returns: None
"""
server = self._get_resource(_server.Server, server)
server.trigger_crash_dump(self)
# ========== Server security groups ========== # ========== Server security groups ==========
def fetch_server_security_groups(self, server): def fetch_server_security_groups(self, server):

View File

@ -488,6 +488,10 @@ class Server(resource.Resource, metadata.MetadataMixin, tag.TagMixin):
body = {"migrate": None} body = {"migrate": None}
self._action(session, body) self._action(session, body)
def trigger_crash_dump(self, session):
body = {"trigger_crash_dump": None}
self._action(session, body)
def get_console_output(self, session, length=None): def get_console_output(self, session, length=None):
body = {"os-getConsoleOutput": {}} body = {"os-getConsoleOutput": {}}
if length is not None: if length is not None:
@ -495,6 +499,14 @@ class Server(resource.Resource, metadata.MetadataMixin, tag.TagMixin):
resp = self._action(session, body) resp = self._action(session, body)
return resp.json() return resp.json()
def get_console_url(self, session, console_type):
action = CONSOLE_TYPE_ACTION_MAPPING.get(console_type)
if not action:
raise ValueError("Unsupported console type %s" % console_type)
body = {action: {'type': console_type}}
resp = self._action(session, body)
return resp.json().get('console')
def live_migrate(self, session, host, force, block_migration, def live_migrate(self, session, host, force, block_migration,
disk_over_commit=False): disk_over_commit=False):
if utils.supports_microversion(session, '2.30'): if utils.supports_microversion(session, '2.30'):
@ -514,14 +526,6 @@ class Server(resource.Resource, metadata.MetadataMixin, tag.TagMixin):
block_migration=block_migration, block_migration=block_migration,
disk_over_commit=disk_over_commit) disk_over_commit=disk_over_commit)
def get_console_url(self, session, console_type):
action = CONSOLE_TYPE_ACTION_MAPPING.get(console_type)
if not action:
raise ValueError("Unsupported console type %s" % console_type)
body = {action: {'type': console_type}}
resp = self._action(session, body)
return resp.json().get('console')
def _live_migrate_30(self, session, host, force, block_migration): def _live_migrate_30(self, session, host, force, block_migration):
microversion = '2.30' microversion = '2.30'
body = {'host': None} body = {'host': None}

View File

@ -921,6 +921,13 @@ class TestCompute(TestComputeProxy):
method_args=["value"], method_args=["value"],
expected_args=[self.proxy]) expected_args=[self.proxy])
def test_server_trigger_dump(self):
self._verify(
"openstack.compute.v2.server.Server.trigger_crash_dump",
self.proxy.trigger_server_crash_dump,
method_args=["value"],
expected_args=[self.proxy])
def test_get_server_output(self): def test_get_server_output(self):
self._verify( self._verify(
"openstack.compute.v2.server.Server.get_console_output", "openstack.compute.v2.server.Server.get_console_output",

View File

@ -820,6 +820,18 @@ class TestServer(base.TestCase):
self.sess.post.assert_called_with( self.sess.post.assert_called_with(
url, json=body, headers=headers, microversion=None) url, json=body, headers=headers, microversion=None)
def test_trigger_crash_dump(self):
sot = server.Server(**EXAMPLE)
res = sot.trigger_crash_dump(self.sess)
self.assertIsNone(res)
url = 'servers/IDENTIFIER/action'
body = {'trigger_crash_dump': None}
headers = {'Accept': ''}
self.sess.post.assert_called_with(
url, json=body, headers=headers, microversion=None)
def test_get_console_output(self): def test_get_console_output(self):
sot = server.Server(**EXAMPLE) sot = server.Server(**EXAMPLE)

View File

@ -0,0 +1,6 @@
---
features:
- |
Add support for Compute API microversion 2.17, which allows admins to
trigger a crash dump for a server. This can be useful for debugging
misbehaving guests.