Skip to content

Commit 38aee6e

Browse files
authored
integration_tests: introduce lxd_use_exec mark (canonical#802)
pycloudlib has modified the way LXD executes tests (canonical/pycloudlib#114): it will always use SSH to access them by default, instead of using `lxc exec`. This behaviour is transparent for them majority of cloud-init's integration tests, but some currently depend on using `lxc exec` to access instances with (intentionally) broken networking: obviously these are not accessible via SSH. pycloudlib retains support for switching an instance to use `lxc exec`. This commit introduces the `lxd_use_exec` mark, which tests can use to indicate to the integration testing framework that they should be so switched, and applies it to all applicable tests.
1 parent 66e2d42 commit 38aee6e

5 files changed

Lines changed: 15 additions & 1 deletion

File tree

integration-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# PyPI requirements for cloud-init integration testing
22
# https://cloudinit.readthedocs.io/en/latest/topics/integration_tests.html
33
#
4-
pycloudlib @ git+https://github.com/canonical/pycloudlib.git@878981e3c7caaf583a8c7c5494dba9d9447acee8
4+
pycloudlib @ git+https://github.com/canonical/pycloudlib.git@3a6c668fed769f00d83d1e6bea7d68953787cc38
55
pytest

tests/integration_tests/bugs/test_gh668.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"user.network-config": NETWORK_CONFIG,
3838
"volatile.eth0.hwaddr": MAC_ADDRESS,
3939
})
40+
@pytest.mark.lxd_use_exec
4041
def test_static_route_to_host(client: IntegrationInstance):
4142
route = client.execute("ip route | grep {}".format(DESTINATION_IP))
4243
assert route.startswith(EXPECTED_ROUTE)

tests/integration_tests/bugs/test_lp1898997.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"volatile.eth0.hwaddr": MAC_ADDRESS,
4040
})
4141
@pytest.mark.lxd_vm
42+
@pytest.mark.lxd_use_exec
4243
@pytest.mark.not_bionic
4344
@pytest.mark.not_xenial
4445
@pytest.mark.sru_2020_11

tests/integration_tests/conftest.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ def _client(request, fixture_utils, session_cloud: IntegrationCloud):
200200
user_data = getter('user_data')
201201
name = getter('instance_name')
202202
lxd_config_dict = getter('lxd_config_dict')
203+
lxd_use_exec = fixture_utils.closest_marker_args_or(
204+
request, 'lxd_use_exec', None
205+
)
203206

204207
launch_kwargs = {}
205208
if name is not None:
@@ -208,10 +211,18 @@ def _client(request, fixture_utils, session_cloud: IntegrationCloud):
208211
if not isinstance(session_cloud, _LxdIntegrationCloud):
209212
pytest.skip("lxd_config_dict requires LXD")
210213
launch_kwargs["config_dict"] = lxd_config_dict
214+
if lxd_use_exec is not None:
215+
if not isinstance(session_cloud, _LxdIntegrationCloud):
216+
pytest.skip("lxd_use_exec requires LXD")
217+
launch_kwargs["execute_via_ssh"] = False
211218

212219
with session_cloud.launch(
213220
user_data=user_data, launch_kwargs=launch_kwargs
214221
) as instance:
222+
if lxd_use_exec is not None:
223+
# Existing instances are not affected by the launch kwargs, so
224+
# ensure it here; we still need the launch kwarg so waiting works
225+
instance.execute_via_ssh = False
215226
previous_failures = request.session.testsfailed
216227
yield instance
217228
test_failed = request.session.testsfailed - previous_failures > 0

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ markers =
176176
oci: test will only run on OCI platform
177177
lxd_config_dict: set the config_dict passed on LXD instance creation
178178
lxd_container: test will only run in LXD container
179+
lxd_use_exec: `execute` will use `lxc exec` instead of SSH
179180
lxd_vm: test will only run in LXD VM
180181
not_xenial: test cannot run on the xenial release
181182
not_bionic: test cannot run on the bionic release

0 commit comments

Comments
 (0)