Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
10 changes: 10 additions & 0 deletions tests/generic_config_updater/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,13 @@ def check_image_version(duthost):
"""
skip_version(duthost, ["201811", "201911", "202012"])

@pytest.fixture(scope="module")
def cfg_facts(duthosts, rand_one_dut_hostname):
"""
Config facts for selected DUT
Args:
duthosts: list of DUTs.
rand_selected_dut: The fixture returns a randomly selected DuT.
"""
duthost = duthosts[rand_one_dut_hostname]
return duthost.config_facts(host=duthost.hostname, source="persistent")['ansible_facts']
39 changes: 22 additions & 17 deletions tests/generic_config_updater/gu_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

logger = logging.getLogger(__name__)

CONTAINER_SERVICES_LIST = ["swss", "syncd", "radv", "lldp", "dhcp_relay", "teamd", "bgp", "pmon", "telemetry", "acms"]

def generate_tmpfile(duthost):
return duthost.shell('mktemp')['stdout']

Expand All @@ -29,12 +31,12 @@ def expect_op_success(duthost, output):
"Please check if json file is validate"
)

def expect_op_success_and_reset_check(duthost, output, container_name, threshold, interval, delay):
'''Add contianer reset check after op success
'''
def expect_op_success_and_reset_check(duthost, output, service_name, timeout, interval, delay):
"""Add contianer reset check after op success
"""
expect_op_success(duthost, output)
if start_limit_hit(duthost, container_name):
reset_start_limit_hit(duthost, container_name, threshold, interval, delay)
if start_limit_hit(duthost, service_name):
reset_start_limit_hit(duthost, service_name, timeout, interval, delay)

def expect_res_success(duthost, output, expected_content_list, unexpected_content_list):
for expected_content in expected_content_list:
Expand All @@ -56,13 +58,13 @@ def expect_op_failure(output):
"The command should fail with non zero return code"
)

def start_limit_hit(duthost, container_name):
def start_limit_hit(duthost, service_name):
"""If start-limit-hit is hit, the service will not start anyway.
"""
service_status = duthost.shell("sudo systemctl status {}.service | grep 'Active'".format(container_name))
service_status = duthost.shell("sudo systemctl status {}.service | grep 'Active'".format(service_name))
pytest_assert(
not service_status['rc'],
"{} service status cannot be found".format(container_name)
"{} service status cannot be found".format(service_name)
)

for line in service_status["stdout_lines"]:
Expand All @@ -71,29 +73,32 @@ def start_limit_hit(duthost, container_name):

return False

def reset_start_limit_hit(duthost, container_name, threshold, interval, delay):
"""Reset container if hit start-limit-hit
def reset_start_limit_hit(duthost, service_name, timeout, interval, delay):
"""Reset service if hit start-limit-hit
"""
logger.info("Reset container '{}' due to start-limit-hit".format(container_name))
logger.info("Reset service '{}' due to start-limit-hit".format(service_name))

service_reset_failed = duthost.shell("sudo systemctl reset-failed {}.service".format(container_name))
service_reset_failed = duthost.shell("sudo systemctl reset-failed {}.service".format(service_name))
pytest_assert(
not service_reset_failed['rc'],
"{} systemctl reset-failed service fails"
)

service_start = duthost.shell("sudo systemctl start {}.service".format(container_name))
service_start = duthost.shell("sudo systemctl start {}.service".format(service_name))
pytest_assert(
not service_start['rc'],
"{} systemctl start service fails"
)

reset_container = wait_until(threshold,
if not service_name in CONTAINER_SERVICES_LIST:
return

reset_service = wait_until(timeout,
interval,
delay,
duthost.is_service_fully_started,
container_name)
service_name)
pytest_assert(
reset_container,
"Failed to reset container '{}' due to start-limit-hit".format(container_name)
reset_service,
"Failed to reset service '{}' due to start-limit-hit".format(service_name)
)
29 changes: 12 additions & 17 deletions tests/generic_config_updater/test_dhcp_relay.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,13 @@
DHCP_RELAY_THRESHOLD=120
DHCP_RELAY_INTERVAL=10

@pytest.fixture(scope="module")
def cfg_facts(duthosts, rand_one_dut_hostname):
duthost = duthosts[rand_one_dut_hostname]
return duthost.config_facts(host=duthost.hostname, source="persistent")['ansible_facts']

@pytest.fixture(scope="module")
def vlan_intfs_dict(utils_vlan_intfs_dict_orig):
''' Add two new vlan for test
""" Add two new vlan for test

If added vlan_id is 108 and 109, it will add a dict as below
{108: {'ip': u'192.168.8.1/24', 'orig': False}, 109: {'ip': u'192.168.9.1/24', 'orig': False}}
'''
"""
logger.info("vlan_intrfs_dict ORIG {}".format(utils_vlan_intfs_dict_orig))
vlan_intfs_dict = utils_vlan_intfs_dict_add(utils_vlan_intfs_dict_orig, 2)
logger.info("vlan_intrfs_dict FINAL {}".format(vlan_intfs_dict))
Expand Down Expand Up @@ -56,7 +51,7 @@ def ensure_dhcp_relay_running(duthost):
)

def create_test_vlans(duthost, cfg_facts, vlan_intfs_dict, first_avai_vlan_port):
'''Generate two vlan config for testing
"""Generate two vlan config for testing

This function should generate two VLAN detail shown below
+-----------+------------------+-----------+----------------+-------------+-----------------------+
Expand All @@ -66,7 +61,7 @@ def create_test_vlans(duthost, cfg_facts, vlan_intfs_dict, first_avai_vlan_port)
+-----------+------------------+-----------+----------------+-------------+-----------------------+
| 109 | 192.168.9.1/24 | Ethernet4 | tagged | disabled | |
+-----------+------------------+-----------+----------------+-------------+-----------------------+
'''
"""

logger.info("CREATE TEST VLANS START")
vlan_ports_list = [{
Expand All @@ -83,7 +78,7 @@ def clean_setup():
pass

def default_setup(duthost, vlan_intfs_list):
'''Generate 4 dhcp server for each vlan
"""Generate 4 dhcp server for each vlan

This VLAN detail shows below
+-----------+------------------+-----------+----------------+-------------+-----------------------+
Expand All @@ -99,7 +94,7 @@ def default_setup(duthost, vlan_intfs_list):
| | | | | | 192.0.109.3 |
| | | | | | 192.0.109.4 |
+-----------+------------------+-----------+----------------+-------------+-----------------------+
'''
"""
cmds = []
expected_content_dict = {}
logger.info("default_setup is initiated")
Expand Down Expand Up @@ -151,8 +146,8 @@ def setup_vlan(duthosts, rand_one_dut_hostname, vlan_intfs_dict, first_avai_vlan
tearDown(duthost, vlan_intfs_dict, first_avai_vlan_port)

def tearDown(duthost, vlan_intfs_dict, first_avai_vlan_port):
'''Clean up VLAN CONFIG for this test
'''
"""Clean up VLAN CONFIG for this test
"""
logger.info("VLAN test ending ...")
config_reload(duthost)

Expand All @@ -161,14 +156,14 @@ def vlan_intfs_list(vlan_intfs_dict):
return [ key for key, value in vlan_intfs_dict.items() if not value['orig'] ]

def ensure_dhcp_server_up(duthost):
'''Wait till dhcp-relay server is setup
"""Wait till dhcp-relay server is setup

Sample output
admin@vlab-01:~$ docker exec dhcp_relay supervisorctl status | grep ^dhcp-relay
dhcp-relay:isc-dhcpv4-relay-Vlan100 RUNNING pid 72, uptime 0:00:09
dhcp-relay:isc-dhcpv4-relay-Vlan1000 RUNNING pid 73, uptime 0:00:09

'''
"""
def _dhcp_server_up():
cmds = 'docker exec dhcp_relay supervisorctl status | grep ^dhcp-relay'
output = duthost.shell(cmds)
Expand All @@ -185,13 +180,13 @@ def _dhcp_server_up():
)

def dhcp_severs_by_vlanid(duthost, vlanid):
'''Get pid and then only output the related dhcp server info for that pid
"""Get pid and then only output the related dhcp server info for that pid

Sample output
admin@vlab-01:~$ docker exec dhcp_relay ps -fp 73
UID PID PPID C STIME TTY TIME CMD
root 73 1 0 06:39 pts/0 00:00:00 /usr/sbin/dhcrelay -d -m discard -a %h:%p %P --name-alias-map-file /tmp/port-name-alias-map.txt -id Vlan1000 -iu Vlan100 -iu PortChannel0001 -iu PortChannel0002 -iu PortChannel0003 -iu PortChannel0004 192.0.0.1 192.0.0.2 192.0.0.3 192.0.0.4
'''
"""
cmds = "docker exec dhcp_relay supervisorctl status | grep ^dhcp-relay \
| grep 'Vlan{} ' | awk '{{print $4}}'".format(vlanid)
output = duthost.shell(cmds)
Expand Down
Loading