diff --git a/libs/net/netattachdef.py b/libs/net/netattachdef.py index 35da5b4445..0ab140d1ab 100644 --- a/libs/net/netattachdef.py +++ b/libs/net/netattachdef.py @@ -120,8 +120,8 @@ def __init__( name: str, namespace: str, config: NetConfig, + client: DynamicClient, resource_name: str | None = None, - client: DynamicClient | None = None, ): """ Create and manage NetworkAttachmentDefinition @@ -132,7 +132,7 @@ def __init__( config (NetConfig): Configuration body, as defined by the CNI spec. resource_name (str): Optional resource name marking (set on the object annotations). - client: (DynamicClient): Optional DynamicClient to use. + client (DynamicClient): Dynamic client used to interact with the cluster. """ super().__init__( name=name, diff --git a/tests/conftest.py b/tests/conftest.py index 46922673e9..5fbe1ef6b9 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -584,6 +584,7 @@ def node_physical_nics(workers_utility_pods): @pytest.fixture(scope="session") def nodes_active_nics( + admin_client, workers, workers_utility_pods, node_physical_nics, @@ -607,7 +608,7 @@ def _bridge_ports(node_interface): nodes_nics = {} for node in workers: nodes_nics[node.name] = {"available": [], "occupied": []} - nns = NodeNetworkState(name=node.name) + nns = NodeNetworkState(name=node.name, client=admin_client) for node_iface in nns.interfaces: iface_name = node_iface["name"] @@ -961,7 +962,11 @@ def started_windows_vm( @pytest.fixture(scope="session") -def worker_nodes_ipv4_false_secondary_nics(nodes_available_nics, schedulable_nodes): +def worker_nodes_ipv4_false_secondary_nics( + admin_client, + nodes_available_nics, + schedulable_nodes, +): """ Function removes ipv4 from secondary nics. """ @@ -969,6 +974,7 @@ def worker_nodes_ipv4_false_secondary_nics(nodes_available_nics, schedulable_nod worker_nics = nodes_available_nics[worker_node.name] with EthernetNetworkConfigurationPolicy( name=f"disable-ipv4-{name_prefix(worker_node.name)}", + client=admin_client, node_selector=get_node_selector_dict(node_selector=worker_node.hostname), interfaces_name=worker_nics, ): @@ -1016,8 +1022,8 @@ def worker_node3(schedulable_nodes): @pytest.fixture(scope="session") -def sriov_namespace(): - return Namespace(name=py_config["sriov_namespace"]) +def sriov_namespace(admin_client): + return Namespace(name=py_config["sriov_namespace"], client=admin_client) @pytest.fixture(scope="session") @@ -1066,20 +1072,29 @@ def sriov_ifaces(sriov_nodes_states, workers_utility_pods): @pytest.fixture(scope="session") -def sriov_node_policy(sriov_unused_ifaces, sriov_nodes_states, workers_utility_pods, sriov_namespace): +def sriov_node_policy( + admin_client, + sriov_unused_ifaces, + sriov_nodes_states, + workers_utility_pods, + sriov_namespace, +): yield from create_sriov_node_policy( nncp_name="test-sriov-policy", namespace=sriov_namespace.name, sriov_iface=sriov_unused_ifaces[0], sriov_nodes_states=sriov_nodes_states, sriov_resource_name="sriov_net", + client=admin_client, ) @pytest.fixture(scope="session") -def mac_pool(hco_namespace): +def mac_pool(admin_client, hco_namespace): return MacPool( - kmp_range=ConfigMap(namespace=hco_namespace.name, name=KUBEMACPOOL_MAC_RANGE_CONFIG).instance["data"] + kmp_range=ConfigMap( + namespace=hco_namespace.name, name=KUBEMACPOOL_MAC_RANGE_CONFIG, client=admin_client + ).instance["data"] ) @@ -1671,6 +1686,7 @@ def term_handler_scope_session(): @pytest.fixture(scope="session") def upgrade_bridge_on_all_nodes( + admin_client, label_schedulable_nodes, hosts_common_available_ports, ): @@ -1680,28 +1696,31 @@ def upgrade_bridge_on_all_nodes( interface_name="br1upgrade", node_selector_labels=NODE_TYPE_WORKER_LABEL, ports=[hosts_common_available_ports[0]], + client=admin_client, ) as br: yield br @pytest.fixture(scope="session") -def bridge_on_one_node(worker_node1): +def bridge_on_one_node(admin_client, worker_node1): with network_device( interface_type=LINUX_BRIDGE, nncp_name="upgrade-br-marker", interface_name="upg-br-mark", node_selector=get_node_selector_dict(node_selector=worker_node1.name), + client=admin_client, ) as br: yield br @pytest.fixture(scope="session") -def upgrade_bridge_marker_nad(bridge_on_one_node, kmp_enabled_namespace, worker_node1): +def upgrade_bridge_marker_nad(admin_client, bridge_on_one_node, kmp_enabled_namespace, worker_node1): with network_nad( nad_type=LINUX_BRIDGE, nad_name=bridge_on_one_node.bridge_name, interface_name=bridge_on_one_node.bridge_name, namespace=kmp_enabled_namespace, + client=admin_client, ) as nad: wait_for_node_marked_by_bridge(bridge_nad=nad, node=worker_node1) yield nad @@ -1752,12 +1771,13 @@ def running_vm_upgrade_b( @pytest.fixture(scope="session") -def upgrade_br1test_nad(upgrade_namespace_scope_session, upgrade_bridge_on_all_nodes): +def upgrade_br1test_nad(admin_client, upgrade_namespace_scope_session, upgrade_bridge_on_all_nodes): with network_nad( nad_type=LINUX_BRIDGE, nad_name=upgrade_bridge_on_all_nodes.bridge_name, interface_name=upgrade_bridge_on_all_nodes.bridge_name, namespace=upgrade_namespace_scope_session, + client=admin_client, ) as nad: yield nad @@ -2224,8 +2244,8 @@ def disabled_default_sources_in_operatorhub_scope_module(admin_client, installin @pytest.fixture(scope="module") -def kmp_deployment(hco_namespace): - return Deployment(namespace=hco_namespace.name, name=KUBEMACPOOL_MAC_CONTROLLER_MANAGER) +def kmp_deployment(admin_client, hco_namespace): + return Deployment(namespace=hco_namespace.name, name=KUBEMACPOOL_MAC_CONTROLLER_MANAGER, client=admin_client) @pytest.fixture(scope="class") diff --git a/tests/infrastructure/sap/test_sap_hana_vm.py b/tests/infrastructure/sap/test_sap_hana_vm.py index 3baeff42da..d28ae08fc7 100644 --- a/tests/infrastructure/sap/test_sap_hana_vm.py +++ b/tests/infrastructure/sap/test_sap_hana_vm.py @@ -340,7 +340,7 @@ def sriov_network_node_policy(admin_client, sriov_namespace): @pytest.fixture(scope="class") -def sriov_nads(namespace, sriov_network_node_policy, sriov_namespace): +def sriov_nads(admin_client, namespace, sriov_network_node_policy, sriov_namespace): nads_list = [] for idx in range(REQUIRED_NUMBER_OF_NETWORKS): with network_nad( @@ -351,6 +351,7 @@ def sriov_nads(namespace, sriov_network_node_policy, sriov_namespace): sriov_network_namespace=namespace.name, macspoofchk="off", teardown=False, + client=admin_client, ) as nad: nads_list.append(nad) yield nads_list @@ -474,7 +475,7 @@ def sap_hana_template_labels(): @pytest.fixture(scope="module") -def sap_hana_template(tmpdir_factory): +def sap_hana_template(admin_client, tmpdir_factory): template_name = "sap_hana_template" template_dir = tmpdir_factory.mktemp(template_name) with create_custom_template_from_url( @@ -482,6 +483,7 @@ def sap_hana_template(tmpdir_factory): template_name=f"{template_name}.yaml", template_dir=template_dir, namespace=NamespacesNames.OPENSHIFT, + client=admin_client, ) as template: yield template diff --git a/tests/install_upgrade_operators/must_gather/conftest.py b/tests/install_upgrade_operators/must_gather/conftest.py index 3b157dc4e2..c09708f708 100644 --- a/tests/install_upgrade_operators/must_gather/conftest.py +++ b/tests/install_upgrade_operators/must_gather/conftest.py @@ -149,24 +149,26 @@ def kubevirt_crd_by_type(cnv_crd_matrix__function__, kubevirt_crd_resources, kub @pytest.fixture(scope="package") -def must_gather_nad(must_gather_bridge, node_gather_unprivileged_namespace, worker_node1): +def must_gather_nad(admin_client, must_gather_bridge, node_gather_unprivileged_namespace, worker_node1): with network_nad( nad_type=must_gather_bridge.bridge_type, nad_name=must_gather_bridge.bridge_name, interface_name=must_gather_bridge.bridge_name, namespace=node_gather_unprivileged_namespace, + client=admin_client, ) as must_gather_nad: wait_for_node_marked_by_bridge(bridge_nad=must_gather_nad, node=worker_node1) yield must_gather_nad @pytest.fixture(scope="package") -def must_gather_bridge(worker_node1): +def must_gather_bridge(admin_client, worker_node1): with network_device( interface_type=LINUX_BRIDGE, nncp_name="must-gather-br", interface_name="mg-br1", node_selector=get_node_selector_dict(node_selector=worker_node1.hostname), + client=admin_client, ) as br: yield br diff --git a/tests/network/bgp/conftest.py b/tests/network/bgp/conftest.py index 36a860fd38..28a9e96315 100644 --- a/tests/network/bgp/conftest.py +++ b/tests/network/bgp/conftest.py @@ -45,8 +45,13 @@ @pytest.fixture(scope="session") -def vlan_nncp(vlan_base_iface: str, worker_node1: Node) -> Generator[libnncp.NodeNetworkConfigurationPolicy]: +def vlan_nncp( + admin_client: DynamicClient, + vlan_base_iface: str, + worker_node1: Node, +) -> Generator[libnncp.NodeNetworkConfigurationPolicy]: with libnncp.NodeNetworkConfigurationPolicy( + client=admin_client, name="test-vlan-nncp", desired_state=libnncp.DesiredState( interfaces=[ @@ -131,7 +136,10 @@ def namespace_cudn(admin_client: DynamicClient) -> Generator[Namespace]: @pytest.fixture(scope="module") -def cudn_layer2(namespace_cudn: Namespace) -> Generator[libcudn.ClusterUserDefinedNetwork]: +def cudn_layer2( + admin_client: DynamicClient, + namespace_cudn: Namespace, +) -> Generator[libcudn.ClusterUserDefinedNetwork]: with libcudn.ClusterUserDefinedNetwork( name="l2-network-cudn", namespace_selector=LabelSelector(matchLabels=CUDN_BGP_LABEL), @@ -144,6 +152,7 @@ def cudn_layer2(namespace_cudn: Namespace) -> Generator[libcudn.ClusterUserDefin ), ), label=APP_CUDN_LABEL, + client=admin_client, ) as cudn: cudn.wait_for_status_success() yield cudn diff --git a/tests/network/bond/test_bond_modes.py b/tests/network/bond/test_bond_modes.py index 5105c4cc65..e28137baea 100644 --- a/tests/network/bond/test_bond_modes.py +++ b/tests/network/bond/test_bond_modes.py @@ -63,6 +63,7 @@ def create_vm(namespace, nad, node_selector, unprivileged_client): @pytest.fixture() def matrix_bond_modes_bond( + admin_client, index_number, link_aggregation_mode_no_connectivity_matrix__function__, nodes_available_nics, @@ -75,6 +76,7 @@ def matrix_bond_modes_bond( with BondNodeNetworkConfigurationPolicy( name=f"matrix-bond{bond_index}-nncp", bond_name=f"mtx-bond{bond_index}", + client=admin_client, bond_ports=nodes_available_nics[worker_node1.name][-2:], mode=link_aggregation_mode_no_connectivity_matrix__function__, node_selector=get_node_selector_dict(node_selector=worker_node1.hostname), @@ -83,18 +85,20 @@ def matrix_bond_modes_bond( @pytest.fixture() -def bond_modes_nad(bridge_device_matrix__function__, namespace, matrix_bond_modes_bond): +def bond_modes_nad(admin_client, bridge_device_matrix__function__, namespace, matrix_bond_modes_bond): with network_nad( namespace=namespace, nad_type=bridge_device_matrix__function__, nad_name=f"bond-nad-{matrix_bond_modes_bond.bond_name}", interface_name=f"br{matrix_bond_modes_bond.bond_name}", + client=admin_client, ) as nad: yield nad @pytest.fixture() def matrix_bond_modes_bridge( + admin_client, bridge_device_matrix__function__, worker_node1, bond_modes_nad, @@ -109,6 +113,7 @@ def matrix_bond_modes_bridge( node_selector=get_node_selector_dict(node_selector=worker_node1.hostname), interface_name=bond_modes_nad.bridge_name, ports=[matrix_bond_modes_bond.bond_name], + client=admin_client, ) as br: yield br @@ -132,6 +137,7 @@ def bond_modes_vm( @pytest.fixture() def bridge_on_bond_fail_over_mac( + admin_client, bridge_device_matrix__function__, worker_node1, bond_modes_nad, @@ -146,14 +152,16 @@ def bridge_on_bond_fail_over_mac( node_selector=get_node_selector_dict(node_selector=worker_node1.hostname), interface_name=bond_modes_nad.bridge_name, ports=[active_backup_bond_with_fail_over_mac.bond_name], + client=admin_client, ) as br: yield br @pytest.fixture() -def active_backup_bond_with_fail_over_mac(index_number, worker_node1, nodes_available_nics): +def active_backup_bond_with_fail_over_mac(admin_client, index_number, worker_node1, nodes_available_nics): bond_index = next(index_number) with BondNodeNetworkConfigurationPolicy( + client=admin_client, name=f"active-bond{bond_index}-nncp", bond_name=f"act-bond{bond_index}", bond_ports=nodes_available_nics[worker_node1.name][-2:], @@ -183,9 +191,10 @@ def vm_with_fail_over_mac_bond( @pytest.fixture() -def bond_resource(index_number, nodes_available_nics, worker_node1): +def bond_resource(admin_client, index_number, nodes_available_nics, worker_node1): bond_idx = next(index_number) with BondNodeNetworkConfigurationPolicy( + client=admin_client, name=f"bond-with-port{bond_idx}nncp", bond_name=f"bond-w-port{bond_idx}", bond_ports=nodes_available_nics[worker_node1.name][-2:], @@ -210,6 +219,7 @@ def test_vm_started(bond_modes_vm): @pytest.mark.polarion("CNV-6583") @pytest.mark.s390x def test_active_backup_bond_with_fail_over_mac( + admin_client, index_number, worker_node1, nodes_available_nics, @@ -219,6 +229,7 @@ def test_active_backup_bond_with_fail_over_mac( with BondNodeNetworkConfigurationPolicy( name=f"test-active-bond{bond_index}-nncp", bond_name=f"test-act-bond{bond_index}", + client=admin_client, bond_ports=nodes_available_nics[worker_node1.name][-2:], node_selector=get_node_selector_dict(node_selector=worker_node1.hostname), options={"fail_over_mac": "active"}, diff --git a/tests/network/bond/test_l2_bridge_over_bond.py b/tests/network/bond/test_l2_bridge_over_bond.py index 5b825fc342..1dc690d862 100644 --- a/tests/network/bond/test_l2_bridge_over_bond.py +++ b/tests/network/bond/test_l2_bridge_over_bond.py @@ -26,18 +26,20 @@ @pytest.fixture(scope="class") -def ovs_linux_br1bond_nad(bridge_device_matrix__class__, namespace): +def ovs_linux_br1bond_nad(admin_client, bridge_device_matrix__class__, namespace): with network_nad( namespace=namespace, nad_type=bridge_device_matrix__class__, nad_name="br1bond-nad", interface_name="br1bond", + client=admin_client, ) as nad: yield nad @pytest.fixture(scope="class") def ovs_linux_bond1_worker_1( + admin_client, index_number, worker_node1, nodes_available_nics, @@ -47,6 +49,7 @@ def ovs_linux_bond1_worker_1( """ bond_idx = next(index_number) with BondNodeNetworkConfigurationPolicy( + client=admin_client, name=f"bond{bond_idx}nncp-worker-1", bond_name=f"bond{bond_idx}", bond_ports=nodes_available_nics[worker_node1.name][-2:], @@ -57,6 +60,7 @@ def ovs_linux_bond1_worker_1( @pytest.fixture(scope="class") def ovs_linux_bond1_worker_2( + admin_client, index_number, worker_node2, nodes_available_nics, @@ -69,6 +73,7 @@ def ovs_linux_bond1_worker_2( with ( BondNodeNetworkConfigurationPolicy( name=f"bond{bond_idx}nncp-worker-2", + client=admin_client, bond_name=ovs_linux_bond1_worker_1.bond_name, # Use the same BOND name for each test. bond_ports=nodes_available_nics[worker_node2.name][-2:], node_selector=get_node_selector_dict(node_selector=worker_node2.hostname), @@ -79,6 +84,7 @@ def ovs_linux_bond1_worker_2( @pytest.fixture(scope="class") def ovs_linux_bridge_on_bond_worker_1( + admin_client, bridge_device_matrix__class__, worker_node1, ovs_linux_br1bond_nad, @@ -93,12 +99,14 @@ def ovs_linux_bridge_on_bond_worker_1( interface_name=ovs_linux_br1bond_nad.bridge_name, node_selector=get_node_selector_dict(node_selector=worker_node1.hostname), ports=[ovs_linux_bond1_worker_1.bond_name], + client=admin_client, ) as br: yield br @pytest.fixture(scope="class") def ovs_linux_bridge_on_bond_worker_2( + admin_client, bridge_device_matrix__class__, worker_node2, ovs_linux_br1bond_nad, @@ -113,6 +121,7 @@ def ovs_linux_bridge_on_bond_worker_2( interface_name=ovs_linux_br1bond_nad.bridge_name, node_selector=get_node_selector_dict(node_selector=worker_node2.hostname), ports=[ovs_linux_bond1_worker_2.bond_name], + client=admin_client, ) as br: yield br diff --git a/tests/network/conftest.py b/tests/network/conftest.py index f7d9306e0f..0d43dbd9f0 100644 --- a/tests/network/conftest.py +++ b/tests/network/conftest.py @@ -145,6 +145,7 @@ def vlan_index_number(vlans_list): @pytest.fixture(scope="module") def brcnv_ovs_nad_vlan_1( + admin_client, hyperconverged_ovs_annotations_enabled_scope_session, namespace, vlan_index_number, @@ -156,6 +157,7 @@ def brcnv_ovs_nad_vlan_1( nad_name=f"{BRCNV}-{vlan_tag}", interface_name=BRCNV, vlan=vlan_tag, + client=admin_client, ) as nad: yield nad @@ -178,8 +180,8 @@ def brcnv_vma_with_vlan_1( @pytest.fixture(scope="session") -def cluster_network_mtu(): - network_resource = Network(name=CLUSTER) +def cluster_network_mtu(admin_client): + network_resource = Network(name=CLUSTER, client=admin_client) if not network_resource.exists: raise ResourceNotFoundError(f"{CLUSTER} Network resource not found.") @@ -213,8 +215,10 @@ def ovn_kubernetes_cluster(admin_client): @pytest.fixture(scope="session") -def network_operator(): - return Network(name=CLUSTER, api_group=Network.ApiGroup.OPERATOR_OPENSHIFT_IO, ensure_exists=True) +def network_operator(admin_client): + return Network( + name=CLUSTER, api_group=Network.ApiGroup.OPERATOR_OPENSHIFT_IO, ensure_exists=True, client=admin_client + ) @pytest.fixture(scope="session", autouse=True) @@ -266,7 +270,7 @@ def _verify_dpdk(): if any(test.get_closest_marker("dpdk") for test in collected_tests): LOGGER.info("Verifying if the cluster supports running DPDK tests...") dpdk_performance_profile_name = "dpdk" - if not PerformanceProfile(name=dpdk_performance_profile_name).exists: + if not PerformanceProfile(name=dpdk_performance_profile_name, client=admin_client).exists: failure_msgs.append( f"DPDK is not configured, the {PerformanceProfile.kind}/{dpdk_performance_profile_name} " "does not exist" @@ -302,7 +306,7 @@ def _verify_jumbo_frame(): def _verify_sriov(): if any(test.get_closest_marker("sriov") for test in collected_tests): LOGGER.info("Verifying if the cluster supports running SRIOV tests...") - if not Namespace(name=py_config["sriov_namespace"]).exists: + if not Namespace(name=py_config["sriov_namespace"], client=admin_client).exists: failure_msgs.append( f"SRIOV operator is not installed, the '{py_config['sriov_namespace']}' namespace does not exist" ) diff --git a/tests/network/connectivity/conftest.py b/tests/network/connectivity/conftest.py index 4468c6ca81..546b1239d6 100644 --- a/tests/network/connectivity/conftest.py +++ b/tests/network/connectivity/conftest.py @@ -35,6 +35,7 @@ def fail_if_not_ipv6_supported_cluster(ipv6_supported_cluster): @pytest.fixture(scope="class") def nncp_linux_bridge_device_worker_1_source( + admin_client, nodes_available_nics, worker_node1, bridge_device_name, @@ -45,12 +46,14 @@ def nncp_linux_bridge_device_worker_1_source( interface_name=bridge_device_name, node_selector=get_node_selector_dict(node_selector=worker_node1.hostname), ports=[nodes_available_nics[worker_node1.name][-1]], + client=admin_client, ) as br: yield br @pytest.fixture(scope="class") def nncp_ovs_bridge_device_worker_1_source( + admin_client, nodes_available_nics, worker_node1, bridge_device_name, @@ -61,12 +64,14 @@ def nncp_ovs_bridge_device_worker_1_source( interface_name=bridge_device_name, node_selector=get_node_selector_dict(node_selector=worker_node1.hostname), ports=[nodes_available_nics[worker_node1.name][-1]], + client=admin_client, ) as br: yield br @pytest.fixture(scope="class") def nncp_linux_bridge_device_worker_2_destination( + admin_client, nodes_available_nics, worker_node2, bridge_device_name, @@ -77,12 +82,14 @@ def nncp_linux_bridge_device_worker_2_destination( interface_name=bridge_device_name, node_selector=get_node_selector_dict(node_selector=worker_node2.hostname), ports=[nodes_available_nics[worker_node2.name][-1]], + client=admin_client, ) as br: yield br @pytest.fixture(scope="class") def nncp_ovs_bridge_device_worker_2_destination( + admin_client, nodes_available_nics, worker_node2, bridge_device_name, @@ -93,12 +100,14 @@ def nncp_ovs_bridge_device_worker_2_destination( interface_name=bridge_device_name, node_selector=get_node_selector_dict(node_selector=worker_node2.hostname), ports=[nodes_available_nics[worker_node2.name][-1]], + client=admin_client, ) as br: yield br @pytest.fixture(scope="class") def nad_linux_bridge( + admin_client, namespace, nncp_linux_bridge_device_worker_1_source, nncp_linux_bridge_device_worker_2_destination, @@ -109,12 +118,14 @@ def nad_linux_bridge( nad_type=LINUX_BRIDGE, nad_name=f"linux-{bridge_device_name}-nad", interface_name=bridge_device_name, + client=admin_client, ) as nad: yield nad @pytest.fixture(scope="class") def nad_ovs_bridge( + admin_client, namespace, nncp_ovs_bridge_device_worker_1_source, nncp_ovs_bridge_device_worker_2_destination, @@ -125,12 +136,14 @@ def nad_ovs_bridge( nad_type=OVS_BRIDGE, nad_name=f"ovs-{bridge_device_name}-nad", interface_name=bridge_device_name, + client=admin_client, ) as nad: yield nad @pytest.fixture(scope="class") def nad_linux_bridge_vlan_1( + admin_client, namespace, nncp_linux_bridge_device_worker_1_source, nncp_linux_bridge_device_worker_2_destination, @@ -143,12 +156,14 @@ def nad_linux_bridge_vlan_1( nad_name=f"linux-{bridge_device_name}-vlan{vlan_id_1}-nad", interface_name=bridge_device_name, vlan=vlan_id_1, + client=admin_client, ) as nad: yield nad @pytest.fixture(scope="class") def nad_ovs_bridge_vlan_1( + admin_client, namespace, nncp_ovs_bridge_device_worker_1_source, nncp_ovs_bridge_device_worker_2_destination, @@ -161,12 +176,14 @@ def nad_ovs_bridge_vlan_1( nad_name=f"ovs-{bridge_device_name}-vlan{vlan_id_1}-nad", interface_name=bridge_device_name, vlan=vlan_id_1, + client=admin_client, ) as nad: yield nad @pytest.fixture(scope="class") def nad_linux_bridge_vlan_2( + admin_client, namespace, nncp_linux_bridge_device_worker_1_source, nncp_linux_bridge_device_worker_2_destination, @@ -179,12 +196,14 @@ def nad_linux_bridge_vlan_2( nad_name=f"linux-{bridge_device_name}-vlan{vlan_id_2}-nad", interface_name=bridge_device_name, vlan=vlan_id_2, + client=admin_client, ) as nad: yield nad @pytest.fixture(scope="class") def nad_ovs_bridge_vlan_2( + admin_client, namespace, nncp_ovs_bridge_device_worker_1_source, nncp_ovs_bridge_device_worker_2_destination, @@ -197,12 +216,14 @@ def nad_ovs_bridge_vlan_2( nad_name=f"ovs-{bridge_device_name}-vlan{vlan_id_2}-nad", interface_name=bridge_device_name, vlan=vlan_id_2, + client=admin_client, ) as nad: yield nad @pytest.fixture(scope="class") def nad_linux_bridge_vlan_3( + admin_client, namespace, nncp_linux_bridge_device_worker_1_source, nncp_linux_bridge_device_worker_2_destination, @@ -215,12 +236,14 @@ def nad_linux_bridge_vlan_3( nad_name=f"linux-{bridge_device_name}-vlan{vlan_id_3}-nad", interface_name=bridge_device_name, vlan=vlan_id_3, + client=admin_client, ) as nad: yield nad @pytest.fixture(scope="class") def nad_ovs_bridge_vlan_3( + admin_client, namespace, nncp_ovs_bridge_device_worker_1_source, nncp_ovs_bridge_device_worker_2_destination, @@ -233,6 +256,7 @@ def nad_ovs_bridge_vlan_3( nad_name=f"ovs-{bridge_device_name}-vlan{vlan_id_3}-nad", interface_name=bridge_device_name, vlan=vlan_id_3, + client=admin_client, ) as nad: yield nad diff --git a/tests/network/dry_run/test_dry_run_kubemacpool.py b/tests/network/dry_run/test_dry_run_kubemacpool.py index 787096c1d1..852fb97d54 100644 --- a/tests/network/dry_run/test_dry_run_kubemacpool.py +++ b/tests/network/dry_run/test_dry_run_kubemacpool.py @@ -32,23 +32,25 @@ def create_dry_run_vm(name, namespace, networks, unprivileged_client, macs=None) @pytest.fixture() -def bridge_on_all_nodes(): +def bridge_on_all_nodes(admin_client): bridge_name = "br-dry-run-test" with network_device( interface_type=LINUX_BRIDGE, nncp_name=f"{bridge_name}-nncp", interface_name=bridge_name, + client=admin_client, ) as dev: yield dev @pytest.fixture() -def linux_bridge_network_nad(namespace, bridge_on_all_nodes): +def linux_bridge_network_nad(admin_client, namespace, bridge_on_all_nodes): with network_nad( nad_type=bridge_on_all_nodes.bridge_type, nad_name=f"{bridge_on_all_nodes.bridge_name}-nad", interface_name=bridge_on_all_nodes.bridge_name, namespace=namespace, + client=admin_client, ) as dry_run_nad: yield dry_run_nad diff --git a/tests/network/flat_overlay/conftest.py b/tests/network/flat_overlay/conftest.py index c8abf53bcd..9de48da3a6 100644 --- a/tests/network/flat_overlay/conftest.py +++ b/tests/network/flat_overlay/conftest.py @@ -43,11 +43,14 @@ @pytest.fixture(scope="module") -def enable_multi_network_policy_usage(network_operator): +def enable_multi_network_policy_usage(admin_client, network_operator): with ResourceEditor(patches={network_operator: {"spec": {"useMultiNetworkPolicy": True}}}): - wait_for_multi_network_policy_resources(deploy_mnp_crd=True) + wait_for_multi_network_policy_resources(client=admin_client, deploy_mnp_crd=True) yield - wait_for_multi_network_policy_resources(deploy_mnp_crd=False) + wait_for_multi_network_policy_resources( + client=admin_client, + deploy_mnp_crd=False, + ) @pytest.fixture(scope="module") @@ -82,19 +85,20 @@ def flat_overlay_second_namespace(admin_client, unprivileged_client): @pytest.fixture(scope="class") -def flat_overlay_vma_vmb_nad(namespace): +def flat_overlay_vma_vmb_nad(admin_client, namespace): with network_nad( nad_type=FLAT_OVERLAY_STR, network_name=FLAT_OVERLAY_VMA_VMB_NETWORK_NAME, nad_name=FLAT_OVERLAY_VMA_VMB_NAD_NAME, namespace=namespace, topology=LAYER2, + client=admin_client, ) as nad: yield nad @pytest.fixture(scope="class") -def flat_overlay_vmc_vmd_nad(namespace): +def flat_overlay_vmc_vmd_nad(admin_client, namespace): nad_for_vms = "vmc-vmd" with network_nad( nad_type=FLAT_OVERLAY_STR, @@ -102,24 +106,26 @@ def flat_overlay_vmc_vmd_nad(namespace): nad_name=f"{FLAT_L2_BASIC_NAD_NAME}-{nad_for_vms}", namespace=namespace, topology=LAYER2, + client=admin_client, ) as nad: yield nad @pytest.fixture(scope="class") -def flat_overlay_vme_nad(flat_overlay_second_namespace): +def flat_overlay_vme_nad(admin_client, flat_overlay_second_namespace): with network_nad( nad_type=FLAT_OVERLAY_STR, network_name=FLAT_OVERLAY_VMA_VMB_NETWORK_NAME, nad_name=FLAT_OVERLAY_VMA_VMB_NAD_NAME, namespace=flat_overlay_second_namespace, topology=LAYER2, + client=admin_client, ) as nad: yield nad @pytest.fixture(scope="class") -def flat_overlay_jumbo_frame_nad(namespace, cluster_hardware_mtu): +def flat_overlay_jumbo_frame_nad(admin_client, namespace, cluster_hardware_mtu): with network_nad( nad_type=FLAT_OVERLAY_STR, network_name=f"{FLAT_L2_BASIC_NETWORK_NAME}-jumbo", @@ -127,6 +133,7 @@ def flat_overlay_jumbo_frame_nad(namespace, cluster_hardware_mtu): namespace=namespace, mtu=cluster_hardware_mtu, topology=LAYER2, + client=admin_client, ) as nad: yield nad @@ -284,6 +291,7 @@ def vmd_flat_overlay_ip_address(vmd_flat_overlay, flat_overlay_vmc_vmd_nad): @pytest.fixture() def vma_egress_multi_network_policy( + admin_client, flat_overlay_vma_vmb_nad, vmb_flat_overlay_ip_address, vma_domain_label, @@ -298,12 +306,14 @@ def vma_egress_multi_network_policy( ip_address=f"{vmb_flat_overlay_ip_address}/{SPECIFIC_HOST_MASK}", ), pod_selector={"matchLabels": vma_domain_label}, + client=admin_client, ) as mnp: yield mnp @pytest.fixture() def vmb_ingress_multi_network_policy( + admin_client, flat_overlay_vma_vmb_nad, vmb_domain_label, ): @@ -316,12 +326,14 @@ def vmb_ingress_multi_network_policy( ingress=create_ip_block( ip_address=f"{random_ipv4_address(net_seed=0, host_address=123)}/{SPECIFIC_HOST_MASK}", ), + client=admin_client, ) as mnp: yield mnp @pytest.fixture() def vmc_ingress_multi_network_policy( + admin_client, flat_overlay_vmc_vmd_nad, vmc_domain_label, vmd_ingress_ip_block, @@ -333,6 +345,7 @@ def vmc_ingress_multi_network_policy( network_name=flat_overlay_vmc_vmd_nad.name, policy_types=["Ingress"], ingress=vmd_ingress_ip_block, + client=admin_client, ) as mnp: yield mnp diff --git a/tests/network/flat_overlay/utils.py b/tests/network/flat_overlay/utils.py index d2c9b7e1f8..30dbb270ad 100644 --- a/tests/network/flat_overlay/utils.py +++ b/tests/network/flat_overlay/utils.py @@ -66,10 +66,12 @@ def create_ip_block(ip_address, ingress=True): return [{network_direction: [{"ipBlock": {"cidr": ip_address}}]}] -def wait_for_multi_network_policy_resources(deploy_mnp_crd=False): +def wait_for_multi_network_policy_resources(client, deploy_mnp_crd=False): sample = None consecutive_check = 0 - mnp_crd = CustomResourceDefinition(name=f"multi-networkpolicies.{NamespacedResource.ApiGroup.K8S_CNI_CNCF_IO}") + mnp_crd = CustomResourceDefinition( + name=f"multi-networkpolicies.{NamespacedResource.ApiGroup.K8S_CNI_CNCF_IO}", client=client + ) try: sampler = TimeoutSampler( wait_timeout=TIMEOUT_3MIN, diff --git a/tests/network/general/test_bridge_marker.py b/tests/network/general/test_bridge_marker.py index 92764592df..8a3a77b311 100644 --- a/tests/network/general/test_bridge_marker.py +++ b/tests/network/general/test_bridge_marker.py @@ -38,29 +38,32 @@ def _get_name(suffix): @pytest.fixture() -def bridge_marker_bridge_network(namespace): +def bridge_marker_bridge_network(admin_client, namespace): with network_nad( nad_type=LINUX_BRIDGE, nad_name=BRIDGEMARKER1, interface_name=BRIDGEMARKER1, namespace=namespace, + client=admin_client, ) as attachdef: yield attachdef @pytest.fixture() -def bridge_networks(namespace): +def bridge_networks(admin_client, namespace): with network_nad( nad_type=LINUX_BRIDGE, nad_name=BRIDGEMARKER2, interface_name=BRIDGEMARKER2, namespace=namespace, + client=admin_client, ) as bridgemarker2_nad: with network_nad( nad_type=LINUX_BRIDGE, nad_name=BRIDGEMARKER3, interface_name=BRIDGEMARKER3, namespace=namespace, + client=admin_client, ) as bridgemarker3_nad: yield bridgemarker2_nad, bridgemarker3_nad @@ -101,28 +104,31 @@ def multi_bridge_attached_vmi(namespace, bridge_networks, unprivileged_client): @pytest.fixture() -def bridge_device_on_all_nodes(): +def bridge_device_on_all_nodes(admin_client): with network_device( interface_type=LINUX_BRIDGE, nncp_name="bridge-marker1", interface_name=BRIDGEMARKER1, + client=admin_client, ) as dev: yield dev @pytest.fixture() -def non_homogenous_bridges(worker_node1, worker_node2): +def non_homogenous_bridges(admin_client, worker_node1, worker_node2): with network_device( interface_type=LINUX_BRIDGE, nncp_name="bridge-marker2", interface_name=BRIDGEMARKER2, node_selector=get_node_selector_dict(node_selector=worker_node1.hostname), + client=admin_client, ) as bridgemarker2_ncp: with network_device( interface_type=LINUX_BRIDGE, nncp_name="bridge-marker3", interface_name=BRIDGEMARKER3, node_selector=get_node_selector_dict(node_selector=worker_node2.hostname), + client=admin_client, ) as bridgemarker3_ncp: yield bridgemarker2_ncp, bridgemarker3_ncp diff --git a/tests/network/general/test_cnv_tuning_regression.py b/tests/network/general/test_cnv_tuning_regression.py index 6d119a151a..e5c74dc7aa 100644 --- a/tests/network/general/test_cnv_tuning_regression.py +++ b/tests/network/general/test_cnv_tuning_regression.py @@ -8,24 +8,26 @@ @pytest.fixture() -def linux_bridge_nad(namespace): +def linux_bridge_nad(admin_client, namespace): with network_nad( namespace=namespace, nad_type=LINUX_BRIDGE, nad_name="br1-nad", interface_name="br1bridge", tuning=True, + client=admin_client, ) as nad: yield nad @pytest.fixture() -def linux_bridge_device(worker_node1, linux_bridge_nad): +def linux_bridge_device(admin_client, worker_node1, linux_bridge_nad): with network_device( interface_type=LINUX_BRIDGE, nncp_name="cnv-tuning-nncp", interface_name=linux_bridge_nad.bridge_name, node_selector=get_node_selector_dict(node_selector=worker_node1.hostname), + client=admin_client, ) as dev: yield dev diff --git a/tests/network/general/test_ip_family_services.py b/tests/network/general/test_ip_family_services.py index e8a93a0542..daa45e2c32 100644 --- a/tests/network/general/test_ip_family_services.py +++ b/tests/network/general/test_ip_family_services.py @@ -73,7 +73,7 @@ def default_ip_family_policy_service(running_vm_for_exposure): @pytest.fixture() def virtctl_expose_service( request, - admin_client, + unprivileged_client, running_vm_for_exposure, dual_stack_cluster, ): @@ -91,6 +91,7 @@ def virtctl_expose_service( svc = get_service( name=svc_name, namespace=running_vm_for_exposure.namespace, + client=unprivileged_client, ) yield svc svc.clean_up() diff --git a/tests/network/jumbo_frame/conftest.py b/tests/network/jumbo_frame/conftest.py index 0fb0b998c2..acd8eb9c04 100644 --- a/tests/network/jumbo_frame/conftest.py +++ b/tests/network/jumbo_frame/conftest.py @@ -109,24 +109,26 @@ def running_vme_jumbo_primary_interface_and_secondary_interface( @pytest.fixture() -def secondary_linux_bridge_nad(namespace, linux_bridge_interface): +def secondary_linux_bridge_nad(admin_client, namespace, linux_bridge_interface): with network_nad( namespace=namespace, nad_type=linux_bridge_interface.bridge_type, nad_name=f"{linux_bridge_interface.name}-nad", interface_name=linux_bridge_interface.bridge_name, + client=admin_client, ) as nad: yield nad @pytest.fixture(scope="module") -def linux_bridge_interface(hosts_common_available_ports): +def linux_bridge_interface(admin_client, hosts_common_available_ports): with network_device( interface_type=LINUX_BRIDGE, nncp_name="sec-br", interface_name="sec-br", ports=[hosts_common_available_ports[-1]], node_selector_labels={WORKER_NODE_LABEL_KEY: ""}, + client=admin_client, ) as br: yield br diff --git a/tests/network/jumbo_frame/test_bond.py b/tests/network/jumbo_frame/test_bond.py index ebaa63ec3b..18d45013ef 100644 --- a/tests/network/jumbo_frame/test_bond.py +++ b/tests/network/jumbo_frame/test_bond.py @@ -35,6 +35,7 @@ @pytest.fixture(scope="class") def jumbo_frame_bond1_worker_1( + admin_client, cluster_hardware_mtu, index_number, worker_node1, @@ -44,6 +45,7 @@ def jumbo_frame_bond1_worker_1( Create BOND if setup support BOND """ with BondNodeNetworkConfigurationPolicy( + client=admin_client, name=f"jumbo-frame-bond{next(index_number)}-nncp", bond_name=BOND_NAME, bond_ports=nodes_available_nics[worker_node1.name][-2:], @@ -55,6 +57,7 @@ def jumbo_frame_bond1_worker_1( @pytest.fixture(scope="class") def jumbo_frame_bond1_worker_2( + admin_client, cluster_hardware_mtu, index_number, worker_node2, @@ -64,6 +67,7 @@ def jumbo_frame_bond1_worker_2( Create BOND if setup support BOND """ with BondNodeNetworkConfigurationPolicy( + client=admin_client, name=f"jumbo-frame-bond{next(index_number)}-nncp", bond_name=BOND_NAME, bond_ports=nodes_available_nics[worker_node2.name][-2:], @@ -75,6 +79,7 @@ def jumbo_frame_bond1_worker_2( @pytest.fixture(scope="class") def jumbo_frame_bridge_on_bond_worker_1( + admin_client, cluster_hardware_mtu, bridge_device_matrix__class__, jumbo_frame_bond1_worker_1, @@ -89,12 +94,14 @@ def jumbo_frame_bridge_on_bond_worker_1( node_selector=jumbo_frame_bond1_worker_1.node_selector, ports=[jumbo_frame_bond1_worker_1.bond_name], mtu=cluster_hardware_mtu, + client=admin_client, ) as br: yield br @pytest.fixture(scope="class") def jumbo_frame_bridge_on_bond_worker_2( + admin_client, cluster_hardware_mtu, bridge_device_matrix__class__, jumbo_frame_bond1_worker_2, @@ -109,12 +116,14 @@ def jumbo_frame_bridge_on_bond_worker_2( node_selector=jumbo_frame_bond1_worker_2.node_selector, ports=[jumbo_frame_bond1_worker_2.bond_name], mtu=cluster_hardware_mtu, + client=admin_client, ) as br: yield br @pytest.fixture(scope="class") def br1bond_nad( + admin_client, cluster_hardware_mtu, bridge_device_matrix__class__, namespace, @@ -127,6 +136,7 @@ def br1bond_nad( nad_name=f"{BRIDGE_NAME}-bond-nad", interface_name=jumbo_frame_bridge_on_bond_worker_1.bridge_name, mtu=cluster_hardware_mtu, + client=admin_client, ) as nad: yield nad diff --git a/tests/network/jumbo_frame/test_bridge.py b/tests/network/jumbo_frame/test_bridge.py index 3a9c691f75..06f4b7d2cc 100644 --- a/tests/network/jumbo_frame/test_bridge.py +++ b/tests/network/jumbo_frame/test_bridge.py @@ -34,6 +34,7 @@ def jumbo_frame_bridge_device_name(index_number): @pytest.fixture(scope="class") def jumbo_frame_bridge_device_worker_1( + admin_client, cluster_hardware_mtu, bridge_device_matrix__class__, worker_node1, @@ -47,12 +48,14 @@ def jumbo_frame_bridge_device_worker_1( node_selector=get_node_selector_dict(node_selector=worker_node1.hostname), ports=[nodes_available_nics[worker_node1.name][-1]], mtu=cluster_hardware_mtu, + client=admin_client, ) as br: yield br @pytest.fixture(scope="class") def jumbo_frame_bridge_device_worker_2( + admin_client, cluster_hardware_mtu, bridge_device_matrix__class__, worker_node2, @@ -66,12 +69,14 @@ def jumbo_frame_bridge_device_worker_2( node_selector=get_node_selector_dict(node_selector=worker_node2.hostname), ports=[nodes_available_nics[worker_node2.name][-1]], mtu=cluster_hardware_mtu, + client=admin_client, ) as br: yield br @pytest.fixture(scope="class") def br1test_bridge_nad( + admin_client, cluster_hardware_mtu, bridge_device_matrix__class__, namespace, @@ -85,6 +90,7 @@ def br1test_bridge_nad( nad_name=f"{jumbo_frame_bridge_device_name}-nad", interface_name=jumbo_frame_bridge_device_name, mtu=cluster_hardware_mtu, + client=admin_client, ) as nad: yield nad diff --git a/tests/network/kubemacpool/conftest.py b/tests/network/kubemacpool/conftest.py index 6a766f6012..d1cdaf2316 100644 --- a/tests/network/kubemacpool/conftest.py +++ b/tests/network/kubemacpool/conftest.py @@ -19,6 +19,7 @@ def kubemacpool_bridge_device_name(index_number): @pytest.fixture(scope="module") def kubemacpool_bridge_device_worker_1( + admin_client, worker_node1, kubemacpool_bridge_device_name, nodes_available_nics, @@ -29,12 +30,14 @@ def kubemacpool_bridge_device_worker_1( interface_name=kubemacpool_bridge_device_name, node_selector=get_node_selector_dict(node_selector=worker_node1.hostname), ports=[nodes_available_nics[worker_node1.name][-1]], + client=admin_client, ) as dev: yield dev @pytest.fixture(scope="module") def kubemacpool_bridge_device_worker_2( + admin_client, worker_node2, kubemacpool_bridge_device_name, nodes_available_nics, @@ -45,12 +48,14 @@ def kubemacpool_bridge_device_worker_2( interface_name=kubemacpool_bridge_device_name, node_selector=get_node_selector_dict(node_selector=worker_node2.hostname), ports=[nodes_available_nics[worker_node2.name][-1]], + client=admin_client, ) as dev: yield dev @pytest.fixture(scope="module") def manual_mac_nad( + admin_client, namespace, kubemacpool_bridge_device_worker_1, kubemacpool_bridge_device_worker_2, @@ -61,12 +66,14 @@ def manual_mac_nad( nad_name=f"{kubemacpool_bridge_device_name}-manual-mac-nad", interface_name=kubemacpool_bridge_device_name, namespace=namespace, + client=admin_client, ) as manual_mac_nad: yield manual_mac_nad @pytest.fixture(scope="module") def automatic_mac_nad( + admin_client, namespace, kubemacpool_bridge_device_worker_1, kubemacpool_bridge_device_worker_2, @@ -77,12 +84,14 @@ def automatic_mac_nad( nad_name=f"{kubemacpool_bridge_device_name}-automatic-mac-nad", interface_name=kubemacpool_bridge_device_name, namespace=namespace, + client=admin_client, ) as automatic_mac_nad: yield automatic_mac_nad @pytest.fixture(scope="module") def manual_mac_out_of_pool_nad( + admin_client, namespace, kubemacpool_bridge_device_worker_1, kubemacpool_bridge_device_worker_2, @@ -93,12 +102,14 @@ def manual_mac_out_of_pool_nad( nad_name=f"{kubemacpool_bridge_device_name}-manual-out-pool-mac-nad", interface_name=kubemacpool_bridge_device_name, namespace=namespace, + client=admin_client, ) as manual_mac_out_pool_nad: yield manual_mac_out_pool_nad @pytest.fixture(scope="module") def automatic_mac_tuning_net_nad( + admin_client, namespace, kubemacpool_bridge_device_worker_1, kubemacpool_bridge_device_worker_2, @@ -109,12 +120,14 @@ def automatic_mac_tuning_net_nad( nad_name=f"{kubemacpool_bridge_device_name}-automatic-mac-tun-net-nad", interface_name=kubemacpool_bridge_device_name, namespace=namespace, + client=admin_client, ) as automatic_mac_tuning_net_nad: yield automatic_mac_tuning_net_nad @pytest.fixture(scope="class") def disabled_ns_nad( + admin_client, disabled_ns, kubemacpool_bridge_device_worker_1, kubemacpool_bridge_device_worker_2, @@ -125,12 +138,14 @@ def disabled_ns_nad( nad_name=f"{kubemacpool_bridge_device_name}-{disabled_ns.name}-nad", interface_name=kubemacpool_bridge_device_name, namespace=disabled_ns, + client=admin_client, ) as nad: yield nad @pytest.fixture(scope="class") def enabled_ns_nad( + admin_client, kmp_enabled_ns, kubemacpool_bridge_device_worker_1, kubemacpool_bridge_device_worker_2, @@ -141,12 +156,14 @@ def enabled_ns_nad( nad_name=f"{kubemacpool_bridge_device_name}-{kmp_enabled_ns.name}-nad", interface_name=kubemacpool_bridge_device_name, namespace=kmp_enabled_ns, + client=admin_client, ) as nad: yield nad @pytest.fixture(scope="class") def no_label_ns_nad( + admin_client, no_label_ns, kubemacpool_bridge_device_worker_1, kubemacpool_bridge_device_worker_2, @@ -157,6 +174,7 @@ def no_label_ns_nad( nad_name=f"{kubemacpool_bridge_device_name}-{no_label_ns.name}-nad", interface_name=kubemacpool_bridge_device_name, namespace=no_label_ns, + client=admin_client, ) as nad: yield nad @@ -251,7 +269,7 @@ def restarted_vmi_b(vm_b): @pytest.fixture(scope="class") -def disabled_ns_vm(disabled_ns, disabled_ns_nad, mac_pool): +def disabled_ns_vm(disabled_ns, disabled_ns_nad, mac_pool, admin_client): networks = {disabled_ns_nad.name: disabled_ns_nad.name} name = f"{disabled_ns.name}-vm" with VirtualMachineForTests( @@ -260,6 +278,7 @@ def disabled_ns_vm(disabled_ns, disabled_ns_nad, mac_pool): networks=networks, interfaces=networks.keys(), body=fedora_vm_body(name=name), + client=admin_client, ) as vm: mac_pool.append_macs(vm=vm) vm.start(wait=True) @@ -269,7 +288,7 @@ def disabled_ns_vm(disabled_ns, disabled_ns_nad, mac_pool): @pytest.fixture(scope="class") -def enabled_ns_vm(kmp_enabled_ns, enabled_ns_nad, mac_pool): +def enabled_ns_vm(kmp_enabled_ns, enabled_ns_nad, mac_pool, admin_client): networks = {enabled_ns_nad.name: enabled_ns_nad.name} name = f"{kmp_enabled_ns.name}-vm" with VirtualMachineForTests( @@ -278,6 +297,7 @@ def enabled_ns_vm(kmp_enabled_ns, enabled_ns_nad, mac_pool): networks=networks, interfaces=networks.keys(), body=fedora_vm_body(name=name), + client=admin_client, ) as vm: mac_pool.append_macs(vm=vm) vm.start(wait=True) @@ -287,7 +307,7 @@ def enabled_ns_vm(kmp_enabled_ns, enabled_ns_nad, mac_pool): @pytest.fixture(scope="class") -def no_label_ns_vm(no_label_ns, no_label_ns_nad, mac_pool): +def no_label_ns_vm(no_label_ns, no_label_ns_nad, mac_pool, admin_client): networks = {no_label_ns_nad.name: no_label_ns_nad.name} name = f"{no_label_ns.name}-vm" with VirtualMachineForTests( @@ -296,6 +316,7 @@ def no_label_ns_vm(no_label_ns, no_label_ns_nad, mac_pool): networks=networks, interfaces=networks.keys(), body=fedora_vm_body(name=name), + client=admin_client, ) as vm: mac_pool.append_macs(vm=vm) vm.start(wait=True) diff --git a/tests/network/kubemacpool/test_kubemacpool.py b/tests/network/kubemacpool/test_kubemacpool.py index 07a9eca84b..7dc2da2e38 100644 --- a/tests/network/kubemacpool/test_kubemacpool.py +++ b/tests/network/kubemacpool/test_kubemacpool.py @@ -128,7 +128,7 @@ def test_disabled_assignment_ns( @pytest.mark.polarion("CNV-4405") @pytest.mark.single_nic @pytest.mark.s390x -def test_kmp_down(namespace, kmp_down): +def test_kmp_down(unprivileged_client, namespace, kmp_down): with pytest.raises(ApiException): - with VirtualMachineForTests(name="kmp-down-vm", namespace=namespace.name): + with VirtualMachineForTests(name="kmp-down-vm", namespace=namespace.name, client=unprivileged_client): return diff --git a/tests/network/l2_bridge/conftest.py b/tests/network/l2_bridge/conftest.py index fd3091d58e..d98b813515 100644 --- a/tests/network/l2_bridge/conftest.py +++ b/tests/network/l2_bridge/conftest.py @@ -53,6 +53,7 @@ def l2_bridge_device_name(index_number): @pytest.fixture(scope="class") def l2_bridge_device_worker_1( + admin_client, bridge_device_matrix__class__, nodes_available_nics, worker_node1, @@ -64,12 +65,14 @@ def l2_bridge_device_worker_1( interface_name=l2_bridge_device_name, node_selector=get_node_selector_dict(node_selector=worker_node1.hostname), ports=[nodes_available_nics[worker_node1.name][-1]], + client=admin_client, ) as br: yield br @pytest.fixture(scope="class") def l2_bridge_device_worker_2( + admin_client, bridge_device_matrix__class__, nodes_available_nics, worker_node2, @@ -81,12 +84,14 @@ def l2_bridge_device_worker_2( interface_name=l2_bridge_device_name, node_selector=get_node_selector_dict(node_selector=worker_node2.hostname), ports=[nodes_available_nics[worker_node2.name][-1]], + client=admin_client, ) as br: yield br @pytest.fixture(scope="class") def dhcp_nad( + admin_client, bridge_device_matrix__class__, namespace, l2_bridge_device_worker_1, @@ -101,12 +106,14 @@ def dhcp_nad( nad_name=f"{l2_bridge_device_name}-dhcp-broadcast-nad-vlan-{vlan_tag}", interface_name=l2_bridge_device_name, vlan=vlan_tag, + client=admin_client, ) as nad: yield nad @pytest.fixture(scope="class") def custom_eth_type_llpd_nad( + admin_client, bridge_device_matrix__class__, namespace, l2_bridge_device_worker_1, @@ -118,12 +125,14 @@ def custom_eth_type_llpd_nad( nad_type=bridge_device_matrix__class__, nad_name=f"{l2_bridge_device_name}-custom-eth-type-icmp-nad", interface_name=l2_bridge_device_name, + client=admin_client, ) as nad: yield nad @pytest.fixture(scope="class") def mpls_nad( + admin_client, bridge_device_matrix__class__, namespace, l2_bridge_device_worker_1, @@ -135,12 +144,14 @@ def mpls_nad( nad_type=bridge_device_matrix__class__, nad_name=f"{l2_bridge_device_name}-mpls-nad", interface_name=l2_bridge_device_name, + client=admin_client, ) as nad: yield nad @pytest.fixture(scope="class") def dot1q_nad( + admin_client, bridge_device_matrix__class__, namespace, l2_bridge_device_worker_1, @@ -152,6 +163,7 @@ def dot1q_nad( nad_type=bridge_device_matrix__class__, nad_name=f"{l2_bridge_device_name}-dot1q-nad", interface_name=l2_bridge_device_name, + client=admin_client, ) as nad: yield nad diff --git a/tests/network/l2_bridge/test_bridge_nic_hot_plug.py b/tests/network/l2_bridge/test_bridge_nic_hot_plug.py index 13896e9601..08732d6cb8 100644 --- a/tests/network/l2_bridge/test_bridge_nic_hot_plug.py +++ b/tests/network/l2_bridge/test_bridge_nic_hot_plug.py @@ -46,15 +46,17 @@ def running_vm_for_nic_hot_plug(namespace, unprivileged_client): @pytest.fixture(scope="module") -def bridge_interface_for_hot_plug(hosts_common_available_ports): +def bridge_interface_for_hot_plug(admin_client, hosts_common_available_ports): yield from create_bridge_interface_for_hot_plug( bridge_name=f"{HOT_PLUG_STR}-br", bridge_port=hosts_common_available_ports[-1], + client=admin_client, ) @pytest.fixture(scope="module") def network_attachment_definition_for_hot_plug( + admin_client, namespace, bridge_interface_for_hot_plug, ): @@ -63,6 +65,7 @@ def network_attachment_definition_for_hot_plug( namespace=namespace.name, name=f"{bridge_name}-nad", config=netattachdef.NetConfig(bridge_name, [netattachdef.CNIPluginBridgeConfig(bridge=bridge_name)]), + client=admin_client, ) as nad: yield nad @@ -174,17 +177,19 @@ def running_vm_for_jumbo_nic_hot_plug(namespace, unprivileged_client): @pytest.fixture() -def bridge_jumbo_interface_for_hot_plug(hosts_common_available_ports, cluster_hardware_mtu): +def bridge_jumbo_interface_for_hot_plug(admin_client, hosts_common_available_ports, cluster_hardware_mtu): yield from create_bridge_interface_for_hot_plug( bridge_name=f"{HOT_PLUG_STR}-jumbo", # hosts_common_available_ports[-1] is already used for another tests bridge. bridge_port=hosts_common_available_ports[-2], mtu=cluster_hardware_mtu, + client=admin_client, ) @pytest.fixture() def network_attachment_definition_for_jumbo_hot_plug( + admin_client, namespace, bridge_jumbo_interface_for_hot_plug, cluster_hardware_mtu, @@ -202,6 +207,7 @@ def network_attachment_definition_for_jumbo_hot_plug( ) ], ), + client=admin_client, ) as nad: yield nad @@ -255,6 +261,7 @@ def hot_plugged_interface_from_flat_overlay_network( @pytest.fixture() def flat_overlay_network_attachment_definition_for_hot_plug( + admin_client, namespace, ): with network_nad( @@ -263,6 +270,7 @@ def flat_overlay_network_attachment_definition_for_hot_plug( nad_name=f"{FLAT_OVERLAY_STR}-nad", network_name=f"{FLAT_OVERLAY_STR}-network", topology=FLAT_OVERLAY_STR, + client=admin_client, ) as nad: yield nad @@ -419,13 +427,14 @@ def vm2_with_hot_plugged_sriov_interface( @pytest.fixture(scope="module") -def sriov_network_for_hot_plug(sriov_node_policy, namespace, sriov_namespace): +def sriov_network_for_hot_plug(admin_client, sriov_node_policy, namespace, sriov_namespace): with network_nad( nad_type=SRIOV, nad_name="sriov-hot-plug-test-network", sriov_resource_name=sriov_node_policy.resource_name, namespace=sriov_namespace, sriov_network_namespace=namespace.name, + client=admin_client, ) as sriov_network: yield sriov_network diff --git a/tests/network/l2_bridge/test_ovs_bridge.py b/tests/network/l2_bridge/test_ovs_bridge.py index f246047bea..59623b7df3 100644 --- a/tests/network/l2_bridge/test_ovs_bridge.py +++ b/tests/network/l2_bridge/test_ovs_bridge.py @@ -29,18 +29,20 @@ def ovs_bridge_on_worker1(worker_node1_pod_executor): @pytest.fixture() -def ovs_bridge_nad(namespace, ovs_bridge_on_worker1): +def ovs_bridge_nad(admin_client, namespace, ovs_bridge_on_worker1): with network_nad( namespace=namespace, nad_type=OVS_BRIDGE, nad_name="ovs-test-nad", interface_name=ovs_bridge_on_worker1, + client=admin_client, ) as nad: yield nad @pytest.fixture(scope="module") def brcnv_ovs_nad_vlan_2( + admin_client, namespace, vlan_index_number, ): @@ -51,6 +53,7 @@ def brcnv_ovs_nad_vlan_2( nad_name=f"{BRCNV}-{vlan_tag}", interface_name=BRCNV, vlan=vlan_tag, + client=admin_client, ) as nad: yield nad diff --git a/tests/network/l2_bridge/utils.py b/tests/network/l2_bridge/utils.py index ec6393f5ce..fe966fec2b 100644 --- a/tests/network/l2_bridge/utils.py +++ b/tests/network/l2_bridge/utils.py @@ -171,6 +171,7 @@ def update_hot_plug_config_in_vm(vm, interfaces, networks=None): def create_bridge_interface_for_hot_plug( bridge_name, bridge_port, + client, mtu=None, ): with network_device( @@ -182,6 +183,7 @@ def create_bridge_interface_for_hot_plug( ipv4_dhcp=True, node_selector_labels=NODE_TYPE_WORKER_LABEL, mtu=mtu, + client=client, ) as br: yield br diff --git a/tests/network/libs/cluster_user_defined_network.py b/tests/network/libs/cluster_user_defined_network.py index 8af3cccc31..2f2f0d1186 100644 --- a/tests/network/libs/cluster_user_defined_network.py +++ b/tests/network/libs/cluster_user_defined_network.py @@ -1,6 +1,7 @@ from dataclasses import asdict, dataclass from enum import Enum +from kubernetes.dynamic import DynamicClient from ocp_resources.cluster_user_defined_network import ClusterUserDefinedNetwork as Cudn from tests.network.libs.apimachinery import dict_normalization_for_dataclass @@ -71,7 +72,12 @@ class ClusterUserDefinedNetwork(Cudn): """ def __init__( - self, name: str, namespace_selector: LabelSelector, network: Network, label: dict[str, str] | None = None + self, + name: str, + namespace_selector: LabelSelector, + network: Network, + client: DynamicClient, + label: dict[str, str] | None = None, ): """ Create and manage ClusterUserDefinedNetwork @@ -84,12 +90,14 @@ def __init__( namespace_selector (NamespaceSelector): NamespaceSelector Label selector for which namespace network should be available for. network (Network): Network is the user-defined-network spec. + client (DynamicClient): Dynamic client used to interact with the cluster. label (dict[str, str]): Optional labels to apply to the ClusterUserDefinedNetwork. """ super().__init__( name=name, namespace_selector=asdict(namespace_selector, dict_factory=dict_normalization_for_dataclass), network=asdict(network, dict_factory=dict_normalization_for_dataclass), + client=client, label=label, ) diff --git a/tests/network/libs/nodenetworkconfigurationpolicy.py b/tests/network/libs/nodenetworkconfigurationpolicy.py index 044a3d0d31..0269bbb685 100644 --- a/tests/network/libs/nodenetworkconfigurationpolicy.py +++ b/tests/network/libs/nodenetworkconfigurationpolicy.py @@ -6,6 +6,7 @@ from enum import Enum from typing import Any +from kubernetes.dynamic import DynamicClient from ocp_resources.exceptions import NNCPConfigurationFailed from ocp_resources.node_network_configuration_policy_latest import NodeNetworkConfigurationPolicy as Nncp from ocp_resources.resource import Resource, ResourceEditor @@ -109,6 +110,7 @@ class NodeNetworkConfigurationPolicy(Nncp): def __init__( self, + client: DynamicClient, name: str, desired_state: DesiredState, node_selector: dict[str, str] | None = None, @@ -121,10 +123,12 @@ def __init__( desired_state (DesiredState): Desired policy configuration - interface creation, modification or removal. node_selector (dict, optional): A node selector that specifies the nodes to apply the node network configuration policy to. + client: Dynamic client used to interact with the cluster. """ self._desired_state = desired_state super().__init__( name=name, + client=client, desired_state=asdict(desired_state, dict_factory=dict_normalization_for_dataclass), node_selector=node_selector, wait_for_resource=True, diff --git a/tests/network/localnet/conftest.py b/tests/network/localnet/conftest.py index db85fb46e5..fea671dff4 100644 --- a/tests/network/localnet/conftest.py +++ b/tests/network/localnet/conftest.py @@ -41,7 +41,7 @@ @pytest.fixture(scope="module") -def nncp_localnet() -> Generator[libnncp.NodeNetworkConfigurationPolicy]: +def nncp_localnet(admin_client: DynamicClient) -> Generator[libnncp.NodeNetworkConfigurationPolicy]: desired_state = libnncp.DesiredState( ovn=libnncp.OVN([ libnncp.BridgeMappings( @@ -53,6 +53,7 @@ def nncp_localnet() -> Generator[libnncp.NodeNetworkConfigurationPolicy]: ) with libnncp.NodeNetworkConfigurationPolicy( + client=admin_client, name="test-localnet-nncp", desired_state=desired_state, node_selector={WORKER_NODE_LABEL_KEY: ""}, @@ -88,6 +89,7 @@ def vlan_id(vlan_index_number: Generator[int]) -> int: @pytest.fixture(scope="module") def cudn_localnet( + admin_client: DynamicClient, vlan_id: int, namespace_localnet_1: Namespace, namespace_localnet_2: Namespace, @@ -97,6 +99,7 @@ def cudn_localnet( match_labels=LOCALNET_TEST_LABEL, vlan_id=vlan_id, physical_network_name=LOCALNET_BR_EX_NETWORK, + client=admin_client, ) as cudn: cudn.wait_for_status_success() yield cudn @@ -104,12 +107,14 @@ def cudn_localnet( @pytest.fixture(scope="module") def cudn_localnet_no_vlan( + admin_client: DynamicClient, namespace_localnet_1: Namespace, ) -> Generator[libcudn.ClusterUserDefinedNetwork]: with localnet_cudn( name=LOCALNET_BR_EX_NETWORK_NO_VLAN, match_labels=LOCALNET_TEST_LABEL, physical_network_name=LOCALNET_BR_EX_NETWORK, + client=admin_client, ) as cudn: cudn.wait_for_status_success() yield cudn @@ -209,6 +214,7 @@ def localnet_client(localnet_running_vms: tuple[BaseVirtualMachine, BaseVirtualM @pytest.fixture(scope="module") def cudn_localnet_ovs_bridge( + admin_client: DynamicClient, vlan_id: int, namespace_localnet_1: Namespace, ) -> Generator[libcudn.ClusterUserDefinedNetwork]: @@ -217,6 +223,7 @@ def cudn_localnet_ovs_bridge( match_labels=LOCALNET_TEST_LABEL, vlan_id=vlan_id, physical_network_name=LOCALNET_OVS_BRIDGE_NETWORK, + client=admin_client, ) as cudn: cudn.wait_for_status_success() yield cudn @@ -353,24 +360,33 @@ def migrated_localnet_vm( @pytest.fixture(scope="module") def nncp_localnet_on_secondary_node_nic( + admin_client: DynamicClient, hosts_common_available_ports: list[str], ) -> Generator[libnncp.NodeNetworkConfigurationPolicy]: - with create_nncp_localnet_on_secondary_node_nic(node_nic_name=(hosts_common_available_ports[-1])) as nncp: + with create_nncp_localnet_on_secondary_node_nic( + node_nic_name=(hosts_common_available_ports[-1]), + client=admin_client, + ) as nncp: yield nncp @pytest.fixture(scope="module") def nncp_localnet_on_secondary_node_nic_with_jumbo_frame( - hosts_common_available_ports: list[str], cluster_hardware_mtu: int + admin_client: DynamicClient, + hosts_common_available_ports: list[str], + cluster_hardware_mtu: int, ) -> Generator[libnncp.NodeNetworkConfigurationPolicy]: with create_nncp_localnet_on_secondary_node_nic( - node_nic_name=(hosts_common_available_ports[-1]), mtu=cluster_hardware_mtu + node_nic_name=(hosts_common_available_ports[-1]), + client=admin_client, + mtu=cluster_hardware_mtu, ) as nncp: yield nncp @pytest.fixture(scope="module") def cudn_localnet_ovs_bridge_jumbo_frame( + admin_client: DynamicClient, vlan_id: int, cluster_hardware_mtu: int, namespace_localnet_1: Namespace, @@ -381,6 +397,7 @@ def cudn_localnet_ovs_bridge_jumbo_frame( vlan_id=vlan_id, physical_network_name=LOCALNET_OVS_BRIDGE_NETWORK, mtu=cluster_hardware_mtu, + client=admin_client, ) as cudn: cudn.wait_for_status_success() yield cudn diff --git a/tests/network/localnet/liblocalnet.py b/tests/network/localnet/liblocalnet.py index 52b5d11b4f..260c1b62b5 100644 --- a/tests/network/localnet/liblocalnet.py +++ b/tests/network/localnet/liblocalnet.py @@ -136,6 +136,7 @@ def localnet_cudn( name: str, match_labels: dict[str, str], physical_network_name: str, + client: DynamicClient, vlan_id: int | None = None, mtu: int | None = None, ) -> libcudn.ClusterUserDefinedNetwork: @@ -152,6 +153,7 @@ def localnet_cudn( name (str): The name of the CUDN resource. match_labels (dict[str, str]): Labels for namespace selection. physical_network_name (str): The name of the physical network to associate with the localnet configuration. + client (DynamicClient): Dynamic client for resource creation. vlan_id (int|None): The VLAN ID to configure for the network. If None, no VLAN is configured. mtu (int): Optional customized MTU of the network. @@ -174,7 +176,10 @@ def localnet_cudn( network = libcudn.Network(topology=libcudn.Network.Topology.LOCALNET.value, localnet=localnet) return libcudn.ClusterUserDefinedNetwork( - name=name, namespace_selector=LabelSelector(matchLabels=match_labels), network=network + name=name, + namespace_selector=LabelSelector(matchLabels=match_labels), + network=network, + client=client, ) @@ -218,7 +223,9 @@ def client_server_active_connection( @contextlib.contextmanager def create_nncp_localnet_on_secondary_node_nic( - node_nic_name: str, mtu: int | None = None + node_nic_name: str, + client: DynamicClient, + mtu: int | None = None, ) -> Generator[libnncp.NodeNetworkConfigurationPolicy, None, None]: """Create NNCP to configure an OVS bridge on a secondary NIC across all worker nodes. @@ -228,6 +235,7 @@ def create_nncp_localnet_on_secondary_node_nic( Args: node_nic_name: Name of the available NIC on all nodes. + client: Dynamic client used to create and manage the NNCP resource. mtu: Optional MTU to configure on the physical NIC. Yields: @@ -276,6 +284,7 @@ def create_nncp_localnet_on_secondary_node_nic( ]), ) with libnncp.NodeNetworkConfigurationPolicy( + client=client, name=bridge_name, desired_state=desired_state, node_selector={WORKER_NODE_LABEL_KEY: ""}, diff --git a/tests/network/macspoof/conftest.py b/tests/network/macspoof/conftest.py index 649a61a978..e929dce32b 100644 --- a/tests/network/macspoof/conftest.py +++ b/tests/network/macspoof/conftest.py @@ -58,31 +58,34 @@ def set_vm_interface_network_mac(vm, mac): @pytest.fixture(scope="class") -def linux_bridge_device_worker_1(nodes_available_nics, worker_node1): +def linux_bridge_device_worker_1(admin_client, nodes_available_nics, worker_node1): with network_device( interface_type=LINUX_BRIDGE, nncp_name=f"bridge-{name_prefix(worker_node1.hostname)}", interface_name=BRIDGE_NAME, node_selector=get_node_selector_dict(node_selector=worker_node1.hostname), ports=[nodes_available_nics[worker_node1.hostname][-1]], + client=admin_client, ) as br_dev: yield br_dev @pytest.fixture(scope="class") -def linux_bridge_device_worker_2(nodes_available_nics, worker_node2): +def linux_bridge_device_worker_2(admin_client, nodes_available_nics, worker_node2): with network_device( interface_type=LINUX_BRIDGE, nncp_name=f"bridge-{name_prefix(worker_node2.hostname)}", interface_name=BRIDGE_NAME, node_selector=get_node_selector_dict(node_selector=worker_node2.hostname), ports=[nodes_available_nics[worker_node2.hostname][-1]], + client=admin_client, ) as br_dev: yield br_dev @pytest.fixture(scope="class") def linux_macspoof_nad( + admin_client, namespace, linux_bridge_device_worker_1, linux_bridge_device_worker_2, @@ -93,6 +96,7 @@ def linux_macspoof_nad( nad_name=linux_bridge_device_worker_1.bridge_name, interface_name=linux_bridge_device_worker_1.iface["name"], macspoofchk=True, + client=admin_client, ) as nad: yield nad diff --git a/tests/network/migration/test_migration.py b/tests/network/migration/test_migration.py index 7b53bcd141..dcf3e406f7 100644 --- a/tests/network/migration/test_migration.py +++ b/tests/network/migration/test_migration.py @@ -64,6 +64,7 @@ def http_port_accessible(vm, server_ip, server_port): @pytest.fixture(scope="module") def bridge_worker_1( + admin_client, worker_node1, nodes_available_nics, ): @@ -73,12 +74,14 @@ def bridge_worker_1( interface_name="migration-br", node_selector=get_node_selector_dict(node_selector=worker_node1.hostname), ports=[nodes_available_nics[worker_node1.name][-1]], + client=admin_client, ) as br: yield br @pytest.fixture(scope="module") def bridge_worker_2( + admin_client, worker_node2, nodes_available_nics, bridge_worker_1, @@ -89,17 +92,19 @@ def bridge_worker_2( interface_name=bridge_worker_1.bridge_name, node_selector=get_node_selector_dict(node_selector=worker_node2.hostname), ports=[nodes_available_nics[worker_node2.name][-1]], + client=admin_client, ) as br: yield br @pytest.fixture(scope="module") -def br1test_nad(namespace, bridge_worker_1, bridge_worker_2): +def br1test_nad(admin_client, namespace, bridge_worker_1, bridge_worker_2): with network_nad( nad_type=bridge_worker_1.bridge_type, nad_name="network-migration-nad", interface_name=bridge_worker_1.bridge_name, namespace=namespace, + client=admin_client, ) as nad: yield nad diff --git a/tests/network/nmstate/conftest.py b/tests/network/nmstate/conftest.py index 9d18cbf1de..c20266a5b4 100644 --- a/tests/network/nmstate/conftest.py +++ b/tests/network/nmstate/conftest.py @@ -71,6 +71,7 @@ def running_nmstate_vmb(nmstate_vmb): @pytest.fixture(scope="module") def bridge_on_management_ifaces_node1( + admin_client, worker_nodes_management_iface_stats, worker_node1, workers_utility_pods, @@ -86,6 +87,7 @@ def bridge_on_management_ifaces_node1( ports=[management_iface], ipv4_enable=True, ipv4_dhcp=True, + client=admin_client, ) as br_dev: # Wait for bridge to get management IP wait_for_address_on_iface(worker_pod=worker_pod, iface_name=br_dev.bridge_name) @@ -97,6 +99,7 @@ def bridge_on_management_ifaces_node1( @pytest.fixture(scope="module") def bridge_on_management_ifaces_node2( + admin_client, workers_utility_pods, worker_nodes_management_iface_stats, worker_node2, @@ -112,6 +115,7 @@ def bridge_on_management_ifaces_node2( ports=[management_iface], ipv4_enable=True, ipv4_dhcp=True, + client=admin_client, ) as br_dev: # Wait for bridge to get management IP wait_for_address_on_iface(worker_pod=worker_pod, iface_name=br_dev.bridge_name) diff --git a/tests/network/nmstate/test_connectivity_after_nmstate_changes.py b/tests/network/nmstate/test_connectivity_after_nmstate_changes.py index 90de8595a6..c1d18ca45c 100644 --- a/tests/network/nmstate/test_connectivity_after_nmstate_changes.py +++ b/tests/network/nmstate/test_connectivity_after_nmstate_changes.py @@ -46,31 +46,34 @@ def restart_nmstate_handler(admin_client, nmstate_ds, nmstate_namespace): @pytest.fixture(scope="class") -def nmstate_linux_bridge_device_worker_1(nodes_available_nics, worker_node1): +def nmstate_linux_bridge_device_worker_1(admin_client, nodes_available_nics, worker_node1): with network_device( interface_type=LINUX_BRIDGE, nncp_name=f"restart-nmstate-{name_prefix(worker_node1.name)}", interface_name=BRIDGE_NAME, node_selector=get_node_selector_dict(node_selector=worker_node1.hostname), ports=[nodes_available_nics[worker_node1.name][-1]], + client=admin_client, ) as br_dev: yield br_dev @pytest.fixture(scope="class") -def nmstate_linux_bridge_device_worker_2(nodes_available_nics, worker_node2): +def nmstate_linux_bridge_device_worker_2(admin_client, nodes_available_nics, worker_node2): with network_device( interface_type=LINUX_BRIDGE, nncp_name=f"restart-nmstate-{name_prefix(worker_node2.name)}", interface_name=BRIDGE_NAME, node_selector=get_node_selector_dict(node_selector=worker_node2.hostname), ports=[nodes_available_nics[worker_node2.name][-1]], + client=admin_client, ) as br_dev: yield br_dev @pytest.fixture(scope="class") def nmstate_linux_nad( + admin_client, namespace, nmstate_linux_bridge_device_worker_1, nmstate_linux_bridge_device_worker_2, @@ -80,6 +83,7 @@ def nmstate_linux_nad( nad_type=nmstate_linux_bridge_device_worker_1.bridge_type, nad_name="nmstate-br1test-nad", interface_name=nmstate_linux_bridge_device_worker_1.bridge_name, + client=admin_client, ) as nad: yield nad diff --git a/tests/network/service_mesh/conftest.py b/tests/network/service_mesh/conftest.py index 87ffd0ae26..093547d744 100644 --- a/tests/network/service_mesh/conftest.py +++ b/tests/network/service_mesh/conftest.py @@ -44,11 +44,12 @@ class GatewayForTests(Gateway): - def __init__(self, app_name, namespace, hosts): + def __init__(self, app_name, namespace, hosts, client): self.name = unique_name(name=app_name, service_type=GATEWAY_TYPE) super().__init__( name=self.name, namespace=namespace, + client=client, ) self.hosts = hosts @@ -69,11 +70,12 @@ def to_dict(self): class DestinationRuleForTests(DestinationRule): - def __init__(self, app_name, namespace, versions): + def __init__(self, app_name, namespace, versions, client): self.name = unique_name(name=app_name, service_type=DESTINATION_RULE_TYPE) super().__init__( name=self.name, namespace=namespace, + client=client, ) self.app_name = app_name self.versions = versions @@ -101,11 +103,13 @@ def __init__( gateways, subset, port, + client, ): self.name = unique_name(name=app_name, service_type=VIRTUAL_SERVICE_TYPE) super().__init__( name=self.name, namespace=namespace, + client=client, ) self.hosts = hosts self.gateways = gateways @@ -141,11 +145,12 @@ def to_dict(self): class PeerAuthenticationForTests(PeerAuthentication): - def __init__(self, name, namespace): + def __init__(self, name, namespace, client): self.name = unique_name(name=name, service_type=PEER_AUTHENTICATION_TYPE) super().__init__( name=self.name, namespace=namespace, + client=client, ) def to_dict(self): @@ -183,7 +188,7 @@ def service_mesh_tests_namespace(namespace, admin_client): @pytest.fixture(scope="class") -def httpbin_deployment_service_mesh(service_mesh_tests_namespace): +def httpbin_deployment_service_mesh(unprivileged_client, service_mesh_tests_namespace): with ServiceMeshDeployments( name="httpbin", namespace=service_mesh_tests_namespace.name, @@ -193,15 +198,17 @@ def httpbin_deployment_service_mesh(service_mesh_tests_namespace): port=SERVICE_MESH_PORT, service_port=SERVICE_MESH_PORT, service_account=True, + client=unprivileged_client, ) as dp: yield dp @pytest.fixture(scope="class") -def httpbin_service_account_service_mesh(httpbin_deployment_service_mesh): +def httpbin_service_account_service_mesh(unprivileged_client, httpbin_deployment_service_mesh): with ServiceAccount( name=httpbin_deployment_service_mesh.app_name, namespace=httpbin_deployment_service_mesh.namespace, + client=unprivileged_client, ) as sa: add_scc_to_service_account( namespace=httpbin_deployment_service_mesh.namespace, @@ -212,11 +219,14 @@ def httpbin_service_account_service_mesh(httpbin_deployment_service_mesh): @pytest.fixture(scope="class") -def httpbin_service_service_mesh(httpbin_deployment_service_mesh, httpbin_service_account_service_mesh): +def httpbin_service_service_mesh( + unprivileged_client, httpbin_deployment_service_mesh, httpbin_service_account_service_mesh +): with ServiceMeshDeploymentService( namespace=httpbin_deployment_service_mesh.namespace, app_name=httpbin_deployment_service_mesh.app_name, port=httpbin_deployment_service_mesh.service_port, + client=unprivileged_client, ) as sv: yield sv @@ -262,7 +272,7 @@ def outside_mesh_vm_fedora_with_service_mesh_annotation( @pytest.fixture(scope="class") -def server_deployment_v1(service_mesh_tests_namespace): +def server_deployment_v1(unprivileged_client, service_mesh_tests_namespace): with ServiceMeshDeployments( name=SERVER_DEMO_NAME, namespace=service_mesh_tests_namespace.name, @@ -271,12 +281,13 @@ def server_deployment_v1(service_mesh_tests_namespace): strategy=SERVER_DEPLOYMENT_STRATEGY, host=SERVER_DEMO_HOST, service_port=SERVICE_MESH_PORT, + client=unprivileged_client, ) as dp: yield dp @pytest.fixture(scope="class") -def server_deployment_v2(server_deployment_v1): +def server_deployment_v2(unprivileged_client, server_deployment_v1): with ServiceMeshDeployments( name=server_deployment_v1.app_name, namespace=server_deployment_v1.namespace, @@ -285,32 +296,35 @@ def server_deployment_v2(server_deployment_v1): strategy=server_deployment_v1.strategy, host=server_deployment_v1.host, service_port=server_deployment_v1.service_port, + client=unprivileged_client, ) as dp: yield dp @pytest.fixture(scope="class") -def server_service_service_mesh(server_deployment_v1): +def server_service_service_mesh(unprivileged_client, server_deployment_v1): with ServiceMeshDeploymentService( app_name=server_deployment_v1.app_name, namespace=server_deployment_v1.namespace, port=server_deployment_v1.service_port, + client=unprivileged_client, ) as sv: yield sv @pytest.fixture(scope="class") -def gateway_service_mesh(server_deployment_v1): +def gateway_service_mesh(unprivileged_client, server_deployment_v1): with GatewayForTests( app_name=server_deployment_v1.app_name, namespace=server_deployment_v1.namespace, hosts=[server_deployment_v1.host], + client=unprivileged_client, ) as gw: yield gw @pytest.fixture(scope="class") -def virtual_service_mesh_service(server_deployment_v1, gateway_service_mesh): +def virtual_service_mesh_service(unprivileged_client, server_deployment_v1, gateway_service_mesh): with VirtualServiceForTests( app_name=server_deployment_v1.app_name, namespace=server_deployment_v1.namespace, @@ -318,16 +332,18 @@ def virtual_service_mesh_service(server_deployment_v1, gateway_service_mesh): gateways=[gateway_service_mesh.name], subset=server_deployment_v1.version, port=server_deployment_v1.service_port, + client=unprivileged_client, ) as vsv: yield vsv @pytest.fixture(scope="class") -def destination_rule_service_mesh(server_deployment_v1, server_deployment_v2): +def destination_rule_service_mesh(unprivileged_client, server_deployment_v1, server_deployment_v2): with DestinationRuleForTests( app_name=server_deployment_v1.app_name, namespace=server_deployment_v1.namespace, versions=[server_deployment_v1.version, server_deployment_v2.version], + client=unprivileged_client, ) as dr: yield dr @@ -397,10 +413,11 @@ def change_routing_to_v2( @pytest.fixture(scope="class") -def peer_authentication_strict_service_mesh(service_mesh_tests_namespace): +def peer_authentication_strict_service_mesh(unprivileged_client, service_mesh_tests_namespace): with PeerAuthenticationForTests( name="default", namespace=service_mesh_tests_namespace.name, + client=unprivileged_client, ) as pa: yield pa diff --git a/tests/network/sriov/conftest.py b/tests/network/sriov/conftest.py index 9c64588c37..9c9820d3c8 100644 --- a/tests/network/sriov/conftest.py +++ b/tests/network/sriov/conftest.py @@ -87,11 +87,12 @@ def sriov_vm( @pytest.fixture(scope="module") -def sriov_network(sriov_node_policy, namespace, sriov_namespace): +def sriov_network(admin_client, sriov_node_policy, namespace, sriov_namespace): """ Create a SR-IOV network linked to SR-IOV policy. """ with network_nad( + client=admin_client, nad_type=SRIOV, nad_name="sriov-test-network", sriov_resource_name=sriov_node_policy.resource_name, @@ -102,7 +103,7 @@ def sriov_network(sriov_node_policy, namespace, sriov_namespace): @pytest.fixture(scope="class") -def sriov_network_vlan(sriov_node_policy, namespace, sriov_namespace, vlan_index_number): +def sriov_network_vlan(admin_client, sriov_node_policy, namespace, sriov_namespace, vlan_index_number): """ Create a SR-IOV VLAN network linked to SR-IOV policy. """ @@ -113,6 +114,7 @@ def sriov_network_vlan(sriov_node_policy, namespace, sriov_namespace, vlan_index namespace=sriov_namespace, sriov_network_namespace=namespace.name, vlan=next(vlan_index_number), + client=admin_client, ) as sriov_network: yield sriov_network @@ -248,13 +250,14 @@ def sriov_vm_migrate(index_number, unprivileged_client, namespace, sriov_network @pytest.fixture(scope="class") -def dpdk_template(namespace, tmpdir_factory): +def dpdk_template(admin_client, namespace, tmpdir_factory): template_dir = tmpdir_factory.mktemp("dpdk_template") with create_custom_template_from_url( url=f"{CNV_SUPPLEMENTAL_TEMPLATES_URL}/testpmd/resource-specs/sriov-vm1-template.yaml", template_name="dpdk_vm_template.yaml", template_dir=template_dir, namespace=namespace.name, + client=admin_client, ) as template: yield template diff --git a/tests/network/upgrade/conftest.py b/tests/network/upgrade/conftest.py index e0afe1d352..78f0a86072 100644 --- a/tests/network/upgrade/conftest.py +++ b/tests/network/upgrade/conftest.py @@ -17,6 +17,7 @@ @pytest.fixture(scope="session") def upgrade_linux_macspoof_nad( + admin_client, upgrade_namespace_scope_session, ): with network_nad( @@ -26,6 +27,7 @@ def upgrade_linux_macspoof_nad( interface_name=NAD_MAC_SPOOF_NAME, macspoofchk=True, add_resource_name=False, + client=admin_client, ) as nad: yield nad diff --git a/tests/network/upgrade/utils.py b/tests/network/upgrade/utils.py index 9ded210477..ffdbb188e5 100644 --- a/tests/network/upgrade/utils.py +++ b/tests/network/upgrade/utils.py @@ -27,9 +27,9 @@ def assert_nmstate_bridge_creation(bridge): sampler = TimeoutSampler( wait_timeout=TIMEOUT_1MIN, sleep=TIMEOUT_5SEC, - func=lambda: NodeNetworkState(name=get_node_selector_name(node_selector=bridge.node_selector)).get_interface( - name=bridge_name - ), + func=lambda: NodeNetworkState( + name=get_node_selector_name(node_selector=bridge.node_selector), client=bridge.client + ).get_interface(name=bridge_name), ) try: for sample in sampler: diff --git a/tests/network/user_defined_network/test_user_defined_network.py b/tests/network/user_defined_network/test_user_defined_network.py index 389501c81d..7a4767bb76 100644 --- a/tests/network/user_defined_network/test_user_defined_network.py +++ b/tests/network/user_defined_network/test_user_defined_network.py @@ -28,13 +28,14 @@ def udn_namespace(admin_client): @pytest.fixture(scope="module") -def namespaced_layer2_user_defined_network(udn_namespace): +def namespaced_layer2_user_defined_network(admin_client, udn_namespace): with Layer2UserDefinedNetwork( name="layer2-udn", namespace=udn_namespace.name, role="Primary", subnets=[f"{random_ipv4_address(net_seed=0, host_address=0)}/24"], ipam={"lifecycle": "Persistent"}, + client=admin_client, ) as udn: udn.wait_for_condition( condition="NetworkAllocationSucceeded", diff --git a/tests/network/utils.py b/tests/network/utils.py index 7ef722ac9e..fc00df4d9e 100644 --- a/tests/network/utils.py +++ b/tests/network/utils.py @@ -32,10 +32,11 @@ class ServiceMeshDeploymentService(Service): - def __init__(self, app_name, namespace, port, port_name=None): + def __init__(self, app_name, namespace, port, client, port_name=None): super().__init__( name=app_name, namespace=namespace, + client=client, ) self.port = port self.app_name = app_name @@ -85,6 +86,7 @@ def __init__( namespace, version, image, + client, replicas=1, command=None, strategy=None, @@ -106,7 +108,7 @@ def __init__( }, } - super().__init__(name=self.name, namespace=namespace, template=template, selector=selector) + super().__init__(name=self.name, namespace=namespace, template=template, selector=selector, client=client) self.version = version self.replicas = replicas self.image = image @@ -183,7 +185,7 @@ def wait_for_address_on_iface(worker_pod, iface_name): samples = TimeoutSampler( wait_timeout=TIMEOUT_2MIN, sleep=1, - func=NodeNetworkState(worker_pod.node.name).ipv4, + func=NodeNetworkState(name=worker_pod.node.name, client=worker_pod.client).ipv4, iface=iface_name, ) try: @@ -323,8 +325,8 @@ def basic_expose_command( ) -def get_service(name, namespace): - service = Service(name=name, namespace=namespace) +def get_service(name, namespace, client): + service = Service(name=name, namespace=namespace, client=client) if service.exists: return service diff --git a/tests/storage/cdi_import/conftest.py b/tests/storage/cdi_import/conftest.py index 532c9c7579..3014a2a4a8 100644 --- a/tests/storage/cdi_import/conftest.py +++ b/tests/storage/cdi_import/conftest.py @@ -46,22 +46,24 @@ def skip_non_shared_storage(storage_class_name_scope_function): @pytest.fixture() -def bridge_on_node(): +def bridge_on_node(admin_client): with network_device( interface_type=LINUX_BRIDGE, nncp_name=BRIDGE_NAME, interface_name=BRIDGE_NAME, + client=admin_client, ) as br: yield br @pytest.fixture() -def linux_nad(namespace, bridge_on_node): +def linux_nad(admin_client, namespace, bridge_on_node): with network_nad( namespace=namespace, nad_type=LINUX_BRIDGE, nad_name=f"{BRIDGE_NAME}-nad", interface_name=bridge_on_node.bridge_name, + client=admin_client, ) as nad: yield nad diff --git a/tests/virt/cluster/common_templates/windows/test_windows_custom_options.py b/tests/virt/cluster/common_templates/windows/test_windows_custom_options.py index aa46645535..b65fcd2598 100644 --- a/tests/virt/cluster/common_templates/windows/test_windows_custom_options.py +++ b/tests/virt/cluster/common_templates/windows/test_windows_custom_options.py @@ -111,22 +111,24 @@ def initialize_and_format_windows_drive(vm, disk_number, partition_number, drive @pytest.fixture(scope="class") -def windows_custom_bridge(): +def windows_custom_bridge(admin_client): with network_device( interface_type=LINUX_BRIDGE, nncp_name="br1-win-custom-nnc", interface_name="br1-win-custom", + client=admin_client, ) as br: yield br @pytest.fixture(scope="class") -def windows_custom_bridge_nad(windows_custom_bridge, namespace): +def windows_custom_bridge_nad(admin_client, windows_custom_bridge, namespace): with network_nad( namespace=namespace, nad_type=windows_custom_bridge.bridge_type, nad_name="br1-win-custom-nad", interface_name=(windows_custom_bridge.bridge_name), + client=admin_client, ) as nad: yield nad diff --git a/tests/virt/node/high_performance_vm/test_numa.py b/tests/virt/node/high_performance_vm/test_numa.py index 5c06e609d8..eaa2051d98 100644 --- a/tests/virt/node/high_performance_vm/test_numa.py +++ b/tests/virt/node/high_performance_vm/test_numa.py @@ -35,12 +35,13 @@ def fail_if_no_numa(schedulable_nodes, workers_utility_pods): @pytest.fixture(scope="module") -def sriov_net(sriov_node_policy, namespace): +def sriov_net(admin_client, sriov_node_policy, namespace): with SriovNetwork( name="numa-sriov-test-net", namespace=sriov_node_policy.namespace, resource_name=sriov_node_policy.resource_name, network_namespace=namespace.name, + client=admin_client, ) as net: yield net diff --git a/tests/virt/node/migration_and_maintenance/test_dedicated_live_migration_network.py b/tests/virt/node/migration_and_maintenance/test_dedicated_live_migration_network.py index 8dd7f462a9..8a3ae9e421 100644 --- a/tests/virt/node/migration_and_maintenance/test_dedicated_live_migration_network.py +++ b/tests/virt/node/migration_and_maintenance/test_dedicated_live_migration_network.py @@ -48,11 +48,12 @@ def migration_interface(hosts_common_available_ports): @pytest.fixture(scope="module") -def dedicated_network_nad(migration_interface, hco_namespace): +def dedicated_network_nad(admin_client, migration_interface, hco_namespace): with MACVLANNetworkAttachmentDefinition( name="migration-nad", namespace=hco_namespace.name, master=migration_interface, + client=admin_client, ) as nad: yield nad diff --git a/tests/virt/node/migration_and_maintenance/utils.py b/tests/virt/node/migration_and_maintenance/utils.py index d0c36231c7..ba976851ff 100644 --- a/tests/virt/node/migration_and_maintenance/utils.py +++ b/tests/virt/node/migration_and_maintenance/utils.py @@ -23,7 +23,7 @@ def __init__( name, namespace, master, - client=None, + client, teardown=True, ): super().__init__(name=name, namespace=namespace, client=client, teardown=teardown) diff --git a/utilities/network.py b/utilities/network.py index c864e43895..f2fe9b0314 100644 --- a/utilities/network.py +++ b/utilities/network.py @@ -65,6 +65,7 @@ def __init__( bridge_name, bridge_type, stp_config, + client, ports=None, mtu=None, node_selector=None, @@ -91,6 +92,7 @@ def __init__( bridge_name (str): Bridge name. bridge_type (str): Bridge type (Linux Bridge, OVS) stp_config (bool): Spanning Tree enabled/disabled. + client (DynamicClient): Dynamic client used to interact with the cluster. ports (list): The bridge's port(s). mtu (int): MTU size ipv4_dhcp: determines if ipv4_dhcp should be used @@ -115,6 +117,7 @@ def __init__( routes=routes, dns_resolver=dns_resolver, state=bridge_state, + client=client, ) self.ovs_bridge_type = OVS_BRIDGE self.linux_bridge_type = LINUX_BRIDGE @@ -176,6 +179,7 @@ def __init__( self, name, bridge_name, + client, stp_config=False, ports=None, mtu=None, @@ -199,6 +203,7 @@ def __init__( bridge_name=bridge_name, bridge_type=LINUX_BRIDGE, stp_config=stp_config, + client=client, ports=ports, set_ipv4=set_ipv4, set_ipv6=set_ipv6, @@ -224,6 +229,7 @@ def __init__( name, bridge_name, ports, + client, stp_config=False, mtu=None, node_selector=None, @@ -240,6 +246,7 @@ def __init__( bridge_name=bridge_name, bridge_type=OVS_BRIDGE, stp_config=stp_config, + client=client, ports=ports, mtu=mtu, node_selector=node_selector, @@ -334,6 +341,7 @@ def __init__( iface_state, base_iface, tag, + client, name=None, node_selector=None, ipv4_enable=False, @@ -357,6 +365,7 @@ def __init__( ipv6_enable=ipv6_enable, dry_run=dry_run, node_selector_labels=node_selector_labels, + client=client, ) self.iface_state = iface_state self.base_iface = base_iface @@ -381,6 +390,7 @@ def __init__( name, bond_name, bond_ports, + client, mode=ACTIVE_BACKUP, mtu=None, primary_bond_port=None, @@ -405,6 +415,7 @@ def __init__( dry_run=dry_run, success_timeout=success_timeout, teardown_absent_ifaces=teardown_absent_ifaces, + client=client, ) self.bond_name = bond_name self.bond_ports = bond_ports @@ -523,6 +534,7 @@ def network_nad( nad_type, nad_name, namespace, + client, interface_name=None, tuning=None, vlan=None, @@ -541,6 +553,7 @@ def network_nad( "namespace": namespace.name, "teardown": teardown, "vlan": vlan, + "client": client, } if nad_type == LINUX_BRIDGE: kwargs["cni_type"] = py_config["linux_bridge_cni"] @@ -573,6 +586,7 @@ class EthernetNetworkConfigurationPolicy(NodeNetworkConfigurationPolicy): def __init__( self, name, + client, interfaces_name=None, iface_state=NodeNetworkConfigurationPolicy.Interface.State.UP, node_selector=None, @@ -608,6 +622,7 @@ def __init__( routes=routes, dry_run=dry_run, success_timeout=success_timeout, + client=client, ) self.interfaces_name = interfaces_name self.ipv4_auto_dns = ipv4_auto_dns @@ -958,6 +973,7 @@ def wait_for_ovs_daemonset_resource(admin_client, hco_namespace): def network_device( interface_type, nncp_name, + client, interface_name=None, ports=None, mtu=None, @@ -973,6 +989,7 @@ def network_device( kwargs = { "name": nncp_name, "mtu": mtu, + "client": client, } if interface_type == SRIOV: kwargs["namespace"] = namespace @@ -1063,6 +1080,7 @@ def create_sriov_node_policy( sriov_iface, sriov_nodes_states, sriov_resource_name, + client, mtu=MTU_9000, ): with network_device( @@ -1074,6 +1092,7 @@ def create_sriov_node_policy( # sriov operator doesnt pass the mtu to the VFs when using vfio-pci device driver (the one we are using) # so the mtu parameter only affects the PF. we need to change the mtu manually on the VM. mtu=mtu, + client=client, ) as policy: wait_for_ready_sriov_nodes(snns=sriov_nodes_states) yield policy diff --git a/utilities/ssp.py b/utilities/ssp.py index 1655ab835f..a55859357f 100644 --- a/utilities/ssp.py +++ b/utilities/ssp.py @@ -150,7 +150,7 @@ def wait_for_condition_message_value(resource, expected_message): @contextmanager -def create_custom_template_from_url(url, template_name, template_dir, namespace): +def create_custom_template_from_url(url, template_name, template_dir, namespace, client): template_filepath = os.path.join(template_dir, template_name) urllib.request.urlretrieve( url=url, @@ -159,6 +159,7 @@ def create_custom_template_from_url(url, template_name, template_dir, namespace) with Template( yaml_file=template_filepath, namespace=namespace, + client=client, ) as template: yield template diff --git a/utilities/unittests/test_ssp.py b/utilities/unittests/test_ssp.py index 3a80fe2a91..2e2ee558da 100644 --- a/utilities/unittests/test_ssp.py +++ b/utilities/unittests/test_ssp.py @@ -347,19 +347,25 @@ def test_create_custom_template_from_url_success(self, mock_template_class, mock mock_template_class.return_value.__exit__ = MagicMock(return_value=None) mock_namespace = MagicMock() + mock_client = MagicMock() with create_custom_template_from_url( url="https://example.com/template.yaml", template_name="custom-template", template_dir="/tmp", namespace=mock_namespace, + client=mock_client, ) as template: assert template == mock_template mock_urlretrieve.assert_called_once_with( url="https://example.com/template.yaml", filename="/tmp/custom-template" ) - mock_template_class.assert_called_once() + mock_template_class.assert_called_once_with( + yaml_file="/tmp/custom-template", + namespace=mock_namespace, + client=mock_client, + ) class TestGuestAgentVersionParser: