Skip to content

Commit

Permalink
[GCU] Add rollback validation test (#5469)
Browse files Browse the repository at this point in the history
Summary: Improve GCU test by adding rollback validation test

What is the motivation for this PR?
Cover test gap for GCU rollback

How did you do it?
Record config before test start, then compare if config is the same after rollback.

How did you verify/test it?
Run test of sonic-mgmt/tests/generic_config_updater/test_bgp*.py on KVM
  • Loading branch information
wen587 authored Jun 16, 2022
1 parent 1f4b306 commit 01862c7
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
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

0 comments on commit 01862c7

Please sign in to comment.