23
23
import sys
24
24
import logging
25
25
import time
26
+ import subprocess
27
+ from sonic_py_common .general import getstatusoutput_noshell
26
28
27
29
PROJECT_NAME = 'QFX5200-32C'
28
30
verbose = False
29
31
DEBUG = False
30
32
FORCE = 0
31
33
32
34
if DEBUG == True :
33
- print sys .argv [0 ]
34
- print 'ARGV :' , sys .argv [1 :]
35
+ print ( sys .argv [0 ])
36
+ print ( 'ARGV :' , sys .argv [1 :])
35
37
36
38
i2c_prefix = '/sys/bus/i2c/devices/'
37
39
70
72
71
73
def my_log (txt ):
72
74
if DEBUG == True :
73
- print txt
75
+ print ( txt )
74
76
return
75
77
76
78
def log_os_system (cmd , show ):
@@ -83,6 +85,10 @@ def log_os_system(cmd, show):
83
85
if show :
84
86
print ('Failed :' + cmd )
85
87
return status , output
88
+
89
+ def write_file (text , file ):
90
+ with open (file , 'w' ) as f :
91
+ f .write (text + '\n ' )
86
92
87
93
def driver_install ():
88
94
global FORCE
@@ -106,7 +112,7 @@ def device_install():
106
112
for i in range (0 ,len (mknod )):
107
113
status , output = log_os_system (mknod [i ], 1 )
108
114
if status :
109
- print output
115
+ print ( output )
110
116
if FORCE == 0 :
111
117
return status
112
118
@@ -123,7 +129,7 @@ def do_install():
123
129
if FORCE == 0 :
124
130
return status
125
131
else :
126
- print PROJECT_NAME .upper ()+ " devices detected...."
132
+ print ( PROJECT_NAME .upper ()+ " devices detected...." )
127
133
return
128
134
129
135
def main ():
@@ -139,70 +145,71 @@ def main():
139
145
140
146
141
147
# Enabling REFPGA
142
- EnableREFFGACmd = 'busybox devmem 0xFED50011 8 0x53'
148
+ EnableREFFGACmd = [ 'busybox' , ' devmem' , ' 0xFED50011' , '8' , ' 0x53']
143
149
try :
144
- os . system (EnableREFFGACmd )
150
+ subprocess . call (EnableREFFGACmd )
145
151
except OSError :
146
- print 'Error: Execution of "%s" failed' , EnableREFFGACmd
152
+ print ( 'Error: Execution of "%s" failed' , EnableREFFGACmd )
147
153
return False
148
154
149
155
time .sleep (2 )
150
156
151
157
# Create CPU Board EEPROM device
152
- CreateEEPROMdeviceCmd = 'sudo echo 24c02 0x51 > /sys/bus/i2c/devices/i2c-0/new_device'
158
+ CreateEEPROMdeviceCmd = '24c02 0x51'
159
+ file = '/sys/bus/i2c/devices/i2c-0/new_device'
153
160
try :
154
- os . system (CreateEEPROMdeviceCmd )
161
+ write_file (CreateEEPROMdeviceCmd , file )
155
162
except OSError :
156
- print 'Error: Execution of "%s" failed' , CreateEEPROMdeviceCmd
163
+ print ( 'Error: Execution of "%s" failed' , CreateEEPROMdeviceCmd )
157
164
return False
158
165
159
166
time .sleep (1 )
160
167
161
168
#Retrieve the Base MAC Address from EEPROM
162
- status , macAddress = commands . getstatusoutput ( "decode-syseeprom -m 0x24" )
169
+ status , macAddress = getstatusoutput_noshell ([ "decode-syseeprom" , "-m" , " 0x24"] )
163
170
if status :
164
- print 'Error: Could not retrieve BASE MAC Address from EEPROM'
171
+ print ( 'Error: Could not retrieve BASE MAC Address from EEPROM' )
165
172
return False
166
173
167
174
#Make eth0 interface down
168
- status , eth0Down = commands . getstatusoutput ( "ifconfig eth0 down" )
175
+ status , eth0Down = getstatusoutput_noshell ([ "ifconfig" , " eth0" , " down"] )
169
176
if status :
170
- print 'Error: Could not make eth0 interface down'
177
+ print ( 'Error: Could not make eth0 interface down' )
171
178
return False
172
179
173
180
#Assign BASE MAC ADDRESS retieved from CPU board EEPROM to eth0 interface
174
- mac_address_prog = "ifconfig eth0 hw ether " + str (macAddress )
181
+ mac_address_prog = [ "ifconfig" , " eth0" , "hw" , " ether" , str (macAddress )]
175
182
176
- status , MACAddressProg = commands . getstatusoutput (mac_address_prog )
183
+ status , MACAddressProg = getstatusoutput_noshell (mac_address_prog )
177
184
if status :
178
- print 'Error: Could not set up "macAddress" for eth0 interface'
185
+ print ( 'Error: Could not set up "macAddress" for eth0 interface' )
179
186
return False
180
187
181
188
#Make eth0 interface up
182
- status , eth0UP = commands . getstatusoutput ( "ifconfig eth0 up" )
189
+ status , eth0UP = getstatusoutput_noshell ([ "ifconfig" , " eth0" , " up"] )
183
190
if status :
184
- print 'Error: Could not make eth0 interface up'
191
+ print ( 'Error: Could not make eth0 interface up' )
185
192
return False
186
193
187
194
# Juniper QFX5200 platform drivers install
188
195
do_install ()
189
196
time .sleep (2 )
190
197
191
198
# Juniper SFP Intialization
192
- JuniperSFPInitCmd = 'python /usr/share/sonic/device/x86_64-juniper_qfx5200-r0/plugins/qfx5200_sfp_init.py'
199
+ JuniperSFPInitCmd = [ 'python' , ' /usr/share/sonic/device/x86_64-juniper_qfx5200-r0/plugins/qfx5200_sfp_init.py']
193
200
try :
194
- os . system (JuniperSFPInitCmd )
201
+ subprocess . call (JuniperSFPInitCmd )
195
202
except OSError :
196
- print 'Error: Execution of "%s" failed' , JuniperSFPInitCmd
203
+ print ( 'Error: Execution of "%s" failed' , JuniperSFPInitCmd )
197
204
return False
198
205
199
206
time .sleep (1 )
200
207
# Invoking the script which retrieves the data from CPU Board and Main Board EEPROM and storing in file
201
- EEPROMDataCmd = 'python /usr/share/sonic/device/x86_64-juniper_qfx5200-r0/plugins/qfx5200_eeprom_data.py'
208
+ EEPROMDataCmd = [ 'python' , ' /usr/share/sonic/device/x86_64-juniper_qfx5200-r0/plugins/qfx5200_eeprom_data.py']
202
209
try :
203
- os . system (EEPROMDataCmd )
210
+ subprocess . call (EEPROMDataCmd )
204
211
except OSError :
205
- print 'Error: Execution of "%s" failed' , EEPROMDataCmd
212
+ print ( 'Error: Execution of "%s" failed' , EEPROMDataCmd )
206
213
return False
207
214
208
215
for x in range (PWMINPUT_NUM ):
@@ -218,16 +225,16 @@ def main():
218
225
hwmon_dir )
219
226
device_path = pwm_input_path_mapping [x ]
220
227
time .sleep (1 )
221
- cmd = ( "sudo echo 22500 > %s" % device_path )
222
- os . system (cmd )
228
+ cmd = " 22500"
229
+ write_file (cmd , device_path )
223
230
224
231
numsensors_input_path_mapping [x ] = NUMSENSORS_PATH .format (
225
232
hwmon_input_node_mapping [x ],
226
233
hwmon_dir )
227
234
numsensors_path = numsensors_input_path_mapping [x ]
228
235
time .sleep (1 )
229
- cmd = ( "sudo echo 0 > %s" % numsensors_path )
230
- os . system (cmd )
236
+ cmd = "0"
237
+ write_file (cmd , numsensors_path )
231
238
232
239
return True
233
240
0 commit comments