Merge ~adam-collard/maas-ci/+git/system-tests:strict-mypy into ~maas-committers/maas-ci/+git/system-tests:master

Proposed by Adam Collard
Status: Merged
Approved by: Adam Collard
Approved revision: ef3006582340306efb9c56833eb34f3f09258062
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~adam-collard/maas-ci/+git/system-tests:strict-mypy
Merge into: ~maas-committers/maas-ci/+git/system-tests:master
Diff against target: 140 lines (+21/-16)
2 files modified
systemtests/api.py (+11/-8)
systemtests/region.py (+10/-8)
Reviewer Review Type Date Requested Status
Alberto Donato (community) Approve
MAAS Lander Approve
Review via email: mp+408073@code.launchpad.net

Commit message

Less Any, more types

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

UNIT TESTS
-b strict-mypy lp:~adam-collard/maas-ci/+git/system-tests into -b master lp:~maas-committers/maas-ci/+git/system-tests

STATUS: SUCCESS
COMMIT: ef3006582340306efb9c56833eb34f3f09258062

review: Approve
Revision history for this message
Alberto Donato (ack) wrote (last edit ):

+1

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 a82fde4..ed92d21 100644
3--- a/systemtests/api.py
4+++ b/systemtests/api.py
5@@ -262,16 +262,17 @@ class AuthenticatedAPIClient:
6 delay=30,
7 )
8
9- def create_zone(self, name: str, description: str) -> Any:
10- return self.execute(
11+ def create_zone(self, name: str, description: str) -> dict[str, Any]:
12+ zone: dict[str, Any] = self.execute(
13 ["zones", "create", f"name={name}", f"description={description}"]
14 )
15+ return zone
16
17 def list_zones(self) -> list[dict[str, Any]]:
18 zones: list[dict[str, Any]] = self.execute(["zones", "read"])
19 return zones
20
21- def read_zone(self, zone_name: str) -> Any:
22+ def read_zone(self, zone_name: str) -> dict[str, Any]:
23 zone: dict[str, Any] = self.execute(["zone", "read", zone_name])
24 return zone
25
26@@ -280,7 +281,7 @@ class AuthenticatedAPIClient:
27 zone_name: str,
28 new_name: Optional[str] = None,
29 new_description: Optional[str] = None,
30- ) -> Any:
31+ ) -> dict[str, Any]:
32 cmd = ["zone", "update", zone_name]
33 if new_name is not None:
34 cmd.append(f"name={new_name}")
35@@ -301,10 +302,11 @@ class AuthenticatedAPIClient:
36 else:
37 return result
38
39- def create_pool(self, name: str, description: str) -> Any:
40- return self.execute(
41+ def create_pool(self, name: str, description: str) -> dict[str, Any]:
42+ pool: dict[str, Any] = self.execute(
43 ["resource-pools", "create", f"name={name}", f"description={description}"]
44 )
45+ return pool
46
47 def list_pools(self) -> list[dict[str, Any]]:
48 resource_pools: list[dict[str, Any]] = self.execute(["resource-pools", "read"])
49@@ -331,11 +333,12 @@ class AuthenticatedAPIClient:
50 pool_obj: dict[str, Any] = self.execute(cmd)
51 return pool_obj
52
53- def delete_pool(self, pool: dict[str, Any]) -> Any:
54+ def delete_pool(self, pool: dict[str, Any]) -> str:
55 try:
56- return self.execute(
57+ result: str = self.execute(
58 ["resource-pool", "delete", str(pool["id"])], json_output=False
59 )
60+ return result
61 except CalledProcessError as err:
62 if "cannot be deleted" in err.stdout:
63 raise CannotDeleteError(err.stdout)
64diff --git a/systemtests/region.py b/systemtests/region.py
65index 5ca3901..ed8856f 100644
66--- a/systemtests/region.py
67+++ b/systemtests/region.py
68@@ -10,7 +10,7 @@ from .lxd import get_lxd
69 from .utils import retries
70
71 if TYPE_CHECKING:
72- from . import api
73+ from .api import AuthenticatedAPIClient
74
75 LOG = getLogger("systemtests.region")
76
77@@ -35,7 +35,9 @@ class MAASRegion:
78 except subprocess.CalledProcessError:
79 return False
80
81- def create_user(self, user: str, password: str, email: str) -> Any:
82+ def create_user(
83+ self, user: str, password: str, email: str
84+ ) -> subprocess.CompletedProcess[str]:
85 return self.execute(
86 [
87 "maas",
88@@ -62,7 +64,7 @@ class MAASRegion:
89 }
90
91 def enable_dhcp(
92- self, config: dict[str, Any], client: api.AuthenticatedAPIClient
93+ self, config: dict[str, Any], client: AuthenticatedAPIClient
94 ) -> None:
95 rack_controllers = get_rack_controllers(client)
96 for network in config["networks"].values():
97@@ -85,7 +87,7 @@ class MAASRegion:
98 raise AssertionError("DHCP couldn't be enabled.")
99
100 def disable_dhcp(
101- self, config: dict[str, Any], client: api.AuthenticatedAPIClient
102+ self, config: dict[str, Any], client: AuthenticatedAPIClient
103 ) -> None:
104 rack_controllers = get_rack_controllers(client)
105 ip_ranges = client.list_ip_ranges()
106@@ -114,7 +116,7 @@ class MAASRegion:
107 lxd = get_lxd(LOG)
108 return lxd.file_exists(self.maas_container, dhcpd_conf_path)
109
110- def set_config(self, key: str, value: str = "") -> Any:
111+ def set_config(self, key: str, value: str = "") -> subprocess.CompletedProcess[str]:
112 if self.installed_from_snap:
113 prefix_cmd = ["maas", "config"]
114 else:
115@@ -122,14 +124,14 @@ class MAASRegion:
116 cmd = prefix_cmd + [f"--{key}", value]
117 return self.execute(cmd)
118
119- def restart(self) -> Any:
120+ def restart(self) -> subprocess.CompletedProcess[str]:
121 if self.installed_from_snap:
122 cmd = ["snap", "restart", "maas"]
123 else:
124 cmd = ["systemctl", "restart", "maas-regiond"]
125 return self.execute(cmd)
126
127- def enable_debug(self) -> Any:
128+ def enable_debug(self) -> subprocess.CompletedProcess[str]:
129 if self.installed_from_snap:
130 return self.execute(["maas", "config", "--enable-debug"])
131 else:
132@@ -147,7 +149,7 @@ def get_dhcp_controller(
133 raise AssertionError(f"Couldn't find rack controller managing DHCP for {cidr}")
134
135
136-def get_rack_controllers(client: api.AuthenticatedAPIClient) -> list[dict[str, Any]]:
137+def get_rack_controllers(client: AuthenticatedAPIClient) -> list[dict[str, Any]]:
138 """Repeatedly attempt to get rack controllers"""
139 attempts = count(1)
140 for elapsed, _ in retries(timeout=300, delay=10):

Subscribers

People subscribed via source and target branches

to all changes: