Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions tests/integration_tests/modules/test_keys_to_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from tests.integration_tests.util import (
HAS_CONSOLE_LOG,
get_console_log,
get_syslog_or_console,
get_journal_syslog,
)

BLACKLIST_USER_DATA = """\
Expand Down Expand Up @@ -52,16 +52,14 @@ class TestKeysToConsoleBlacklist:

@pytest.mark.parametrize("key_type", ["ECDSA"])
def test_excluded_keys(self, class_client, key_type):
assert "({})".format(key_type) not in get_syslog_or_console(
class_client
)
assert "({})".format(key_type) not in get_journal_syslog(class_client)

# retry decorator here because it can take some time to be reflected
# in syslog
# in the journal
@retry(tries=60, delay=1)
@pytest.mark.parametrize("key_type", ["ED25519", "RSA"])
def test_included_keys(self, class_client, key_type):
assert "({})".format(key_type) in get_syslog_or_console(class_client)
assert "({})".format(key_type) in get_journal_syslog(class_client)


@pytest.mark.user_data(BLACKLIST_ALL_KEYS_USER_DATA)
Expand All @@ -75,12 +73,12 @@ class TestAllKeysToConsoleBlacklist:
"""

def test_header_excluded(self, class_client):
assert "BEGIN SSH HOST KEY FINGERPRINTS" not in get_syslog_or_console(
assert "BEGIN SSH HOST KEY FINGERPRINTS" not in get_journal_syslog(
class_client
)

def test_footer_excluded(self, class_client):
assert "END SSH HOST KEY FINGERPRINTS" not in get_syslog_or_console(
assert "END SSH HOST KEY FINGERPRINTS" not in get_journal_syslog(
class_client
)

Expand All @@ -95,17 +93,15 @@ class TestKeysToConsoleDisabled:

@pytest.mark.parametrize("key_type", ["ECDSA", "ED25519", "RSA"])
def test_keys_excluded(self, class_client, key_type):
assert "({})".format(key_type) not in get_syslog_or_console(
class_client
)
assert "({})".format(key_type) not in get_journal_syslog(class_client)

def test_header_excluded(self, class_client):
assert "BEGIN SSH HOST KEY FINGERPRINTS" not in get_syslog_or_console(
assert "BEGIN SSH HOST KEY FINGERPRINTS" not in get_journal_syslog(
class_client
)

def test_footer_excluded(self, class_client):
assert "END SSH HOST KEY FINGERPRINTS" not in get_syslog_or_console(
assert "END SSH HOST KEY FINGERPRINTS" not in get_journal_syslog(
class_client
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
OS_IMAGE_TYPE,
PLATFORM,
)
from tests.integration_tests.util import HAS_CONSOLE_LOG, get_syslog_or_console
from tests.integration_tests.util import HAS_CONSOLE_LOG, get_journal_syslog

USER_DATA_SSH_AUTHKEY_DISABLE = """\
#cloud-config
Expand Down Expand Up @@ -55,10 +55,10 @@ def test_ssh_authkey_fingerprints_disable(self, client):
reason=f"No console_log available for minimal images on {PLATFORM}",
)
def test_ssh_authkey_fingerprints_enable(self, client):
syslog_output = get_syslog_or_console(client)
assert re.search(r"256 SHA256:.*(ECDSA)", syslog_output) is not None
assert re.search(r"256 SHA256:.*(ED25519)", syslog_output) is not None
assert re.search(r"2048 SHA256:.*(RSA)", syslog_output) is None
log_output = get_journal_syslog(client)
assert re.search(r"256 SHA256:.*(ECDSA)", log_output) is not None
assert re.search(r"256 SHA256:.*(ED25519)", log_output) is not None
assert re.search(r"2048 SHA256:.*(RSA)", log_output) is None


@pytest.mark.user_data(
Expand Down
21 changes: 10 additions & 11 deletions tests/integration_tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@

from cloudinit.subp import subp
from tests.integration_tests.decorators import retry
from tests.integration_tests.integration_settings import (
OS_IMAGE_TYPE,
PLATFORM,
)
from tests.integration_tests.integration_settings import PLATFORM
from tests.integration_tests.releases import CURRENT_RELEASE, NOBLE

LOG = logging.getLogger("integration_testing.util")
Expand Down Expand Up @@ -578,13 +575,15 @@ def get_console_log(client: "IntegrationInstance"):
return console_log


@retry(tries=5, delay=1) # Retry on get_console_log failures
def get_syslog_or_console(client: "IntegrationInstance") -> str:
"""minimal OS_IMAGE_TYPE does not contain rsyslog"""
if OS_IMAGE_TYPE == "minimal" and HAS_CONSOLE_LOG:
return get_console_log(client)
else:
return client.read_from_file("/var/log/syslog")
@retry(tries=5, delay=1) # Retry on transient journalctl failures
def get_journal_syslog(client: "IntegrationInstance") -> str:
"""Syslog events are categorized _TRANSPORT=syslog from systemd v205."""
# Prefer syslog transport categorized messages over presence of
# /var/log/syslog as systemd v255 introduced systemd-executor
# which sandboxes unit processes resulting in direct writes to
# /dev/console being logged directly to journal binary instead
# of mirrored as rsyslog events.
return client.execute(["journalctl", "_TRANSPORT=syslog", "-b", "0"])
Comment on lines +579 to +586


@lru_cache()
Expand Down
Loading