Merge ~adam-collard/maas-ci/+git/system-tests:power-state-directly into ~maas-committers/maas-ci/+git/system-tests:master

Proposed by Adam Collard
Status: Merged
Approved by: Diego Mascialino
Approved revision: 326ca3d4cfdae88303a4044d1fcf1a6f98dda2bf
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~adam-collard/maas-ci/+git/system-tests:power-state-directly
Merge into: ~maas-committers/maas-ci/+git/system-tests:master
Diff against target: 59 lines (+12/-6)
3 files modified
systemtests/api.py (+10/-0)
systemtests/tests_per_machine/test_hardware_sync.py (+1/-4)
systemtests/utils.py (+1/-2)
Reviewer Review Type Date Requested Status
Diego Mascialino (community) Approve
MAAS Lander Approve
Review via email: mp+426892@code.launchpad.net

Commit message

Query power state directly when waiting

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

UNIT TESTS
-b power-state-directly lp:~adam-collard/maas-ci/+git/system-tests into -b master lp:~maas-committers/maas-ci/+git/system-tests

STATUS: SUCCESS
COMMIT: 326ca3d4cfdae88303a4044d1fcf1a6f98dda2bf

review: Approve
Revision history for this message
Diego Mascialino (dmascialino) :
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 4fe28d6..0bf1c14 100644
3--- a/systemtests/api.py
4+++ b/systemtests/api.py
5@@ -65,6 +65,10 @@ class Tag(TypedDict):
6 resource_uri: str
7
8
9+class PowerResponse(TypedDict):
10+ state: str
11+
12+
13 # TODO: Expand these to TypedDict matching API response structure
14
15 Subnet = Dict[str, Any]
16@@ -662,6 +666,12 @@ class AuthenticatedAPIClient:
17 )
18 return result
19
20+ def query_power_state(self, machine: Machine) -> str:
21+ result: PowerResponse = self.execute(
22+ ["machine", "query-power-state", machine["system_id"]]
23+ )
24+ return result["state"]
25+
26
27 class QuietAuthenticatedAPIClient(AuthenticatedAPIClient):
28 """An Authenticated API Client that is quiet."""
29diff --git a/systemtests/tests_per_machine/test_hardware_sync.py b/systemtests/tests_per_machine/test_hardware_sync.py
30index 3e24d1c..d7f9243 100644
31--- a/systemtests/tests_per_machine/test_hardware_sync.py
32+++ b/systemtests/tests_per_machine/test_hardware_sync.py
33@@ -232,11 +232,8 @@ def test_hardware_sync(
34
35 yield remove_device
36
37- system_id = hardware_sync_machine.machine["system_id"]
38 for retry_info in retries(60, 5):
39- power_state = maas_api_client.execute(
40- ["machine", system_id, "query-power_state"]
41- )["state"]
42+ power_state = maas_api_client.query_power_state(hardware_sync_machine.machine)
43 if power_state == "off":
44 break
45 elif power_state == "on":
46diff --git a/systemtests/utils.py b/systemtests/utils.py
47index a6302aa..8a829b8 100644
48--- a/systemtests/utils.py
49+++ b/systemtests/utils.py
50@@ -208,8 +208,7 @@ def wait_for_machine_to_power_off(
51 """Blocks execution until the given machine is powered off."""
52 quiet_client = api.QuietAuthenticatedAPIClient.from_api_client(api_client)
53 for retry_info in retries(10 * 60, 10):
54- machine = quiet_client.read_machine(machine)
55- power_state = machine["power_state"]
56+ power_state = quiet_client.query_power_state(machine)
57 if power_state == "off":
58 quiet_client.logger.debug(f"{machine_name} is powered off, continuing")
59 return machine

Subscribers

People subscribed via source and target branches

to all changes: