Skip to content

Commit

Permalink
Fix for GCU Dhcp_Relay issue in KVM test failure (sonic-net#9800)
Browse files Browse the repository at this point in the history
Why I did it
This PR is created to resolve GCU DHCP_Relay issues in kvm test failure in Update submodule sonic-utilities to the latest HEAD

Summary: Fixed PR issues in fixture/duthost_utilites.py to solve vlan addition changes on Port

Signed-off-by: Rida Hanif rida.hanif@xflowresearch.com
  • Loading branch information
ridahanif96 authored Sep 8, 2023
1 parent 513c9ec commit 9432ac1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
30 changes: 28 additions & 2 deletions tests/common/fixtures/duthost_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,6 @@ def utils_vlan_ports_list(duthosts, rand_one_dut_hostname, rand_selected_dut, tb
vlan_port['permit_vlanid'].append(vlan['vlanid'])
if 'pvid' in vlan_port:
vlan_ports_list.append(vlan_port)

return vlan_ports_list


Expand Down Expand Up @@ -416,6 +415,7 @@ def utils_create_test_vlans(duthost, cfg_facts, vlan_ports_list, vlan_intfs_dict
delete_untagged_vlan: check to delete unttaged vlan
'''
cmds = []
port_mode_added = {} # Keep track of whether switchport mode has been added for each port
logger.info("Add vlans, assign IPs")
for k, v in list(vlan_intfs_dict.items()):
if v['orig']:
Expand All @@ -435,12 +435,15 @@ def utils_create_test_vlans(duthost, cfg_facts, vlan_ports_list, vlan_intfs_dict
cmds.append("config vlan member del {} {}".format(vid, vlan_port['dev']))
except KeyError:
continue

logger.info("Add members to Vlans")
for vlan_port in vlan_ports_list:
for permit_vlanid in vlan_port['permit_vlanid']:
if vlan_intfs_dict[int(permit_vlanid)]['orig']:
continue
if vlan_port['dev'] not in port_mode_added:
switchport_mode_set(duthost, vlan_port['dev'])
logger.info("trunk mode added")
port_mode_added[vlan_port['dev']] = True
cmds.append('config vlan member add {tagged} {id} {port}'.format(
tagged=('--untagged' if vlan_port['pvid'] == permit_vlanid else ''),
id=permit_vlanid,
Expand All @@ -450,6 +453,29 @@ def utils_create_test_vlans(duthost, cfg_facts, vlan_ports_list, vlan_intfs_dict
duthost.shell_cmds(cmds=cmds)


def switchport_mode_set(duthost, port):

mode_json = "/tmp/mode_set.json"

mode_set = '''
cat << EOF > %s
{
"PORT": {
"{port}": {
"mode": "trunk"
}
}
}
EOF
''' % (mode_json)

duthost.shell(mode_set)
duthost.command("sudo config load {} -y".format(mode_json))
yield
duthost.command("rm {}".format(mode_json))
logger.info("Json dump-file added in to the DUT")


def _dut_qos_map(dut):
"""
A helper function to get QoS map from DUT host.
Expand Down
1 change: 0 additions & 1 deletion tests/generic_config_updater/test_dhcp_relay.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ 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 = [{
'dev': first_avai_vlan_port,
Expand Down

0 comments on commit 9432ac1

Please sign in to comment.