Skip to content

Commit

Permalink
[dhcp_relay]Fix the clear dhcp6relay_counters CLI (#13148)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dgsudharsan authored and mssonicbld committed Feb 16, 2023
1 parent e849455 commit 6862692
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys
import click
import importlib
importlib.import_module('show.plugins.dhcp-relay')
dhcp6_relay = importlib.import_module('show.plugins.dhcp-relay')

import utilities_common.cli as clicommon

Expand All @@ -16,7 +16,7 @@ def dhcp6relay_clear():
def dhcp6relay_clear_counters(interface):
""" Clear dhcp6relay message counts """

counter = DHCPv6_Counter()
counter = dhcp6_relay.DHCPv6_Counter()
counter_intf = counter.get_interface()

if interface:
Expand Down

0 comments on commit 6862692

Please sign in to comment.