Skip to content
Merged
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
34 changes: 34 additions & 0 deletions tests/integration_tests/bugs/test_lp1813396.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""Integration test for lp-1813396

Ensure gpg is called with no tty flag.
"""

import pytest

from tests.integration_tests.instances import IntegrationInstance
from tests.integration_tests.log_utils import verify_ordered_items_in_text


USER_DATA = """\
#cloud-config
apt:
sources:
cloudinit:
source: 'deb [arch=amd64] http://ppa.launchpad.net/cloud-init-dev/daily/ubuntu focal main'
keyserver: keyserver.ubuntu.com
keyid: E4D304DF
""" # noqa: E501


@pytest.mark.sru_2020_11
@pytest.mark.user_data(USER_DATA)
def test_gpg_no_tty(client: IntegrationInstance):
log = client.read_from_file('/var/log/cloud-init.log')
to_verify = [
"Running command ['gpg', '--no-tty', "
"'--keyserver=keyserver.ubuntu.com', '--recv-keys', 'E4D304DF'] "
"with allowed return codes [0] (shell=False, capture=True)",
"Imported key 'E4D304DF' from keyserver 'keyserver.ubuntu.com'",
"finish: modules-config/config-apt-configure: SUCCESS",
]
verify_ordered_items_in_text(to_verify, log)
12 changes: 5 additions & 7 deletions tests/integration_tests/log_utils.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
def ordered_items_in_text(to_verify: list, text: str) -> bool:
"""Return if all items in list appear in order in text.
def verify_ordered_items_in_text(to_verify: list, text: str):
"""Assert all items in list appear in order in text.

Examples:
ordered_items_in_text(['a', '1'], 'ab1') # Returns True
ordered_items_in_text(['1', 'a'], 'ab1') # Returns False
verify_ordered_items_in_text(['a', '1'], 'ab1') # passes
verify_ordered_items_in_text(['1', 'a'], 'ab1') # raises AssertionError
"""
index = 0
for item in to_verify:
index = text[index:].find(item)
if index < 0:
return False
return True
assert index > -1, "Expected item not found: '{}'".format(item)
5 changes: 2 additions & 3 deletions tests/integration_tests/modules/test_power_state_change.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from tests.integration_tests.clouds import IntegrationCloud
from tests.integration_tests.instances import IntegrationInstance
from tests.integration_tests.log_utils import ordered_items_in_text
from tests.integration_tests.log_utils import verify_ordered_items_in_text

USER_DATA = """\
#cloud-config
Expand Down Expand Up @@ -80,8 +80,7 @@ def test_poweroff(self, session_cloud: IntegrationCloud,
"running 'init-local'",
'config-power-state-change already ran',
]
assert ordered_items_in_text(lines_to_check, log), (
'Expected data not in logs')
verify_ordered_items_in_text(lines_to_check, log)

@pytest.mark.user_data(USER_DATA.format(delay='0', mode='poweroff',
timeout='0', condition='false'))
Expand Down