From d1668797b44de975b4b5e5e356b4f7a072054574 Mon Sep 17 00:00:00 2001 From: James Falcon Date: Wed, 9 Dec 2020 16:17:47 -0600 Subject: [PATCH 1/3] Integration test for lp-1813396 Ensure gpg works even if VM provides no /dev/tty --- .../integration_tests/bugs/test_lp1813396.py | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 tests/integration_tests/bugs/test_lp1813396.py diff --git a/tests/integration_tests/bugs/test_lp1813396.py b/tests/integration_tests/bugs/test_lp1813396.py new file mode 100644 index 00000000000..7f30d614bd1 --- /dev/null +++ b/tests/integration_tests/bugs/test_lp1813396.py @@ -0,0 +1,33 @@ +"""Integration test for lp-1813396 + +Ensure gpg works even if VM provides no /dev/tty""" + +import pytest + +from tests.integration_tests.instances import IntegrationInstance +from tests.integration_tests.log_utils import ordered_items_in_text + + +USER_DATA = """\ +#cloud-config +apt: + sources: + docker: + source: 'deb [arch=amd64] https://download.docker.com/linux/debian stretch stable' + keyserver: keyserver.ubuntu.com + keyid: 0EBFCD88 +""" # 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', '0EBFCD88'] " + "with allowed return codes [0] (shell=False, capture=True)", + "Imported key '0EBFCD88' from keyserver 'keyserver.ubuntu.com'", + "finish: modules-config/config-apt-configure: SUCCESS", + ] + assert ordered_items_in_text(to_verify, log) From b1034a775d90329e2d231cd4ebbb9330b8a67a48 Mon Sep 17 00:00:00 2001 From: James Falcon Date: Wed, 9 Dec 2020 19:18:23 -0600 Subject: [PATCH 2/3] review comments --- tests/integration_tests/bugs/test_lp1813396.py | 17 +++++++++-------- tests/integration_tests/log_utils.py | 12 +++++------- .../modules/test_power_state_change.py | 5 ++--- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/tests/integration_tests/bugs/test_lp1813396.py b/tests/integration_tests/bugs/test_lp1813396.py index 7f30d614bd1..7ad0e809346 100644 --- a/tests/integration_tests/bugs/test_lp1813396.py +++ b/tests/integration_tests/bugs/test_lp1813396.py @@ -1,21 +1,22 @@ """Integration test for lp-1813396 -Ensure gpg works even if VM provides no /dev/tty""" +Ensure gpg is called with no tty flag. +""" import pytest 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 apt: sources: - docker: - source: 'deb [arch=amd64] https://download.docker.com/linux/debian stretch stable' + cloudinit: + source: 'deb [arch=amd64] http://ppa.launchpad.net/cloud-init-dev/daily/ubuntu focal main' keyserver: keyserver.ubuntu.com - keyid: 0EBFCD88 + keyid: E4D304DF """ # noqa: E501 @@ -25,9 +26,9 @@ 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', '0EBFCD88'] " + "'--keyserver=keyserver.ubuntu.com', '--recv-keys', 'E4D304DF'] " "with allowed return codes [0] (shell=False, capture=True)", - "Imported key '0EBFCD88' from keyserver 'keyserver.ubuntu.com'", + "Imported key 'E4D304DF' from keyserver 'keyserver.ubuntu.com'", "finish: modules-config/config-apt-configure: SUCCESS", ] - assert ordered_items_in_text(to_verify, log) + verify_ordered_items_in_text(to_verify, log) diff --git a/tests/integration_tests/log_utils.py b/tests/integration_tests/log_utils.py index fa807389612..40baae7b79d 100644 --- a/tests/integration_tests/log_utils.py +++ b/tests/integration_tests/log_utils.py @@ -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) diff --git a/tests/integration_tests/modules/test_power_state_change.py b/tests/integration_tests/modules/test_power_state_change.py index 60e0e583abe..48ce43bf5c3 100644 --- a/tests/integration_tests/modules/test_power_state_change.py +++ b/tests/integration_tests/modules/test_power_state_change.py @@ -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 @@ -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') + assert verify_ordered_items_in_text(lines_to_check, log) @pytest.mark.user_data(USER_DATA.format(delay='0', mode='poweroff', timeout='0', condition='false')) From f7426bdeaace487c875a01a6a2f6e1773f5224d0 Mon Sep 17 00:00:00 2001 From: Daniel Watkins Date: Thu, 10 Dec 2020 11:04:55 -0500 Subject: [PATCH 3/3] Update tests/integration_tests/modules/test_power_state_change.py --- tests/integration_tests/modules/test_power_state_change.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration_tests/modules/test_power_state_change.py b/tests/integration_tests/modules/test_power_state_change.py index 48ce43bf5c3..844dccfacf5 100644 --- a/tests/integration_tests/modules/test_power_state_change.py +++ b/tests/integration_tests/modules/test_power_state_change.py @@ -80,7 +80,7 @@ def test_poweroff(self, session_cloud: IntegrationCloud, "running 'init-local'", 'config-power-state-change already ran', ] - assert verify_ordered_items_in_text(lines_to_check, log) + verify_ordered_items_in_text(lines_to_check, log) @pytest.mark.user_data(USER_DATA.format(delay='0', mode='poweroff', timeout='0', condition='false'))