23
23
24
24
SNIFFER_SYSLOG_IDENTIFIER = "sniffer"
25
25
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
-
35
26
# SDK sniffer env variable
36
27
ENV_VARIABLE_SX_SNIFFER = 'SX_SNIFFER_ENABLE'
37
28
ENV_VARIABLE_SX_SNIFFER_TARGET = 'SX_SNIFFER_TARGET'
@@ -94,28 +85,6 @@ def run_command(command, display_cmd=False, ignore_error=False):
94
85
sys .exit (proc .returncode )
95
86
96
87
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
-
119
88
# generate sniffer target file name include a time stamp.
120
89
def sniffer_filename_generate (path , filename_prefix , filename_ext ):
121
90
time_stamp = time .strftime ("%Y%m%d%H%M%S" )
@@ -160,7 +129,7 @@ def conf_file_copy(src, dest):
160
129
161
130
162
131
def 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 )
164
133
run_command (command )
165
134
conf_file_copy (SNIFFER_CONF_FILE_IN_CONTAINER , TMP_SNIFFER_CONF_FILE )
166
135
@@ -176,21 +145,21 @@ def sniffer_env_variable_set(enable, env_variable_name, env_variable_string=""):
176
145
env_variable_exist_string = env_variable_read (env_variable_name )
177
146
if env_variable_exist_string :
178
147
if enable is True :
179
- print "sniffer is already running , do nothing"
148
+ print "sniffer is already enabled , do nothing"
180
149
ignore = True
181
150
else :
182
151
env_variable_delete (env_variable_exist_string )
183
152
else :
184
153
if enable is True :
185
154
env_variable_write (env_variable_string )
186
155
else :
187
- print "sniffer is already turned off , do nothing"
156
+ print "sniffer is already disabled , do nothing"
188
157
ignore = True
189
158
190
159
if not ignore :
191
160
config_file_send ()
192
161
193
- command = 'rm -rf ' + TMP_SNIFFER_CONF_FILE
162
+ command = 'rm -rf {}' . format ( TMP_SNIFFER_CONF_FILE )
194
163
run_command (command )
195
164
196
165
return ignore
@@ -217,32 +186,30 @@ def _abort_if_false(ctx, param, value):
217
186
# 'mlnx' group
218
187
@click .group ()
219
188
def 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
226
191
227
192
228
193
# 'sniffer' group
229
194
@mlnx .group ()
230
195
def sniffer ():
231
- """sniffer - Utility for managing Mellanox SDK/PRM sniffer"""
196
+ """ Utility for managing Mellanox SDK/PRM sniffer """
232
197
pass
233
198
234
199
235
200
# '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 ):
238
206
"""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 ()
240
211
241
212
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?' )
246
213
def sdk_sniffer_enable ():
247
214
"""Enable SDK Sniffer"""
248
215
print "Enabling SDK sniffer"
@@ -264,15 +231,11 @@ def sdk_sniffer_enable():
264
231
err = restart_swss ()
265
232
if err is not 0 :
266
233
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
268
235
else :
269
236
pass
270
237
271
238
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?' )
276
239
def sdk_sniffer_disable ():
277
240
"""Disable SDK Sniffer"""
278
241
print "Disabling SDK sniffer"
@@ -282,54 +245,23 @@ def sdk_sniffer_disable():
282
245
err = restart_swss ()
283
246
if err is not 0 :
284
247
return
285
- print "SDK sniffer is disabled "
248
+ print "Disabled SDK sniffer"
286
249
else :
287
250
pass
288
251
289
252
290
253
# 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
326
264
327
- @cli.group()
328
- def status():
329
- """Sniffer running status - Command Line to show sniffer running status"""
330
- pass
331
-
332
- '''
333
265
334
266
if __name__ == '__main__' :
335
- mlnx ()
267
+ sniffer ()
0 commit comments