summaryrefslogtreecommitdiff
path: root/tests/integration_tests/datasources
diff options
context:
space:
mode:
Diffstat (limited to 'tests/integration_tests/datasources')
-rw-r--r--tests/integration_tests/datasources/test_lxd_discovery.py43
-rw-r--r--tests/integration_tests/datasources/test_network_dependency.py17
2 files changed, 31 insertions, 29 deletions
diff --git a/tests/integration_tests/datasources/test_lxd_discovery.py b/tests/integration_tests/datasources/test_lxd_discovery.py
index 3f05e906..da010813 100644
--- a/tests/integration_tests/datasources/test_lxd_discovery.py
+++ b/tests/integration_tests/datasources/test_lxd_discovery.py
@@ -1,4 +1,5 @@
import json
+
import pytest
import yaml
@@ -9,10 +10,10 @@ from tests.integration_tests.util import verify_clean_log
def _customize_envionment(client: IntegrationInstance):
client.write_to_file(
- '/etc/cloud/cloud.cfg.d/99-detect-lxd.cfg',
- 'datasource_list: [LXD]\n',
+ "/etc/cloud/cloud.cfg.d/99-detect-lxd.cfg",
+ "datasource_list: [LXD]\n",
)
- client.execute('cloud-init clean --logs')
+ client.execute("cloud-init clean --logs")
client.restart()
@@ -25,40 +26,44 @@ def test_lxd_datasource_discovery(client: IntegrationInstance):
"""Test that DataSourceLXD is detected instead of NoCloud."""
_customize_envionment(client)
nic_dev = "enp5s0" if client.settings.PLATFORM == "lxd_vm" else "eth0"
- result = client.execute('cloud-init status --long')
+ result = client.execute("cloud-init status --long")
if not result.ok:
- raise AssertionError('cloud-init failed:\n%s', result.stderr)
+ raise AssertionError("cloud-init failed:\n%s", result.stderr)
if "DataSourceLXD" not in result.stdout:
raise AssertionError(
- 'cloud-init did not discover DataSourceLXD', result.stdout
+ "cloud-init did not discover DataSourceLXD", result.stdout
)
- netplan_yaml = client.execute('cat /etc/netplan/50-cloud-init.yaml')
+ netplan_yaml = client.execute("cat /etc/netplan/50-cloud-init.yaml")
netplan_cfg = yaml.safe_load(netplan_yaml)
assert {
- 'network': {'ethernets': {nic_dev: {'dhcp4': True}}, 'version': 2}
+ "network": {"ethernets": {nic_dev: {"dhcp4": True}}, "version": 2}
} == netplan_cfg
- log = client.read_from_file('/var/log/cloud-init.log')
+ log = client.read_from_file("/var/log/cloud-init.log")
verify_clean_log(log)
- result = client.execute('cloud-id')
+ result = client.execute("cloud-id")
if result.stdout != "lxd":
raise AssertionError(
"cloud-id didn't report lxd. Result: %s", result.stdout
)
# Validate config instance data represented
- data = json.loads(client.read_from_file(
- '/run/cloud-init/instance-data.json')
+ data = json.loads(
+ client.read_from_file("/run/cloud-init/instance-data.json")
)
v1 = data["v1"]
ds_cfg = data["ds"]
assert "lxd" == v1["platform"]
assert "LXD socket API v. 1.0 (/dev/lxd/sock)" == v1["subplatform"]
- ds_cfg = json.loads(client.execute('cloud-init query ds').stdout)
+ ds_cfg = json.loads(client.execute("cloud-init query ds").stdout)
assert ["_doc", "_metadata_api_version", "config", "meta-data"] == sorted(
list(ds_cfg.keys())
)
if (
- client.settings.PLATFORM == "lxd_vm" and
- ImageSpecification.from_os_image().release in ("xenial", "bionic")
+ client.settings.PLATFORM == "lxd_vm"
+ and ImageSpecification.from_os_image().release
+ in (
+ "xenial",
+ "bionic",
+ )
):
# pycloudlib injects user.vendor_data for lxd_vm on bionic and xenial
# to start the lxd-agent.
@@ -74,17 +79,13 @@ def test_lxd_datasource_discovery(client: IntegrationInstance):
assert {"public-keys": v1["public_ssh_keys"][0]} == (
yaml.safe_load(ds_cfg["config"]["user.meta-data"])
)
- assert (
- "#cloud-config\ninstance-id" in ds_cfg["meta-data"]
- )
+ assert "#cloud-config\ninstance-id" in ds_cfg["meta-data"]
# Assert NoCloud seed data is still present in cloud image metadata
# This will start failing if we redact metadata templates from
# https://cloud-images.ubuntu.com/daily/server/jammy/current/\
# jammy-server-cloudimg-amd64-lxd.tar.xz
nocloud_metadata = yaml.safe_load(
- client.read_from_file(
- "/var/lib/cloud/seed/nocloud-net/meta-data"
- )
+ client.read_from_file("/var/lib/cloud/seed/nocloud-net/meta-data")
)
assert client.instance.name == nocloud_metadata["instance-id"]
assert (
diff --git a/tests/integration_tests/datasources/test_network_dependency.py b/tests/integration_tests/datasources/test_network_dependency.py
index 24e71f9d..32ac7053 100644
--- a/tests/integration_tests/datasources/test_network_dependency.py
+++ b/tests/integration_tests/datasources/test_network_dependency.py
@@ -6,10 +6,10 @@ from tests.integration_tests.instances import IntegrationInstance
def _customize_envionment(client: IntegrationInstance):
# Insert our "disable_network_activation" file here
client.write_to_file(
- '/etc/cloud/cloud.cfg.d/99-disable-network-activation.cfg',
- 'disable_network_activation: true\n',
+ "/etc/cloud/cloud.cfg.d/99-disable-network-activation.cfg",
+ "disable_network_activation: true\n",
)
- client.execute('cloud-init clean --logs')
+ client.execute("cloud-init clean --logs")
client.restart()
@@ -20,13 +20,14 @@ def _customize_envionment(client: IntegrationInstance):
def test_network_activation_disabled(client: IntegrationInstance):
"""Test that the network is not activated during init mode."""
_customize_envionment(client)
- result = client.execute('systemctl status google-guest-agent.service')
+ result = client.execute("systemctl status google-guest-agent.service")
if not result.ok:
raise AssertionError(
- 'google-guest-agent is not active:\n%s', result.stdout)
- log = client.read_from_file('/var/log/cloud-init.log')
+ "google-guest-agent is not active:\n%s", result.stdout
+ )
+ log = client.read_from_file("/var/log/cloud-init.log")
assert "Running command ['netplan', 'apply']" not in log
- assert 'Not bringing up newly configured network interfaces' in log
- assert 'Bringing up newly configured network interfaces' not in log
+ assert "Not bringing up newly configured network interfaces" in log
+ assert "Bringing up newly configured network interfaces" not in log