-
Notifications
You must be signed in to change notification settings - Fork 1k
GCU loopback interface test #4814
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
10f5cbb
GCU loopback interface test
wen587 d351592
make each test independent and resolve comment
wen587 e855c7d
always remove temp file whether test succeed or fail
wen587 19dd653
Add rollback instead of config_reload
wen587 21621ed
tune rollback func and remove unnecessary sudo
wen587 18f390a
1. add checkpoint file existence check 2. add vrf test for lo intf
wen587 96fe6b8
remove logging info
wen587 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,211 @@ | ||
| import logging | ||
| import pytest | ||
|
|
||
| from tests.common.helpers.assertions import pytest_assert | ||
| from tests.generic_config_updater.gu_utils import apply_patch, expect_op_success, expect_op_failure | ||
| from tests.generic_config_updater.gu_utils import generate_tmpfile, delete_tmpfile | ||
| from tests.generic_config_updater.gu_utils import create_checkpoint, delete_checkpoint, rollback_or_reload | ||
|
|
||
| # Test on t0 topo to verify functionality and to choose predefined variable | ||
| # "LOOPBACK_INTERFACE": { | ||
| # "Loopback0": {}, | ||
| # "Loopback0|10.1.0.32/32": {}, | ||
| # "Loopback0|FC00:1::32/128": {} | ||
| # } | ||
| pytestmark = [ | ||
| pytest.mark.topology('t0'), | ||
| ] | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| @pytest.fixture(autouse=True) | ||
| def setup_env(duthosts, rand_one_dut_hostname): | ||
| """ | ||
| Setup/teardown fixture for each loopback interface test | ||
| Args: | ||
| duthosts: list of DUTs. | ||
| rand_selected_dut: The fixture returns a randomly selected DuT. | ||
| """ | ||
| duthost = duthosts[rand_one_dut_hostname] | ||
| create_checkpoint(duthost) | ||
|
|
||
| yield | ||
ghooo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| try: | ||
| logger.info("Rolled back to original checkpoint") | ||
isabelmsft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| rollback_or_reload(duthost) | ||
| finally: | ||
| delete_checkpoint(duthost) | ||
|
|
||
| # Cleanup LOOPBACK_INTERFACE config | ||
| def cleanup_lo_interface_config(duthost, cfg_facts): | ||
| lo_interfaces = cfg_facts.get('LOOPBACK_INTERFACE', {}) | ||
| for lo_interface in lo_interfaces: | ||
| del_loopback_interface = duthost.shell("sudo config loopback del {}".format(lo_interface), | ||
| module_ignore_errors=True) | ||
| pytest_assert(not del_loopback_interface['rc'], | ||
| "Loopback interface '{}' is not deleted successfully".format(lo_interface)) | ||
|
|
||
| def test_lo_interface_tc1_add_init(duthost, cfg_facts): | ||
| """ Clean up orig lo interface and test initial addion of v4 and v6 lo intf | ||
|
|
||
| Expected output | ||
| "LOOPBACK_INTERFACE": { | ||
| "Loopback0": {}, | ||
| "Loopback0|10.1.0.32/32": {}, | ||
| "Loopback0|FC00:1::32/128": {} | ||
| } | ||
| """ | ||
| cleanup_lo_interface_config(duthost, cfg_facts) | ||
|
|
||
| json_patch = [ | ||
| { | ||
| "op": "add", | ||
| "path": "/LOOPBACK_INTERFACE", | ||
| "value": { | ||
| "Loopback0": {}, | ||
| "Loopback0|10.1.0.32/32": {}, | ||
| "Loopback0|FC00:1::32/128": {} | ||
| } | ||
| } | ||
| ] | ||
|
|
||
| tmpfile = generate_tmpfile(duthost) | ||
| logger.info("tmpfile {}".format(tmpfile)) | ||
|
|
||
| try: | ||
| output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile) | ||
| expect_op_success(duthost, output) | ||
ghooo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| finally: | ||
| delete_tmpfile(duthost, tmpfile) | ||
|
|
||
| def test_lo_interface_tc2_add_duplicate(duthost): | ||
| """ Add v4 and v6 duplicate lo intf to config | ||
|
|
||
| Note: the Identifier '/' as changed to '~1' | ||
| Initial Loopback setup in t0 | ||
| "LOOPBACK_INTERFACE": { | ||
| "Loopback0": {}, | ||
| "Loopback0|10.1.0.32/32": {}, | ||
| "Loopback0|FC00:1::32/128": {} | ||
| } | ||
| """ | ||
| json_patch = [ | ||
| { | ||
| "op": "add", | ||
| "path": "/LOOPBACK_INTERFACE/Loopback0|10.1.0.32~132", | ||
ghooo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "value": {} | ||
| }, | ||
| { | ||
| "op": "add", | ||
| "path": "/LOOPBACK_INTERFACE/Loopback0|FC00:1::32~1128", | ||
| "value": {} | ||
| } | ||
| ] | ||
|
|
||
| tmpfile = generate_tmpfile(duthost) | ||
| logger.info("tmpfile {}".format(tmpfile)) | ||
|
|
||
| try: | ||
| output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile) | ||
| expect_op_success(duthost, output) | ||
| finally: | ||
| delete_tmpfile(duthost, tmpfile) | ||
|
|
||
| @pytest.mark.parametrize("op, name, dummy_lo_interface_v4, dummy_lo_interface_v6", [ | ||
| ("add", "Loopback0", "587.1.0.32~132", "FC00:1::32~1128"), | ||
| ("add", "Loopback0", "10.1.0.32~132", "FC00:1::xyz~1128"), | ||
| ("remove", "Loopback0", "10.1.0.33~132", "FC00:1::32~1128"), | ||
| ("remove", "Loopback0", "10.1.0.32~132", "FC00:1::33~1128") | ||
| ]) | ||
| def test_lo_interface_tc3_xfail(duthost, op, name, | ||
| dummy_lo_interface_v4, dummy_lo_interface_v6): | ||
| """ Test expect fail testcase | ||
|
|
||
| ("add", "Loopback0", "587.1.0.32~132", "FC00:1::32~1128"), ADD Invalid IPv4 address | ||
| ("add", "Loopback0", "10.1.0.32~132", "FC00:1::xyz~1128"), ADD Invalid IPv6 address | ||
| ("remove", "Loopback0", "10.1.0.33~132", "FC00:1::32~1128"), REMOVE Unexist IPv4 address | ||
| ("remove", "Loopback0", "10.1.0.32~132", "FC00:1::33~1128") REMOVE Unexist IPv6 address | ||
| """ | ||
| dummy_lo_interface_v4 = name + "|" + dummy_lo_interface_v4 | ||
| dummy_lo_interface_v6 = name + "|" + dummy_lo_interface_v6 | ||
|
|
||
| json_patch = [ | ||
| { | ||
| "op": "{}".format(op), | ||
| "path": "/LOOPBACK_INTERFACE/{}".format(dummy_lo_interface_v4), | ||
| "value": {} | ||
| }, | ||
| { | ||
| "op": "{}".format(op), | ||
| "path": "/LOOPBACK_INTERFACE/{}".format(dummy_lo_interface_v6), | ||
| "value": {} | ||
| } | ||
| ] | ||
|
|
||
| tmpfile = generate_tmpfile(duthost) | ||
| logger.info("tmpfile {}".format(tmpfile)) | ||
|
|
||
| try: | ||
| output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile) | ||
| expect_op_failure(output) | ||
| finally: | ||
| delete_tmpfile(duthost, tmpfile) | ||
|
|
||
| def test_lo_interface_tc4_replace(duthost): | ||
| """ Replace v4 and v6 loopback intf ip | ||
| Expected output | ||
| "LOOPBACK_INTERFACE": { | ||
| "Loopback0": {}, | ||
| "Loopback0|10.1.0.33/32": {}, | ||
| "Loopback0|FC00:1::33/128": {} | ||
| } | ||
| """ | ||
| json_patch = [ | ||
| { | ||
| "op": "remove", | ||
| "path": "/LOOPBACK_INTERFACE/Loopback0|FC00:1::32~1128" | ||
| }, | ||
| { | ||
| "op": "remove", | ||
| "path": "/LOOPBACK_INTERFACE/Loopback0|10.1.0.32~132" | ||
| }, | ||
| { | ||
| "op": "add", | ||
| "path": "/LOOPBACK_INTERFACE/Loopback0|10.1.0.33~132", | ||
| "value": {} | ||
| }, | ||
| { | ||
| "op": "add", | ||
| "path": "/LOOPBACK_INTERFACE/Loopback0|FC00:1::33~1128", | ||
| "value": {} | ||
| } | ||
| ] | ||
|
|
||
| tmpfile = generate_tmpfile(duthost) | ||
| logger.info("tmpfile {}".format(tmpfile)) | ||
|
|
||
| try: | ||
| output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile) | ||
| expect_op_success(duthost, output) | ||
| finally: | ||
| delete_tmpfile(duthost, tmpfile) | ||
|
|
||
| def test_lo_interface_tc5_remove(duthost): | ||
| """ Remove v4 and v6 loopback intf config | ||
| """ | ||
| json_patch = [ | ||
| { | ||
| "op": "remove", | ||
| "path": "/LOOPBACK_INTERFACE" | ||
| } | ||
| ] | ||
|
|
||
| tmpfile = generate_tmpfile(duthost) | ||
| logger.info("tmpfile {}".format(tmpfile)) | ||
|
|
||
| try: | ||
| output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile) | ||
| expect_op_success(duthost, output) | ||
| finally: | ||
| delete_tmpfile(duthost, tmpfile) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.