From 408a991f83b8658aabce212efc2386e8cc42022c Mon Sep 17 00:00:00 2001 From: paavaanan Date: Wed, 12 Dec 2018 00:29:32 +0530 Subject: [PATCH] Fix to make alias 'key' as optional atrribute in config/show commands (#405) --- config/main.py | 17 +++++++++++++++++ show/main.py | 11 +++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/config/main.py b/config/main.py index 90d0f1225749..a6ac57f0cd43 100755 --- a/config/main.py +++ b/config/main.py @@ -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') diff --git a/show/main.py b/show/main.py index 802a67f04f95..f303e4ac2e05 100755 --- a/show/main.py +++ b/show/main.py @@ -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