Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[config] SNMP Service restart fix for consecutive configs #2554

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3087,8 +3087,12 @@ def add_snmp_agent_address(ctx, agentip, port, vrf):
config_db.set_entry('SNMP_AGENT_ADDRESS_CONFIG', key, {})

#Restarting the SNMP service will regenerate snmpd.conf and rerun snmpd
cmd="systemctl restart snmp"
os.system (cmd)
try:
clicommon.run_command("systemctl reset-failed snmp.service", display_cmd=False)
clicommon.run_command("systemctl restart snmp.service", display_cmd=False)
except SystemExit as e:
click.echo("Restart service snmp failed with error {}".format(e))
raise click.Abort()

@snmpagentaddress.command('del')
@click.argument('agentip', metavar='<SNMP AGENT LISTENING IP Address>', required=True)
Expand All @@ -3106,8 +3110,12 @@ def del_snmp_agent_address(ctx, agentip, port, vrf):
key = key+vrf
config_db = ctx.obj['db']
config_db.set_entry('SNMP_AGENT_ADDRESS_CONFIG', key, None)
cmd="systemctl restart snmp"
os.system (cmd)
try:
clicommon.run_command("systemctl reset-failed snmp.service", display_cmd=False)
clicommon.run_command("systemctl restart snmp.service", display_cmd=False)
except SystemExit as e:
click.echo("Restart service snmp failed with error {}".format(e))
raise click.Abort()

@config.group(cls=clicommon.AbbreviationGroup)
@click.pass_context
Expand Down Expand Up @@ -3137,8 +3145,12 @@ def modify_snmptrap_server(ctx, ver, serverip, port, vrf, comm):
else:
config_db.mod_entry('SNMP_TRAP_CONFIG', "v3TrapDest", {"DestIp": serverip, "DestPort": port, "vrf": vrf, "Community": comm})

cmd="systemctl restart snmp"
os.system (cmd)
try:
clicommon.run_command("systemctl reset-failed snmp.service", display_cmd=False)
clicommon.run_command("systemctl restart snmp.service", display_cmd=False)
except SystemExit as e:
click.echo("Restart service snmp failed with error {}".format(e))
raise click.Abort()

@snmptrap.command('del')
@click.argument('ver', metavar='<SNMP Version>', type=click.Choice(['1', '2', '3']), required=True)
Expand All @@ -3153,8 +3165,13 @@ def delete_snmptrap_server(ctx, ver):
config_db.mod_entry('SNMP_TRAP_CONFIG', "v2TrapDest", None)
else:
config_db.mod_entry('SNMP_TRAP_CONFIG', "v3TrapDest", None)
cmd="systemctl restart snmp"
os.system (cmd)

try:
clicommon.run_command("systemctl reset-failed snmp.service", display_cmd=False)
clicommon.run_command("systemctl restart snmp.service", display_cmd=False)
except SystemExit as e:
click.echo("Restart service snmp failed with error {}".format(e))
raise click.Abort()



Expand Down