-
Notifications
You must be signed in to change notification settings - Fork 750
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
Create a test case for testing L2 configuration. #14714
Changes from 1 commit
3a729c4
7a7fb41
2fd62ab
615ebea
b47390f
81fecd3
fd436d4
3a120c5
14e7527
c1aebcd
56997e5
58cb31c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# conftest.py for L2 configuration. | ||
|
||
|
||
def pytest_addoption(parser): | ||
# Target image to upgrade to. | ||
parser.addoption( | ||
"--target_image", | ||
action="store", | ||
default="", | ||
help="Specify a target image for upgrade", | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
""" | ||
Tests related to L2 configuration | ||
""" | ||
import logging | ||
import pytest | ||
|
||
from tests.common import reboot | ||
from tests.common.config_reload import config_reload | ||
from tests.common.helpers.assertions import pytest_assert | ||
|
||
CONFIG_DB = '/etc/sonic/config_db.json' | ||
CONFIG_DB_BAK = '/etc/sonic/config_db.json.bak' | ||
TARGET_IMG_LOCALHOST = '/var/tmp/target_sonic_localhost.bin' | ||
TARGET_IMG_DUTHOST = '/var/tmp/target_sonic_duthost.bin' | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
pytestmark = [ | ||
pytest.mark.topology('any') | ||
] | ||
|
||
|
||
def test_l2_config_and_upgrade(request, duthosts, rand_one_dut_hostname, localhost): | ||
""" | ||
@summary: A testcase that verifies DB migrator does not add bad data. | ||
1. Cold reboot. | ||
2. Configure switch into L2 mode. | ||
3. Install a new image. | ||
4. Reboot into the new image. DB migrator does its work. | ||
5. Verify. | ||
|
||
Args: | ||
request: From pytest. | ||
duthosts: set of DUTs. | ||
rand_one_duthostname: sample a random DUT. | ||
localhost: localhost object. | ||
tbinfo: testbed info | ||
""" | ||
# Setup. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
duthost = duthosts[rand_one_dut_hostname] | ||
hwsku = duthost.facts["hwsku"] | ||
|
||
# Get target image path: | ||
target_image = request.config.getoption('target_image', default=None) | ||
if target_image is None: | ||
pytest.skip("Skipping test due to missing --target_image.") | ||
init_img = duthost.shell('sudo sonic-installer list | grep Current | cut -f2 -d " "')['stdout'] | ||
|
||
# Step 1: Reboot. | ||
reboot(duthost, localhost, reboot_type="cold") | ||
|
||
# Step 2: Configure DUT into L2 mode. | ||
# Save original config | ||
duthost.shell("sudo cp {} {}".format(CONFIG_DB, CONFIG_DB_BAK)) | ||
# Perform L2 configuration | ||
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") | ||
|
||
# Step 3: Install new image and reboot. | ||
init_img = duthost.shell('sudo sonic-installer list | grep Current | cut -f2 -d " "')['stdout'] | ||
logger.info("Init image: {}".format(init_img)) | ||
localhost.get_url(url=target_image, dest=TARGET_IMG_LOCALHOST) | ||
duthost.copy(src=TARGET_IMG_LOCALHOST, dest=TARGET_IMG_DUTHOST) | ||
duthost.shell("sudo sonic-installer install -y {}".format(TARGET_IMG_DUTHOST)) | ||
reboot(duthost, localhost, reboot_type="cold") | ||
new_img = duthost.shell('sudo sonic-installer list | grep Current | cut -f2 -d " "')['stdout'] | ||
logger.info("New image: {}".format(new_img)) | ||
|
||
# Step 4: Verifies no config fro minigraph is written into ConfigDB. | ||
try: | ||
for table in ["TELEMETRY", "RESTAPI", "DEVICE_METADATA"]: | ||
count = int(duthost.shell('redis-cli --scan --pattern "{}*" | wc -l'.format(table))['stdout']) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like this reflect a real issue as I can see those unwanted table all the time, i.e. before l2, after l2, and after installing the image. admin@vlab-01:~$ sonic-db-cli CONFIG_DB KEYS "TELEMETRY|*" |
||
pytest_assert(count == 0, "{} table is not empty!".format(table)) | ||
except Exception: | ||
raise | ||
finally: | ||
# Restore from L2 and new images, restore image first. | ||
duthost.shell("sudo sonic-installer set-next-boot {}".format(init_img)) | ||
reboot(duthost, localhost, reboot_type="cold") | ||
cur_img = duthost.shell('sudo sonic-installer list | grep Current | cut -f2 -d " "')['stdout'] | ||
logger.info("Current image: {}".format(cur_img)) | ||
duthost.shell("sudo cp {} {}".format(CONFIG_DB_BAK, CONFIG_DB)) | ||
config_reload(duthost) | ||
duthost.shell("sudo rm {}".format(CONFIG_DB_BAK)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nightly test is used to verify specified sonic version, if we upgrade sonic image in this test, we can't add test to nightly test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what the issue is asking so if we can't upgrade, we need to find another way to trigger db_migrator?
Btw the test will restore the original image. Is that good enough?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please confirm with Vaibhav, I guess we need to upgrade from 20191130.xx to 20240531.xx and verify L2 configuration.
If we do this in nightly test for 20240531.xx, how do you choose new image to upgrade?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll check with him. Maybe we should do a --source_image and --target_image. It will make more sense to upgrade from an older image to 20240531 in the nightly test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checked with Vaibhab, this test should be in nightly. I will rewrite part of the test according to test_upgrade_path.py to better accommodate that.