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
This commit is contained in:
Joshua Watt 2023-08-24 16:47:39 -06:00
parent e1103a3b62
commit 32b3158dd2
3 changed files with 45 additions and 0 deletions

View File

@ -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")

View File

@ -40,6 +40,7 @@ providers:
- name: fake-label
diskimage: fake-image
min-ram: 8192
console-log: True
flavor-name: 'Fake'
instance-properties:
prop1: foo

View File

@ -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