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

[GCU] Add rollback validation test #5469

Merged
merged 3 commits into from
Jun 16, 2022
Merged
Show file tree
Hide file tree
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
21 changes: 21 additions & 0 deletions tests/generic_config_updater/test_bgp_prefix.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@
PREFIXES_V4_RE = "ip prefix-list PL_ALLOW_LIST_DEPLOYMENT_ID_0_COMMUNITY_{}_V4 seq \d+ permit {}"
PREFIXES_V6_RE = "ipv6 prefix-list PL_ALLOW_LIST_DEPLOYMENT_ID_0_COMMUNITY_{}_V6 seq \d+ permit {}"

def get_bgp_prefix_runningconfig(duthost):
""" Get bgp prefix config
"""
cmds = "show runningconfiguration bgp"
output = duthost.shell(cmds)
pytest_assert(not output['rc'],
"'{}' failed with rc={}".format(cmds, output['rc'])
)

# Sample:
# ip prefix-list PL_ALLOW_LIST_DEPLOYMENT_ID_0_COMMUNITY_empty_V4 seq 30 permit 10.20.0.0/16 le 32
# ipv6 prefix-list PL_ALLOW_LIST_DEPLOYMENT_ID_0_COMMUNITY_empty_V6 seq 20 deny ::/0 ge 65
bgp_prefix_pattern = r"(?:ip|ipv6) prefix-list.*(?:deny|permit).*"
bgp_prefix_config = re.findall(bgp_prefix_pattern, output['stdout'])
return bgp_prefix_config

@pytest.fixture(autouse=True)
def setup_env(duthosts, rand_one_dut_hostname):
"""
Expand All @@ -30,13 +46,18 @@ def setup_env(duthosts, rand_one_dut_hostname):
rand_selected_dut: The fixture returns a randomly selected DuT.
"""
duthost = duthosts[rand_one_dut_hostname]
original_bgp_prefix_config = get_bgp_prefix_runningconfig(duthost)
create_checkpoint(duthost)

yield

try:
logger.info("Rolled back to original checkpoint")
rollback_or_reload(duthost)
current_bgp_prefix_config = get_bgp_prefix_runningconfig(duthost)
pytest_assert(set(original_bgp_prefix_config) == set(current_bgp_prefix_config),
"bgp prefix config are not suppose to change after test"
)
finally:
delete_checkpoint(duthost)

Expand Down
26 changes: 26 additions & 0 deletions tests/generic_config_updater/test_bgp_speaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,27 @@ def lo_intf_ips(duthost, tbinfo):
return ip, ipv6
pytest_assert(True, "Required ipv4 and ipv6 to start the test")

def get_bgp_speaker_runningconfig(duthost):
""" Get bgp speaker config that contains src_address and ip_range

Sample output in t0:
['\n neighbor BGPSLBPassive update-source 10.1.0.32',
'\n neighbor BGPVac update-source 10.1.0.32',
'\n bgp listen range 10.255.0.0/25 peer-group BGPSLBPassive',
'\n bgp listen range 192.168.0.0/21 peer-group BGPVac']
"""
cmds = "show runningconfiguration bgp"
output = duthost.shell(cmds)
pytest_assert(not output['rc'],
"'{}' failed with rc={}".format(cmds, output['rc'])
)

# Sample:
# neighbor BGPSLBPassive update-source 10.1.0.32
# bgp listen range 192.168.0.0/21 peer-group BGPVac
bgp_speaker_pattern = r"\s+neighbor.*update-source.*|\s+bgp listen range.*"
bgp_speaker_config = re.findall(bgp_speaker_pattern, output['stdout'])
return bgp_speaker_config

@pytest.fixture(autouse=True)
def setup_env(duthosts, rand_one_dut_hostname):
Expand All @@ -63,13 +84,18 @@ def setup_env(duthosts, rand_one_dut_hostname):
rand_selected_dut: The fixture returns a randomly selected DuT.
"""
duthost = duthosts[rand_one_dut_hostname]
original_bgp_speaker_config = get_bgp_speaker_runningconfig(duthost)
create_checkpoint(duthost)

yield

try:
logger.info("Rolled back to original checkpoint")
rollback_or_reload(duthost)
current_bgp_speaker_config = get_bgp_speaker_runningconfig(duthost)
pytest_assert(set(original_bgp_speaker_config) == set(current_bgp_speaker_config),
"bgp speaker config are not suppose to change after test"
)
finally:
delete_checkpoint(duthost)

Expand Down
21 changes: 21 additions & 0 deletions tests/generic_config_updater/test_bgpl.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import pytest
import re

from netaddr import IPNetwork
from tests.common.helpers.assertions import pytest_assert
Expand All @@ -14,6 +15,21 @@

logger = logging.getLogger(__name__)

def get_bgp_monitor_runningconfig(duthost):
""" Get bgp listener config
"""
cmds = "show runningconfiguration bgp"
output = duthost.shell(cmds)
pytest_assert(not output['rc'],
"'{}' failed with rc={}".format(cmds, output['rc'])
)

# Sample:
# neighbor 11.0.0.1 description BGPMonitor
bgp_listener_pattern = r"\s+neighbor.*description BGPMonitor"
bgp_listener_config = re.findall(bgp_listener_pattern, output['stdout'])
return bgp_listener_config

@pytest.fixture(autouse=True)
def setup_env(duthosts, rand_one_dut_hostname):
"""
Expand All @@ -23,13 +39,18 @@ def setup_env(duthosts, rand_one_dut_hostname):
rand_selected_dut: The fixture returns a randomly selected DuT.
"""
duthost = duthosts[rand_one_dut_hostname]
original_bgp_listener_config = get_bgp_monitor_runningconfig(duthost)
create_checkpoint(duthost)

yield

try:
logger.info("Rolled back to original checkpoint")
rollback_or_reload(duthost)
current_bgp_listener_config = get_bgp_monitor_runningconfig(duthost)
pytest_assert(set(original_bgp_listener_config) == set(current_bgp_listener_config),
"bgp listener config are not suppose to change after test"
)
finally:
delete_checkpoint(duthost)

Expand Down