4
4
import os
5
5
6
6
import tests .common_utils as utils
7
- from sonic_py_common .general import getstatusoutput_noshell
8
7
9
8
10
9
#TODO: Remove this fixuture once SONiC moves to python3.x
@@ -22,18 +21,20 @@ class TestCfgGen(object):
22
21
@pytest .fixture (autouse = True )
23
22
def setup_teardown (self ):
24
23
self .test_dir = os .path .dirname (os .path .realpath (__file__ ))
25
- self .script_file = [ utils .PYTHON_INTERPRETTER , os .path .join (
26
- self .test_dir , '..' , 'sonic-cfggen' )]
24
+ self .script_file = utils .PYTHON_INTERPRETTER + ' ' + os .path .join (
25
+ self .test_dir , '..' , 'sonic-cfggen' )
27
26
self .sample_yang_file = os .path .join (self .test_dir ,
28
27
'test_yang_data.json' )
29
28
30
29
def run_script (self , arg , check_stderr = False ):
31
- print ('\n Running sonic-cfggen ' , arg )
30
+ print ('\n Running sonic-cfggen ' + arg )
32
31
if check_stderr :
33
- output = subprocess .check_output (self .script_file + arg ,
34
- stderr = subprocess .STDOUT )
32
+ output = subprocess .check_output (self .script_file + ' ' + arg ,
33
+ stderr = subprocess .STDOUT ,
34
+ shell = True )
35
35
else :
36
- output = subprocess .check_output (self .script_file + arg )
36
+ output = subprocess .check_output (self .script_file + ' ' + arg ,
37
+ shell = True )
37
38
38
39
if utils .PY3x :
39
40
output = output .decode ()
@@ -47,31 +48,32 @@ def run_script(self, arg, check_stderr=False):
47
48
return output
48
49
49
50
def run_diff (self , file1 , file2 ):
50
- _ , output = getstatusoutput_noshell (['diff' , '-u' , file1 , file2 ])
51
- return output
51
+ return subprocess .check_output ('diff -u {} {} || true' .format (
52
+ file1 , file2 ),
53
+ shell = True )
52
54
53
55
def run_script_with_yang_arg (self , arg , check_stderr = False ):
54
- args = [ "-Y" , self .sample_yang_file ] + arg
56
+ args = "-Y {} {}" . format ( self .sample_yang_file , arg )
55
57
return self .run_script (arg = args , check_stderr = check_stderr )
56
58
57
59
def test_print_data (self ):
58
- arg = [ "--print-data" ]
60
+ arg = "--print-data"
59
61
output = self .run_script_with_yang_arg (arg )
60
62
assert len (output .strip ()) > 0
61
63
62
64
63
65
def test_jinja_expression (self , expected_router_type = 'LeafRouter' ):
64
- arg = [ "-v" , "DEVICE_METADATA[\' localhost\' ][\' type\' ]" ]
66
+ arg = " -v \ " DEVICE_METADATA[\' localhost\' ][\' type\' ]\" "
65
67
output = self .run_script_with_yang_arg (arg )
66
68
assert output .strip () == expected_router_type
67
69
68
70
def test_hwsku (self ):
69
- arg = [ "-v" , "DEVICE_METADATA[\' localhost\' ][\' hwsku\' ]" ]
71
+ arg = "-v \ " DEVICE_METADATA[\' localhost\' ][\' hwsku\' ]\" "
70
72
output = self .run_script_with_yang_arg (arg )
71
73
assert output .strip () == "Force10-S6000"
72
74
73
75
def test_device_metadata (self ):
74
- arg = [ "--var-json" , "DEVICE_METADATA" ]
76
+ arg = "--var-json \ " DEVICE_METADATA\" "
75
77
output = json .loads (self .run_script_with_yang_arg (arg ))
76
78
assert (output ['localhost' ] == {\
77
79
'bgp_asn' : '65100' ,
@@ -85,7 +87,7 @@ def test_device_metadata(self):
85
87
86
88
87
89
def test_port_table (self ):
88
- arg = [ "--var-json" , "PORT" ]
90
+ arg = "--var-json \ " PORT\" "
89
91
output = json .loads (self .run_script_with_yang_arg (arg ))
90
92
assert (output == \
91
93
{'Ethernet0' : {'admin_status' : 'up' , 'alias' : 'eth0' , 'description' : 'Ethernet0' , 'fec' : 'rs' , 'lanes' : '65, 66' , 'mtu' : '9100' , 'pfc_asym' : 'on' , 'speed' : '40000' },
@@ -99,7 +101,7 @@ def test_port_table(self):
99
101
})
100
102
101
103
def test_portchannel_table (self ):
102
- arg = [ "--var-json" , "PORTCHANNEL" ]
104
+ arg = "--var-json \ " PORTCHANNEL\" "
103
105
output = json .loads (self .run_script_with_yang_arg (arg ))
104
106
assert (output == \
105
107
{'PortChannel1001' : {'admin_status' : 'up' ,
@@ -114,7 +116,7 @@ def test_portchannel_table(self):
114
116
'mtu' : '9100' }})
115
117
116
118
def test_portchannel_member_table (self ):
117
- arg = [ "--var-json" , "PORTCHANNEL_MEMBER" ]
119
+ arg = "--var-json \ " PORTCHANNEL_MEMBER\" "
118
120
output = json .loads (self .run_script_with_yang_arg (arg ))
119
121
assert (output == \
120
122
{ "PortChannel1001|Ethernet0" : {},
@@ -124,7 +126,7 @@ def test_portchannel_member_table(self):
124
126
})
125
127
126
128
def test_interface_table (self ):
127
- arg = [ "--var-json" , "INTERFACE" ]
129
+ arg = "--var-json \ " INTERFACE\" "
128
130
output = json .loads (self .run_script_with_yang_arg (arg ))
129
131
assert (output == {\
130
132
"Ethernet8" : {},
@@ -148,15 +150,15 @@ def test_interface_table(self):
148
150
})
149
151
150
152
def test_portchannel_interface_table (self ):
151
- arg = [ "--var-json" , "PORTCHANNEL_INTERFACE" ]
153
+ arg = "--var-json \ " PORTCHANNEL_INTERFACE\" "
152
154
output = json .loads (self .run_script_with_yang_arg (arg ))
153
155
assert (output == {\
154
156
"PortChannel1001|10.0.0.1/31" : {},
155
157
"PortChannel1002|10.0.0.60/31" : {}
156
158
})
157
159
158
160
def test_loopback_table (self ):
159
- arg = [ "--var-json" , "LOOPBACK_INTERFACE" ]
161
+ arg = "--var-json \ " LOOPBACK_INTERFACE\" "
160
162
output = json .loads (self .run_script_with_yang_arg (arg ))
161
163
assert (output == {\
162
164
"Loopback0" : {},
@@ -171,7 +173,7 @@ def test_loopback_table(self):
171
173
})
172
174
173
175
def test_acl_table (self ):
174
- arg = [ "--var-json" , "ACL_TABLE" ]
176
+ arg = "--var-json \ " ACL_TABLE\" "
175
177
output = json .loads (self .run_script_with_yang_arg (arg ))
176
178
assert (output == {\
177
179
'DATAACL' : {'policy_desc' : 'DATAACL' , 'ports' : ['PortChannel1001' ,'PortChannel1002' ], 'stage' : 'ingress' , 'type' : 'L3' },
@@ -181,7 +183,7 @@ def test_acl_table(self):
181
183
'SSH_ONLY' : {'policy_desc' : 'SSH_ONLY' , 'services' : ['SSH' ], 'stage' : 'ingress' , 'type' : 'CTRLPLANE' }})
182
184
183
185
def test_acl_rule (self ):
184
- arg = [ "--var-json" , "ACL_RULE" ]
186
+ arg = "--var-json \ " ACL_RULE\" "
185
187
output = json .loads (self .run_script_with_yang_arg (arg ))
186
188
assert (output == {\
187
189
"DATAACL|Rule1" : {
@@ -199,7 +201,7 @@ def test_acl_rule(self):
199
201
})
200
202
201
203
def test_vlan_table (self ):
202
- arg = [ "--var-json" , "VLAN" ]
204
+ arg = "--var-json \ " VLAN\" "
203
205
output = json .loads (self .run_script_with_yang_arg (arg ))
204
206
assert (output == {\
205
207
"Vlan100" : {
@@ -216,7 +218,7 @@ def test_vlan_table(self):
216
218
})
217
219
218
220
def test_vlan_interface (self ):
219
- arg = [ "--var-json" , "VLAN_INTERFACE" ]
221
+ arg = "--var-json \ " VLAN_INTERFACE\" "
220
222
output = json .loads (self .run_script_with_yang_arg (arg ))
221
223
assert (output == {\
222
224
"Vlan100" : {},
@@ -231,7 +233,7 @@ def test_vlan_interface(self):
231
233
})
232
234
233
235
def test_vlan_member (self ):
234
- arg = [ "--var-json" , "VLAN_MEMBER" ]
236
+ arg = "--var-json \ " VLAN_MEMBER\" "
235
237
output = json .loads (self .run_script_with_yang_arg (arg ))
236
238
assert (output == {\
237
239
"Vlan100|Ethernet24" : {
@@ -243,7 +245,7 @@ def test_vlan_member(self):
243
245
})
244
246
245
247
def test_vlan_crm (self ):
246
- arg = [ "--var-json" , "CRM" ]
248
+ arg = "--var-json \ " CRM\" "
247
249
output = json .loads (self .run_script_with_yang_arg (arg ))
248
250
assert (output == {\
249
251
"Config" : {
0 commit comments