forked from sonic-net/sonic-mgmt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Test gap] Test dhcp_relay with source port ip enabled (sonic-net#14653)
Description of PR Summary: Fixes sonic-net#3624 Mitigate the test gap: Test dhcp relay with source port ip in relay enabled. Approach What is the motivation for this PR? Fixes sonic-net#3624 Mitigate the test gap: Test dhcp relay with source port ip in relay enabled. How did you do it? Enhance dhcp_relay ptf test to verify the src_ip in relay packets Add a fixture which modify deployment_id to 8 and enable source port ip in relay Add a test case exactly same with test_dhcp_relay_default but include fixture enable_source_port_ip_in_relay. How did you verify/test it? Run on local dev vm, dhcp_relay/test_dhcp_relay.py::test_interface_binding PASSED [ 12%] dhcp_relay/test_dhcp_relay.py::test_dhcp_relay_default PASSED [ 25%] dhcp_relay/test_dhcp_relay.py::test_dhcp_relay_with_source_port_ip_in_relay_enabled PASSED [ 37%] dhcp_relay/test_dhcp_relay.py::test_dhcp_relay_after_link_flap PASSED [ 50%] dhcp_relay/test_dhcp_relay.py::test_dhcp_relay_start_with_uplinks_down PASSED [ 62%] dhcp_relay/test_dhcp_relay.py::test_dhcp_relay_unicast_mac PASSED [ 75%] dhcp_relay/test_dhcp_relay.py::test_dhcp_relay_random_sport PASSED [ 87%] dhcp_relay/test_dhcp_relay.py::test_dhcp_relay_counter SKIPPED (skip...) [100%] and PR test will test it again. co-authorized by: jianquanye@microsoft.com
- Loading branch information
1 parent
3ddd293
commit 3112407
Showing
3 changed files
with
298 additions
and
4 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,147 @@ | ||
import json | ||
import logging | ||
|
||
import pytest | ||
|
||
from tests.common import config_reload | ||
from tests.common.helpers.assertions import pytest_assert | ||
|
||
logger = logging.getLogger(__name__) | ||
DEFAULT_CHECKPOINT_NAME = "test" | ||
|
||
|
||
def generate_tmpfile(duthost): | ||
"""Generate temp file | ||
""" | ||
return duthost.shell('mktemp')['stdout'] | ||
|
||
|
||
def apply_patch(duthost, json_data, dest_file): | ||
"""Run apply-patch on target duthost | ||
Args: | ||
duthost: Device Under Test (DUT) | ||
json_data: Source json patch to apply | ||
dest_file: Destination file on duthost | ||
""" | ||
duthost.copy(content=json.dumps(json_data, indent=4), dest=dest_file) | ||
|
||
cmds = 'config apply-patch {}'.format(dest_file) | ||
|
||
logger.info("Commands: {}".format(cmds)) | ||
output = duthost.shell(cmds, module_ignore_errors=True) | ||
|
||
return output | ||
|
||
|
||
def delete_tmpfile(duthost, tmpfile): | ||
"""Delete temp file | ||
""" | ||
duthost.file(path=tmpfile, state='absent') | ||
|
||
|
||
def create_checkpoint(duthost, cp=DEFAULT_CHECKPOINT_NAME): | ||
"""Run checkpoint on target duthost | ||
Args: | ||
duthost: Device Under Test (DUT) | ||
cp: checkpoint filename | ||
""" | ||
cmds = 'config checkpoint {}'.format(cp) | ||
|
||
logger.info("Commands: {}".format(cmds)) | ||
output = duthost.shell(cmds, module_ignore_errors=True) | ||
|
||
pytest_assert( | ||
not output['rc'] | ||
and "Checkpoint created successfully" in output['stdout'] | ||
and verify_checkpoints_exist(duthost, cp), | ||
"Failed to config a checkpoint file: {}".format(cp) | ||
) | ||
|
||
|
||
def list_checkpoints(duthost): | ||
"""List checkpoint on target duthost | ||
Args: | ||
duthost: Device Under Test (DUT) | ||
""" | ||
cmds = 'config list-checkpoints' | ||
|
||
logger.info("Commands: {}".format(cmds)) | ||
output = duthost.shell(cmds, module_ignore_errors=True) | ||
|
||
pytest_assert( | ||
not output['rc'], | ||
"Failed to list all checkpoint file" | ||
) | ||
|
||
return output | ||
|
||
|
||
def verify_checkpoints_exist(duthost, cp): | ||
"""Check if checkpoint file exist in duthost | ||
""" | ||
output = list_checkpoints(duthost) | ||
return '"{}"'.format(cp) in output['stdout'] | ||
|
||
|
||
def rollback(duthost, cp=DEFAULT_CHECKPOINT_NAME): | ||
"""Run rollback on target duthost | ||
Args: | ||
duthost: Device Under Test (DUT) | ||
cp: rollback filename | ||
""" | ||
cmds = 'config rollback {}'.format(cp) | ||
|
||
logger.info("Commands: {}".format(cmds)) | ||
output = duthost.shell(cmds, module_ignore_errors=True) | ||
|
||
return output | ||
|
||
|
||
def rollback_or_reload(duthost, cp=DEFAULT_CHECKPOINT_NAME): | ||
"""Run rollback on target duthost. config_reload if rollback failed. | ||
Args: | ||
duthost: Device Under Test (DUT) | ||
""" | ||
output = rollback(duthost, cp) | ||
|
||
if output['rc'] or "Config rolled back successfully" not in output['stdout']: | ||
config_reload(duthost) | ||
pytest.fail("config rollback failed. Restored by config_reload") | ||
|
||
|
||
def delete_checkpoint(duthost, cp=DEFAULT_CHECKPOINT_NAME): | ||
"""Run checkpoint on target duthost | ||
Args: | ||
duthost: Device Under Test (DUT) | ||
cp: checkpoint filename | ||
""" | ||
pytest_assert( | ||
verify_checkpoints_exist(duthost, cp), | ||
"Failed to find the checkpoint file: {}".format(cp) | ||
) | ||
|
||
cmds = 'config delete-checkpoint {}'.format(cp) | ||
|
||
logger.info("Commands: {}".format(cmds)) | ||
output = duthost.shell(cmds, module_ignore_errors=True) | ||
|
||
pytest_assert( | ||
not output['rc'] and "Checkpoint deleted successfully" in output['stdout'], | ||
"Failed to delete a checkpoint file: {}".format(cp) | ||
) | ||
|
||
|
||
def expect_op_success(duthost, output): | ||
"""Expected success from apply-patch output | ||
""" | ||
pytest_assert(not output['rc'], "Command is not running successfully") | ||
pytest_assert( | ||
"Patch applied successfully" in output['stdout'], | ||
"Please check if json file is validate" | ||
) |
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