Skip to content

Commit

Permalink
Fix to make alias 'key' as optional atrribute in config/show commands (
Browse files Browse the repository at this point in the history
  • Loading branch information
paavaanan authored and jleveque committed Dec 11, 2018
1 parent 28fd82e commit 408a991
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
17 changes: 17 additions & 0 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,23 @@ def set_interface_naming_mode(mode):
user = os.getenv('SUDO_USER')
bashrc_ifacemode_line = "export SONIC_CLI_IFACE_MODE={}".format(mode)

# Ensure all interfaces have an 'alias' key in PORT dict
config_db = ConfigDBConnector()
config_db.connect()
port_dict = config_db.get_table('PORT')

if not port_dict:
click.echo("port_dict is None!")
raise click.Abort()

for port_name in port_dict.keys():
try:
if port_dict[port_name]['alias']:
pass
except KeyError:
click.echo("Platform does not support alias mapping")
raise click.Abort()

if not user:
user = os.getenv('USER')

Expand Down
11 changes: 7 additions & 4 deletions show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,13 @@ def __init__(self):
raise click.Abort()

for port_name in self.port_dict.keys():
if self.alias_max_length < len(
self.port_dict[port_name]['alias']):
self.alias_max_length = len(
self.port_dict[port_name]['alias'])
try:
if self.alias_max_length < len(
self.port_dict[port_name]['alias']):
self.alias_max_length = len(
self.port_dict[port_name]['alias'])
except KeyError:
break

def name_to_alias(self, interface_name):
"""Return vendor interface alias if SONiC
Expand Down

0 comments on commit 408a991

Please sign in to comment.