2021-09-24 00:01:26 -05:00
|
|
|
import click
|
2022-01-16 00:08:01 -06:00
|
|
|
import importlib
|
[dhcp_relay]Fix the clear dhcp6relay_counters CLI (#13148)
Avoid traceback on sonic-clear command
sonic-clear dhcp6relay_counters
Traceback (most recent call last):
File "/usr/local/bin/sonic-clear", line 8, in <module>
sys.exit(cli())
File "/usr/local/lib/python3.9/dist-packages/click/core.py", line 764, in __call__
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.9/dist-packages/click/core.py", line 717, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.9/dist-packages/click/core.py", line 1137, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.9/dist-packages/click/core.py", line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.9/dist-packages/click/core.py", line 555, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.9/dist-packages/clear/plugins/dhcp-relay.py", line 19, in dhcp6relay_clear_counters
counter = DHCPv6_Counter()
NameError: name 'DHCPv6_Counter' is not defined
- How I did it
Corrected the way to import using importlib
- How to verify it
Tested the sonic-clear command and verified no traceback is seen
2022-12-26 01:14:59 -06:00
|
|
|
dhcp6_relay = importlib.import_module('show.plugins.dhcp-relay')
|
2021-09-24 00:01:26 -05:00
|
|
|
|
|
|
|
import utilities_common.cli as clicommon
|
|
|
|
|
|
|
|
|
2023-03-06 12:48:25 -06:00
|
|
|
def clear_dhcp_relay_ipv6_counter(interface):
|
|
|
|
counter = dhcp6_relay.DHCPv6_Counter()
|
|
|
|
counter_intf = counter.get_interface()
|
|
|
|
|
|
|
|
if interface:
|
|
|
|
counter.clear_table(interface)
|
|
|
|
else:
|
|
|
|
for intf in counter_intf:
|
|
|
|
counter.clear_table(intf)
|
|
|
|
|
|
|
|
|
2021-09-24 00:01:26 -05:00
|
|
|
# sonic-clear dhcp6relay_counters
|
|
|
|
@click.group(cls=clicommon.AliasedGroup)
|
|
|
|
def dhcp6relay_clear():
|
|
|
|
pass
|
|
|
|
|
2023-03-06 12:48:25 -06:00
|
|
|
|
2021-09-24 00:01:26 -05:00
|
|
|
@dhcp6relay_clear.command('dhcp6relay_counters')
|
|
|
|
@click.option('-i', '--interface', required=False)
|
|
|
|
def dhcp6relay_clear_counters(interface):
|
|
|
|
""" Clear dhcp6relay message counts """
|
2023-03-06 12:48:25 -06:00
|
|
|
clear_dhcp_relay_ipv6_counter(interface)
|
2021-10-19 05:10:36 -05:00
|
|
|
|
2021-09-24 00:01:26 -05:00
|
|
|
|
2023-03-06 12:48:25 -06:00
|
|
|
@click.group(cls=clicommon.AliasedGroup, name="dhcp_relay")
|
|
|
|
def dhcp_relay():
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
@dhcp_relay.group(cls=clicommon.AliasedGroup, name="ipv6")
|
|
|
|
def dhcp_relay_ipv6():
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
@dhcp_relay_ipv6.command('counters')
|
|
|
|
@click.option('-i', '--interface', required=False)
|
|
|
|
def clear_dhcp_relay_ipv6_counters(interface):
|
|
|
|
""" Clear dhcp_relay ipv6 message counts """
|
|
|
|
clear_dhcp_relay_ipv6_counter(interface)
|
|
|
|
|
2021-09-24 00:01:26 -05:00
|
|
|
|
|
|
|
def register(cli):
|
|
|
|
cli.add_command(dhcp6relay_clear_counters)
|
2023-03-06 12:48:25 -06:00
|
|
|
cli.add_command(dhcp_relay)
|
|
|
|
|
2021-09-24 00:01:26 -05:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
dhcp6relay_clear_counters()
|
2023-03-06 12:48:25 -06:00
|
|
|
dhcp_relay()
|