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

Create a test case for testing L2 configuration. #14714

Merged
merged 12 commits into from
Nov 5, 2024

Conversation

hdwhdw
Copy link
Contributor

@hdwhdw hdwhdw commented Sep 24, 2024

Reference: https://github.com/sonic-net/SONiC/wiki/L2-Switch-mode

Description of PR

Create a test case for configuring switch to L2 mode.

Summary:
Add a test case for writing L2 configuration into config DB. This is precursor to a testcase requested in
issue 8777 #8777

Fixes # (issue)

Type of change

  • Bug fix
  • Testbed and Framework(new/improvement)
  • [x ] Test case(new/improvement)

Back port request

  • 202012
  • 202205
  • 202305
  • 202311
  • 202405

Approach

Add a test case

What is the motivation for this PR?

Address #8777

How did you do it?

How did you verify/test it?

Ran on virtual switch.

Any platform specific information?

No.

Supported testbed topology if it's a new test case?

Any.

Documentation

@mssonicbld
Copy link
Collaborator

The pre-commit check detected issues in the files touched by this pull request.
The pre-commit check is a mandatory check, please fix detected issues.

Detailed pre-commit check results:
trim trailing whitespace.................................................Passed
fix end of files.........................................................Passed
check yaml...........................................(no files to check)Skipped
check for added large files..............................................Passed
check python ast.........................................................Passed
flake8...................................................................Failed
- hook id: flake8
- exit code: 1

tests/l2/test_l2_configure.py:52:1: E302 expected 2 blank lines, found 1

flake8...............................................(no files to check)Skipped
check conditional mark sort..........................(no files to check)Skipped

To run the pre-commit checks locally, you can follow below steps:

  1. Ensure that default python is python3. In sonic-mgmt docker container, default python is python2. You can run
    the check by activating the python3 virtual environment in sonic-mgmt docker container or outside of sonic-mgmt
    docker container.
  2. Ensure that the pre-commit package is installed:
sudo pip install pre-commit
  1. Go to repository root folder
  2. Install the pre-commit hooks:
pre-commit install
  1. Use pre-commit to check staged file:
pre-commit
  1. Alternatively, you can check committed files using:
pre-commit run --from-ref <commit_id> --to-ref <commit_id>

@mssonicbld
Copy link
Collaborator

The pre-commit check detected issues in the files touched by this pull request.
The pre-commit check is a mandatory check, please fix detected issues.

Detailed pre-commit check results:
trim trailing whitespace.................................................Passed
fix end of files.........................................................Passed
check yaml...........................................(no files to check)Skipped
check for added large files..............................................Passed
check python ast.........................................................Passed
flake8...................................................................Failed
- hook id: flake8
- exit code: 1

tests/l2/test_l2_configure.py:52:1: E302 expected 2 blank lines, found 1

flake8...............................................(no files to check)Skipped
check conditional mark sort..........................(no files to check)Skipped

To run the pre-commit checks locally, you can follow below steps:

  1. Ensure that default python is python3. In sonic-mgmt docker container, default python is python2. You can run
    the check by activating the python3 virtual environment in sonic-mgmt docker container or outside of sonic-mgmt
    docker container.
  2. Ensure that the pre-commit package is installed:
sudo pip install pre-commit
  1. Go to repository root folder
  2. Install the pre-commit hooks:
pre-commit install
  1. Use pre-commit to check staged file:
pre-commit
  1. Alternatively, you can check committed files using:
pre-commit run --from-ref <commit_id> --to-ref <commit_id>

" | sudo config load /dev/stdin -y".format(hwsku)
duthost.shell(l2_cfg)
duthost.shell("sudo config qos reload --no-dynamic-buffer")
time.sleep(30)
Copy link
Contributor

@qiluo-msft qiluo-msft Sep 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

time.sleep(30)

time.sleep(30)

We should try best to remove sleeping for fixed time:

  1. if too long, waste overall test runtime
  2. if too short, test may be flaky on some weaker hwsku

Could you use function "wait_until" for a special signal? You may use redis-cli monitor to observe what is really happening.

Or maybe you do not need to sleep at all? #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this. This is replaced by a reboot (which is one step in the expected test case).

# Restore from L2
logger.info("Restoring DUT into L3 mode.")
duthost.shell("sudo config reload -y")
time.sleep(30)
Copy link
Contributor

@qiluo-msft qiluo-msft Sep 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

time.sleep(30)

time.sleep(30)

The same. #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed. config_reload api resolve this issue.

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.")
Copy link
Contributor

@qiluo-msft qiluo-msft Sep 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pytest_expect

pytest_expect

I do not understand these expect test.

Since previously we have a bugfix, we should test RESTAPI, TELEMETRY, DEVICE_METADATA tables are not in ConfigDB after reboot
#Closed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry please take this commit as a draft. I updated the test expectation to enforce the expectation you said. Please take a look.

@ganglyu
Copy link
Contributor

ganglyu commented Sep 27, 2024

Step 3 is not included in this test.
#8777

  1. Cold reboot a device.
  2. Perform L2 config steps via L2 Switch mode · sonic-net/SONiC Wiki (github.com)
  3. Install target image.
  4. Cold reboot
  5. Check config_db

duthost.shell(l2_cfg)
duthost.shell("sudo config qos reload --no-dynamic-buffer")
duthost.shell("sudo config save -y")
reboot(duthost, localhost)
Copy link
Contributor

@ganglyu ganglyu Sep 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After cold rebooting, the image version remains unchanged, and the db_migrator will not function. Consequently, the CONFIG_DB will remain the same.
Therefore, this test cannot verify our bug fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated test. Please take a look.


# Restore from L2
logger.info("Restoring DUT into L3 mode.")
duthost.shell("sudo config reload -y")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have config_reload API to guarantee some critical service is up

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as the above comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

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.")
Copy link
Contributor

@xincunli-sonic xincunli-sonic Sep 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pytest_expect

please use this structure:

try:
pytest assert ...
except:
optional block
Handling of exception (if required)
else:
execute if no exception, in your case may not needed.
finally:
Restore old config (always executed)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -9,6 +9,16 @@ def pytest_assert(condition, message=None):
pytest.fail(message)


def pytest_expect(condition, message=None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pytest_expect

use try catch finally instead of this way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

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.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

orig_vlan != new_vlan

In L2, is there any specific vlan changed? Same to int, also I saw wiki mentioned QoS reload, are you going to check buffer related config as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed this check. This is not the focus of the test so I was just placing this here as a place holder.

Args:
duthosts: set of DUTs.
"""
# Setup.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mssonicbld
Copy link
Collaborator

The pre-commit check detected issues in the files touched by this pull request.
The pre-commit check is a mandatory check, please fix detected issues.

Detailed pre-commit check results:
trim trailing whitespace.................................................Failed
- hook id: trailing-whitespace
- exit code: 1
- files were modified by this hook

Fixing tests/l2/test_l2_configure.py

fix end of files.........................................................Failed
- hook id: end-of-file-fixer
- exit code: 1
- files were modified by this hook

Fixing tests/l2/conftest.py

check yaml...........................................(no files to check)Skipped
check for added large files..............................................Passed
check python ast.........................................................Passed
flake8...................................................................Failed
- hook id: flake8
- exit code: 1
...
[truncated extra lines, please run pre-commit locally to view full check results]

To run the pre-commit checks locally, you can follow below steps:

  1. Ensure that default python is python3. In sonic-mgmt docker container, default python is python2. You can run
    the check by activating the python3 virtual environment in sonic-mgmt docker container or outside of sonic-mgmt
    docker container.
  2. Ensure that the pre-commit package is installed:
sudo pip install pre-commit
  1. Go to repository root folder
  2. Install the pre-commit hooks:
pre-commit install
  1. Use pre-commit to check staged file:
pre-commit
  1. Alternatively, you can check committed files using:
pre-commit run --from-ref <commit_id> --to-ref <commit_id>

@hdwhdw
Copy link
Contributor Author

hdwhdw commented Oct 1, 2024

Updated the testcase according to comment. The test case should reflect what the issue is looking for.

# conftest.py for L2 configuration.


def pytest_addoption(parser):
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

# 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'])
Copy link
Contributor

@qiluo-msft qiluo-msft Oct 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redis-cli

are you checking ConfigDB? by default it is checkin ApplDB.

suggest to use sonic-db-cli instead of redis-cli. #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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|*"
TELEMETRY|gnmi
TELEMETRY|certs

@mssonicbld
Copy link
Collaborator

The pre-commit check detected issues in the files touched by this pull request.
The pre-commit check is a mandatory check, please fix detected issues.

Detailed pre-commit check results:
trim trailing whitespace.................................................Failed
- hook id: trailing-whitespace
- exit code: 1
- files were modified by this hook

Fixing tests/remote_run_tests.sh

fix end of files.........................................................Passed
check yaml...........................................(no files to check)Skipped
check for added large files..............................................Passed
check python ast.........................................................Passed
flake8...................................................................Failed
- hook id: flake8
- exit code: 1

tests/l2/test_l2_configure.py:65:52: F821 undefined name 'tbinfo'
tests/l2/test_l2_configure.py:66:5: F841 local variable 'mg_ip' is assigned to but never used
tests/l2/test_l2_configure.py:67:5: F841 local variable 'init_config' is assigned to but never used

flake8...............................................(no files to check)Skipped
...
[truncated extra lines, please run pre-commit locally to view full check results]

To run the pre-commit checks locally, you can follow below steps:

  1. Ensure that default python is python3. In sonic-mgmt docker container, default python is python2. You can run
    the check by activating the python3 virtual environment in sonic-mgmt docker container or outside of sonic-mgmt
    docker container.
  2. Ensure that the pre-commit package is installed:
sudo pip install pre-commit
  1. Go to repository root folder
  2. Install the pre-commit hooks:
pre-commit install
  1. Use pre-commit to check staged file:
pre-commit
  1. Alternatively, you can check committed files using:
pre-commit run --from-ref <commit_id> --to-ref <commit_id>

@hdwhdw hdwhdw force-pushed the l2-mode branch 2 times, most recently from 66e89cc to 47d615f Compare October 10, 2024 20:34
@hdwhdw hdwhdw requested a review from StormLiangMS as a code owner October 10, 2024 20:39
for table in ["TELEMETRY", "RESTAPI"]:
pytest_assert(
is_table_empty(duthost, table), "{} table is not empty!".format(table)
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to recover original configuration.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already done in the setup_env fixture in the same file.

qiluo-msft
qiluo-msft previously approved these changes Oct 29, 2024
@hdwhdw hdwhdw requested review from wen587, ganglyu, qiluo-msft and xincunli-sonic and removed request for wen587 and xincunli-sonic October 29, 2024 20:56
logger = logging.getLogger(__name__)

pytestmark = [
pytest.mark.topology("any"),
Copy link
Contributor

@qiluo-msft qiluo-msft Oct 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any

any

we can limit to t0 topo. no need to test l2 mode on t1 topo. #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Done.

The test will now simply configure L2 and then check config db.

TESTED:
passed on 202012.66 (image with db_migrator fix)
failed on 202012.76 (image without fix)
failed at master head (with fixes, so indicates some other bugs)
@hdwhdw
Copy link
Contributor Author

hdwhdw commented Oct 30, 2024

Force push to fix a commit message.

@ganglyu
Copy link
Contributor

ganglyu commented Oct 30, 2024

Can you check database version before and after config reload?

admin@str-msn2700-20:~$ sonic-db-cli CONFIG_DB hgetall "VERSIONS|DATABASE"
{'VERSION': 'version_202305_01'}

@hdwhdw
Copy link
Contributor Author

hdwhdw commented Oct 30, 2024

@ganglyu done.

@hdwhdw
Copy link
Contributor Author

hdwhdw commented Oct 30, 2024

@ganglyu
daweihuang@sonic-mgmt:/data/sonic-mgmt/tests$ cat logs/test.log | grep "Database version" 30/10/2024 02:09:22 test_l2_configure.test_no_hardcoded_mini L0147 INFO | Database version before L2 configuration reload: version_2_0_0 30/10/2024 02:12:20 test_l2_configure.test_no_hardcoded_mini L0153 INFO | Database version after L2 configuration reload: version_2_0_0

Copy link
Contributor

@ganglyu ganglyu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Database version is not changed after config reload, so db migrator should not change anything.
I don't understand why database is changed, but I will approve this PR for further investigation.

"gwaddr": "{}"
}}
}},
"DEVICE_METADATA": {{
Copy link
Contributor

@qiluo-msft qiluo-msft Oct 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DEVICE_METADATA

The step in test does not follow https://github.com/sonic-net/SONiC/wiki/L2-Switch-mode exactly. For example, DualToR is not considered. And the commands used does not exact match. #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the record, this comes from testbed_set_l2.yml. The wiki way requires running over console and I haven't find a reliable API in sonic-mgmt that pass the test. I'll see if there is any other way to make it work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spoke with Gang and Xin yesterday. And it appears the testbed_set_l2.yml method of setting up is a L2 mode is a workaround since ansible library requires the ssh session to be always active, and we don't have library support for doing it through console.

@hdwhdw hdwhdw requested a review from xincunli-sonic November 4, 2024 23:53
@qiluo-msft qiluo-msft merged commit 9c12485 into sonic-net:master Nov 5, 2024
15 checks passed
veronica-arista pushed a commit to veronica-arista/sonic-mgmt that referenced this pull request Nov 7, 2024
Reference: https://github.com/sonic-net/SONiC/wiki/L2-Switch-mode

### Description of PR
Create a test case for configuring switch to L2 mode.

Summary:
Add a test case for writing L2 configuration into config DB. This is precursor to a testcase requested in
issue 8777 sonic-net#8777

### Approach
Add a test case
#### What is the motivation for this PR?
Address sonic-net#8777

#### How did you do it?

#### How did you verify/test it?
Ran on virtual switch.
sreejithsreekumaran pushed a commit to sreejithsreekumaran/sonic-mgmt that referenced this pull request Nov 15, 2024
Reference: https://github.com/sonic-net/SONiC/wiki/L2-Switch-mode

### Description of PR
Create a test case for configuring switch to L2 mode.

Summary:
Add a test case for writing L2 configuration into config DB. This is precursor to a testcase requested in
issue 8777 sonic-net#8777

### Approach
Add a test case
#### What is the motivation for this PR?
Address sonic-net#8777

#### How did you do it?

#### How did you verify/test it?
Ran on virtual switch.
yutongzhang-microsoft pushed a commit to yutongzhang-microsoft/sonic-mgmt that referenced this pull request Nov 21, 2024
Reference: https://github.com/sonic-net/SONiC/wiki/L2-Switch-mode

### Description of PR
Create a test case for configuring switch to L2 mode.

Summary:
Add a test case for writing L2 configuration into config DB. This is precursor to a testcase requested in
issue 8777 sonic-net#8777

### Approach
Add a test case
#### What is the motivation for this PR?
Address sonic-net#8777

#### How did you do it?

#### How did you verify/test it?
Ran on virtual switch.
@hdwhdw hdwhdw deleted the l2-mode branch January 7, 2025 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants