Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 43 additions & 28 deletions tests/generic_config_updater/test_eth_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import pytest
import re
import random

from tests.common.helpers.assertions import pytest_assert
from tests.generic_config_updater.gu_utils import apply_patch, expect_op_success, expect_op_failure
Expand All @@ -10,7 +11,6 @@

logger = logging.getLogger(__name__)


@pytest.fixture(autouse=True)
def ensure_dut_readiness(duthost):
"""
Expand Down Expand Up @@ -75,6 +75,24 @@ def get_ethernet_port_not_in_portchannel(duthost):
break
return port_name

def get_port_speeds_for_test(duthost):
"""
Get the speeds parameters for case test_update_speed, including 2 valid speeds and 1 invalid speed

Args:
duthost: DUT host object
"""
speeds_to_test = []
invalid_speed = ("20a", False)
if duthost.get_facts()['asic_type'] == 'vs':
valid_speeds = ['20000', '40000']
else:
valid_speeds = duthost.get_supported_speeds('Ethernet0')
pytest_assert(valid_speeds, "Failed to get any valid port speed to test.")
valid_speeds_to_test = random.sample(valid_speeds, 2 if len(valid_speeds) >= 2 else len(valid_speeds))
speeds_to_test = [(speed, True) for speed in valid_speeds_to_test]
speeds_to_test.append(invalid_speed)
return speeds_to_test

def test_remove_lanes(duthost, ensure_dut_readiness):
json_patch = [
Expand Down Expand Up @@ -214,33 +232,30 @@ def test_update_valid_invalid_index(duthost, ensure_dut_readiness, index, is_val
delete_tmpfile(duthost, tmpfile)


@pytest.mark.parametrize("speed, is_valid", [
("20000", True),
("40000", True),
("20a", False)
])
def test_update_speed(duthost, ensure_dut_readiness, speed, is_valid):
json_patch = [
{
"op": "replace",
"path": "/PORT/Ethernet0/speed",
"value": "{}".format(speed)
}
]

tmpfile = generate_tmpfile(duthost)
logger.info("tmpfile {}".format(tmpfile))

try:
output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)
if is_valid:
expect_op_success(duthost, output)
current_status_speed = check_interface_status(duthost, "Speed").replace("G", "000")
pytest_assert(current_status_speed == speed, "Failed to properly configure interface speed to requested value {}".format(speed))
else:
expect_op_failure(output)
finally:
delete_tmpfile(duthost, tmpfile)
def test_update_speed(duthost, ensure_dut_readiness):
speed_params = get_port_speeds_for_test(duthost)
for speed, is_valid in speed_params:
json_patch = [
{
"op": "replace",
"path": "/PORT/Ethernet0/speed",
"value": "{}".format(speed)
}
]

tmpfile = generate_tmpfile(duthost)
logger.info("tmpfile {}".format(tmpfile))

try:
output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)
if is_valid:
expect_op_success(duthost, output)
current_status_speed = check_interface_status(duthost, "Speed").replace("G", "000")
pytest_assert(current_status_speed == speed, "Failed to properly configure interface speed to requested value {}".format(speed))
else:
expect_op_failure(output)
finally:
delete_tmpfile(duthost, tmpfile)


def test_update_description(duthost, ensure_dut_readiness):
Expand Down