Skip to content

Commit

Permalink
Fixed profile naming for barefoot platform
Browse files Browse the repository at this point in the history
  • Loading branch information
Taras Keryk committed Dec 12, 2022
1 parent 208824d commit 8d56a08
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 17 deletions.
27 changes: 19 additions & 8 deletions config/plugins/barefoot.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,38 @@ def profile(profile):

# Get chip family
hwsku_dir = device_info.get_path_to_hwsku_dir()
chip_family = ""
with open(hwsku_dir + '/switch-tna-sai.conf') as file:
chip_family = json.load(file)['chip_list'][0]['chip_family'].lower()

# Check if profile is supported
if chip_family == 'tofino' and profile[0] == 'y' or \
chip_family == 'tofino2' and profile[0] == 'x':
if chip_family == 'tofino' and profile[0] != 'x' or \
chip_family == 'tofino2' and profile[0] != 'y':
click.echo('Specified profile is unsupported on the system')
raise click.Abort()

# Check if profile exists

# Check if profile <profile_name>_<chip_family> exists
no_arch_information = False
completed_process = subprocess.run(['docker', 'exec', '-it', 'syncd',
'test', '-d', '/opt/bfn/install_' + profile + '_profile'])
'test', '-d', '/opt/bfn/install_' + profile + '_' + chip_family])

# Otherwise, check if profile <profile_name>_profile exists (only for tofino and tofino2)
if completed_process.returncode != 0:
click.echo('No profile with the provided name found')
if chip_family == 'tofino' or chip_family == 'tofino2':
completed_process = subprocess.run(['docker', 'exec', '-it', 'syncd',
'test', '-d', '/opt/bfn/install_' + profile + '_profile'])
no_arch_information = True

if completed_process.returncode != 0:
click.echo('No profile with the provided name found for {}'.format(chip_family))
raise click.Abort()

# Update configuration
config_db = ConfigDBConnector()
config_db.connect()
config_db.mod_entry('DEVICE_METADATA', 'localhost',
{'p4_profile': profile + '_profile'})
profile += '_profile' if no_arch_information else '_' + chip_family
config_db.mod_entry('DEVICE_METADATA', 'localhost', {'p4_profile': profile})

subprocess.run(['systemctl', 'restart', 'swss'], check=True)

def register(cli):
Expand Down
7 changes: 7 additions & 0 deletions show/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,10 @@ def firmware(args):
subprocess.check_call(cmd, shell=True)
except subprocess.CalledProcessError as e:
sys.exit(e.returncode)

# 'barefoot' subcommand ("show platform barefoot")
@platform.command()
def barefoot():
"""Show Barefoot profile information"""
cmd = "barefoot profile"
clicommon.run_command(cmd)
26 changes: 17 additions & 9 deletions show/plugins/barefoot.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,32 @@ def profile():
hwsku_dir = device_info.get_path_to_hwsku_dir()
with open(hwsku_dir + '/switch-tna-sai.conf') as file:
chip_family = json.load(file)['chip_list'][0]['chip_family'].lower()

# Print current profile
click.echo('Current profile: ', nl=False)
subprocess.run('docker exec -it syncd readlink /opt/bfn/install | sed '
r's/install_\\\(.\*\\\)_profile/\\1/', check=True, shell=True)

# Exclude current and unsupported profiles
r's/install_\\\(.\*\\\)_profile/\\1/'
r' | sed s/install_\\\(.\*\\\)_tofino.\*/\\1/', check=True, shell=True)

# Check if profile naming format contains tofino family information
output = subprocess.check_output(['docker', 'exec', '-it', 'syncd', 'ls', '/opt/bfn']).strip().decode()
suffix = '_' + chip_family if '_tofino' in output else '_profile'

# Check supported profiles
opts = ''
if chip_family == 'tofino':
opts = r'\! -name install_y\*_profile '
opts = r' -name install_x\*' + suffix
elif chip_family == 'tofino2':
opts = r'\! -name install_x\*_profile '

opts = r' -name install_y\*' + suffix
else:
opts = r' -name \*' + suffix

# Print profile list
click.echo('Available profile(s):')
subprocess.run('docker exec -it syncd find /opt/bfn -mindepth 1 '
r'-maxdepth 1 -type d -name install_\*_profile ' + opts + '| sed '
r's%/opt/bfn/install_\\\(.\*\\\)_profile%\\1%', shell=True)
r'-maxdepth 1 -type d,l ' + opts + '| sed '
r's%/opt/bfn/install_\\\(.\*\\\)_profile%\\1%'
r' | sed s%/opt/bfn/install_\\\(.\*\\\)_tofino.\*%\\1%', shell=True)

def register(cli):
version_info = device_info.get_sonic_version_info()
Expand Down

0 comments on commit 8d56a08

Please sign in to comment.