From 013795500c3176f5f4130740bbbf75f2010f64e9 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Thu, 9 Dec 2021 17:34:41 +0000 Subject: [PATCH] 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 --- openstack/compute/v2/_proxy.py | 17 ++++++++++++++++ openstack/compute/v2/server.py | 20 +++++++++++-------- openstack/tests/unit/compute/v2/test_proxy.py | 7 +++++++ .../tests/unit/compute/v2/test_server.py | 12 +++++++++++ ...te-microversion-2-17-b05cb87580b8d56a.yaml | 6 ++++++ 5 files changed, 54 insertions(+), 8 deletions(-) create mode 100644 releasenotes/notes/compute-microversion-2-17-b05cb87580b8d56a.yaml diff --git a/openstack/compute/v2/_proxy.py b/openstack/compute/v2/_proxy.py index f9a56cf50..48072b7b5 100644 --- a/openstack/compute/v2/_proxy.py +++ b/openstack/compute/v2/_proxy.py @@ -1011,6 +1011,23 @@ class Proxy(proxy.Proxy): server = self._get_resource(_server.Server, server) 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 ========== def fetch_server_security_groups(self, server): diff --git a/openstack/compute/v2/server.py b/openstack/compute/v2/server.py index 8a16df0c0..6fb688cc0 100644 --- a/openstack/compute/v2/server.py +++ b/openstack/compute/v2/server.py @@ -488,6 +488,10 @@ class Server(resource.Resource, metadata.MetadataMixin, tag.TagMixin): body = {"migrate": None} 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): body = {"os-getConsoleOutput": {}} if length is not None: @@ -495,6 +499,14 @@ class Server(resource.Resource, metadata.MetadataMixin, tag.TagMixin): resp = self._action(session, body) 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, disk_over_commit=False): if utils.supports_microversion(session, '2.30'): @@ -514,14 +526,6 @@ class Server(resource.Resource, metadata.MetadataMixin, tag.TagMixin): block_migration=block_migration, 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): microversion = '2.30' body = {'host': None} diff --git a/openstack/tests/unit/compute/v2/test_proxy.py b/openstack/tests/unit/compute/v2/test_proxy.py index 4f6a4f60c..172fd198c 100644 --- a/openstack/tests/unit/compute/v2/test_proxy.py +++ b/openstack/tests/unit/compute/v2/test_proxy.py @@ -921,6 +921,13 @@ class TestCompute(TestComputeProxy): method_args=["value"], 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): self._verify( "openstack.compute.v2.server.Server.get_console_output", diff --git a/openstack/tests/unit/compute/v2/test_server.py b/openstack/tests/unit/compute/v2/test_server.py index f677e21d5..85adacc92 100644 --- a/openstack/tests/unit/compute/v2/test_server.py +++ b/openstack/tests/unit/compute/v2/test_server.py @@ -820,6 +820,18 @@ class TestServer(base.TestCase): self.sess.post.assert_called_with( 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): sot = server.Server(**EXAMPLE) diff --git a/releasenotes/notes/compute-microversion-2-17-b05cb87580b8d56a.yaml b/releasenotes/notes/compute-microversion-2-17-b05cb87580b8d56a.yaml new file mode 100644 index 000000000..e8f8c5107 --- /dev/null +++ b/releasenotes/notes/compute-microversion-2-17-b05cb87580b8d56a.yaml @@ -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.