From d88b15cf4475d87100df08988a7a86f94700f9b4 Mon Sep 17 00:00:00 2001 From: oviner Date: Mon, 13 May 2024 10:14:42 +0300 Subject: [PATCH] add_route_nad_obj function Signed-off-by: oviner --- ocs_ci/ocs/constants.py | 2 + ocs_ci/ocs/resources/storage_cluster.py | 49 +++++++++++++++++++ .../node_network_configuration_policy.yaml | 29 +++++++++++ 3 files changed, 80 insertions(+) create mode 100644 ocs_ci/templates/ocs-deployment/node_network_configuration_policy.yaml diff --git a/ocs_ci/ocs/constants.py b/ocs_ci/ocs/constants.py index ce7b986f81e..26deede15ca 100644 --- a/ocs_ci/ocs/constants.py +++ b/ocs_ci/ocs/constants.py @@ -904,6 +904,8 @@ MULTUS_CLUSTER_NET_YAML = os.path.join( TEMPLATE_DEPLOYMENT_DIR, "multus-cluster-net.yaml" ) +NETWORK_ATTACHEMENT_DEFINITION = "network-attachment-definitions.k8s.cni.cncf.io" + OPERATOR_SOURCE_NAME = "ocs-operatorsource" diff --git a/ocs_ci/ocs/resources/storage_cluster.py b/ocs_ci/ocs/resources/storage_cluster.py index 356f5c491bf..b5f14806acd 100644 --- a/ocs_ci/ocs/resources/storage_cluster.py +++ b/ocs_ci/ocs/resources/storage_cluster.py @@ -1,6 +1,7 @@ """ StorageCluster related functionalities """ + import copy import ipaddress import logging @@ -2728,3 +2729,51 @@ def resize_osd(new_osd_size, check_size=True): format_type="json", ) return res + + +def get_network_attachment_definitions( + nad_name, namespace=config.ENV_DATA["cluster_namespace"] +): + """ + Get network_attachment_definitions obj + + Args: + nad_name (str) : network_attachment_definition name + namespace (str): Namespace of the resource + + Returns: + network_attachment_definitions (obj) : network_attachment_definitions object + + """ + return OCP( + kind=constants.NETWORK_ATTACHEMENT_DEFINITION, + namespace=namespace, + resource_name=nad_name, + ) + + +def add_route_nad_obj( + nad_name, + namespace=config.ENV_DATA["cluster_namespace"], + route_dst="192.168.252.0/24", +): + """ + Add route section to network_attachment_definitions object + + Args: + nad_name: network_attachment_definition name + namespace: Namespace of the resource + + """ + nad_obj = get_network_attachment_definitions(nad_name=nad_name, namespace=namespace) + nad_config_str = nad_obj.data["spec"]["config"] + nad_config_dict = json.loads(nad_config_str) + nad_config_dict["ipam"]["routes"] = [{"dst": route_dst}] + nad_config_dict_string = json.dumps(nad_config_dict) + params = f"""[{{ "op": "replace", "path": "/spec/config", + "value": {str(nad_config_dict_string)}}}]""" + nad_obj.patch( + resource_name=nad_name, + params=params.strip("\n"), + format_type="json", + ) diff --git a/ocs_ci/templates/ocs-deployment/node_network_configuration_policy.yaml b/ocs_ci/templates/ocs-deployment/node_network_configuration_policy.yaml new file mode 100644 index 00000000000..d5b804799ef --- /dev/null +++ b/ocs_ci/templates/ocs-deployment/node_network_configuration_policy.yaml @@ -0,0 +1,29 @@ +apiVersion: nmstate.io/v1 +kind: NodeNetworkConfigurationPolicy +metadata: + name: ceph-public-net-shim-worker-node + namespace: openshift-storage +spec: + nodeSelector: + node-role.kubernetes.io/worker: "" + kubernetes.io/hostname: worker-node + desiredState: + interfaces: + - name: odf-pub-shim + description: Shim interface used to connect host to OpenShift Data Foundation public Multus network + type: mac-vlan + state: up + mac-vlan: + base-iface: enp1s0f1 + mode: bridge + promiscuous: true + ipv4: + enabled: true + dhcp: false + address: + - ip: 192.168.252.1 # STATIC IP FOR worker node + prefix-length: 24 + routes: + config: + - destination: 192.168.20.0/24 + next-hop-interface: odf-pub-shim