From f105f257b52b83319a8b8c9c3df5a9db7808ae9b Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Tue, 28 Dec 2021 02:58:29 +0000 Subject: [PATCH 1/2] [config] Fix snmpagentaddress doesn't support the uppercase letters for ipv6 address (#4852) -What I did Snmpagentaddress now support upper letters input for ipv6 address Fix some grammer mistakes -How I did Convert all agentip to lower letters to match netifaces addresses delete ; after break, convert addfress to address -How to verify it 'sudo config snmpagentaddress add FC00:1::32 -v mgmt' The ipv6 address can be obtained by command 'sudo ifconfig' --- config/main.py | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/config/main.py b/config/main.py index 5046275f6e..ae96111cc7 100644 --- a/config/main.py +++ b/config/main.py @@ -1376,16 +1376,6 @@ def reload(db, filename, yes, load_sysinfo, no_service_restart, disable_arp_cach click.echo("Input {} config file(s) separated by comma for multiple files ".format(num_cfg_file)) return - if load_sysinfo: - command = "{} -j {} -v DEVICE_METADATA.localhost.hwsku".format(SONIC_CFGGEN_PATH, filename) - proc = subprocess.Popen(command, shell=True, text=True, stdout=subprocess.PIPE) - cfg_hwsku, err = proc.communicate() - if err: - click.echo("Could not get the HWSKU from config file, exiting") - sys.exit(1) - else: - cfg_hwsku = cfg_hwsku.strip() - # For dual ToR devices, cache ARP and FDB info localhost_metadata = db.cfgdb.get_table('DEVICE_METADATA')['localhost'] cache_arp_table = not disable_arp_cache and 'subtype' in localhost_metadata and localhost_metadata['subtype'].lower() == 'dualtor' @@ -1427,6 +1417,25 @@ def reload(db, filename, yes, load_sysinfo, no_service_restart, disable_arp_cach click.echo("The config file {} doesn't exist".format(file)) continue + if load_sysinfo: + try: + command = "{} -j {} -v DEVICE_METADATA.localhost.hwsku".format(SONIC_CFGGEN_PATH, file) + proc = subprocess.Popen(command, shell=True, text=True, stdout=subprocess.PIPE) + output, err = proc.communicate() + + except FileNotFoundError as e: + click.echo("{}".format(str(e)), err=True) + raise click.Abort() + except Exception as e: + click.echo("{}\n{}".format(type(e), str(e)), err=True) + raise click.Abort() + + if not output: + click.secho("Could not get the HWSKU from config file, Exiting!!!", fg='magenta') + sys.exit(1) + + cfg_hwsku = output.strip() + if namespace is None: config_db = ConfigDBConnector() else: @@ -2463,6 +2472,8 @@ def snmpagentaddress(ctx): def add_snmp_agent_address(ctx, agentip, port, vrf): """Add the SNMP agent listening IP:Port%Vrf configuration""" + #Convert agentip to lower to match netifaces addresses + agentip = agentip.lower() #Construct SNMP_AGENT_ADDRESS_CONFIG table key in the format ip|| if not clicommon.is_ipaddress(agentip): click.echo("Invalid IP address") @@ -2481,11 +2492,11 @@ def add_snmp_agent_address(ctx, agentip, port, vrf): for ipaddr in ipaddresses[ip_family[ip.version]]: if agentip == ipaddr['addr']: found = 1 - break; + break if found == 1: - break; + break else: - click.echo("IP addfress is not available") + click.echo("IP address is not available") return key = agentip+'|' From 172b44ee94b286dea46908057dfc77081dfbbba6 Mon Sep 17 00:00:00 2001 From: xwjiang2021 Date: Tue, 4 Jan 2022 06:20:13 +0000 Subject: [PATCH 2/2] [config] Change the way to solve issue 4852 -What I did Snmpagentaddress now support upper letters input for ipv6 address -How I did Compare the lower letter of input and netifaces addresses -How to verify it 'sudo config snmpagentaddress add FC00:1::32 -v mgmt' The ipv6 address can be obtained by command 'sudo ifconfig' --- config/main.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/config/main.py b/config/main.py index ae96111cc7..2229c982f0 100644 --- a/config/main.py +++ b/config/main.py @@ -2472,8 +2472,6 @@ def snmpagentaddress(ctx): def add_snmp_agent_address(ctx, agentip, port, vrf): """Add the SNMP agent listening IP:Port%Vrf configuration""" - #Convert agentip to lower to match netifaces addresses - agentip = agentip.lower() #Construct SNMP_AGENT_ADDRESS_CONFIG table key in the format ip|| if not clicommon.is_ipaddress(agentip): click.echo("Invalid IP address") @@ -2490,7 +2488,7 @@ def add_snmp_agent_address(ctx, agentip, port, vrf): ipaddresses = netifaces.ifaddresses(intf) if ip_family[ip.version] in ipaddresses: for ipaddr in ipaddresses[ip_family[ip.version]]: - if agentip == ipaddr['addr']: + if agentip.lower() == ipaddr['addr'].lower(): found = 1 break if found == 1: