Merge ~adam-collard/maas-ci/+git/system-tests:lxd-vm-bug into ~maas-committers/maas-ci/+git/system-tests:master

Proposed by Adam Collard
Status: Merged
Approved by: Adam Collard
Approved revision: cbcdc8148d0104d843bcc034aa2267884c04f5f5
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~adam-collard/maas-ci/+git/system-tests:lxd-vm-bug
Merge into: ~maas-committers/maas-ci/+git/system-tests:master
Diff against target: 88 lines (+17/-12)
3 files modified
systemtests/api.py (+4/-0)
systemtests/conftest.py (+10/-7)
systemtests/utils.py (+3/-5)
Reviewer Review Type Date Requested Status
MAAS Lander Approve
Diego Mascialino (community) Approve
Review via email: mp+427363@code.launchpad.net

Commit message

Expose LXD on AuthenticatedAPIClient

Refactor with a tiny change to report machine_name instead of hostname

To post a comment you must log in.
Revision history for this message
Diego Mascialino (dmascialino) :
review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b lxd-vm-bug lp:~adam-collard/maas-ci/+git/system-tests into -b master lp:~maas-committers/maas-ci/+git/system-tests

STATUS: SUCCESS
COMMIT: cbcdc8148d0104d843bcc034aa2267884c04f5f5

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/systemtests/api.py b/systemtests/api.py
2index cff8d03..7e68c0e 100644
3--- a/systemtests/api.py
4+++ b/systemtests/api.py
5@@ -134,6 +134,10 @@ class AuthenticatedAPIClient:
6 return f"<AuthenticatedAPIClient for {self.api_client.url!r}>"
7
8 @property
9+ def lxd(self) -> lxd.CLILXD:
10+ return self.api_client.lxd
11+
12+ @property
13 def logger(self) -> Logger:
14 return self.api_client.logger
15
16diff --git a/systemtests/conftest.py b/systemtests/conftest.py
17index 553be7a..1c92187 100644
18--- a/systemtests/conftest.py
19+++ b/systemtests/conftest.py
20@@ -1,5 +1,6 @@
21 from __future__ import annotations
22
23+from logging import getLogger
24 from typing import TYPE_CHECKING, Any, Iterator
25
26 import pytest
27@@ -28,6 +29,7 @@ from .fixtures import (
28 unauthenticated_maas_api_client,
29 zone,
30 )
31+from .lxd import get_lxd
32 from .machine_config import MachineConfig
33 from .state import (
34 authenticated_admin,
35@@ -71,6 +73,8 @@ __all__ = [
36
37 STATUS_READY = 4
38
39+LOG = getLogger("systemtests.conftest")
40+
41
42 def pytest_addoption(parser: Parser) -> None:
43 def config_type(filename: str) -> dict[str, Any]:
44@@ -157,13 +161,12 @@ def hardware_sync_machine(
45 devices_config=machine_config.devices_config,
46 )
47 if machine_config.power_type == "lxd":
48- devices = authenticated_admin.api_client.lxd.list_instance_devices(
49- machine_config.name
50- )
51- for device in machine_config.devices_config:
52- if device["device_name"] in devices:
53- authenticated_admin.api_client.lxd.remove_instance_device(
54- machine_config.name, device["device_name"]
55+ lxd = get_lxd(LOG)
56+ current_devices = lxd.list_instance_devices(machine_config.name)
57+ for additional_device in machine_config.devices_config:
58+ if additional_device["device_name"] in current_devices:
59+ lxd.remove_instance_device(
60+ machine_config.name, additional_device["device_name"]
61 )
62 authenticated_admin.release_machine(machine)
63 wait_for_machine(
64diff --git a/systemtests/utils.py b/systemtests/utils.py
65index 8a829b8..98456d2 100644
66--- a/systemtests/utils.py
67+++ b/systemtests/utils.py
68@@ -197,7 +197,7 @@ def wait_for_new_machine(
69 maybe_machines = quiet_client.list_machines(mac_address=mac_address)
70 debug_outputs.append(repr(maybe_machines))
71 if "lxd" in [m["power_type"] for m in machines]:
72- debug_outputs.append(repr(api_client.api_client.lxd.list_instances()))
73+ debug_outputs.append(repr(api_client.lxd.list_instances()))
74
75 raise UnexpectedMachineStatus(mac_address, "New", retry_info.elapsed, debug_outputs)
76
77@@ -219,11 +219,9 @@ def wait_for_machine_to_power_off(
78
79 debug_outputs = [repr(machine)]
80 if machine["power_type"] == "lxd":
81- debug_outputs.append(
82- repr(api_client.api_client.lxd.list_instances()[machine_name])
83- )
84+ debug_outputs.append(repr(api_client.lxd.list_instances()[machine_name]))
85 raise UnexpectedMachineStatus(
86- machine["hostname"], "power_off", retry_info.elapsed, debug_outputs
87+ machine_name, "power_off", retry_info.elapsed, debug_outputs
88 )
89
90

Subscribers

People subscribed via source and target branches

to all changes: