forked from sonic-net/sonic-mgmt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IPv6 only]Add a fixture to convert the DUT to IPv6 only, and enhance…
… the connection plugin to retry with IPv6 addr if IPv4 addr is unavailable (sonic-net#11957) Approach What is the motivation for this PR? Support test mgmt-ip IPv6 only scenario. How did you do it? Remove the IPv4 mgmt address before the test module starts, and restore after the test module is finished. Enhance the connection plugging to first connect with the IPv4 address, and retry with the IPv6 address if IPv4 is unavailable. Add a new test module with examples to test the IPv6-only scenario. How did you verify/test it? Run on physical testbeds, with dual-stack mgmt-ip addresses testbed and only with IPv6/IPv4 mgmt-ip address testbed. ================================================================================================================== test session starts ================================================================================================================== ip/test_mgmt_ipv6_only.py::test_bgp_facts[-None] PASSED [ 25%] ip/test_mgmt_ipv6_only.py::test_bgp_facts_ipv6_only[-None] PASSED [ 50%] ip/test_mgmt_ipv6_only.py::test_show_features[-4] PASSED [ 75%] ip/test_mgmt_ipv6_only.py::test_show_features_ipv6_only[-4] PASSED [100%] -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html --------------------------------------------------------------------------------------------- generated xml file: /var/src/sonic-mgmt-int/tests/logs/tr.xml --------------------------------------------------------------------------------------------- ======================================================================================================= 4 passed, 3 warnings in 741.52s (0:12:21) ======================================================================================================= INFO:root:Can not get Allure report URL. Please check logs jianquanye@sonic-mgmt-jianquanye:/var/src/sonic-mgmt-int/tests$
- Loading branch information
1 parent
234a7ec
commit afd7fce
Showing
4 changed files
with
247 additions
and
4 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import pytest | ||
|
||
from tests.common.fixtures.duthost_utils import convert_and_restore_config_db_to_ipv6_only # noqa F401 | ||
from tests.common.helpers.assertions import pytest_assert | ||
|
||
pytestmark = [ | ||
pytest.mark.topology('any'), | ||
pytest.mark.device_type('vs') | ||
] | ||
|
||
|
||
def test_bgp_facts_ipv6_only(duthosts, enum_frontend_dut_hostname, enum_asic_index, | ||
convert_and_restore_config_db_to_ipv6_only): # noqa F811 | ||
"""compare the bgp facts between observed states and target state""" | ||
|
||
duthost = duthosts[enum_frontend_dut_hostname] | ||
|
||
bgp_facts = duthost.bgp_facts(instance_id=enum_asic_index)['ansible_facts'] | ||
namespace = duthost.get_namespace_from_asic_id(enum_asic_index) | ||
config_facts = duthost.config_facts(host=duthost.hostname, source="running", namespace=namespace)['ansible_facts'] | ||
sonic_db_cmd = "sonic-db-cli {}".format("-n " + namespace if namespace else "") | ||
for k, v in list(bgp_facts['bgp_neighbors'].items()): | ||
# Verify bgp sessions are established | ||
assert v['state'] == 'established' | ||
# Verify local ASNs in bgp sessions | ||
assert v['local AS'] == int(config_facts['DEVICE_METADATA']['localhost']['bgp_asn'].encode().decode("utf-8")) | ||
# Check bgpmon functionality by validate STATE DB contains this neighbor as well | ||
state_fact = duthost.shell('{} STATE_DB HGET "NEIGH_STATE_TABLE|{}" "state"' | ||
.format(sonic_db_cmd, k), module_ignore_errors=False)['stdout_lines'] | ||
peer_type = duthost.shell('{} STATE_DB HGET "NEIGH_STATE_TABLE|{}" "peerType"' | ||
.format(sonic_db_cmd, k), | ||
module_ignore_errors=False)['stdout_lines'] | ||
assert state_fact[0] == "Established" | ||
assert peer_type[0] == "i-BGP" if v['remote AS'] == v['local AS'] else "e-BGP" | ||
|
||
# In multi-asic, would have 'BGP_INTERNAL_NEIGHBORS' and possibly no 'BGP_NEIGHBOR' (ebgp) neighbors. | ||
nbrs_in_cfg_facts = {} | ||
nbrs_in_cfg_facts.update(config_facts.get('BGP_NEIGHBOR', {})) | ||
nbrs_in_cfg_facts.update(config_facts.get('BGP_INTERNAL_NEIGHBOR', {})) | ||
# In VoQ Chassis, we would have BGP_VOQ_CHASSIS_NEIGHBOR as well. | ||
nbrs_in_cfg_facts.update(config_facts.get('BGP_VOQ_CHASSIS_NEIGHBOR', {})) | ||
for k, v in list(nbrs_in_cfg_facts.items()): | ||
# Compare the bgp neighbors name with config db bgp neighbors name | ||
assert v['name'] == bgp_facts['bgp_neighbors'][k]['description'] | ||
# Compare the bgp neighbors ASN with config db | ||
assert int(v['asn'].encode().decode("utf-8")) == bgp_facts['bgp_neighbors'][k]['remote AS'] | ||
|
||
|
||
def test_show_features_ipv6_only(duthosts, enum_dut_hostname, convert_and_restore_config_db_to_ipv6_only): # noqa F811 | ||
"""Verify show features command output against CONFIG_DB | ||
""" | ||
|
||
duthost = duthosts[enum_dut_hostname] | ||
features_dict, succeeded = duthost.get_feature_status() | ||
pytest_assert(succeeded, "failed to obtain feature status") | ||
for cmd_key, cmd_value in list(features_dict.items()): | ||
redis_value = duthost.shell('/usr/bin/redis-cli -n 4 --raw hget "FEATURE|{}" "state"' | ||
.format(cmd_key), module_ignore_errors=False)['stdout'] | ||
pytest_assert(redis_value.lower() == cmd_value.lower(), | ||
"'{}' is '{}' which does not match with config_db".format(cmd_key, cmd_value)) |