@@ -22,7 +22,6 @@ def setUp(self):
22
22
for asic in range (NUM_ASIC ):
23
23
self .port_config .append (os .path .join (self .test_data_dir , "sample_port_config-{}.ini" .format (asic )))
24
24
25
-
26
25
def run_script (self , argument , check_stderr = False ):
27
26
print '\n Running sonic-cfggen ' + argument
28
27
if check_stderr :
@@ -40,7 +39,6 @@ def run_script(self, argument, check_stderr=False):
40
39
def run_diff (self , file1 , file2 ):
41
40
return subprocess .check_output ('diff -u {} {} || true' .format (file1 , file2 ), shell = True )
42
41
43
-
44
42
def run_script_for_asic (self ,argument ,asic , port_config = None ):
45
43
argument = "{} -n asic{} " .format (argument , asic )
46
44
if port_config :
@@ -52,16 +50,14 @@ def test_dummy_run(self):
52
50
argument = ''
53
51
output = self .run_script (argument )
54
52
self .assertEqual (output , '' )
55
-
53
+
56
54
def test_hwsku (self ):
57
55
argument = "-v \" DEVICE_METADATA[\' localhost\' ][\' hwsku\' ]\" -m \" {}\" " .format (self .sample_graph )
58
56
output = self .run_script (argument )
59
57
self .assertEqual (output .strip (), SKU )
60
-
61
58
for asic in range (NUM_ASIC ):
62
59
output = self .run_script_for_asic (argument , asic )
63
60
self .assertEqual (output .strip (), SKU )
64
-
65
61
66
62
def test_print_data (self ):
67
63
argument = "-m \" {}\" --print-data" .format (self .sample_graph )
@@ -70,8 +66,7 @@ def test_print_data(self):
70
66
for asic in range (NUM_ASIC ):
71
67
output = self .run_script_for_asic (argument , asic )
72
68
self .assertGreater (len (output .strip ()) , 0 )
73
-
74
-
69
+
75
70
def test_additional_json_data (self ):
76
71
argument = '-a \' {"key1":"value1"}\' -v key1'
77
72
output = self .run_script (argument )
@@ -80,7 +75,6 @@ def test_additional_json_data(self):
80
75
output = self .run_script_for_asic (argument , asic )
81
76
self .assertEqual (output .strip (), 'value1' )
82
77
83
-
84
78
def test_read_yaml (self ):
85
79
argument = '-v yml_item -y ' + os .path .join (self .test_dir , 'test.yml' )
86
80
output = yaml .load (self .run_script (argument ))
@@ -123,20 +117,20 @@ def test_mgmt_port(self):
123
117
for asic in range (NUM_ASIC ):
124
118
output = json .loads (self .run_script_for_asic (argument , asic , self .port_config [asic ]))
125
119
self .assertDictEqual (output , {})
126
-
120
+
127
121
def test_frontend_asic_portchannels (self ):
128
122
argument = "-m {} -p {} -n asic0 --var-json \" PORTCHANNEL\" " .format (self .sample_graph , self .port_config [0 ])
129
123
output = json .loads (self .run_script (argument ))
130
124
self .assertDictEqual (output , \
131
- {'PortChannel0002' : {'admin_status' : 'up' , 'min_links' : '2' , 'members' : ['Ethernet0' , 'Ethernet4' ], 'mtu' : '9100' },
132
- 'PortChannel4001' : {'admin_status' : 'up' , 'min_links' : '2' , 'members' : ['Ethernet-BP0' , 'Ethernet-BP4' ], 'mtu' : '9100' },
125
+ {'PortChannel0002' : {'admin_status' : 'up' , 'min_links' : '2' , 'members' : ['Ethernet0' , 'Ethernet4' ], 'mtu' : '9100' },
126
+ 'PortChannel4001' : {'admin_status' : 'up' , 'min_links' : '2' , 'members' : ['Ethernet-BP0' , 'Ethernet-BP4' ], 'mtu' : '9100' },
133
127
'PortChannel4002' : {'admin_status' : 'up' , 'min_links' : '2' , 'members' : ['Ethernet-BP8' , 'Ethernet-BP12' ], 'mtu' : '9100' }})
134
-
128
+
135
129
def test_backend_asic_portchannels (self ):
136
130
argument = "-m {} -p {} -n asic3 --var-json \" PORTCHANNEL\" " .format (self .sample_graph , self .port_config [3 ])
137
131
output = json .loads (self .run_script (argument ))
138
132
self .assertDictEqual (output , \
139
- {'PortChannel4013' : {'admin_status' : 'up' , 'min_links' : '2' , 'members' : ['Ethernet-BP384' , 'Ethernet-BP388' ], 'mtu' : '9100' },
133
+ {'PortChannel4013' : {'admin_status' : 'up' , 'min_links' : '2' , 'members' : ['Ethernet-BP384' , 'Ethernet-BP388' ], 'mtu' : '9100' },
140
134
'PortChannel4014' : {'admin_status' : 'up' , 'min_links' : '2' , 'members' : ['Ethernet-BP392' , 'Ethernet-BP396' ], 'mtu' : '9100' }})
141
135
142
136
def test_frontend_asic_portchannel_mem (self ):
@@ -145,34 +139,33 @@ def test_frontend_asic_portchannel_mem(self):
145
139
self .assertListEqual (output .keys (), \
146
140
['PortChannel4002|Ethernet-BP8' , 'PortChannel0002|Ethernet0' , 'PortChannel0002|Ethernet4' , 'PortChannel4002|Ethernet-BP12' , 'PortChannel4001|Ethernet-BP0' , 'PortChannel4001|Ethernet-BP4' ])
147
141
148
-
149
142
def test_backend_asic_portchannels_mem (self ):
150
143
argument = "-m {} -p {} -n asic3 --var-json \" PORTCHANNEL_MEMBER\" " .format (self .sample_graph , self .port_config [3 ])
151
144
output = json .loads (self .run_script (argument ))
152
145
self .assertListEqual (output .keys (), \
153
146
['PortChannel4013|Ethernet-BP384' , 'PortChannel4014|Ethernet-BP392' , 'PortChannel4014|Ethernet-BP396' , 'PortChannel4013|Ethernet-BP388' ])
154
147
155
148
def test_frontend_asic_portchannel_intf (self ):
156
- argument = "-m {} -p {} -n asic0 --var-json \" PORTCHANNEL_INTERFACE\" " .format (self .sample_graph , self .port_config [0 ])
149
+ argument = "-m {} -p {} -n asic0 --var-json \" PORTCHANNEL_INTERFACE\" " .format (self .sample_graph , self .port_config [0 ])
157
150
output = json .loads (self .run_script (argument ))
158
151
self .assertListEqual (output .keys (), \
159
152
['PortChannel4001|10.1.0.1/31' , 'PortChannel0002|FC00::1/126' , 'PortChannel4002|10.1.0.3/31' , 'PortChannel0002' , 'PortChannel0002|10.0.0.0/31' , 'PortChannel4001' , 'PortChannel4002' ])
160
-
153
+
161
154
def test_backend_asic_portchannel_intf (self ):
162
- argument = "-m {} -p {} -n asic3 --var-json \" PORTCHANNEL_INTERFACE\" " .format (self .sample_graph , self .port_config [3 ])
155
+ argument = "-m {} -p {} -n asic3 --var-json \" PORTCHANNEL_INTERFACE\" " .format (self .sample_graph , self .port_config [3 ])
163
156
output = json .loads (self .run_script (argument ))
164
157
self .assertListEqual (output .keys (), \
165
158
['PortChannel4013' , 'PortChannel4013|10.1.0.2/31' , 'PortChannel4014' , 'PortChannel4014|10.1.0.6/31' ])
166
-
159
+
167
160
def test_frontend_asic_device_neigh (self ):
168
161
argument = "-m {} -p {} -n asic0 --var-json \" DEVICE_NEIGHBOR\" " .format (self .sample_graph , self .port_config [0 ])
169
162
output = json .loads (self .run_script (argument ))
170
163
self .assertDictEqual (output , \
171
164
{'Ethernet0' : {'name' : '01T2' , 'port' : 'Ethernet1' },
172
- 'Ethernet4' : {'name' : '01T2' , 'port' : 'Ethernet2' },
173
- 'Ethernet-BP4' : {'name' : 'ASIC2' , 'port' : 'Eth1-ASIC2' },
174
- 'Ethernet-BP12' : {'name' : 'ASIC3' , 'port' : 'Eth1-ASIC3' },
175
- 'Ethernet-BP0' : {'name' : 'ASIC2' , 'port' : 'Eth0-ASIC2' },
165
+ 'Ethernet4' : {'name' : '01T2' , 'port' : 'Ethernet2' },
166
+ 'Ethernet-BP4' : {'name' : 'ASIC2' , 'port' : 'Eth1-ASIC2' },
167
+ 'Ethernet-BP12' : {'name' : 'ASIC3' , 'port' : 'Eth1-ASIC3' },
168
+ 'Ethernet-BP0' : {'name' : 'ASIC2' , 'port' : 'Eth0-ASIC2' },
176
169
'Ethernet-BP8' : {'name' : 'ASIC3' , 'port' : 'Eth0-ASIC3' }})
177
170
178
171
def test_frontend_asic_device_neigh_metadata (self ):
@@ -191,7 +184,7 @@ def test_backend_asic_device_neigh(self):
191
184
'Ethernet-BP384' : {'name' : 'ASIC0' , 'port' : 'Eth6-ASIC0' },
192
185
'Ethernet-BP392' : {'name' : 'ASIC1' , 'port' : 'Eth6-ASIC1' },
193
186
'Ethernet-BP388' : {'name' : 'ASIC0' , 'port' : 'Eth7-ASIC0' }})
194
-
187
+
195
188
def test_backend_device_neigh_metadata (self ):
196
189
argument = "-m {} -p {} -n asic3 --var-json \" DEVICE_NEIGHBOR_METADATA\" " .format (self .sample_graph , self .port_config [3 ])
197
190
output = json .loads (self .run_script (argument ))
@@ -212,7 +205,7 @@ def test_backend_asic_bgp_neighbor(self):
212
205
argument = "-m {} -p {} -n asic3 --var-json \" BGP_NEIGHBOR\" " .format (self .sample_graph , self .port_config [3 ])
213
206
output = json .loads (self .run_script (argument ))
214
207
self .assertDictEqual (output , \
215
- {'10.1.0.7' : {'rrclient' : 0 , 'name' : 'ASIC1' , 'local_addr' : '10.1.0.6' , 'nhopself' : 0 , 'holdtime' : '0' , 'asn' : '65100' , 'keepalive' : '0' },
208
+ {'10.1.0.7' : {'rrclient' : 0 , 'name' : 'ASIC1' , 'local_addr' : '10.1.0.6' , 'nhopself' : 0 , 'holdtime' : '0' , 'asn' : '65100' , 'keepalive' : '0' },
216
209
'10.1.0.3' : {'rrclient' : 0 , 'name' : 'ASIC0' , 'local_addr' : '10.1.0.2' , 'nhopself' : 0 , 'holdtime' : '0' , 'asn' : '65100' , 'keepalive' : '0' }})
217
210
218
211
def test_device_asic_metadata (self ):
@@ -225,5 +218,4 @@ def test_device_asic_metadata(self):
225
218
if asic == 0 or asic == 1 :
226
219
self .assertEqual (output ['localhost' ]['sub_role' ], 'FrontEnd' )
227
220
else :
228
- self .assertEqual (output ['localhost' ]['sub_role' ], 'BackEnd' )
229
-
221
+ self .assertEqual (output ['localhost' ]['sub_role' ], 'BackEnd' )
0 commit comments