Skip to content
Closed
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 libs/net/netattachdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
44 changes: 32 additions & 12 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"]
Expand Down Expand Up @@ -961,14 +962,19 @@ 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.
"""
for worker_node in schedulable_nodes:
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,
):
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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"]
)


Expand Down Expand Up @@ -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,
):
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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")
Expand Down
6 changes: 4 additions & 2 deletions tests/infrastructure/sap/test_sap_hana_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down Expand Up @@ -474,14 +475,15 @@ 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(
url=f"{CNV_SUPPLEMENTAL_TEMPLATES_URL}/saphana/rhel8.saphana.yaml",
template_name=f"{template_name}.yaml",
template_dir=template_dir,
namespace=NamespacesNames.OPENSHIFT,
client=admin_client,
) as template:
yield template

Expand Down
6 changes: 4 additions & 2 deletions tests/install_upgrade_operators/must_gather/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 11 additions & 2 deletions tests/network/bgp/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=[
Expand Down Expand Up @@ -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),
Expand All @@ -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
Expand Down
17 changes: 14 additions & 3 deletions tests/network/bond/test_bond_modes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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),
Expand All @@ -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,
Expand All @@ -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

Expand All @@ -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,
Expand All @@ -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:],
Expand Down Expand Up @@ -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:],
Expand All @@ -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,
Expand All @@ -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"},
Expand Down
Loading
Loading