-
Notifications
You must be signed in to change notification settings - Fork 746
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create test cases for testing L2 configuration.
- Loading branch information
Showing
2 changed files
with
101 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
""" | ||
Tests related to L2 configuration | ||
""" | ||
import logging | ||
import pytest | ||
import time | ||
|
||
from tests.common import reboot | ||
from tests.common.helpers.assertions import pytest_expect | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
pytestmark = [ | ||
pytest.mark.topology('any') | ||
] | ||
|
||
|
||
def test_l2_configure(duthosts, rand_one_dut_hostname): | ||
""" | ||
@summary: Test configuring dut as a L2 switch. | ||
Args: | ||
duthosts: set of DUTs. | ||
""" | ||
# Setup. | ||
duthost = duthosts[rand_one_dut_hostname] | ||
hwsku = duthost.facts["hwsku"] | ||
|
||
# Store original config for comparison. | ||
orig_vlan = duthost.shell("show vlan config")["stdout"] | ||
orig_int = duthost.shell("show int status")["stdout"] | ||
|
||
# Perform L2 configuration | ||
logger.info("Configuring DUT into L2 mode.") | ||
l2_cfg = "sudo sonic-cfggen --preset l2 -p -H -k {}" \ | ||
" | sudo config load /dev/stdin -y".format(hwsku) | ||
duthost.shell(l2_cfg) | ||
duthost.shell("sudo config qos reload --no-dynamic-buffer") | ||
time.sleep(30) | ||
|
||
logger.info("Checking vlan and interface facts.") | ||
new_vlan = duthost.shell("show vlan config")["stdout"] | ||
new_int = duthost.shell("show int status")["stdout"] | ||
pytest_expect(orig_vlan != new_vlan, "vlan config not updated.") | ||
pytest_expect(orig_int != new_int, "interface status not updated.") | ||
|
||
# Restore from L2 | ||
logger.info("Restoring DUT into L3 mode.") | ||
duthost.shell("sudo config reload -y") | ||
time.sleep(30) | ||
|
||
|
||
def test_l2_configure_over_reboot(duthosts, rand_one_dut_hostname, localhost): | ||
""" | ||
@summary: Test configuring dut as a L2 switch and reboot. | ||
Args: | ||
duthosts: set of DUTs. | ||
""" | ||
# Setup. | ||
duthost = duthosts[rand_one_dut_hostname] | ||
hwsku = duthost.facts["hwsku"] | ||
|
||
# Save original config | ||
duthost.shell("sudo cp /etc/sonic/config_db.json /tmp/orig_config.json") | ||
|
||
# Store original config for comparison. | ||
orig_vlan = duthost.shell("show vlan config")["stdout"] | ||
orig_int = duthost.shell("show int status")["stdout"] | ||
|
||
# Perform L2 configuration | ||
logger.info("Configuring DUT into L2 mode.") | ||
l2_cfg = "sudo sonic-cfggen --preset l2 -p -H -k {}" \ | ||
" | sudo config load /dev/stdin -y".format(hwsku) | ||
duthost.shell(l2_cfg) | ||
duthost.shell("sudo config qos reload --no-dynamic-buffer") | ||
duthost.shell("sudo config save -y") | ||
reboot(duthost, localhost) | ||
time.sleep(30) | ||
|
||
logger.info("Checking vlan and interface facts.") | ||
new_vlan = duthost.shell("show vlan config")["stdout"] | ||
new_int = duthost.shell("show int status")["stdout"] | ||
pytest_expect(orig_vlan != new_vlan, "vlan config not updated.") | ||
pytest_expect(orig_int != new_int, "interface status not updated.") | ||
|
||
# Restore from L2 | ||
logger.info("Restoring DUT into L3 mode.") | ||
duthost.shell("sudo config reload /tmp/orig_config.json -y") | ||
duthost.shell("sudo config save -y") | ||
time.sleep(30) |