Skip to content

Commit

Permalink
test: allow verify_clean_boot to ignore all or specific tracebacks (c…
Browse files Browse the repository at this point in the history
…anonical#5209)

Ensure ignore_warnings=True or ignore_errors=True is honored and
not overridden by supplemental warning texts appended.
  • Loading branch information
blackboxsw authored and holmanb committed Aug 2, 2024
1 parent 412f54f commit 6399a6e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
4 changes: 4 additions & 0 deletions tests/integration_tests/datasources/test_nocloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,10 @@ def test_nocloud_ftps_unencrypted_server_fails(
" a scheme of ftps://, which is not allowed. Use ftp:// "
"to allow connecting to insecure ftp servers.",
],
ignore_tracebacks=[
'ftplib.error_perm: 500 Command "AUTH" not understood.',
"UrlError: Attempted to connect to an insecure ftp server",
],
)

def test_nocloud_ftps_encrypted_server_succeeds(
Expand Down
48 changes: 37 additions & 11 deletions tests/integration_tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def verify_clean_boot(
instance: "IntegrationInstance",
ignore_warnings: Optional[Union[List[str], bool]] = None,
ignore_errors: Optional[Union[List[str], bool]] = None,
ignore_tracebacks: Optional[Union[List[str], bool]] = None,
require_warnings: Optional[list] = None,
require_errors: Optional[list] = None,
):
Expand Down Expand Up @@ -94,14 +95,17 @@ def verify_clean_boot(

def append_or_create_list(
maybe_list: Optional[Union[List[str], bool]], value: str
) -> List[str]:
) -> Optional[Union[List[str], bool]]:
"""handle multiple types"""
if isinstance(maybe_list, list):
maybe_list.append(value)
elif maybe_list is None or isinstance(maybe_list, bool):
elif maybe_list is True:
return True # Ignoring all texts, so no need to append.
elif maybe_list in (None, False):
maybe_list = [value]
return maybe_list

traceback_texts = []
# Define exceptions by matrix of platform and Ubuntu release
if "azure" == PLATFORM:
# Consistently on all Azure launches:
Expand All @@ -122,12 +126,17 @@ def append_or_create_list(
ignore_errors = append_or_create_list(
ignore_warnings, "Stderr: RTNETLINK answers: File exists"
)
traceback_texts.append("Stderr: RTNETLINK answers: File exists")
# LP: #1833446
ignore_warnings = append_or_create_list(
ignore_warnings,
"UrlError: 404 Client Error: Not Found for url: "
"http://169.254.169.254/latest/meta-data/",
)
traceback_texts.append(
"UrlError: 404 Client Error: Not Found for url: "
"http://169.254.169.254/latest/meta-data/"
)
# Oracle has a file in /etc/cloud/cloud.cfg.d that contains
# users:
# - default
Expand All @@ -143,22 +152,17 @@ def append_or_create_list(
instance,
ignore_warnings=ignore_warnings,
ignore_errors=ignore_errors,
ignore_tracebacks=ignore_tracebacks,
require_warnings=require_warnings,
require_errors=require_errors,
)
# assert no Tracebacks
assert (
"0"
== instance.execute(
"grep --count Traceback /var/log/cloud-init.log"
).stdout.strip()
), "Unexpected traceback found in /var/log/cloud-init.log"


def _verify_clean_boot(
instance: "IntegrationInstance",
ignore_warnings: Optional[Union[List[str], bool]] = None,
ignore_errors: Optional[Union[List[str], bool]] = None,
ignore_tracebacks: Optional[Union[List[str], bool]] = None,
require_warnings: Optional[list] = None,
require_errors: Optional[list] = None,
):
Expand All @@ -181,9 +185,9 @@ def _verify_clean_boot(
if expected in current_error:
required_errors_found.add(expected)

# check for unexpected errors
if ignore_errors is True:
continue
# check for unexpected errors
for expected in [*ignore_errors, *require_errors]:
if expected in current_error:
break
Expand All @@ -198,9 +202,9 @@ def _verify_clean_boot(
if expected in current_warning:
required_warnings_found.add(expected)

# check for unexpected warnings
if ignore_warnings is True:
continue
# check for unexpected warnings
for expected in [*ignore_warnings, *require_warnings]:
if expected in current_warning:
break
Expand Down Expand Up @@ -241,6 +245,28 @@ def _verify_clean_boot(
)
assert not errors, message

if ignore_tracebacks is True:
return
# assert no unexpected Tracebacks
expected_traceback_count = 0
traceback_count = int(
instance.execute(
"grep --count Traceback /var/log/cloud-init.log"
).stdout.strip()
)
if ignore_tracebacks:
for expected_traceback in ignore_tracebacks:
expected_traceback_count += int(
instance.execute(
f"grep --count '{expected_traceback}'"
" /var/log/cloud-init.log"
).stdout.strip()
)
assert expected_traceback_count == traceback_count, (
f"{traceback_count - expected_traceback_count} unexpected traceback(s)"
" found in /var/log/cloud-init.log"
)


def verify_clean_log(log: str, ignore_deprecations: bool = True):
"""Assert no unexpected tracebacks or warnings in logs"""
Expand Down

0 comments on commit 6399a6e

Please sign in to comment.