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
diff --git a/systemtests/api.py b/systemtests/api.py
index a82fde4..ed92d21 100644
--- a/systemtests/api.py
+++ b/systemtests/api.py
@@ -262,16 +262,17 @@ class AuthenticatedAPIClient:
262 delay=30,262 delay=30,
263 )263 )
264264
265 def create_zone(self, name: str, description: str) -> Any:265 def create_zone(self, name: str, description: str) -> dict[str, Any]:
266 return self.execute(266 zone: dict[str, Any] = self.execute(
267 ["zones", "create", f"name={name}", f"description={description}"]267 ["zones", "create", f"name={name}", f"description={description}"]
268 )268 )
269 return zone
269270
270 def list_zones(self) -> list[dict[str, Any]]:271 def list_zones(self) -> list[dict[str, Any]]:
271 zones: list[dict[str, Any]] = self.execute(["zones", "read"])272 zones: list[dict[str, Any]] = self.execute(["zones", "read"])
272 return zones273 return zones
273274
274 def read_zone(self, zone_name: str) -> Any:275 def read_zone(self, zone_name: str) -> dict[str, Any]:
275 zone: dict[str, Any] = self.execute(["zone", "read", zone_name])276 zone: dict[str, Any] = self.execute(["zone", "read", zone_name])
276 return zone277 return zone
277278
@@ -280,7 +281,7 @@ class AuthenticatedAPIClient:
280 zone_name: str,281 zone_name: str,
281 new_name: Optional[str] = None,282 new_name: Optional[str] = None,
282 new_description: Optional[str] = None,283 new_description: Optional[str] = None,
283 ) -> Any:284 ) -> dict[str, Any]:
284 cmd = ["zone", "update", zone_name]285 cmd = ["zone", "update", zone_name]
285 if new_name is not None:286 if new_name is not None:
286 cmd.append(f"name={new_name}")287 cmd.append(f"name={new_name}")
@@ -301,10 +302,11 @@ class AuthenticatedAPIClient:
301 else:302 else:
302 return result303 return result
303304
304 def create_pool(self, name: str, description: str) -> Any:305 def create_pool(self, name: str, description: str) -> dict[str, Any]:
305 return self.execute(306 pool: dict[str, Any] = self.execute(
306 ["resource-pools", "create", f"name={name}", f"description={description}"]307 ["resource-pools", "create", f"name={name}", f"description={description}"]
307 )308 )
309 return pool
308310
309 def list_pools(self) -> list[dict[str, Any]]:311 def list_pools(self) -> list[dict[str, Any]]:
310 resource_pools: list[dict[str, Any]] = self.execute(["resource-pools", "read"])312 resource_pools: list[dict[str, Any]] = self.execute(["resource-pools", "read"])
@@ -331,11 +333,12 @@ class AuthenticatedAPIClient:
331 pool_obj: dict[str, Any] = self.execute(cmd)333 pool_obj: dict[str, Any] = self.execute(cmd)
332 return pool_obj334 return pool_obj
333335
334 def delete_pool(self, pool: dict[str, Any]) -> Any:336 def delete_pool(self, pool: dict[str, Any]) -> str:
335 try:337 try:
336 return self.execute(338 result: str = self.execute(
337 ["resource-pool", "delete", str(pool["id"])], json_output=False339 ["resource-pool", "delete", str(pool["id"])], json_output=False
338 )340 )
341 return result
339 except CalledProcessError as err:342 except CalledProcessError as err:
340 if "cannot be deleted" in err.stdout:343 if "cannot be deleted" in err.stdout:
341 raise CannotDeleteError(err.stdout)344 raise CannotDeleteError(err.stdout)
diff --git a/systemtests/region.py b/systemtests/region.py
index 5ca3901..ed8856f 100644
--- a/systemtests/region.py
+++ b/systemtests/region.py
@@ -10,7 +10,7 @@ from .lxd import get_lxd
10from .utils import retries10from .utils import retries
1111
12if TYPE_CHECKING:12if TYPE_CHECKING:
13 from . import api13 from .api import AuthenticatedAPIClient
1414
15LOG = getLogger("systemtests.region")15LOG = getLogger("systemtests.region")
1616
@@ -35,7 +35,9 @@ class MAASRegion:
35 except subprocess.CalledProcessError:35 except subprocess.CalledProcessError:
36 return False36 return False
3737
38 def create_user(self, user: str, password: str, email: str) -> Any:38 def create_user(
39 self, user: str, password: str, email: str
40 ) -> subprocess.CompletedProcess[str]:
39 return self.execute(41 return self.execute(
40 [42 [
41 "maas",43 "maas",
@@ -62,7 +64,7 @@ class MAASRegion:
62 }64 }
6365
64 def enable_dhcp(66 def enable_dhcp(
65 self, config: dict[str, Any], client: api.AuthenticatedAPIClient67 self, config: dict[str, Any], client: AuthenticatedAPIClient
66 ) -> None:68 ) -> None:
67 rack_controllers = get_rack_controllers(client)69 rack_controllers = get_rack_controllers(client)
68 for network in config["networks"].values():70 for network in config["networks"].values():
@@ -85,7 +87,7 @@ class MAASRegion:
85 raise AssertionError("DHCP couldn't be enabled.")87 raise AssertionError("DHCP couldn't be enabled.")
8688
87 def disable_dhcp(89 def disable_dhcp(
88 self, config: dict[str, Any], client: api.AuthenticatedAPIClient90 self, config: dict[str, Any], client: AuthenticatedAPIClient
89 ) -> None:91 ) -> None:
90 rack_controllers = get_rack_controllers(client)92 rack_controllers = get_rack_controllers(client)
91 ip_ranges = client.list_ip_ranges()93 ip_ranges = client.list_ip_ranges()
@@ -114,7 +116,7 @@ class MAASRegion:
114 lxd = get_lxd(LOG)116 lxd = get_lxd(LOG)
115 return lxd.file_exists(self.maas_container, dhcpd_conf_path)117 return lxd.file_exists(self.maas_container, dhcpd_conf_path)
116118
117 def set_config(self, key: str, value: str = "") -> Any:119 def set_config(self, key: str, value: str = "") -> subprocess.CompletedProcess[str]:
118 if self.installed_from_snap:120 if self.installed_from_snap:
119 prefix_cmd = ["maas", "config"]121 prefix_cmd = ["maas", "config"]
120 else:122 else:
@@ -122,14 +124,14 @@ class MAASRegion:
122 cmd = prefix_cmd + [f"--{key}", value]124 cmd = prefix_cmd + [f"--{key}", value]
123 return self.execute(cmd)125 return self.execute(cmd)
124126
125 def restart(self) -> Any:127 def restart(self) -> subprocess.CompletedProcess[str]:
126 if self.installed_from_snap:128 if self.installed_from_snap:
127 cmd = ["snap", "restart", "maas"]129 cmd = ["snap", "restart", "maas"]
128 else:130 else:
129 cmd = ["systemctl", "restart", "maas-regiond"]131 cmd = ["systemctl", "restart", "maas-regiond"]
130 return self.execute(cmd)132 return self.execute(cmd)
131133
132 def enable_debug(self) -> Any:134 def enable_debug(self) -> subprocess.CompletedProcess[str]:
133 if self.installed_from_snap:135 if self.installed_from_snap:
134 return self.execute(["maas", "config", "--enable-debug"])136 return self.execute(["maas", "config", "--enable-debug"])
135 else:137 else:
@@ -147,7 +149,7 @@ def get_dhcp_controller(
147 raise AssertionError(f"Couldn't find rack controller managing DHCP for {cidr}")149 raise AssertionError(f"Couldn't find rack controller managing DHCP for {cidr}")
148150
149151
150def get_rack_controllers(client: api.AuthenticatedAPIClient) -> list[dict[str, Any]]:152def get_rack_controllers(client: AuthenticatedAPIClient) -> list[dict[str, Any]]:
151 """Repeatedly attempt to get rack controllers"""153 """Repeatedly attempt to get rack controllers"""
152 attempts = count(1)154 attempts = count(1)
153 for elapsed, _ in retries(timeout=300, delay=10):155 for elapsed, _ in retries(timeout=300, delay=10):

Subscribers

People subscribed via source and target branches

to all changes: