From 32b3158dd23b59290eec0dd8e8aab3754c99428e Mon Sep 17 00:00:00 2001 From: Joshua Watt Date: Thu, 24 Aug 2023 16:47:39 -0600 Subject: [PATCH] tests: Add test for console logging on keyscan error Adds a test to verify that the Adapter API to fetch the console logs when a keyscan error occurs is called correctly. Change-Id: I599b97f6829406ddfc7f1355b85c73fbe57533e7 --- nodepool/driver/fake/adapter.py | 7 ++++ .../tests/fixtures/node_no_min_ready.yaml | 1 + nodepool/tests/unit/test_launcher.py | 37 +++++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/nodepool/driver/fake/adapter.py b/nodepool/driver/fake/adapter.py index 3121c5bd9..78bfa70c2 100644 --- a/nodepool/driver/fake/adapter.py +++ b/nodepool/driver/fake/adapter.py @@ -120,6 +120,10 @@ class FakeOpenStackCloud(object): def _get_volume_quota(): return 100, 1000000 + @staticmethod + def _get_server_console(name_or_id): + return None + def __init__(self, images=None, networks=None): self.compute = FakeSession(self) self.pause_creates = False @@ -399,6 +403,9 @@ class FakeOpenStackCloud(object): self.log.debug("Deleted port ID: %s", port_id) self._down_ports = tmp_ports + def get_server_console(self, name_or_id): + return self.__class__._get_server_console(name_or_id) + class FakeUploadFailCloud(FakeOpenStackCloud): log = logging.getLogger("nodepool.FakeUploadFailCloud") diff --git a/nodepool/tests/fixtures/node_no_min_ready.yaml b/nodepool/tests/fixtures/node_no_min_ready.yaml index 1f0b424c5..3068e0e98 100644 --- a/nodepool/tests/fixtures/node_no_min_ready.yaml +++ b/nodepool/tests/fixtures/node_no_min_ready.yaml @@ -40,6 +40,7 @@ providers: - name: fake-label diskimage: fake-image min-ram: 8192 + console-log: True flavor-name: 'Fake' instance-properties: prop1: foo diff --git a/nodepool/tests/unit/test_launcher.py b/nodepool/tests/unit/test_launcher.py index c79eabb22..33344e83a 100644 --- a/nodepool/tests/unit/test_launcher.py +++ b/nodepool/tests/unit/test_launcher.py @@ -1217,6 +1217,43 @@ class TestLauncher(tests.DBTestCase): # exhausting retries self._node_launch_keyscan_failure(4, zk.FAILED) + def test_node_launch_keyscan_failure_console_log(self): + log_count = 0 + + def fake_get_server_console(name_or_id): + nonlocal log_count + log_count += 1 + return f"TEST CONSOLE LOG {log_count}\nSECOND LINE {log_count}" + + with self.assertLogs("nodepool.StateMachineNodeLauncher.fake-provider", + level="INFO") as logs: + self.useFixture(fixtures.MockPatchObject( + fakeadapter.FakeAdapter.fake_cloud, '_get_server_console', + fake_get_server_console + )) + self._node_launch_keyscan_failure(4, zk.FAILED) + + # Max attempts is 3 so there should be one console log for each + # attempt + self.assertEqual(log_count, 3) + + check_lines = { + "TEST CONSOLE LOG 1", + "SECOND LINE 1", + "TEST CONSOLE LOG 2", + "SECOND LINE 2", + "TEST CONSOLE LOG 3", + "SECOND LINE 3", + } + + for line in logs.output: + for c in check_lines: + if line.endswith(c): + check_lines.remove(c) + break + + self.assertFalse(check_lines) + def test_node_launch_with_broken_znodes(self): """Test that node launch still works if there are broken znodes""" # Create a znode without type