Skip to content

Commit

Permalink
[gcu][dhcp_relay] Fix dhcp_relay container is not running in gcu test (
Browse files Browse the repository at this point in the history
…#16460)

What is the motivation for this PR?
In gcu dhcp_relay test, it would add 2 vlans with 4 dhcp servers. Previously all 8 dhcp servers are added by cli separately, it would restart dhcp_relay container 8 times, which would cause dhcp_relay container is not running in gcu test in some low performance devices.

How did you do it?
Use sonic-db-cli to add dhcp servers, then manually resetart dhcp_relay container once.

How did you verify/test it?
Run tests
  • Loading branch information
yaqiangz authored and mssonicbld committed Jan 15, 2025
1 parent d6efd90 commit dd6cb4f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
16 changes: 16 additions & 0 deletions tests/common/dhcp_relay_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from tests.common.helpers.assertions import pytest_assert
from tests.common.utilities import wait_until


def restart_dhcp_service(duthost):
duthost.shell('systemctl reset-failed dhcp_relay')
duthost.shell('systemctl restart dhcp_relay')
duthost.shell('systemctl reset-failed dhcp_relay')

def _is_dhcp_relay_ready():
output = duthost.shell('docker exec dhcp_relay supervisorctl status | grep dhcp | awk \'{print $2}\'',
module_ignore_errors=True)
return (not output['rc'] and output['stderr'] == '' and len(output['stdout_lines']) != 0 and
all(element == 'RUNNING' for element in output['stdout_lines']))

pytest_assert(wait_until(120, 1, 10, _is_dhcp_relay_ready), "dhcp_relay is not ready after restarting")
10 changes: 5 additions & 5 deletions tests/generic_config_updater/test_dhcp_relay.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from tests.common.gu_utils import generate_tmpfile, delete_tmpfile
from tests.common.gu_utils import format_json_patch_for_multiasic
from tests.common.gu_utils import create_checkpoint, delete_checkpoint, rollback_or_reload, rollback
from tests.common.dhcp_relay_utils import restart_dhcp_service


pytestmark = [
pytest.mark.topology('t0', 'm0'),
Expand Down Expand Up @@ -108,16 +110,14 @@ def default_setup(duthost, vlan_intfs_list):
# Generate 4 dhcp servers for each new created vlan
for vlan in vlan_intfs_list:
expected_content_dict[vlan] = []
cmds.append('sonic-db-cli CONFIG_DB hset "VLAN|Vlan{}" "dhcp_servers@" "{}"'
.format(vlan, ",".join(["192.0.{}.{}".format(vlan, i) for i in range(1, 5)])))
for i in range(1, 5):
cmds.append('config vlan dhcp_relay add {} 192.0.{}.{}'.format(vlan, vlan, i))
expected_content_dict[vlan].append('192.0.{}.{}'.format(vlan, i))

duthost.shell_cmds(cmds=cmds)

pytest_assert(
duthost.is_service_fully_started('dhcp_relay'),
"dhcp_relay service is not running during setup"
)
restart_dhcp_service(duthost)

logger.info("default setup expected_content_dict {}".format(expected_content_dict))
for vlanid in expected_content_dict:
Expand Down

0 comments on commit dd6cb4f

Please sign in to comment.