2323
2424SNIFFER_SYSLOG_IDENTIFIER = "sniffer"
2525
26- # Mellanox platform name
27- MLNX_PLATFORM_NAME = 'mellanox'
28-
29- # sonic-cfggen -y /etc/sonic/sonic_version.yml -v asic_type
30- PLATFORM_ROOT_PATH = '/usr/share/sonic/device'
31- SONIC_CFGGEN_PATH = '/usr/local/bin/sonic-cfggen'
32- SONIC_VERSION_PATH = '/etc/sonic/sonic_version.yml'
33- ASIC_TYPE_KEY = 'asic_type'
34-
3526# SDK sniffer env variable
3627ENV_VARIABLE_SX_SNIFFER = 'SX_SNIFFER_ENABLE'
3728ENV_VARIABLE_SX_SNIFFER_TARGET = 'SX_SNIFFER_TARGET'
@@ -94,28 +85,6 @@ def run_command(command, display_cmd=False, ignore_error=False):
9485 sys .exit (proc .returncode )
9586
9687
97- # Get asic type with command "sonic-cfggen -y /etc/sonic/sonic_version.yml -v asic_type"
98- def get_asic_type ():
99- try :
100- proc = subprocess .Popen ([SONIC_CFGGEN_PATH , '-y' , SONIC_VERSION_PATH , '-v' , ASIC_TYPE_KEY ],
101- stdout = subprocess .PIPE ,
102- shell = False ,
103- stderr = subprocess .STDOUT )
104- stdout = proc .communicate ()[0 ]
105- proc .wait ()
106- asic_type = stdout .rstrip ('\n ' )
107- except OSError , e :
108- raise OSError ("Cannot detect platform asic type, %s" % str (e ))
109-
110- return asic_type
111-
112-
113- # verify if the platform is with Mellanox asic.
114- def verify_asic_type ():
115- asic_type = get_asic_type ()
116- return cmp (asic_type , MLNX_PLATFORM_NAME )
117-
118-
11988# generate sniffer target file name include a time stamp.
12089def sniffer_filename_generate (path , filename_prefix , filename_ext ):
12190 time_stamp = time .strftime ("%Y%m%d%H%M%S" )
@@ -160,7 +129,7 @@ def conf_file_copy(src, dest):
160129
161130
162131def conf_file_receive ():
163- command = ' docker exec -ti ' + CONTAINER_NAME + ' bash -c " touch ' + SNIFFER_CONF_FILE + '"'
132+ command = " docker exec {} bash -c ' touch {}'" . format ( CONTAINER_NAME , SNIFFER_CONF_FILE )
164133 run_command (command )
165134 conf_file_copy (SNIFFER_CONF_FILE_IN_CONTAINER , TMP_SNIFFER_CONF_FILE )
166135
@@ -176,21 +145,21 @@ def sniffer_env_variable_set(enable, env_variable_name, env_variable_string=""):
176145 env_variable_exist_string = env_variable_read (env_variable_name )
177146 if env_variable_exist_string :
178147 if enable is True :
179- print "sniffer is already running , do nothing"
148+ print "sniffer is already enabled , do nothing"
180149 ignore = True
181150 else :
182151 env_variable_delete (env_variable_exist_string )
183152 else :
184153 if enable is True :
185154 env_variable_write (env_variable_string )
186155 else :
187- print "sniffer is already turned off , do nothing"
156+ print "sniffer is already disabled , do nothing"
188157 ignore = True
189158
190159 if not ignore :
191160 config_file_send ()
192161
193- command = 'rm -rf ' + TMP_SNIFFER_CONF_FILE
162+ command = 'rm -rf {}' . format ( TMP_SNIFFER_CONF_FILE )
194163 run_command (command )
195164
196165 return ignore
@@ -217,32 +186,30 @@ def _abort_if_false(ctx, param, value):
217186# 'mlnx' group
218187@click .group ()
219188def mlnx ():
220- """Mellanox platform specific configuration tasks"""
221- # check the platform info, this command only work on Mellanox platform
222- err = verify_asic_type ()
223- if err != 0 :
224- print "This command only supported on Mellanox platform"
225- sys .exit (2 )
189+ """ Mellanox platform configuration tasks """
190+ pass
226191
227192
228193# 'sniffer' group
229194@mlnx .group ()
230195def sniffer ():
231- """sniffer - Utility for managing Mellanox SDK/PRM sniffer"""
196+ """ Utility for managing Mellanox SDK/PRM sniffer """
232197 pass
233198
234199
235200# 'sdk' subgroup
236- @sniffer .group ()
237- def sdk ():
201+ @sniffer .command ()
202+ @click .option ('-y' , '--yes' , is_flag = True , callback = _abort_if_false , expose_value = False ,
203+ prompt = 'To change SDK sniffer status, swss service will be restarted, continue?' )
204+ @click .argument ('option' , type = click .Choice (["enable" , "disable" ]))
205+ def sdk (option ):
238206 """SDK Sniffer - Command Line to enable/disable SDK sniffer"""
239- pass
207+ if option == 'enable' :
208+ sdk_sniffer_enable ()
209+ elif option == 'disable' :
210+ sdk_sniffer_disable ()
240211
241212
242- # 'sniffer sdk enable' command
243- @sdk .command ('enable' )
244- @click .option ('-y' , '--yes' , is_flag = True , callback = _abort_if_false , expose_value = False ,
245- prompt = 'To enable SDK sniffer swss service will be restarted, continue?' )
246213def sdk_sniffer_enable ():
247214 """Enable SDK Sniffer"""
248215 print "Enabling SDK sniffer"
@@ -264,15 +231,11 @@ def sdk_sniffer_enable():
264231 err = restart_swss ()
265232 if err is not 0 :
266233 return
267- print 'SDK sniffer is enabled , recording file is %s. ' % sdk_sniffer_filename
234+ print 'Enabled SDK sniffer, recording file is %s' % sdk_sniffer_filename
268235 else :
269236 pass
270237
271238
272- # 'sniffer sdk disable' command
273- @sdk .command ('disable' )
274- @click .option ('-y' , '--yes' , is_flag = True , callback = _abort_if_false , expose_value = False ,
275- prompt = 'To disable SDK sniffer swss service will be restarted, continue?' )
276239def sdk_sniffer_disable ():
277240 """Disable SDK Sniffer"""
278241 print "Disabling SDK sniffer"
@@ -282,54 +245,23 @@ def sdk_sniffer_disable():
282245 err = restart_swss ()
283246 if err is not 0 :
284247 return
285- print "SDK sniffer is disabled "
248+ print "Disabled SDK sniffer"
286249 else :
287250 pass
288251
289252
290253# place holders for 'sniff prm enable/disable' and 'sniffer all enable/disable'
291- '''
292- @cli.group()
293- def prm():
294- """PRM Sniffer - Command Line to enable/disable PRM sniffer"""
295- pass
296-
297-
298- @prm.command('enable')
299- def enable_prm_sniffer():
300- """Enable SDK sniffer"""
301- pass
302-
303-
304- @prm.command('disable')
305- def disable_prm_sniffer():
306- """Disable PRM sniffer"""
307- pass
308-
309-
310- @cli.group()
311- def all():
312- """ALL SNIFFERS - Command line to enable/disable PRM and SDK sniffer"""
313- pass
314-
315-
316- @all.command('enable')
317- def enable_all_sniffer():
318- """Enable PRM and SDK sniffers"""
319- pass
320-
321-
322- @all.command('disable')
323- def disable_all_sniffer():
324- """Disable PRM and SDK sniffers"""
325- pass
254+ # @sniffer.command()
255+ # @click.argument('option', type=click.Choice(["enable", "disable"]))
256+ # def prf():
257+ # pass
258+ #
259+ #
260+ # @sniffer.command()
261+ # @click.argument('option', type=click.Choice(["enable", "disable"]))
262+ # def all():
263+ # pass
326264
327- @cli.group()
328- def status():
329- """Sniffer running status - Command Line to show sniffer running status"""
330- pass
331-
332- '''
333265
334266if __name__ == '__main__' :
335- mlnx ()
267+ sniffer ()
0 commit comments