Skip to content

Commit

Permalink
Added changes to get NAD VLAN mapping info from csv file and prepare …
Browse files Browse the repository at this point in the history
…NAD VLAN map CR

Added unit test test
Added StaticPath CRD to acc-provision manifest
  • Loading branch information
YogeshRajmane committed Aug 29, 2023
1 parent 6aeed44 commit 3dc94d2
Show file tree
Hide file tree
Showing 56 changed files with 6,423 additions and 8 deletions.
59 changes: 58 additions & 1 deletion provision/acc_provision/acc_provision.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import argparse
import base64
import copy
import csv
import functools
import ipaddress
import requests
Expand Down Expand Up @@ -96,6 +97,49 @@ def yaml_quote(s):
return "'%s'" % str(s).replace("'", "''")


def get_csv_contents(file_path):
csv_data = []
try:
with open(file_path, 'r') as csv_file:
csv_reader = csv.DictReader(csv_file)
for row in csv_reader:
csv_data.append(row)
except Exception as ex:
print("Error while getting CSV %s file contents. Error: %s") % (file_path, ex)
return csv_data


def prepare_nadvlanmap(file_path):
csv_data = get_csv_contents(file_path)
all_resources = {}
old_namespace = ''
old_nad_prefix = ''
network = ''
vlan_id = ''
try:
for resource in csv_data:
namespace = resource['Namespace']
nad_prefix = resource['NAD Prefix']
if (namespace and namespace != old_namespace) or (nad_prefix and nad_prefix != old_nad_prefix):
resource_header = namespace + "/" + nad_prefix
if resource_header not in all_resources.keys():
all_resources[resource_header] = []
old_namespace = namespace
old_nad_prefix = nad_prefix

network = resource['Network'] if resource['Network'] else network
vlan_id = resource['VLAN ID'] if resource['VLAN ID'] else vlan_id
resource_item = {
"label": network,
"vlans": vlan_id.split('.')[0]
}
all_resources[resource_header].append(resource_item)
except Exception as ex:
print("Error while preparing yaml contents from given CSV %s file. Error: %s" % (file_path, ex))
all_resources = {}
return all_resources


def yaml_indent(s, **kwargs):
return yaml.dump(s, **kwargs)

Expand Down Expand Up @@ -1947,7 +1991,20 @@ def generate_kube_yaml(config, operator_output, operator_tar, operator_cr_output
if not tar_path or tar_path == "-":
tar_path = operator_output + ".tar.gz"

temp = ''.join(template.stream(config=config))
yaml_output = {}
if config.get("chained_cni_config", {}).get("enable"):
file_path = config["chained_cni_config"].get("ip_sheet_file")
if not file_path or not os.path.isfile(file_path):
config["chained_cni_config"].pop('ip_sheet_file', None)
else:
all_resources = prepare_nadvlanmap(file_path)
if all_resources:
yaml_output = yaml.dump(all_resources, default_flow_style=False)
else:
config["chained_cni_config"].pop('ip_sheet_file', None)
temp = ''.join(template.stream(config=config, input=yaml_output))
else:
temp = ''.join(template.stream(config=config))
parsed_temp = temp.split("---")
# Find the place where to put the acioperators configmap
for cmap_idx in range(len(parsed_temp)):
Expand Down
151 changes: 151 additions & 0 deletions provision/acc_provision/templates/aci-containers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2030,6 +2030,8 @@ rules:
- "aci.fabricattachment"
resources:
- nodefabricnetworkattachments
- nadvlanmaps
- staticfabricnetworkattachments
verbs:
- get
- list
Expand Down Expand Up @@ -3482,4 +3484,153 @@ spec:
type: object
served: true
storage: true
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.12.0
name: staticfabricnetworkattachments.aci.fabricattachment
spec:
group: aci.fabricattachment
names:
kind: StaticFabricNetworkAttachment
listKind: StaticFabricNetworkAttachmentList
plural: staticfabricnetworkattachments
singular: staticfabricnetworkattachment
scope: Cluster
versions:
- name: v1
schema:
openAPIV3Schema:
description: StaticFabricAttachment allows attaching aeps to NAD based and
regular vlans created by aci controller
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
properties:
nadVlanRefs:
description: Refer to a NADVlanLabel defined in NadVlanMap CR
items:
properties:
aeps:
items:
type: string
type: array
nadVlanLabel:
type: string
required:
- aeps
- nadVlanLabel
type: object
type: array
vlans:
description: Refer to vlan/s directly
items:
properties:
aeps:
items:
type: string
type: array
vlans:
type: string
required:
- aeps
- vlans
type: object
type: array
type: object
status:
description: StaticFabricNetworkAttachmentStatus defines the observed
state of StaticFabricNetworkAttachment
properties:
state:
type: string
type: object
type: object
x-kubernetes-validations:
- rule: "self.metadata.name == 'staticfabricnetworkattachment'"
message: "Only one instance with name staticfabricnetworkattachment allowed"
served: true
storage: true
subresources:
status: {}
---
apiVersion: aci.fabricattachment/v1
kind: NadVlanMap
metadata:
name: nad-vlan-map
namespace: aci-containers-system
spec:
nadVlanMapping:
{% if config.chained_cni_config.ip_sheet_file %}
{{ input|indent(width=4) }}
{% else %}
"pccmm/pc-mm":
- label: pc-mm-oam
vlans: "3023"
- label: pc-mm-ran-1
vlans: "3829"
- label: pc-mm-ran-2
vlans: "3879"
- label: pc-mm-signaling-1
vlans: "3877"
- label: pc-mm-signaling-2
vlans: "3878"
- label: pc-mm-media
vlans: "3826"
- label: pc-mm-li
vlans: "3830"
"pccsm/eric-pc-routing-engine":
- label: pc-sm-media
vlans: "3801"
- label: pc-sm-signaling
vlans: "3852"
- label: pc-sm-li-x2
vlans: "3840"
"pccsm/eric-pc-vpn-gateway-forwarder":
- label: pc-sm-media
vlans: "3801"
- label: pc-sm-signaling
vlans: "3852"
- label: pc-sm-li-x2
vlans: "3840"
- label: pc-sm-intra
vlans: "3701"
"pcg/eric-pcg-routing-engine":
- label: pc-up-ran
vlans: "3804"
- label: pc-up-dn
vlans: "3805"
- label: pc-up-signaling
vlans: "3827"
- label: pc-up-media
vlans: "3851"
- label: pc-up-li-x3
vlans: "3850"
"pcg/eric-pc-up-data-plane":
- label: pc-up-ran
vlans: "3804"
- label: pc-up-dn
vlans: "3805"
- label: pc-up-signaling
vlans: "3827"
- label: pc-up-media
vlans: "3851"
- label: pc-up-li-x3
vlans: "3850"
- label: pc-up-intrafrwd
vlans: "3700"
{% endif %}
{% endif %}
12 changes: 12 additions & 0 deletions provision/acc_provision/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,18 @@ def test_override_use_global_scope_vlan():
)


@in_testdir
def test_chained_mode_nad_vlan_map():
run_provision(
"chained_mode_nad_vlan_map.inp.yaml",
"chained_mode_nad_vlan_map.kube.yaml",
"chained_mode_nad_vlan_map_tar",
None,
"chained_mode_nad_vlan_map.apic.txt",
overrides={"flavor": "openshift-sdn-ovn-baremetal"}
)


@in_testdir
def test_flavor_openshift_411_baremetal():
run_provision(
Expand Down
Loading

0 comments on commit 3dc94d2

Please sign in to comment.