Skip to content

Commit 97bfd21

Browse files
Integration test for LP: #1813396 and canonical#669 (canonical#719)
Ensure gpg is called with --no-tty flag. Also, refactored the "ordered_items_in_text" to assert if the line is missing and provide a more useful error message.
1 parent 1d1649e commit 97bfd21

3 files changed

Lines changed: 41 additions & 10 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""Integration test for lp-1813396
2+
3+
Ensure gpg is called with no tty flag.
4+
"""
5+
6+
import pytest
7+
8+
from tests.integration_tests.instances import IntegrationInstance
9+
from tests.integration_tests.log_utils import verify_ordered_items_in_text
10+
11+
12+
USER_DATA = """\
13+
#cloud-config
14+
apt:
15+
sources:
16+
cloudinit:
17+
source: 'deb [arch=amd64] http://ppa.launchpad.net/cloud-init-dev/daily/ubuntu focal main'
18+
keyserver: keyserver.ubuntu.com
19+
keyid: E4D304DF
20+
""" # noqa: E501
21+
22+
23+
@pytest.mark.sru_2020_11
24+
@pytest.mark.user_data(USER_DATA)
25+
def test_gpg_no_tty(client: IntegrationInstance):
26+
log = client.read_from_file('/var/log/cloud-init.log')
27+
to_verify = [
28+
"Running command ['gpg', '--no-tty', "
29+
"'--keyserver=keyserver.ubuntu.com', '--recv-keys', 'E4D304DF'] "
30+
"with allowed return codes [0] (shell=False, capture=True)",
31+
"Imported key 'E4D304DF' from keyserver 'keyserver.ubuntu.com'",
32+
"finish: modules-config/config-apt-configure: SUCCESS",
33+
]
34+
verify_ordered_items_in_text(to_verify, log)
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
def ordered_items_in_text(to_verify: list, text: str) -> bool:
2-
"""Return if all items in list appear in order in text.
1+
def verify_ordered_items_in_text(to_verify: list, text: str):
2+
"""Assert all items in list appear in order in text.
33
44
Examples:
5-
ordered_items_in_text(['a', '1'], 'ab1') # Returns True
6-
ordered_items_in_text(['1', 'a'], 'ab1') # Returns False
5+
verify_ordered_items_in_text(['a', '1'], 'ab1') # passes
6+
verify_ordered_items_in_text(['1', 'a'], 'ab1') # raises AssertionError
77
"""
88
index = 0
99
for item in to_verify:
1010
index = text[index:].find(item)
11-
if index < 0:
12-
return False
13-
return True
11+
assert index > -1, "Expected item not found: '{}'".format(item)

tests/integration_tests/modules/test_power_state_change.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from tests.integration_tests.clouds import IntegrationCloud
1111
from tests.integration_tests.instances import IntegrationInstance
12-
from tests.integration_tests.log_utils import ordered_items_in_text
12+
from tests.integration_tests.log_utils import verify_ordered_items_in_text
1313

1414
USER_DATA = """\
1515
#cloud-config
@@ -80,8 +80,7 @@ def test_poweroff(self, session_cloud: IntegrationCloud,
8080
"running 'init-local'",
8181
'config-power-state-change already ran',
8282
]
83-
assert ordered_items_in_text(lines_to_check, log), (
84-
'Expected data not in logs')
83+
verify_ordered_items_in_text(lines_to_check, log)
8584

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

0 commit comments

Comments
 (0)