-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CLI Support for IPv6 Helpers and DHCPv6 Relay Counters (#8593)
- Loading branch information
Showing
10 changed files
with
257 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
TEST_DATA = [ | ||
[ | ||
"DHCPv6_Helpers", | ||
{ | ||
"config_db": { | ||
"DHCP_RELAY": { | ||
"Vlan1000": { | ||
"dhcpv6_servers": [ | ||
"fc02:2000::1", | ||
"fc02:2000::2" | ||
], | ||
"dhcpv6_option|rfc6939_support": "true" | ||
} | ||
} | ||
}, | ||
}, | ||
], | ||
] |
43 changes: 43 additions & 0 deletions
43
dockers/docker-dhcp-relay/cli-plugin-tests/test_show_dhcp6relay_counters.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import sys | ||
import os | ||
from unittest import mock | ||
sys.path.append('../cli/show/plugins/') | ||
import show_dhcp_relay as show | ||
|
||
from click.testing import CliRunner | ||
|
||
try: | ||
modules_path = os.path.join(os.path.dirname(__file__), "../../../src/sonic-utilities") | ||
test_path = os.path.join(modules_path, "tests") | ||
mock_table_path = os.path.join(test_path, "mock_tables") | ||
sys.path.insert(0, modules_path) | ||
sys.path.insert(0, test_path) | ||
sys.path.insert(0, mock_table_path) | ||
import dbconnector | ||
except KeyError: | ||
pass | ||
|
||
expected_counts = """\ | ||
Message Type Vlan1000 | ||
-------------- ----------- | ||
Solicit | ||
Advertise | ||
Request | ||
Confirm | ||
Renew | ||
Rebind | ||
Reply | ||
Release | ||
Decline | ||
Relay-Forward | ||
Relay-Reply | ||
""" | ||
|
||
class TestDhcp6RelayCounters(object): | ||
|
||
def test_show_counts(self): | ||
runner = CliRunner() | ||
result = runner.invoke(show.dhcp6relay_counters.commands["counts"], ["-i Vlan1000"]) | ||
assert result.output == expected_counts | ||
|
40 changes: 40 additions & 0 deletions
40
dockers/docker-dhcp-relay/cli-plugin-tests/test_show_dhcpv6_helper.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import pytest | ||
import sys | ||
import os | ||
sys.path.append('../cli/show/plugins/') | ||
import show_dhcp_relay as show | ||
from click.testing import CliRunner | ||
from swsscommon import swsscommon | ||
from mock_config import TEST_DATA | ||
from parameterized import parameterized | ||
from pyfakefs.fake_filesystem_unittest import patchfs | ||
|
||
try: | ||
sys.path.insert(0, '../../../src/sonic-host-services/tests/common') | ||
from mock_configdb import MockConfigDb | ||
swsscommon.ConfigDBConnector = MockConfigDb | ||
except KeyError: | ||
pass | ||
|
||
expected_table = """\ | ||
-------- ------------ | ||
Vlan1000 fc02:2000::1 | ||
fc02:2000::2 | ||
-------- ------------ | ||
""" | ||
|
||
DBCONFIG_PATH = '/var/run/redis/sonic-db/database_config.json' | ||
|
||
class TestDhcpRelayHelper(object): | ||
|
||
@parameterized.expand(TEST_DATA) | ||
@patchfs | ||
def test_show_dhcpv6_helper(self, test_name, test_data, fs): | ||
if not os.path.exists(DBCONFIG_PATH): | ||
fs.create_file(DBCONFIG_PATH) | ||
MockConfigDb.set_config_db(test_data["config_db"]) | ||
runner = CliRunner() | ||
table = MockConfigDb.get_table(self, "DHCP_RELAY") | ||
result = show.get_data(table, "Vlan1000") | ||
assert result == expected_table | ||
|
32 changes: 32 additions & 0 deletions
32
dockers/docker-dhcp-relay/cli/clear/plugins/clear_dhcp6relay_counter.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import sys | ||
import click | ||
sys.path.insert(0, '../../show/plugins/') | ||
from show_dhcp6relay_counters import DHCPv6_Counter | ||
|
||
import utilities_common.cli as clicommon | ||
|
||
|
||
# sonic-clear dhcp6relay_counters | ||
@click.group(cls=clicommon.AliasedGroup) | ||
def dhcp6relay_clear(): | ||
pass | ||
|
||
@dhcp6relay_clear.command('dhcp6relay_counters') | ||
@click.option('-i', '--interface', required=False) | ||
def dhcp6relay_clear_counters(interface): | ||
""" Clear dhcp6relay message counts """ | ||
|
||
counter = DHCPv6_Counter() | ||
counter_intf = counter.get_interface() | ||
|
||
if interface: | ||
counter.clear_table(interface) | ||
else: | ||
for intf in counter_intf: | ||
counter.clear_table(intf) | ||
|
||
def register(cli): | ||
cli.add_command(dhcp6relay_clear_counters) | ||
|
||
if __name__ == '__main__': | ||
dhcp6relay_clear_counters() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters