summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Falcon <therealfalcon@gmail.com>2021-08-20 11:02:57 -0500
committerGitHub <noreply@github.com>2021-08-20 11:02:57 -0500
commit94679e178613ab5b12327829ca54855ac5b1c1c0 (patch)
tree280d81922b0d905926ff4f2af264b14d1664eda8
parent776bd36385b3bd5c796479983afd2c9492cbdbe4 (diff)
downloadcloud-init-git-94679e178613ab5b12327829ca54855ac5b1c1c0.tar.gz
Add integration test for sensitive jinja substitution (#986)
Ensure jinja templates work for both instance-data.json and instance-data-sensitive.json. Test for LP: #1931392 Also removed test_runcmd.py as it's made redundant by this change.
-rw-r--r--tests/integration_tests/modules/test_combined.py20
-rw-r--r--tests/integration_tests/modules/test_runcmd.py25
2 files changed, 20 insertions, 25 deletions
diff --git a/tests/integration_tests/modules/test_combined.py b/tests/integration_tests/modules/test_combined.py
index 97b59558..27f3c074 100644
--- a/tests/integration_tests/modules/test_combined.py
+++ b/tests/integration_tests/modules/test_combined.py
@@ -15,6 +15,7 @@ from tests.integration_tests.instances import IntegrationInstance
from tests.integration_tests.util import verify_ordered_items_in_text
USER_DATA = """\
+## template: jinja
#cloud-config
apt:
primary:
@@ -31,6 +32,9 @@ locale: en_GB.UTF-8
locale_configfile: /etc/default/locale
ntp:
servers: ['ntp.ubuntu.com']
+runcmd:
+ - echo {{ds.meta_data.local_hostname}} > /var/tmp/runcmd_output
+ - echo {{merged_cfg.def_log_file}} >> /var/tmp/runcmd_output
"""
@@ -92,6 +96,22 @@ class TestCombined:
'en_US.UTF-8'
], locale_gen)
+ def test_runcmd_with_variable_substitution(
+ self, class_client: IntegrationInstance
+ ):
+ """Test runcmd, while including jinja substitution.
+
+ Ensure we can also substitue variables from instance-data-sensitive
+ LP: #1931392
+ """
+ client = class_client
+ expected = [
+ client.execute('hostname').stdout.strip(),
+ '/var/log/cloud-init.log',
+ ]
+ output = client.read_from_file('/var/tmp/runcmd_output')
+ verify_ordered_items_in_text(expected, output)
+
def test_no_problems(self, class_client: IntegrationInstance):
"""Test no errors, warnings, or tracebacks"""
client = class_client
diff --git a/tests/integration_tests/modules/test_runcmd.py b/tests/integration_tests/modules/test_runcmd.py
deleted file mode 100644
index 50d1851e..00000000
--- a/tests/integration_tests/modules/test_runcmd.py
+++ /dev/null
@@ -1,25 +0,0 @@
-"""Integration test for the runcmd module.
-
-This test specifies a command to be executed by the ``runcmd`` module
-and then checks if that command was executed during boot.
-
-(This is ported from
-``tests/cloud_tests/testcases/modules/runcmd.yaml``.)"""
-
-import pytest
-
-
-USER_DATA = """\
-#cloud-config
-runcmd:
- - echo cloud-init run cmd test > /var/tmp/run_cmd
-"""
-
-
-@pytest.mark.ci
-class TestRuncmd:
-
- @pytest.mark.user_data(USER_DATA)
- def test_runcmd(self, client):
- runcmd_output = client.read_from_file("/var/tmp/run_cmd")
- assert runcmd_output.strip() == "cloud-init run cmd test"