From 88baf3db16b4266bad5ecddd7d8df23dd57d0e25 Mon Sep 17 00:00:00 2001 From: Longxiang Lyu <35479537+lolyu@users.noreply.github.com> Date: Wed, 6 Oct 2021 00:49:01 +0800 Subject: [PATCH] [sonic_sku_create] Add SKU creation support for Arista devices (#1841) What I did Let's add Arista support to the SKU creator tool NOTE: only creation from XML file is supported now How I did it Enable the SKU creator tool to parse Arista port alias Signed-off-by: Longxiang Lyu --- scripts/sonic_sku_create.py | 65 ++++++--- .../Arista-7050CX3-32S-C32/port_config.ini | 35 +++++ .../7050_files/Arista-7050CX3-32S-D48C8.xml | 61 +++++++++ .../Arista-7050CX3-32S-D48C8/port_config.ini | 57 ++++++++ tests/sku_create_input/7050_files/default_sku | 1 + .../Arista-7260CX3-C64/port_config.ini | 67 ++++++++++ .../7260_files/Arista-7260CX3-D108C8.xml | 126 ++++++++++++++++++ .../Arista-7260CX3-D108C8/port_config.ini | 123 +++++++++++++++++ tests/sku_create_input/7260_files/default_sku | 1 + tests/sku_create_test.py | 71 ++++++---- 10 files changed, 561 insertions(+), 46 deletions(-) create mode 100644 tests/sku_create_input/7050_files/Arista-7050CX3-32S-C32/port_config.ini create mode 100644 tests/sku_create_input/7050_files/Arista-7050CX3-32S-D48C8.xml create mode 100644 tests/sku_create_input/7050_files/Arista-7050CX3-32S-D48C8/port_config.ini create mode 100644 tests/sku_create_input/7050_files/default_sku create mode 100644 tests/sku_create_input/7260_files/Arista-7260CX3-C64/port_config.ini create mode 100644 tests/sku_create_input/7260_files/Arista-7260CX3-D108C8.xml create mode 100644 tests/sku_create_input/7260_files/Arista-7260CX3-D108C8/port_config.ini create mode 100644 tests/sku_create_input/7260_files/default_sku diff --git a/scripts/sonic_sku_create.py b/scripts/sonic_sku_create.py index cc81782353..e32af358f1 100755 --- a/scripts/sonic_sku_create.py +++ b/scripts/sonic_sku_create.py @@ -23,6 +23,7 @@ """ import argparse +import itertools import json import os import re @@ -74,6 +75,11 @@ class SkuCreate(object): Tool for SKU creator """ + PORT_ALIAS_PATTERNS = ( + re.compile(r"^etp(?P\d+)(?P[a-d]?)"), + re.compile(r"^Ethernet(?P\d+)(/)?(?(2)(?P[1-4]+))") + ) + def __init__(self): self.portconfig_dict = {} @@ -96,7 +102,7 @@ def __init__(self): self.bko_dict = {} def sku_def_parser(self, sku_def): - # Parsing XML sku definition file to extract Interface speed and InterfaceName(alias) to be used to analyze split configuration + # Parsing XML sku definition file to extract Interface speed and InterfaceName(alias) |/<#> to be used to analyze split configuration # Rest of the fields are used as placeholders for portconfig_dict [name,lanes,SPEED,ALIAS,index] try: f = open(str(sku_def),"r") @@ -525,20 +531,28 @@ def break_a_port(self, port_name, port_split): exit(1) self.break_in_cfg(self.cfg_file,port_name,port_split,lanes_str_result) + def _parse_interface_alias(self, alias): + """Analyze the front panel port index and split index based on the alias.""" + for alias_pattern in self.PORT_ALIAS_PATTERNS: + m = alias_pattern.match(alias) + if m: + return m.group("port_index"), m.group("lane") + return None, None + def split_analyze(self): # Analyze the front panl ports split based on the interfaces alias names # fpp_split is a hash with key=front panel port and values is a list of lists ([alias],[index]) alias_index = PORTCONFIG_HEADER.index('alias') for idx, ifc in self.portconfig_dict.items(): - pattern = '^etp([0-9]{1,})([a-d]?)' - m = re.match(pattern,str(ifc[alias_index])) - if int(m.group(1)) not in self.fpp_split : - self.fpp_split[int(m.group(1))] = [[ifc[alias_index]],[idx]] #1 + pi, _ = self._parse_interface_alias(ifc[alias_index]) + pi = int(pi) + if pi not in self.fpp_split : + self.fpp_split[pi] = [[ifc[alias_index]],[idx]] #1 else: - self.fpp_split[int(m.group(1))][0].append(str(ifc[alias_index])) #+= 1 - self.fpp_split[int(m.group(1))][1].append(idx) + self.fpp_split[pi][0].append(str(ifc[alias_index])) #+= 1 + self.fpp_split[pi][1].append(idx) if (self.verbose): - print("split_analyze -> ",m.group(1), " : ", self.fpp_split[int(m.group(1))]) + print("split_analyze -> ", pi, " : ", self.fpp_split[pi]) self.num_of_fpp = len(list(self.fpp_split.keys())) def get_default_lanes(self): @@ -549,14 +563,14 @@ def get_default_lanes(self): if line_header[0] == "#" : del line_header[0] # if hashtag is in a different column, remove it to align column header and data alias_index = line_header.index('alias') lanes_index = line_header.index('lanes') - pattern = '^etp([0-9]{1,})' for line in f: line_arr = line.split() - m = re.match(pattern,line_arr[alias_index]) - self.default_lanes_per_port.insert(int(m.group(1))-1,line_arr[lanes_index]) + pi, _ = self._parse_interface_alias(line_arr[alias_index]) + pi = int(pi) + self.default_lanes_per_port.insert(pi - 1, line_arr[lanes_index]) if (self.verbose): - print("get_default_lanes -> ",m.group(1), " : ", self.default_lanes_per_port[int(m.group(1))-1]) - f.close() + print("get_default_lanes -> ", pi, " : ", self.default_lanes_per_port[pi - 1]) + except IOError: print("Could not open file "+ self.base_file_path, file=sys.stderr) exit(1) @@ -572,19 +586,26 @@ def set_lanes(self): idx_arr = sorted(values[1]) splt = len(splt_arr) - pattern = '(\d+),(\d+),(\d+),(\d+)' #Currently the assumption is that the default(base) is 4 lanes + lanes = [_.strip() for _ in self.default_lanes_per_port[fp - 1].split(",")] + lanes_count = len(lanes) + if lanes_count % splt != 0: + print("Lanes(%s) could not be evenly splitted by %d." % (self.default_lanes_per_port[fp - 1], splt)) + exit(1) + + # split the lanes + it = iter(lanes) + lanes_splitted = list(iter(lambda: tuple(itertools.islice(it, lanes_count // splt)), ())) - m = re.match(pattern,self.default_lanes_per_port[fp-1]) if (splt == 1): - self.portconfig_dict[idx_arr[0]][lanes_index] = m.group(1)+","+m.group(2)+","+m.group(3)+","+m.group(4) + self.portconfig_dict[idx_arr[0]][lanes_index] = ",".join(lanes_splitted[0]) self.portconfig_dict[idx_arr[0]][index_index] = str(fp) self.portconfig_dict[idx_arr[0]][name_index] = "Ethernet"+str((fp-1)*4) if (self.verbose): print("set_lanes -> FP: ",fp, "Split: ",splt) print("PortConfig_dict ",idx_arr[0],":", self.portconfig_dict[idx_arr[0]]) elif (splt == 2): - self.portconfig_dict[idx_arr[0]][lanes_index] = m.group(1)+","+m.group(2) - self.portconfig_dict[idx_arr[1]][lanes_index] = m.group(3)+","+m.group(4) + self.portconfig_dict[idx_arr[0]][lanes_index] = ",".join(lanes_splitted[0]) + self.portconfig_dict[idx_arr[1]][lanes_index] = ",".join(lanes_splitted[1]) self.portconfig_dict[idx_arr[0]][index_index] = str(fp) self.portconfig_dict[idx_arr[1]][index_index] = str(fp) self.portconfig_dict[idx_arr[0]][name_index] = "Ethernet"+str((fp-1)*4) @@ -594,10 +615,10 @@ def set_lanes(self): print("PortConfig_dict ",idx_arr[0],":", self.portconfig_dict[idx_arr[0]]) print("PortConfig_dict ",idx_arr[1],":", self.portconfig_dict[idx_arr[1]]) elif (splt == 4): - self.portconfig_dict[idx_arr[0]][lanes_index] = m.group(1) - self.portconfig_dict[idx_arr[1]][lanes_index] = m.group(2) - self.portconfig_dict[idx_arr[2]][lanes_index] = m.group(3) - self.portconfig_dict[idx_arr[3]][lanes_index] = m.group(4) + self.portconfig_dict[idx_arr[0]][lanes_index] = ",".join(lanes_splitted[0]) + self.portconfig_dict[idx_arr[1]][lanes_index] = ",".join(lanes_splitted[1]) + self.portconfig_dict[idx_arr[2]][lanes_index] = ",".join(lanes_splitted[2]) + self.portconfig_dict[idx_arr[3]][lanes_index] = ",".join(lanes_splitted[3]) self.portconfig_dict[idx_arr[0]][index_index] = str(fp) self.portconfig_dict[idx_arr[1]][index_index] = str(fp) self.portconfig_dict[idx_arr[2]][index_index] = str(fp) diff --git a/tests/sku_create_input/7050_files/Arista-7050CX3-32S-C32/port_config.ini b/tests/sku_create_input/7050_files/Arista-7050CX3-32S-C32/port_config.ini new file mode 100644 index 0000000000..ce59cd5c97 --- /dev/null +++ b/tests/sku_create_input/7050_files/Arista-7050CX3-32S-C32/port_config.ini @@ -0,0 +1,35 @@ +# name lanes alias index speed +Ethernet0 1,2,3,4 Ethernet1/1 1 100000 +Ethernet4 5,6,7,8 Ethernet2/1 2 100000 +Ethernet8 9,10,11,12 Ethernet3/1 3 100000 +Ethernet12 13,14,15,16 Ethernet4/1 4 100000 +Ethernet16 21,22,23,24 Ethernet5/1 5 100000 +Ethernet20 17,18,19,20 Ethernet6/1 6 100000 +Ethernet24 25,26,27,28 Ethernet7/1 7 100000 +Ethernet28 29,30,31,32 Ethernet8/1 8 100000 +Ethernet32 37,38,39,40 Ethernet9/1 9 100000 +Ethernet36 33,34,35,36 Ethernet10/1 10 100000 +Ethernet40 41,42,43,44 Ethernet11/1 11 100000 +Ethernet44 45,46,47,48 Ethernet12/1 12 100000 +Ethernet48 53,54,55,56 Ethernet13/1 13 100000 +Ethernet52 49,50,51,52 Ethernet14/1 14 100000 +Ethernet56 57,58,59,60 Ethernet15/1 15 100000 +Ethernet60 61,62,63,64 Ethernet16/1 16 100000 +Ethernet64 69,70,71,72 Ethernet17/1 17 100000 +Ethernet68 65,66,67,68 Ethernet18/1 18 100000 +Ethernet72 73,74,75,76 Ethernet19/1 19 100000 +Ethernet76 77,78,79,80 Ethernet20/1 20 100000 +Ethernet80 85,86,87,88 Ethernet21/1 21 100000 +Ethernet84 81,82,83,84 Ethernet22/1 22 100000 +Ethernet88 89,90,91,92 Ethernet23/1 23 100000 +Ethernet92 93,94,95,96 Ethernet24/1 24 100000 +Ethernet96 101,102,103,104 Ethernet25/1 25 100000 +Ethernet100 97,98,99,100 Ethernet26/1 26 100000 +Ethernet104 105,106,107,108 Ethernet27/1 27 100000 +Ethernet108 109,110,111,112 Ethernet28/1 28 100000 +Ethernet112 117,118,119,120 Ethernet29/1 29 100000 +Ethernet116 113,114,115,116 Ethernet30/1 30 100000 +Ethernet120 121,122,123,124 Ethernet31/1 31 100000 +Ethernet124 125,126,127,128 Ethernet32/1 32 100000 +Ethernet128 129 Ethernet33 33 10000 +Ethernet132 128 Ethernet34 34 10000 diff --git a/tests/sku_create_input/7050_files/Arista-7050CX3-32S-D48C8.xml b/tests/sku_create_input/7050_files/Arista-7050CX3-32S-D48C8.xml new file mode 100644 index 0000000000..d67b32a40d --- /dev/null +++ b/tests/sku_create_input/7050_files/Arista-7050CX3-32S-D48C8.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/sku_create_input/7050_files/Arista-7050CX3-32S-D48C8/port_config.ini b/tests/sku_create_input/7050_files/Arista-7050CX3-32S-D48C8/port_config.ini new file mode 100644 index 0000000000..25670f87d9 --- /dev/null +++ b/tests/sku_create_input/7050_files/Arista-7050CX3-32S-D48C8/port_config.ini @@ -0,0 +1,57 @@ +# name lanes alias index speed +Ethernet0 1,2 Ethernet1/1 1 50000 +Ethernet2 3,4 Ethernet1/3 1 50000 +Ethernet4 5,6 Ethernet2/1 2 50000 +Ethernet6 7,8 Ethernet2/3 2 50000 +Ethernet8 9,10 Ethernet3/1 3 50000 +Ethernet10 11,12 Ethernet3/3 3 50000 +Ethernet12 13,14 Ethernet4/1 4 50000 +Ethernet14 15,16 Ethernet4/3 4 50000 +Ethernet16 21,22 Ethernet5/1 5 50000 +Ethernet18 23,24 Ethernet5/3 5 50000 +Ethernet20 17,18 Ethernet6/1 6 50000 +Ethernet22 19,20 Ethernet6/3 6 50000 +Ethernet24 25,26,27,28 Ethernet7/1 7 100000 +Ethernet28 29,30,31,32 Ethernet8/1 8 100000 +Ethernet32 37,38,39,40 Ethernet9/1 9 100000 +Ethernet36 33,34,35,36 Ethernet10/1 10 100000 +Ethernet40 41,42 Ethernet11/1 11 50000 +Ethernet42 43,44 Ethernet11/3 11 50000 +Ethernet44 45,46 Ethernet12/1 12 50000 +Ethernet46 47,48 Ethernet12/3 12 50000 +Ethernet48 53,54 Ethernet13/1 13 50000 +Ethernet50 55,56 Ethernet13/3 13 50000 +Ethernet52 49,50 Ethernet14/1 14 50000 +Ethernet54 51,52 Ethernet14/3 14 50000 +Ethernet56 57,58 Ethernet15/1 15 50000 +Ethernet58 59,60 Ethernet15/3 15 50000 +Ethernet60 61,62 Ethernet16/1 16 50000 +Ethernet62 63,64 Ethernet16/3 16 50000 +Ethernet64 69,70 Ethernet17/1 17 50000 +Ethernet66 71,72 Ethernet17/3 17 50000 +Ethernet68 65,66 Ethernet18/1 18 50000 +Ethernet70 67,68 Ethernet18/3 18 50000 +Ethernet72 73,74 Ethernet19/1 19 50000 +Ethernet74 75,76 Ethernet19/3 19 50000 +Ethernet76 77,78 Ethernet20/1 20 50000 +Ethernet78 79,80 Ethernet20/3 20 50000 +Ethernet80 85,86 Ethernet21/1 21 50000 +Ethernet82 87,88 Ethernet21/3 21 50000 +Ethernet84 81,82 Ethernet22/1 22 50000 +Ethernet86 83,84 Ethernet22/3 22 50000 +Ethernet88 89,90,91,92 Ethernet23/1 23 100000 +Ethernet92 93,94,95,96 Ethernet24/1 24 100000 +Ethernet96 101,102,103,104 Ethernet25/1 25 100000 +Ethernet100 97,98,99,100 Ethernet26/1 26 100000 +Ethernet104 105,106 Ethernet27/1 27 50000 +Ethernet106 107,108 Ethernet27/3 27 50000 +Ethernet108 109,110 Ethernet28/1 28 50000 +Ethernet110 111,112 Ethernet28/3 28 50000 +Ethernet112 117,118 Ethernet29/1 29 50000 +Ethernet114 119,120 Ethernet29/3 29 50000 +Ethernet116 113,114 Ethernet30/1 30 50000 +Ethernet118 115,116 Ethernet30/3 30 50000 +Ethernet120 121,122 Ethernet31/1 31 50000 +Ethernet122 123,124 Ethernet31/3 31 50000 +Ethernet124 125,126 Ethernet32/1 32 50000 +Ethernet126 127,128 Ethernet32/3 32 50000 diff --git a/tests/sku_create_input/7050_files/default_sku b/tests/sku_create_input/7050_files/default_sku new file mode 100644 index 0000000000..bff7a549cb --- /dev/null +++ b/tests/sku_create_input/7050_files/default_sku @@ -0,0 +1 @@ +Arista-7050CX3-32S-C32 t1 diff --git a/tests/sku_create_input/7260_files/Arista-7260CX3-C64/port_config.ini b/tests/sku_create_input/7260_files/Arista-7260CX3-C64/port_config.ini new file mode 100644 index 0000000000..3940948a35 --- /dev/null +++ b/tests/sku_create_input/7260_files/Arista-7260CX3-C64/port_config.ini @@ -0,0 +1,67 @@ +# name lanes alias index speed +Ethernet0 77,78,79,80 Ethernet1/1 1 100000 +Ethernet4 65,66,67,68 Ethernet2/1 2 100000 +Ethernet8 85,86,87,88 Ethernet3/1 3 100000 +Ethernet12 89,90,91,92 Ethernet4/1 4 100000 +Ethernet16 109,110,111,112 Ethernet5/1 5 100000 +Ethernet20 97,98,99,100 Ethernet6/1 6 100000 +Ethernet24 5,6,7,8 Ethernet7/1 7 100000 +Ethernet28 13,14,15,16 Ethernet8/1 8 100000 +Ethernet32 25,26,27,28 Ethernet9/1 9 100000 +Ethernet36 21,22,23,24 Ethernet10/1 10 100000 +Ethernet40 37,38,39,40 Ethernet11/1 11 100000 +Ethernet44 45,46,47,48 Ethernet12/1 12 100000 +Ethernet48 57,58,59,60 Ethernet13/1 13 100000 +Ethernet52 53,54,55,56 Ethernet14/1 14 100000 +Ethernet56 117,118,119,120 Ethernet15/1 15 100000 +Ethernet60 121,122,123,124 Ethernet16/1 16 100000 +Ethernet64 141,142,143,144 Ethernet17/1 17 100000 +Ethernet68 133,134,135,136 Ethernet18/1 18 100000 +Ethernet72 197,198,199,200 Ethernet19/1 19 100000 +Ethernet76 205,206,207,208 Ethernet20/1 20 100000 +Ethernet80 217,218,219,220 Ethernet21/1 21 100000 +Ethernet84 213,214,215,216 Ethernet22/1 22 100000 +Ethernet88 229,230,231,232 Ethernet23/1 23 100000 +Ethernet92 237,238,239,240 Ethernet24/1 24 100000 +Ethernet96 249,250,251,252 Ethernet25/1 25 100000 +Ethernet100 245,246,247,248 Ethernet26/1 26 100000 +Ethernet104 149,150,151,152 Ethernet27/1 27 100000 +Ethernet108 153,154,155,156 Ethernet28/1 28 100000 +Ethernet112 173,174,175,176 Ethernet29/1 29 100000 +Ethernet116 161,162,163,164 Ethernet30/1 30 100000 +Ethernet120 181,182,183,184 Ethernet31/1 31 100000 +Ethernet124 185,186,187,188 Ethernet32/1 32 100000 +Ethernet128 69,70,71,72 Ethernet33/1 33 100000 +Ethernet132 73,74,75,76 Ethernet34/1 34 100000 +Ethernet136 93,94,95,96 Ethernet35/1 35 100000 +Ethernet140 81,82,83,84 Ethernet36/1 36 100000 +Ethernet144 101,102,103,104 Ethernet37/1 37 100000 +Ethernet148 105,106,107,108 Ethernet38/1 38 100000 +Ethernet152 9,10,11,12 Ethernet39/1 39 100000 +Ethernet156 1,2,3,4 Ethernet40/1 40 100000 +Ethernet160 17,18,19,20 Ethernet41/1 41 100000 +Ethernet164 29,30,31,32 Ethernet42/1 42 100000 +Ethernet168 41,42,43,44 Ethernet43/1 43 100000 +Ethernet172 33,34,35,36 Ethernet44/1 44 100000 +Ethernet176 49,50,51,52 Ethernet45/1 45 100000 +Ethernet180 61,62,63,64 Ethernet46/1 46 100000 +Ethernet184 125,126,127,128 Ethernet47/1 47 100000 +Ethernet188 113,114,115,116 Ethernet48/1 48 100000 +Ethernet192 129,130,131,132 Ethernet49/1 49 100000 +Ethernet196 137,138,139,140 Ethernet50/1 50 100000 +Ethernet200 201,202,203,204 Ethernet51/1 51 100000 +Ethernet204 193,194,195,196 Ethernet52/1 52 100000 +Ethernet208 209,210,211,212 Ethernet53/1 53 100000 +Ethernet212 221,222,223,224 Ethernet54/1 54 100000 +Ethernet216 233,234,235,236 Ethernet55/1 55 100000 +Ethernet220 225,226,227,228 Ethernet56/1 56 100000 +Ethernet224 241,242,243,244 Ethernet57/1 57 100000 +Ethernet228 253,254,255,256 Ethernet58/1 58 100000 +Ethernet232 157,158,159,160 Ethernet59/1 59 100000 +Ethernet236 145,146,147,148 Ethernet60/1 60 100000 +Ethernet240 165,166,167,168 Ethernet61/1 61 100000 +Ethernet244 169,170,171,172 Ethernet62/1 62 100000 +Ethernet248 189,190,191,192 Ethernet63/1 63 100000 +Ethernet252 177,178,179,180 Ethernet64/1 64 100000 +Ethernet256 257 Ethernet65 65 10000 +Ethernet260 259 Ethernet66 66 10000 diff --git a/tests/sku_create_input/7260_files/Arista-7260CX3-D108C8.xml b/tests/sku_create_input/7260_files/Arista-7260CX3-D108C8.xml new file mode 100644 index 0000000000..f5eb162eb7 --- /dev/null +++ b/tests/sku_create_input/7260_files/Arista-7260CX3-D108C8.xml @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/sku_create_input/7260_files/Arista-7260CX3-D108C8/port_config.ini b/tests/sku_create_input/7260_files/Arista-7260CX3-D108C8/port_config.ini new file mode 100644 index 0000000000..c06fdd581e --- /dev/null +++ b/tests/sku_create_input/7260_files/Arista-7260CX3-D108C8/port_config.ini @@ -0,0 +1,123 @@ +# name lanes alias index speed +Ethernet0 77,78 Ethernet1/1 1 50000 +Ethernet2 79,80 Ethernet1/3 1 50000 +Ethernet4 65,66 Ethernet2/1 2 50000 +Ethernet6 67,68 Ethernet2/3 2 50000 +Ethernet8 85,86 Ethernet3/1 3 50000 +Ethernet10 87,88 Ethernet3/3 3 50000 +Ethernet12 89,90 Ethernet4/1 4 50000 +Ethernet14 91,92 Ethernet4/3 4 50000 +Ethernet16 109,110 Ethernet5/1 5 50000 +Ethernet18 111,112 Ethernet5/3 5 50000 +Ethernet20 97,98 Ethernet6/1 6 50000 +Ethernet22 99,100 Ethernet6/3 6 50000 +Ethernet24 5,6 Ethernet7/1 7 50000 +Ethernet26 7,8 Ethernet7/3 7 50000 +Ethernet28 13,14 Ethernet8/1 8 50000 +Ethernet30 15,16 Ethernet8/3 8 50000 +Ethernet32 25,26 Ethernet9/1 9 50000 +Ethernet34 27,28 Ethernet9/3 9 50000 +Ethernet36 21,22 Ethernet10/1 10 50000 +Ethernet38 23,24 Ethernet10/3 10 50000 +Ethernet40 37,38 Ethernet11/1 11 50000 +Ethernet42 39,40 Ethernet11/3 11 50000 +Ethernet44 45,46 Ethernet12/1 12 50000 +Ethernet46 47,48 Ethernet12/3 12 50000 +Ethernet48 57,58,59,60 Ethernet13/1 13 100000 +Ethernet52 53,54,55,56 Ethernet14/1 14 100000 +Ethernet56 117,118,119,120 Ethernet15/1 15 100000 +Ethernet60 121,122,123,124 Ethernet16/1 16 100000 +Ethernet64 141,142,143,144 Ethernet17/1 17 100000 +Ethernet68 133,134,135,136 Ethernet18/1 18 100000 +Ethernet72 197,198,199,200 Ethernet19/1 19 100000 +Ethernet76 205,206,207,208 Ethernet20/1 20 100000 +Ethernet80 217,218 Ethernet21/1 21 50000 +Ethernet82 219,220 Ethernet21/3 21 50000 +Ethernet84 213,214 Ethernet22/1 22 50000 +Ethernet86 215,216 Ethernet22/3 22 50000 +Ethernet88 229,230 Ethernet23/1 23 50000 +Ethernet90 231,232 Ethernet23/3 23 50000 +Ethernet92 237,238 Ethernet24/1 24 50000 +Ethernet94 239,240 Ethernet24/3 24 50000 +Ethernet96 249,250 Ethernet25/1 25 50000 +Ethernet98 251,252 Ethernet25/3 25 50000 +Ethernet100 245,246 Ethernet26/1 26 50000 +Ethernet102 247,248 Ethernet26/3 26 50000 +Ethernet104 149,150 Ethernet27/1 27 50000 +Ethernet106 151,152 Ethernet27/3 27 50000 +Ethernet108 153,154 Ethernet28/1 28 50000 +Ethernet110 155,156 Ethernet28/3 28 50000 +Ethernet112 173,174 Ethernet29/1 29 50000 +Ethernet114 175,176 Ethernet29/3 29 50000 +Ethernet116 161,162 Ethernet30/1 30 50000 +Ethernet118 163,164 Ethernet30/3 30 50000 +Ethernet120 181,182 Ethernet31/1 31 50000 +Ethernet122 183,184 Ethernet31/3 31 50000 +Ethernet124 185,186 Ethernet32/1 32 50000 +Ethernet126 187,188 Ethernet32/3 32 50000 +Ethernet128 69,70 Ethernet33/1 33 50000 +Ethernet130 71,72 Ethernet33/3 33 50000 +Ethernet132 73,74 Ethernet34/1 34 50000 +Ethernet134 75,76 Ethernet34/3 34 50000 +Ethernet136 93,94 Ethernet35/1 35 50000 +Ethernet138 95,96 Ethernet35/3 35 50000 +Ethernet140 81,82 Ethernet36/1 36 50000 +Ethernet142 83,84 Ethernet36/3 36 50000 +Ethernet144 101,102 Ethernet37/1 37 50000 +Ethernet146 103,104 Ethernet37/3 37 50000 +Ethernet148 105,106 Ethernet38/1 38 50000 +Ethernet150 107,108 Ethernet38/3 38 50000 +Ethernet152 9,10 Ethernet39/1 39 50000 +Ethernet154 11,12 Ethernet39/3 39 50000 +Ethernet156 1,2 Ethernet40/1 40 50000 +Ethernet158 3,4 Ethernet40/3 40 50000 +Ethernet160 17,18 Ethernet41/1 41 50000 +Ethernet162 19,20 Ethernet41/3 41 50000 +Ethernet164 29,30 Ethernet42/1 42 50000 +Ethernet166 31,32 Ethernet42/3 42 50000 +Ethernet168 41,42 Ethernet43/1 43 50000 +Ethernet170 43,44 Ethernet43/3 43 50000 +Ethernet172 33,34 Ethernet44/1 44 50000 +Ethernet174 35,36 Ethernet44/3 44 50000 +Ethernet176 49,50 Ethernet45/1 45 50000 +Ethernet178 51,52 Ethernet45/3 45 50000 +Ethernet180 61,62 Ethernet46/1 46 50000 +Ethernet182 63,64 Ethernet46/3 46 50000 +Ethernet184 125,126 Ethernet47/1 47 50000 +Ethernet186 127,128 Ethernet47/3 47 50000 +Ethernet188 113,114 Ethernet48/1 48 50000 +Ethernet190 115,116 Ethernet48/3 48 50000 +Ethernet192 129,130 Ethernet49/1 49 50000 +Ethernet194 131,132 Ethernet49/3 49 50000 +Ethernet196 137,138 Ethernet50/1 50 50000 +Ethernet198 139,140 Ethernet50/3 50 50000 +Ethernet200 201,202 Ethernet51/1 51 50000 +Ethernet202 203,204 Ethernet51/3 51 50000 +Ethernet204 193,194 Ethernet52/1 52 50000 +Ethernet206 195,196 Ethernet52/3 52 50000 +Ethernet208 209,210 Ethernet53/1 53 50000 +Ethernet210 211,212 Ethernet53/3 53 50000 +Ethernet212 221,222 Ethernet54/1 54 50000 +Ethernet214 223,224 Ethernet54/3 54 50000 +Ethernet216 233,234 Ethernet55/1 55 50000 +Ethernet218 235,236 Ethernet55/3 55 50000 +Ethernet220 225,226 Ethernet56/1 56 50000 +Ethernet222 227,228 Ethernet56/3 56 50000 +Ethernet224 241,242 Ethernet57/1 57 50000 +Ethernet226 243,244 Ethernet57/3 57 50000 +Ethernet228 253,254 Ethernet58/1 58 50000 +Ethernet230 255,256 Ethernet58/3 58 50000 +Ethernet232 157,158 Ethernet59/1 59 50000 +Ethernet234 159,160 Ethernet59/3 59 50000 +Ethernet236 145,146 Ethernet60/1 60 50000 +Ethernet238 147,148 Ethernet60/3 60 50000 +Ethernet240 165,166 Ethernet61/1 61 50000 +Ethernet242 167,168 Ethernet61/3 61 50000 +Ethernet244 169,170 Ethernet62/1 62 50000 +Ethernet246 171,172 Ethernet62/3 62 50000 +Ethernet248 189,190 Ethernet63/1 63 50000 +Ethernet250 191,192 Ethernet63/3 63 50000 +Ethernet252 177,178 Ethernet64/1 64 50000 +Ethernet254 179,180 Ethernet64/3 64 50000 +Ethernet256 257 Ethernet65 65 10000 +Ethernet260 259 Ethernet66 66 10000 diff --git a/tests/sku_create_input/7260_files/default_sku b/tests/sku_create_input/7260_files/default_sku new file mode 100644 index 0000000000..959766d95f --- /dev/null +++ b/tests/sku_create_input/7260_files/default_sku @@ -0,0 +1 @@ +Arista-7260CX3-C64 t1 diff --git a/tests/sku_create_test.py b/tests/sku_create_test.py index 27e65bb0f5..ec449a6045 100644 --- a/tests/sku_create_test.py +++ b/tests/sku_create_test.py @@ -10,11 +10,26 @@ test_path = os.path.dirname(os.path.abspath(__file__)) modules_path = os.path.dirname(test_path) scripts_path = os.path.join(modules_path, "scripts") -xml_input_path = os.path.join(modules_path, "tests/sku_create_input/2700_files") -output_xml_dir_path = os.path.join(modules_path, "tests/sku_create_input/2700_files/Mellanox-SN2700-D48C8_NEW/") -sku_def_file = os.path.join(xml_input_path, "Mellanox-SN2700-D48C8.xml") -output_xml_file_path = os.path.join(modules_path, "tests/sku_create_input/2700_files/Mellanox-SN2700-D48C8_NEW/port_config.ini") -model_xml_file_path = os.path.join(modules_path, "tests/sku_create_input/2700_files/Mellanox-SN2700-D48C8/port_config.ini") + +# xml file input related test resources +xml_input_paths = ["tests/sku_create_input/2700_files", "tests/sku_create_input/7050_files", "tests/sku_create_input/7260_files"] +output_xml_dir_paths = [ + "tests/sku_create_input/2700_files/Mellanox-SN2700-D48C8_NEW/", + "tests/sku_create_input/7050_files/Arista-7050CX3-32S-D48C8_NEW", + "tests/sku_create_input/7260_files/Arista-7260CX3-D108C8_NEW" +] +sku_def_files = ["Mellanox-SN2700-D48C8.xml", "Arista-7050CX3-32S-D48C8.xml", "Arista-7260CX3-D108C8.xml"] +output_xml_file_paths = [ + "tests/sku_create_input/2700_files/Mellanox-SN2700-D48C8_NEW/port_config.ini", + "tests/sku_create_input/7050_files/Arista-7050CX3-32S-D48C8_NEW/port_config.ini", + "tests/sku_create_input/7260_files/Arista-7260CX3-D108C8_NEW/port_config.ini" +] +model_xml_file_paths = [ + "tests/sku_create_input/2700_files/Mellanox-SN2700-D48C8/port_config.ini", + "tests/sku_create_input/7050_files/Arista-7050CX3-32S-D48C8/port_config.ini", + "tests/sku_create_input/7260_files/Arista-7260CX3-D108C8/port_config.ini" +] + minigraph_input_path = os.path.join(modules_path, "tests/sku_create_input/3800_files") output_minigraph_dir_path = os.path.join(modules_path, "tests/sku_create_input/3800_files/Mellanox-SN3800-D28C50_NEW/") minigraph_file = os.path.join(minigraph_input_path, "t0-1-06-minigraph.xml") @@ -70,26 +85,34 @@ def are_file_contents_same(self,fname1,fname2): return True def test_sku_from_xml_file(self): - if (os.path.exists(output_xml_dir_path)): - shutil.rmtree(output_xml_dir_path) - - my_command = sku_create_script + " -f " + sku_def_file + " -d " + xml_input_path - - #Test case execution without stdout - result = subprocess.check_output(my_command,stderr=subprocess.STDOUT,shell=True) - print(result) - - #Check if the Output file exists - if (os.path.exists(output_xml_file_path)): - print("Output file: ",output_xml_file_path, "exists. SUCCESS!") - else: - pytest.fail("Output file: {} does not exist. FAILURE!".format(output_xml_file_path)) + test_resources = zip(xml_input_paths, output_xml_dir_paths, sku_def_files, output_xml_file_paths, model_xml_file_paths) + for xml_input_path, output_xml_dir_path, sku_def_file, output_xml_file_path, model_xml_file_path in test_resources: + xml_input_path = os.path.join(modules_path, xml_input_path) + output_xml_dir_path = os.path.join(modules_path, output_xml_dir_path) + sku_def_file = os.path.join(xml_input_path, sku_def_file) + output_xml_file_path = os.path.join(modules_path, output_xml_file_path) + model_xml_file_path = os.path.join(modules_path, model_xml_file_path) + + if (os.path.exists(output_xml_dir_path)): + shutil.rmtree(output_xml_dir_path) + + my_command = sku_create_script + " -f " + sku_def_file + " -d " + xml_input_path + + #Test case execution without stdout + result = subprocess.check_output(my_command,stderr=subprocess.STDOUT,shell=True) + print(result) + + #Check if the Output file exists + if (os.path.exists(output_xml_file_path)): + print("Output file: ",output_xml_file_path, "exists. SUCCESS!") + else: + pytest.fail("Output file: {} does not exist. FAILURE!".format(output_xml_file_path)) - #Check if the Output file and the model file have same contents - if self.are_file_contents_same(output_xml_file_path, model_xml_file_path) == True: - print("Output file: ",output_xml_file_path, " and model file: ",model_xml_file_path, "contents are same. SUCCESS!") - else: - pytest.fail("Output file: {} and model file: {} contents are not same. FAILURE!".format(output_xml_file_path, model_xml_file_path)) + #Check if the Output file and the model file have same contents + if self.are_file_contents_same(output_xml_file_path, model_xml_file_path) == True: + print("Output file: ",output_xml_file_path, " and model file: ",model_xml_file_path, "contents are same. SUCCESS!") + else: + pytest.fail("Output file: {} and model file: {} contents are not same. FAILURE!".format(output_xml_file_path, model_xml_file_path)) def test_sku_from_minigraph_file(self): if (os.path.exists(output_minigraph_dir_path)):