diff --git a/config/plugins/barefoot.py b/config/plugins/barefoot.py index 088ee8e928..6dff86a22e 100644 --- a/config/plugins/barefoot.py +++ b/config/plugins/barefoot.py @@ -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 _ 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 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): diff --git a/show/platform.py b/show/platform.py index 1916e10d84..7e1d921186 100644 --- a/show/platform.py +++ b/show/platform.py @@ -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) diff --git a/show/plugins/barefoot.py b/show/plugins/barefoot.py index bc80c47ba3..c69c245359 100644 --- a/show/plugins/barefoot.py +++ b/show/plugins/barefoot.py @@ -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()