Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests to Run

The following tests should be run to verify this PR:

Critical (directly affected)

  • tests/install_upgrade_operators/crypto_policy/test_hco_override_api_server_crypto_policy.py::test_hco_overriding_apiserver_crypto_policy — Line 72 changed from sample[resource] to crypto_policy - this is a semantic bug fix in the dict comprehension that checks for conflicting resources. The variable crypto_policy is the value from sample.items() iteration, so this fixes a redundant/incorrect dict lookup. This test directly exercises the changed logic path. (High confidence)

Standard (regression safety)

  • tests/storage/test_cdi_resources.py::test_verify_cdi_res_app_label — The verify_cdi_app_label function had its conditional logic restructured from separate if/elif/elif branches to a combined if (A or B or C): continue pattern. While logically equivalent, the operator precedence of and/or without explicit parentheses needs verification - the original used separate elif clauses which had clearer short-circuit semantics. (Medium confidence)

Summary

  • 2 test files recommended (1 critical, 1 standard)
  • AI Provider: Claude (claude-opus-4-6[1m])

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ default_language_version:

repos:
- repo: https://github.com/PyCQA/autoflake
rev: "v2.3.1"
rev: "v2.3.3"
hooks:
- id: autoflake
args:
Expand All @@ -13,7 +13,7 @@ repos:
stages: [pre-commit]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.1
rev: v0.15.4
hooks:
- id: ruff
stages: [pre-commit]
Expand Down
10 changes: 4 additions & 6 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
Pytest conftest file for CNV tests
"""
Expand Down Expand Up @@ -684,10 +683,9 @@ def pytest_runtest_makereport(item, call):

elif report.failed:
if reprcrash := getattr(report.longrepr, "reprcrash", None):
if message := getattr(report.longrepr, "message", None):
setattr(report, SETUP_ERROR, message)

elif message := getattr(reprcrash, "message", None):
if (message := getattr(report.longrepr, "message", None)) or (
message := getattr(reprcrash, "message", None)
):
setattr(report, SETUP_ERROR, message)


Expand Down Expand Up @@ -880,7 +878,7 @@ def is_skip_must_gather(node: Node) -> bool:

def get_inspect_command_namespace_string(node: Node, test_name: str) -> str:
namespace_str = ""
components = [key for key in NAMESPACE_COLLECTION.keys() if f"tests/{key}/" in test_name]
components = [key for key in NAMESPACE_COLLECTION if f"tests/{key}/" in test_name]
if not components:
LOGGER.warning(f"{test_name} does not require special data collection on failure")
else:
Expand Down
10 changes: 5 additions & 5 deletions libs/net/netattachdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class IpamStatic(Ipam):
"""

type: str = field(default="static", init=False)
addresses: list["IpamStatic.Address"]
addresses: list[IpamStatic.Address]
routes: list[IpamRoute] | None = None

@dataclass
Expand All @@ -61,7 +61,7 @@ class CNIPluginBridgeConfig(CNIPluginConfig):
mtu: int | None = None
vlan: int | None = None
macspoofchk: bool | None = None
disableContainerInterface: bool | None = None # noqa: N815
disableContainerInterface: bool | None = None


@dataclass
Expand All @@ -76,8 +76,8 @@ class CNIPluginOvnK8sConfig(CNIPluginConfig):

type: str = field(default="ovn-k8s-cni-overlay", init=False)
topology: str
netAttachDefName: str # noqa: N815
vlanID: int | None = None # noqa: N815
netAttachDefName: str
vlanID: int | None = None

class Topology(Enum):
LOCALNET = "localnet"
Expand Down Expand Up @@ -105,7 +105,7 @@ class NetConfig:

name: str
plugins: list[CNIPluginConfig]
cniVersion: str = _DEFAULT_CNI_VERSION # noqa: N815
cniVersion: str = _DEFAULT_CNI_VERSION


class NetworkAttachmentDefinition(NamespacedResource):
Expand Down
23 changes: 13 additions & 10 deletions libs/net/traffic_generator.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import contextlib
import logging
from abc import ABC, abstractmethod
from typing import Final, Generator
from collections.abc import Generator
from typing import Final

from ocp_resources.pod import Pod
from ocp_utilities.exceptions import CommandExecFailed
Expand All @@ -27,7 +28,7 @@ def __init__(self, server_ip: str, server_port: int):
self._cmd = f"{_IPERF_BIN} --client {self._server_ip} --time 0 --port {self.server_port} --connect-timeout 300"

@abstractmethod
def __enter__(self) -> "BaseTcpClient":
def __enter__(self) -> BaseTcpClient:
pass

@abstractmethod
Expand Down Expand Up @@ -58,7 +59,7 @@ def __init__(
self._port = port
self._cmd = f"{_IPERF_BIN} --server --port {self._port} --one-off"

def __enter__(self) -> "TcpServer":
def __enter__(self) -> TcpServer:
self._vm.console(
commands=[f"{self._cmd} &"],
timeout=_DEFAULT_CMD_TIMEOUT_SEC,
Expand Down Expand Up @@ -105,7 +106,7 @@ def __init__(
self._vm = vm
self._cmd += f" --set-mss {maximum_segment_size}" if maximum_segment_size else ""

def __enter__(self) -> "VMTcpClient":
def __enter__(self) -> VMTcpClient:
self._vm.console(
commands=[f"{self._cmd} &"],
timeout=_DEFAULT_CMD_TIMEOUT_SEC,
Expand Down Expand Up @@ -166,7 +167,7 @@ def __init__(self, pod: Pod, server_ip: str, server_port: int, bind_interface: s
self._container = _IPERF_BIN
self._cmd += f" --bind {bind_interface}" if bind_interface else ""

def __enter__(self) -> "PodTcpClient":
def __enter__(self) -> PodTcpClient:
# run the command in the background using nohup to ensure it keeps running after the exec session ends
self._pod.execute(
command=["sh", "-c", f"nohup {self._cmd} >/tmp/{_IPERF_BIN}.log 2>&1 &"], container=self._container
Expand Down Expand Up @@ -199,7 +200,7 @@ def client_server_active_connection(
port: int = IPERF_SERVER_PORT,
maximum_segment_size: int = 0,
ip_family: int = 4,
) -> Generator[tuple[VMTcpClient, TcpServer], None, None]:
) -> Generator[tuple[VMTcpClient, TcpServer]]:
"""Start iperf3 client-server connection with continuous TCP traffic flow.

Automatically starts an iperf3 server and client, with traffic flowing continuously
Expand All @@ -221,11 +222,13 @@ def client_server_active_connection(
Note:
Traffic runs with infinite duration until context exits.
"""
with TcpServer(vm=server_vm, port=port) as server:
with VMTcpClient(
with (
TcpServer(vm=server_vm, port=port) as server,
VMTcpClient(
vm=client_vm,
server_ip=str(lookup_iface_status_ip(vm=server_vm, iface_name=spec_logical_network, ip_family=ip_family)),
server_port=port,
maximum_segment_size=maximum_segment_size,
) as client:
yield client, server
) as client,
):
yield client, server
2 changes: 1 addition & 1 deletion libs/storage/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(self, name: str):
self.name = name
self.storage_config = self.get_storage_config()

def supported_storage_classes(self) -> list["StorageClass"]:
def supported_storage_classes(self) -> list[StorageClass]:
return [
StorageClass(
name=StorageClassNames.CEPH_RBD_VIRTUALIZATION,
Expand Down
26 changes: 13 additions & 13 deletions libs/vm/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@dataclass
class VMSpec:
template: Template
runStrategy: str = VirtualMachine.RunStrategy.HALTED # noqa: N815
runStrategy: str = VirtualMachine.RunStrategy.HALTED


@dataclass
Expand All @@ -29,7 +29,7 @@ class VMISpec:
domain: Domain
networks: list[Network] | None = None
volumes: list[Volume] | None = None
terminationGracePeriodSeconds: int | None = None # noqa: N815
terminationGracePeriodSeconds: int | None = None
affinity: Affinity | None = None


Expand Down Expand Up @@ -92,30 +92,30 @@ class Network:

@dataclass
class Multus:
networkName: str # noqa: N815
networkName: str


@dataclass
class Affinity:
podAntiAffinity: PodAntiAffinity # noqa: N815
podAntiAffinity: PodAntiAffinity


@dataclass
class PodAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution: list[PodAffinityTerm] # noqa: N815
requiredDuringSchedulingIgnoredDuringExecution: list[PodAffinityTerm]


@dataclass
class PodAffinityTerm:
labelSelector: LabelSelector # noqa: N815
topologyKey: str # noqa: N815
namespaceSelector: dict[str, Any] | None = None # noqa: N815
labelSelector: LabelSelector
topologyKey: str
namespaceSelector: dict[str, Any] | None = None
namespaces: list[str] | None = None


@dataclass
class LabelSelector:
matchExpressions: list[LabelSelectorRequirement] # noqa: N815
matchExpressions: list[LabelSelectorRequirement]


@dataclass
Expand All @@ -128,8 +128,8 @@ class LabelSelectorRequirement:
@dataclass
class Volume:
name: str
containerDisk: ContainerDisk | None = None # noqa: N815
cloudInitNoCloud: CloudInitNoCloud | None = None # noqa: N815
containerDisk: ContainerDisk | None = None
cloudInitNoCloud: CloudInitNoCloud | None = None


@dataclass
Expand All @@ -139,5 +139,5 @@ class ContainerDisk:

@dataclass
class CloudInitNoCloud:
networkData: str # noqa: N815
userData: str | None = None # noqa: N815
networkData: str
userData: str | None = None
31 changes: 12 additions & 19 deletions scripts/tests_analyzer/pytest_marker_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

# Generated using Claude cli

# flake8: noqa: N802

"""
Pytest Marker Analyzer
Expand Down Expand Up @@ -772,10 +771,9 @@ def _process_test_file_for_markers(
if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):
if node.name.startswith("test_"):
for decorator in node.decorator_list:
if is_marker(decorator=decorator, marker_names=marker_names):
tests.append(node.name)
break
elif check_parametrize_marks(decorator=decorator, marker_names=marker_names):
if is_marker(decorator=decorator, marker_names=marker_names) or check_parametrize_marks(
decorator=decorator, marker_names=marker_names
):
tests.append(node.name)
break
elif isinstance(node, ast.ClassDef):
Expand All @@ -794,10 +792,9 @@ def _process_test_file_for_markers(
if isinstance(item, (ast.FunctionDef, ast.AsyncFunctionDef)):
if item.name.startswith("test_"):
for decorator in item.decorator_list:
if is_marker(decorator=decorator, marker_names=marker_names):
tests.append(f"{node.name}::{item.name}")
break
elif check_parametrize_marks(decorator=decorator, marker_names=marker_names):
if is_marker(
decorator=decorator, marker_names=marker_names
) or check_parametrize_marks(decorator=decorator, marker_names=marker_names):
tests.append(f"{node.name}::{item.name}")
break

Expand Down Expand Up @@ -1568,11 +1565,9 @@ def _extract_marked_tests_from_file(self, file_path: Path) -> list[str]:
# Module-level function with marker
if node.name.startswith("test_"):
for decorator in node.decorator_list:
if is_marker(decorator=decorator, marker_names=self.marker_names):
tests.append(node.name)
break
# Also check for markers in parametrize pytest.param(..., marks=...)
elif check_parametrize_marks(decorator=decorator, marker_names=self.marker_names):
if is_marker(
decorator=decorator, marker_names=self.marker_names
) or check_parametrize_marks(decorator=decorator, marker_names=self.marker_names):
tests.append(node.name)
break

Expand All @@ -1597,11 +1592,9 @@ def _extract_marked_tests_from_file(self, file_path: Path) -> list[str]:
if item.name.startswith("test_"):
# Check method-level markers
for decorator in item.decorator_list:
if is_marker(decorator=decorator, marker_names=self.marker_names):
tests.append(f"{node.name}::{item.name}")
break
# Also check parametrize marks
elif check_parametrize_marks(
if is_marker(
decorator=decorator, marker_names=self.marker_names
) or check_parametrize_marks(
decorator=decorator, marker_names=self.marker_names
):
tests.append(f"{node.name}::{item.name}")
Expand Down
1 change: 0 additions & 1 deletion tests/chaos/oadp/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ def rebooted_vm_source_node(rhel_vm_with_dv_running, oadp_backup_in_progress, wo

LOGGER.info(f"Waiting for node {vm_node.name} to come back online")
wait_for_node_status(node=vm_node, status=True, wait_timeout=TIMEOUT_10MIN)
return


@pytest.fixture()
Expand Down
12 changes: 6 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import tempfile
from bisect import bisect_left
from collections import defaultdict
from datetime import datetime, timezone
from datetime import UTC, datetime
from signal import SIGINT, SIGTERM, getsignal, signal
from subprocess import check_output

Expand Down Expand Up @@ -265,7 +265,7 @@ def session_start_time() -> datetime:
Returns:
datetime: UTC timestamp when test session began (timezone-naive)
"""
return datetime.now(timezone.utc).replace(tzinfo=None)
return datetime.now(UTC).replace(tzinfo=None)


@pytest.fixture(scope="session")
Expand Down Expand Up @@ -2258,16 +2258,16 @@ def rhel_vm_with_instance_type_and_preference(
with (
instance_type_for_test_scope_class as vm_instance_type,
vm_preference_for_test as vm_preference,
):
with VirtualMachineForTests(
VirtualMachineForTests(
client=unprivileged_client,
name="rhel-vm-with-instance-type",
namespace=namespace.name,
image=Images.Rhel.RHEL9_REGISTRY_GUEST_IMG,
vm_instance_type=vm_instance_type,
vm_preference=vm_preference,
) as vm:
yield vm
) as vm,
):
yield vm


@pytest.fixture(scope="session")
Expand Down
2 changes: 1 addition & 1 deletion tests/global_config_amd64.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
if _dir in ["encoding", "py_file"]:
continue

config[_dir] = locals()[_dir] # noqa: F821
config[_dir] = locals()[_dir]
2 changes: 1 addition & 1 deletion tests/global_config_arm64.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@
if _dir in ["encoding", "py_file"]:
continue

config[_dir] = locals()[_dir] # noqa: F821
config[_dir] = locals()[_dir]
2 changes: 1 addition & 1 deletion tests/global_config_aro.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@
if _dir in ["encoding", "py_file"]:
continue

config[_dir] = locals()[_dir] # noqa: F821
config[_dir] = locals()[_dir]
2 changes: 1 addition & 1 deletion tests/global_config_aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@
if _dir in ["encoding", "py_file"]:
continue

config[_dir] = locals()[_dir] # noqa: F821
config[_dir] = locals()[_dir]
2 changes: 1 addition & 1 deletion tests/global_config_ibm_spectrum_sc.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@
if _dir in ["encoding", "py_file"]:
continue

config[_dir] = locals()[_dir] # noqa: F821
config[_dir] = locals()[_dir]
2 changes: 1 addition & 1 deletion tests/global_config_interop.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
if _dir in ["encoding", "py_file"]:
continue

config[_dir] = locals()[_dir] # noqa: F821
config[_dir] = locals()[_dir]
2 changes: 1 addition & 1 deletion tests/global_config_interop_sno.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@
if _dir in ["encoding", "py_file"]:
continue

config[_dir] = locals()[_dir] # noqa: F821
config[_dir] = locals()[_dir]
Loading
Loading