Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some miscellaneous integration test fixes (SC-606) #1103

Merged
merged 2 commits into from
Nov 15, 2021
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
51 changes: 27 additions & 24 deletions tests/integration_tests/modules/test_apt.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
Fix-Broken "true";
}
}
proxy: "http://proxy.internal:3128"
http_proxy: "http://squid.internal:3128"
ftp_proxy: "ftp://squid.internal:3128"
https_proxy: "https://squid.internal:3128"
primary:
- arches: [default]
uri: http://badarchive.ubuntu.com/ubuntu
Expand All @@ -38,9 +34,9 @@
deb-src $SECURITY $RELEASE-security multiverse
sources:
test_keyserver:
keyid: 72600DB15B8E4C8B1964B868038ACC97C660A937
keyserver: keyserver.ubuntu.com
source: "deb http://ppa.launchpad.net/cloud-init-raharper/curtin-dev/ubuntu $RELEASE main"
keyid: 110E21D8B0E2A1F0243AF6820856F197B892ACEA
keyserver: keyserver.ubuntu.com
source: "deb http://ppa.launchpad.net/canonical-kernel-team/ppa/ubuntu $RELEASE main"
test_ppa:
keyid: 441614D8
keyserver: keyserver.ubuntu.com
Expand Down Expand Up @@ -95,10 +91,8 @@
r"deb-src http://badsecurity.ubuntu.com/ubuntu [a-z]+-security multiverse",
]

TEST_KEYSERVER_KEY = "7260 0DB1 5B8E 4C8B 1964 B868 038A CC97 C660 A937"

TEST_KEYSERVER_KEY = "110E 21D8 B0E2 A1F0 243A F682 0856 F197 B892 ACEA"
TEST_PPA_KEY = "3552 C902 B4DD F7BD 3842 1821 015D 28D7 4416 14D8"

TEST_KEY = "1FF0 D853 5EF7 E719 E5C8 1B9C 083D 06FB E4D3 04DF"
TEST_SIGNED_BY_KEY = "A2EB 2DEC 0BD7 519B 7B38 BE38 376A 290E C806 8B11"

Expand Down Expand Up @@ -148,18 +142,6 @@ def test_apt_conf(self, class_client: IntegrationInstance):
assert 'Assume-Yes "true";' in apt_config
assert 'Fix-Broken "true";' in apt_config

def test_apt_proxy(self, class_client: IntegrationInstance):
"""Test the apt proxy functionality.

Ported from tests/cloud_tests/testcases/modules/apt_configure_proxy.py
"""
out = class_client.read_from_file(
'/etc/apt/apt.conf.d/90cloud-init-aptproxy')
assert 'Acquire::http::Proxy "http://proxy.internal:3128";' in out
assert 'Acquire::http::Proxy "http://squid.internal:3128";' in out
assert 'Acquire::ftp::Proxy "ftp://squid.internal:3128";' in out
assert 'Acquire::https::Proxy "https://squid.internal:3128";' in out

def test_ppa_source(self, class_client: IntegrationInstance):
"""Test the apt ppa functionality.

Expand All @@ -186,7 +168,6 @@ def test_signed_by(self, class_client: IntegrationInstance):
"deb [signed-by=/etc/apt/cloud-init.gpg.d/test_signed_by.gpg] "
"http://ppa.launchpad.net/juju/stable/ubuntu"
" {} main".format(release))
print(class_client.execute('cat /var/log/cloud-init.log'))
path_contents = class_client.read_from_file(
'/etc/apt/sources.list.d/test_signed_by.list')
assert path_contents == source
Expand Down Expand Up @@ -230,7 +211,7 @@ def test_keyserver(self, class_client: IntegrationInstance):
)

assert (
'http://ppa.launchpad.net/cloud-init-raharper/curtin-dev/ubuntu'
'http://ppa.launchpad.net/canonical-kernel-team/ppa/ubuntu'
) in test_keyserver_contents

assert TEST_KEYSERVER_KEY in self.get_keys(class_client)
Expand Down Expand Up @@ -342,3 +323,25 @@ def test_disable_apt_pipelining(self, class_client: IntegrationInstance):
'/etc/apt/apt.conf.d/90cloud-init-pipelining'
)
assert 'Acquire::http::Pipeline-Depth "0";' in conf


APT_PROXY_DATA = """\
#cloud-config
apt:
proxy: "http://proxy.internal:3128"
http_proxy: "http://squid.internal:3128"
ftp_proxy: "ftp://squid.internal:3128"
https_proxy: "https://squid.internal:3128"
"""


@pytest.mark.ubuntu
@pytest.mark.user_data(APT_PROXY_DATA)
def test_apt_proxy(client: IntegrationInstance):
"""Test the apt proxy data gets written correctly."""
out = client.read_from_file(
'/etc/apt/apt.conf.d/90cloud-init-aptproxy')
assert 'Acquire::http::Proxy "http://proxy.internal:3128";' in out
assert 'Acquire::http::Proxy "http://squid.internal:3128";' in out
assert 'Acquire::ftp::Proxy "ftp://squid.internal:3128";' in out
assert 'Acquire::https::Proxy "https://squid.internal:3128";' in out
18 changes: 18 additions & 0 deletions tests/integration_tests/modules/test_combined.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,21 @@
locale_configfile: /etc/default/locale
ntp:
servers: ['ntp.ubuntu.com']
rsyslog:
configs:
- "*.* @@127.0.0.1"
- filename: 0-basic-config.conf
content: |
module(load="imtcp")
input(type="imtcp" port="514")
$template RemoteLogs,"/var/tmp/rsyslog.log"
*.* ?RemoteLogs
& ~
remotes:
me: "127.0.0.1"
runcmd:
- echo 'hello world' > /var/tmp/runcmd_output
- logger "My test log"
"""


Expand Down Expand Up @@ -102,6 +115,11 @@ def test_configured_locale(self, class_client: IntegrationInstance):
'en_US.UTF-8'
], locale_gen)

def test_rsyslog(self, class_client: IntegrationInstance):
"""Test rsyslog is configured correctly."""
client = class_client
assert 'My test log' in client.read_from_file('/var/tmp/rsyslog.log')

def test_runcmd(self, class_client: IntegrationInstance):
"""Test runcmd works as expected"""
client = class_client
Expand Down
5 changes: 5 additions & 0 deletions tests/integration_tests/modules/test_keys_to_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
``tests/cloud_tests/testcases/modules/keys_to_console.yaml``.)"""
import pytest

from tests.integration_tests.util import retry

BLACKLIST_USER_DATA = """\
#cloud-config
ssh_fp_console_blacklist: [ssh-dss, ssh-dsa, ecdsa-sha2-nistp256]
Expand All @@ -30,6 +32,9 @@ def test_excluded_keys(self, class_client, key_type):
syslog = class_client.read_from_file("/var/log/syslog")
assert "({})".format(key_type) not in syslog

# retry decorator here because it can take some time to be reflected
# in syslog
@retry(tries=30, delay=1)
@pytest.mark.parametrize("key_type", ["ED25519", "RSA"])
def test_included_keys(self, class_client, key_type):
syslog = class_client.read_from_file("/var/log/syslog")
Expand Down
39 changes: 39 additions & 0 deletions tests/integration_tests/modules/test_puppet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""Test installation configuration of puppet module."""
import pytest

from tests.integration_tests.instances import IntegrationInstance
from tests.integration_tests.util import verify_clean_log

SERVICE_DATA = """\
#cloud-config
puppet:
install: true
install_type: packages
"""


@pytest.mark.user_data(SERVICE_DATA)
def test_puppet_service(client: IntegrationInstance):
"""Basic test that puppet gets installed and runs."""
log = client.read_from_file('/var/log/cloud-init.log')
verify_clean_log(log)
assert client.execute('systemctl is-active puppet').ok
assert "Running command ['puppet', 'agent'" not in log


EXEC_DATA = """\
#cloud-config
puppet:
install: true
install_type: packages
exec: true
exec_args: ['--noop']
"""


@pytest.mark.user_data
@pytest.mark.user_data(EXEC_DATA)
def test_pupet_exec(client: IntegrationInstance):
"""Basic test that puppet gets installed and runs."""
log = client.read_from_file('/var/log/cloud-init.log')
assert "Running command ['puppet', 'agent', '--noop']" in log
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

import pytest

from tests.integration_tests.util import retry


USER_DATA_SSH_AUTHKEY_DISABLE = """\
#cloud-config
Expand All @@ -38,6 +40,9 @@ def test_ssh_authkey_fingerprints_disable(self, client):
"Skipping module named ssh-authkey-fingerprints, "
"logging of SSH fingerprints disabled") in cloudinit_output

# retry decorator here because it can take some time to be reflected
# in syslog
@retry(tries=30, delay=1)
@pytest.mark.user_data(USER_DATA_SSH_AUTHKEY_ENABLE)
def test_ssh_authkey_fingerprints_enable(self, client):
syslog_output = client.read_from_file("/var/log/syslog")
Expand Down
9 changes: 9 additions & 0 deletions tests/integration_tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ def verify_clean_log(log):
'http://169.254.169.254/latest/meta-data/')
warning_texts.append(fetch_error_text)
traceback_texts.append(fetch_error_text)
# Oracle has a file in /etc/cloud/cloud.cfg.d that contains
# users:
# - default
# - name: opc
# ssh_redirect_user: true
# This can trigger a warning about opc having no public key
warning_texts.append(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big deal for this integration test, but seems like we might want instance.cloud awareness in verify_clean_logs for azure vs oracle cases. But, this can wait until we have a third use-case.

'Unable to disable SSH logins for opc given ssh_redirect_user'
)

for warning_text in warning_texts:
expected_warnings += log.count(warning_text)
Expand Down