Skip to content

Commit 902e14f

Browse files
authored
Revert "Revert "[Barefoot] Added CLI to list/set P4 profile (sonic-net#1951)"" (sonic-net#2019)
Refer to sonic-net#1951 for details The PR sonic-net#1951 was reverted in sonic-net#2016 because it was thought to be causing the build failure in sonic-swss TestWarmReboot UTs. But it seems the failures in TestWarmReboot are still occurring e.g. sonic-net#2017 [build](https://dev.azure.com/mssonic/build/_build/results?buildId=65653&view=logs&s=859b8d9a-8fd6-5a5c-6f5e-f84f1990894e) I think we can reapply sonic-net#1951 and need to investigate TestWarmReboot tests instability
1 parent 5cc9dd5 commit 902e14f

File tree

3 files changed

+143
-0
lines changed

3 files changed

+143
-0
lines changed

config/plugins/barefoot.py

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env python
2+
3+
import click
4+
import json
5+
import subprocess
6+
from sonic_py_common import device_info
7+
from swsscommon.swsscommon import ConfigDBConnector
8+
9+
def abort_if_false(ctx, param, value):
10+
if not value:
11+
ctx.abort()
12+
13+
@click.group()
14+
def barefoot():
15+
pass
16+
17+
@barefoot.command()
18+
@click.option('-y', '--yes', is_flag=True, callback=abort_if_false,
19+
expose_value=False, prompt='Swss service will be restarted, continue?')
20+
@click.argument('profile')
21+
def profile(profile):
22+
# Check if profile can be changed
23+
completed_process = subprocess.run(['docker', 'exec', '-it', 'syncd',
24+
'test', '-h', '/opt/bfn/install'])
25+
if completed_process.returncode != 0:
26+
click.echo('Cannot change profile: default one is in use')
27+
raise click.Abort()
28+
29+
# Get chip family
30+
hwsku_dir = device_info.get_path_to_hwsku_dir()
31+
with open(hwsku_dir + '/switch-tna-sai.conf') as file:
32+
chip_family = json.load(file)['chip_list'][0]['chip_family'].lower()
33+
34+
# Check if profile is supported
35+
if chip_family == 'tofino' and profile[0] == 'y' or \
36+
chip_family == 'tofino2' and profile[0] == 'x':
37+
click.echo('Specified profile is unsupported on the system')
38+
raise click.Abort()
39+
40+
# Check if profile exists
41+
completed_process = subprocess.run(['docker', 'exec', '-it', 'syncd',
42+
'test', '-d', '/opt/bfn/install_' + profile + '_profile'])
43+
if completed_process.returncode != 0:
44+
click.echo('No profile with the provided name found')
45+
raise click.Abort()
46+
47+
# Update configuration
48+
config_db = ConfigDBConnector()
49+
config_db.connect()
50+
config_db.mod_entry('DEVICE_METADATA', 'localhost',
51+
{'p4_profile': profile + '_profile'})
52+
subprocess.run(['systemctl', 'restart', 'swss'], check=True)
53+
54+
def register(cli):
55+
version_info = device_info.get_sonic_version_info()
56+
if version_info and version_info.get('asic_type') == 'barefoot':
57+
cli.commands['platform'].add_command(barefoot)

doc/Command-Reference.md

+39
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@
119119
* [Platform Component Firmware config commands](#platform-component-firmware-config-commands)
120120
* [Platform Component Firmware vendor specific behaviour](#platform-component-firmware-vendor-specific-behaviour)
121121
* [Platform Specific Commands](#platform-specific-commands)
122+
* [Mellanox Platform Specific Commands](#mellanox-platform-specific-commands)
123+
* [Barefoot Platform Specific Commands](#barefoot-platform-specific-commands)
122124
* [PortChannels](#portchannels)
123125
* [PortChannel Show commands](#portchannel-show-commands)
124126
* [PortChannel Config commands](#portchannel-config-commands)
@@ -6583,6 +6585,8 @@ Go Back To [Beginning of the document](#) or [Beginning of this section](#platfo
65836585
65846586
## Platform Specific Commands
65856587
6588+
### Mellanox Platform Specific Commands
6589+
65866590
There are few commands that are platform specific. Mellanox has used this feature and implemented Mellanox specific commands as follows.
65876591
65886592
**show platform mlnx sniffer**
@@ -6652,6 +6656,41 @@ In order to avoid that confirmation the -y / --yes option should be used.
66526656
NOTE: In order to avoid that confirmation the -y / --yes option should be used.
66536657
```
66546658
6659+
### Barefoot Platform Specific Commands
6660+
6661+
**show platform barefoot profile**
6662+
6663+
This command displays active P4 profile and lists available ones.
6664+
6665+
- Usage:
6666+
```
6667+
show platform barefoot profile
6668+
```
6669+
6670+
- Example:
6671+
```
6672+
admin@sonic:~$ show platform barefoot profile
6673+
Current profile: x1
6674+
Available profile(s):
6675+
x1
6676+
x2
6677+
```
6678+
6679+
**config platform barefoot profile**
6680+
6681+
This command sets P4 profile.
6682+
6683+
- Usage:
6684+
```
6685+
config platform barefoot profile <p4_profile> [-y|--yes]
6686+
```
6687+
6688+
- Example:
6689+
```
6690+
admin@sonic:~$ sudo config platform barefoot profile x1
6691+
Swss service will be restarted, continue? [y/N]: y
6692+
```
6693+
66556694
Go Back To [Beginning of the document](#) or [Beginning of this section](#platform-specific-commands)
66566695
66576696

show/plugins/barefoot.py

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env python
2+
3+
import click
4+
import json
5+
import subprocess
6+
from sonic_py_common import device_info
7+
8+
@click.group()
9+
def barefoot():
10+
pass
11+
12+
@barefoot.command()
13+
def profile():
14+
# Check if profile can be changed
15+
completed_process = subprocess.run(['docker', 'exec', '-it', 'syncd',
16+
'test', '-h', '/opt/bfn/install'])
17+
if completed_process.returncode != 0:
18+
click.echo('Current profile: default')
19+
return
20+
21+
# Get chip family
22+
hwsku_dir = device_info.get_path_to_hwsku_dir()
23+
with open(hwsku_dir + '/switch-tna-sai.conf') as file:
24+
chip_family = json.load(file)['chip_list'][0]['chip_family'].lower()
25+
26+
# Print current profile
27+
click.echo('Current profile: ', nl=False)
28+
subprocess.run('docker exec -it syncd readlink /opt/bfn/install | sed '
29+
r's/install_\\\(.\*\\\)_profile/\\1/', check=True, shell=True)
30+
31+
# Exclude current and unsupported profiles
32+
opts = ''
33+
if chip_family == 'tofino':
34+
opts = r'\! -name install_y\*_profile '
35+
elif chip_family == 'tofino2':
36+
opts = r'\! -name install_x\*_profile '
37+
38+
# Print profile list
39+
click.echo('Available profile(s):')
40+
subprocess.run('docker exec -it syncd find /opt/bfn -mindepth 1 '
41+
r'-maxdepth 1 -type d -name install_\*_profile ' + opts + '| sed '
42+
r's%/opt/bfn/install_\\\(.\*\\\)_profile%\\1%', shell=True)
43+
44+
def register(cli):
45+
version_info = device_info.get_sonic_version_info()
46+
if version_info and version_info.get('asic_type') == 'barefoot':
47+
cli.commands['platform'].add_command(barefoot)

0 commit comments

Comments
 (0)