Skip to content

Commit dfc0ffb

Browse files
committed
Refactor and fix types to get pyright happy
1 parent 8674d33 commit dfc0ffb

File tree

15 files changed

+104
-84
lines changed

15 files changed

+104
-84
lines changed

python/understack-workflows/tests/test_bmc_chassis_info.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@
55
from ipaddress import IPv4Interface
66

77
from understack_workflows import bmc_chassis_info
8+
from understack_workflows.bmc import Bmc
89

9-
FIXTURE_PATH = "json_samples/bmc_chassis_info"
10+
FIXTURE_PATH = pathlib.Path("json_samples/bmc_chassis_info")
1011

1112

12-
class FakeBmc:
13+
class FakeBmc(Bmc):
1314
def __init__(self, fixtures):
1415
self.fixtures = fixtures
1516
self.ip_address = "1.2.3.4"
1617

17-
def redfish_request(self, path: str) -> dict:
18+
def redfish_request(self, path: str, *_args, **_kw) -> dict:
1819
path = path.replace("/", "_") + ".json"
1920
return self.fixtures[path]
2021

python/understack-workflows/tests/test_nautobot_device.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def test_find_or_create():
162162
description="Integrated NIC 1 Port 1",
163163
mac_address="D4:04:E6:4F:8D:B4",
164164
status="Active",
165-
ip_address=[],
165+
ip_address=None,
166166
neighbor_device_id="275ef491-2b27-4d1b-bd45-330bd6b7e0cf",
167167
neighbor_device_name="f20-2-1.iad3.rackspace.net",
168168
neighbor_interface_id="f9a5cc87-d10a-4827-99e8-48961fd1d773",
@@ -178,7 +178,7 @@ def test_find_or_create():
178178
description="Integrated NIC 1 Port 2",
179179
mac_address="D4:04:E6:4F:8D:B5",
180180
status="Active",
181-
ip_address=[],
181+
ip_address=None,
182182
neighbor_device_id="05f6715a-4dbe-4fd6-af20-1e73adb285c2",
183183
neighbor_device_name="f20-2-2.iad3.rackspace.net",
184184
neighbor_interface_id="2148cf50-f70e-42c9-9f68-8ce98d61498c",
@@ -194,7 +194,7 @@ def test_find_or_create():
194194
description="NIC in Slot 1 Port 1",
195195
mac_address="14:23:F3:F5:25:F0",
196196
status="Active",
197-
ip_address=[],
197+
ip_address=None,
198198
neighbor_device_id="05f6715a-4dbe-4fd6-af20-1e73adb285c2",
199199
neighbor_device_name="f20-2-2.iad3.rackspace.net",
200200
neighbor_interface_id="f72bb830-3f3c-4aba-b7d5-9680ea4d358e",
@@ -210,7 +210,7 @@ def test_find_or_create():
210210
description="NIC in Slot 1 Port 2",
211211
mac_address="14:23:F3:F5:25:F1",
212212
status="Active",
213-
ip_address=[],
213+
ip_address=None,
214214
neighbor_device_id="275ef491-2b27-4d1b-bd45-330bd6b7e0cf",
215215
neighbor_device_name="f20-2-1.iad3.rackspace.net",
216216
neighbor_interface_id="c210be75-1038-4ba3-9923-60050e1c5362",

python/understack-workflows/tests/test_topology.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
type="A_25GBASE_X_SFP28",
1818
description="Integrated NIC 1 Port 1",
1919
mac_address="D4:04:E6:4F:8D:B4",
20-
status={"id": "d4bcbafa-3033-433b-b21b-a20acf9d1324"},
21-
ip_address=[],
20+
status="Active",
21+
ip_address=None,
2222
neighbor_device_id="275ef491-2b27-4d1b-bd45-330bd6b7e0cf",
2323
neighbor_device_name="f20-2-1.iad3.rackspace.net",
2424
neighbor_interface_id="f9a5cc87-d10a-4827-99e8-48961fd1d773",
@@ -33,8 +33,8 @@
3333
type="A_25GBASE_X_SFP28",
3434
description="Integrated NIC 1 Port 2",
3535
mac_address="D4:04:E6:4F:8D:B5",
36-
status={"id": "d4bcbafa-3033-433b-b21b-a20acf9d1324"},
37-
ip_address=[],
36+
status="Active",
37+
ip_address=None,
3838
neighbor_device_id="05f6715a-4dbe-4fd6-af20-1e73adb285c2",
3939
neighbor_device_name="f20-2-2.iad3.rackspace.net",
4040
neighbor_interface_id="2148cf50-f70e-42c9-9f68-8ce98d61498c",

python/understack-workflows/understack_workflows/bmc.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from understack_workflows.bmc_password_standard import standard_password
1010
from understack_workflows.helpers import credential
1111

12-
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
12+
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) # type: ignore
1313
logging.getLogger("urllib3").setLevel(logging.WARNING)
1414

1515
HEADERS = {
@@ -58,6 +58,8 @@ def redfish_request(
5858
)
5959
if r.text:
6060
return r.json()
61+
else:
62+
return {}
6163

6264
def sushy(self):
6365
return Sushy(

python/understack-workflows/understack_workflows/bmc_credentials.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from understack_workflows.helpers import setup_logger
55

6-
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
6+
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) # type: ignore
77

88
FACTORY_PASSWORD = "calvin"
99

@@ -45,7 +45,7 @@ def set_bmc_password(ip_address, required_password, username="root"):
4545
logger.info("Production BMC credentials are working on this BMC.")
4646

4747

48-
def _verify_auth(host: str, username: str = "root", password: str = "") -> str:
48+
def _verify_auth(host: str, username: str = "root", password: str = "") -> str | None:
4949
"""Test whether provided credentials work against a secured API endpoint.
5050
5151
Returns Session authentication token on success

python/understack-workflows/understack_workflows/bmc_network_config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ def bmc_set_permanent_ip_addr(bmc: Bmc, interface_info: InterfaceInfo):
1616
logger.info("BMC interface was not set to DHCP")
1717
return
1818

19+
if not (interface_info.ipv4_address and interface_info.ipv4_gateway):
20+
raise ValueError("BMC InterfaceInfo has missing IP information")
21+
1922
payload = {
2023
"Attributes": {
2124
"IPv4.1.DHCPEnable": "Disabled",

python/understack-workflows/understack_workflows/ironic/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def delete_port(self, port_id: str):
5858
port_id,
5959
)
6060

61-
def list_ports(self, node_id: dict):
61+
def list_ports(self, node_id: str):
6262
self._ensure_logged_in()
6363

6464
return self.client.port.list(node=node_id, detail=True)

python/understack-workflows/understack_workflows/ironic_node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def create_or_update(
2929
ironic_node = create_ironic_node(
3030
client, node_uuid, device_hostname, driver, bmc
3131
)
32-
return ironic_node.provision_state
32+
return ironic_node.provision_state # type: ignore
3333

3434
if ironic_node.provision_state in STATES_ALLOWING_UPDATES:
3535
update_ironic_node(client, node_uuid, device_hostname, driver, bmc)

python/understack-workflows/understack_workflows/main/print_bmc_password.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def main(program_name, bmc_ip_address=None):
1818
print("Please set the BMC_MASTER environment variable", file=sys.stderr)
1919
exit(1)
2020

21-
password = standard_password(bmc_ip_address, os.getenv("BMC_MASTER"))
21+
password = standard_password(str(bmc_ip_address), str(os.getenv("BMC_MASTER")))
2222
print(password)
2323

2424

python/understack-workflows/understack_workflows/main/sync_keystone.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,16 @@ def handle_project_create(conn: Connection, nautobot: Nautobot, project_id: uuid
7171
ten = ten_api.create(
7272
id=str(project_id), name=project.name, description=project.description
7373
)
74-
logger.info(f"tenant '{project_id!s}' created {ten.created}")
74+
logger.info(f"tenant '{project_id!s}' created {ten.created}") # type: ignore
7575

7676

7777
def handle_project_update(conn: Connection, nautobot: Nautobot, project_id: uuid.UUID):
7878
logger.info(f"got request to update tenant {project_id!s}")
7979
project = conn.identity.get_project(project_id.hex)
8080
ten = nautobot.session.tenancy.tenants.get(project_id)
81-
ten.description = project.description
82-
ten.save()
83-
logger.info(f"tenant '{project_id!s}' last updated {ten.last_updated}")
81+
ten.description = project.description # type: ignore
82+
ten.save() # type: ignore
83+
logger.info(f"tenant '{project_id!s}' last updated {ten.last_updated}") # type: ignore
8484

8585

8686
def handle_project_delete(conn: Connection, nautobot: Nautobot, project_id: uuid.UUID):
@@ -89,7 +89,7 @@ def handle_project_delete(conn: Connection, nautobot: Nautobot, project_id: uuid
8989
if not ten:
9090
logger.warn(f"tenant '{project_id!s}' does not exist already")
9191
return
92-
ten.delete()
92+
ten.delete() # type: ignore
9393
logger.info(f"deleted tenant {project_id!s}")
9494

9595

0 commit comments

Comments
 (0)