Skip to content

Commit e86e2e6

Browse files
committed
chore: enable additional Python code quality checks and fixes
Enabled a number of additional Python code quality checks and perform all the fixes associated with them.
1 parent a256983 commit e86e2e6

36 files changed

Lines changed: 383 additions & 367 deletions

python/cinder-understack/pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,9 @@ filterwarnings = "ignore::DeprecationWarning"
4949
# use our default and override anything we need specifically
5050
extend = "../pyproject.toml"
5151
target-version = "py312"
52+
53+
[tool.ruff.lint.per-file-ignores]
54+
"cinder_understack/tests/*.py" = [
55+
"S101", # allow 'assert' for pytest
56+
"PT009", # OpenStack TestCase base class uses unittest-style assertions
57+
]

python/ironic-understack/ironic_understack/inspect_hook_update_baremetal_ports.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import re
22
from typing import Any
3+
from typing import ClassVar
34

45
from ironic import objects
56
from ironic.common import exception
@@ -19,7 +20,7 @@ class InspectHookUpdateBaremetalPorts(base.InspectionHook):
1920

2021
# "validate-interfaces" provides the all_interfaces field in plugin_data.
2122
# "parse-lldp" provides the parsed_lldp field in plugin_data.
22-
dependencies = ["validate-interfaces", "parse-lldp"]
23+
dependencies: ClassVar[list[str]] = ["validate-interfaces", "parse-lldp"]
2324

2425
def __call__(self, task, inventory, plugin_data):
2526
"""Update Ports' local_link_info and physnet based on LLDP data.

python/ironic-understack/ironic_understack/port_bios_name_hook.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import ClassVar
2+
13
from ironic.drivers.modules.inspector.hooks import base
24
from oslo_log import log as logging
35

@@ -22,7 +24,7 @@ class PortBiosNameHook(base.InspectionHook):
2224

2325
# "ports" hook creates baremetal ports for each physical NIC, be sure to run
2426
# this first because we will only be updating ports that already exist:
25-
dependencies = ["ports"]
27+
dependencies: ClassVar[list[str]] = ["ports"]
2628

2729
def __call__(self, task, inventory, plugin_data):
2830
"""Populate the baremetal_port.extra.bios_name attribute."""

python/ironic-understack/ironic_understack/redfish_inspect_understack.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def inspect_hardware(self, task):
105105
LOG.warning("No resource class matched for %s", task.node.uuid)
106106
return upstream_state
107107

108-
device_type, resource_class = match_result
108+
_device_type, resource_class = match_result
109109
LOG.info("Matched %s to resource class %s", task.node.uuid, resource_class.name)
110110

111111
task.node.resource_class = resource_class.name

python/ironic-understack/ironic_understack/resource_class.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,5 @@ def classify(self, machine):
8484
if not match_result:
8585
raise NoMatchError(f"No resource class found for {machine}")
8686
else:
87-
device_type, resource_class = match_result
87+
_device_type, resource_class = match_result
8888
return resource_class.name

python/ironic-understack/ironic_understack/tests/test_portgroup_name_middleware.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ def test_invalid_number_above_range(self):
7373
assert str(PORT_CHANNEL_MAX) in error
7474

7575
def test_invalid_number_zero(self):
76-
is_valid, error = validate_portgroup_name("node01-port-channel0")
76+
is_valid, _ = validate_portgroup_name("node01-port-channel0")
7777
assert is_valid is False
7878

7979
def test_invalid_number_very_large(self):
80-
is_valid, error = validate_portgroup_name("node01-port-channel99999")
80+
is_valid, _ = validate_portgroup_name("node01-port-channel99999")
8181
assert is_valid is False
8282

8383

python/ironic-understack/ironic_understack/tests/test_vlan_group_name_convention.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,13 @@ def test_vlan_group_name_invalid_format():
8787

8888

8989
def test_vlan_group_name_unknown_suffix():
90-
with pytest.raises(TopologyError, match="suffix a1-1-99.abc1 is not present"):
90+
with pytest.raises(TopologyError, match=r"suffix a1-1-99\.abc1 is not present"):
9191
vlan_group_names([port("a1-1-99.abc1")], mapping)
9292

93-
with pytest.raises(TopologyError, match="suffix a1-1-5f.abc1 is not present"):
93+
with pytest.raises(TopologyError, match=r"suffix a1-1-5f\.abc1 is not present"):
9494
vlan_group_names([port("a1-1-5f.abc1")], mapping)
9595

96-
with pytest.raises(TopologyError, match="suffix a1-1-xyz.abc1 is not present"):
96+
with pytest.raises(TopologyError, match=r"suffix a1-1-xyz\.abc1 is not present"):
9797
vlan_group_names([port("a1-1-xyz.abc1")], mapping)
9898

9999

python/neutron-understack/neutron_understack/routers.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,7 @@ def is_only_router_port_on_network(
7878
)
7979

8080
LOG.debug("Router ports found: %(ports)s", {"ports": other_router_ports})
81-
if len(other_router_ports) > 1:
82-
return False
83-
else:
84-
return True
81+
return not len(other_router_ports) > 1
8582

8683

8784
def add_subport_to_trunk(shared_port: PortDict, segment: NetworkSegmentDict) -> None:
@@ -138,7 +135,7 @@ def fetch_or_create_router_segment(context: PortContext) -> NetworkSegmentDict:
138135

139136
def ovn_client() -> OVNClient | None:
140137
"""Retrieve the OVN client from the OVN ML2 plugin."""
141-
global _cached_ovn_client
138+
global _cached_ovn_client # noqa: PLW0603
142139
if _cached_ovn_client:
143140
return _cached_ovn_client
144141

python/neutron-understack/neutron_understack/tests/conftest.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def network(project_id, network_id) -> Network:
103103

104104

105105
@pytest.fixture
106-
def patch_extend_subnet(mocker) -> None:
106+
def _patch_extend_subnet(mocker) -> None:
107107
"""Ml2 Plugin extend subnet patch.
108108
109109
This patch is needed as the Ml2Plugin's _make_subnet_dict method is calling
@@ -119,7 +119,7 @@ def patch_extend_subnet(mocker) -> None:
119119

120120

121121
@pytest.fixture
122-
def ml2_plugin(patch_extend_subnet) -> Ml2PluginNoInit:
122+
def ml2_plugin(_patch_extend_subnet) -> Ml2PluginNoInit:
123123
return Ml2PluginNoInit()
124124

125125

@@ -291,7 +291,7 @@ def understack_trunk_driver(understack_driver) -> UnderStackTrunkDriver:
291291

292292

293293
@pytest.fixture
294-
def ironic_baremetal_port_physical_network(mocker, understack_driver) -> None:
294+
def _ironic_baremetal_port_physical_network(mocker, understack_driver) -> None:
295295
mocker.patch.object(
296296
understack_driver.ironic_client,
297297
"baremetal_port_physical_network",
@@ -300,12 +300,12 @@ def ironic_baremetal_port_physical_network(mocker, understack_driver) -> None:
300300

301301

302302
@pytest.fixture(autouse=True)
303-
def undersync_sync_devices_patch(mocker, understack_driver) -> None:
303+
def _undersync_sync_devices_patch(mocker, understack_driver) -> None:
304304
mocker.patch.object(understack_driver.undersync, "sync_devices")
305305

306306

307307
@pytest.fixture
308-
def utils_fetch_subport_network_id_patch(mocker, network_id) -> None:
308+
def _utils_fetch_subport_network_id_patch(mocker, network_id) -> None:
309309
mocker.patch(
310310
"neutron_understack.utils.fetch_subport_network_id",
311311
return_value=str(network_id),
@@ -354,7 +354,7 @@ def oslo_config():
354354

355355

356356
@pytest.fixture
357-
def ml2_understack_conf(oslo_config, ucvni_group_id) -> None:
357+
def _ml2_understack_conf(oslo_config, ucvni_group_id) -> None:
358358
oslo_config.config(
359359
ucvni_group=str(ucvni_group_id),
360360
group="ml2_understack",

python/neutron-understack/neutron_understack/tests/test_neutron_understack_mech.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def test_with_simple_port(self, understack_driver, port_context):
1010
understack_driver.undersync.sync_devices.assert_called_once()
1111

1212

13-
@pytest.mark.usefixtures("ironic_baremetal_port_physical_network")
13+
@pytest.mark.usefixtures("_ironic_baremetal_port_physical_network")
1414
class TestBindPort:
1515
def test_with_no_trunk(
1616
self,
@@ -44,7 +44,7 @@ def test_with_trunk_details(
4444

4545

4646
class TestCreateNetworkPostCommit:
47-
@pytest.mark.usefixtures("ml2_understack_conf")
47+
@pytest.mark.usefixtures("_ml2_understack_conf")
4848
def test_vxlan_network(
4949
self,
5050
mocker,

0 commit comments

Comments
 (0)