Skip to content
Merged
Show file tree
Hide file tree
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
24 changes: 14 additions & 10 deletions tests/common/fixtures/duthost_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,7 @@ def ports_list(duthosts, rand_one_dut_hostname, rand_selected_dut, tbinfo):
duthost = duthosts[rand_one_dut_hostname]
cfg_facts = duthost.config_facts(host=duthost.hostname, source="persistent")['ansible_facts']
mg_facts = rand_selected_dut.get_extended_minigraph_facts(tbinfo)
config_ports = {
k: {**v, 'mode': 'trunk'}
for k, v in list(cfg_facts['PORT'].items())
if v.get('admin_status', 'down') == 'up'
}
config_ports = {k: v for k, v in list(cfg_facts['PORT'].items()) if v.get('admin_status', 'down') == 'up'}
config_port_indices = {k: v for k, v in list(mg_facts['minigraph_ptf_indices'].items()) if k in config_ports}
ptf_ports_available_in_topo = {
port_index: 'eth{}'.format(port_index) for port_index in list(config_port_indices.values())
Expand Down Expand Up @@ -269,11 +265,7 @@ def utils_vlan_ports_list(duthosts, rand_one_dut_hostname, rand_selected_dut, tb
cfg_facts = duthost.config_facts(host=duthost.hostname, source="persistent")['ansible_facts']
mg_facts = rand_selected_dut.get_extended_minigraph_facts(tbinfo)
vlan_ports_list = []
config_ports = {
k: {**v, 'mode': 'trunk'}
for k, v in list(cfg_facts['PORT'].items())
if v.get('admin_status', 'down') == 'up'
}
config_ports = {k: v for k, v in list(cfg_facts['PORT'].items()) if v.get('admin_status', 'down') == 'up'}
config_portchannels = cfg_facts.get('PORTCHANNEL_MEMBER', {})
config_port_indices = {k: v for k, v in list(mg_facts['minigraph_ptf_indices'].items()) if k in config_ports}
config_ports_vlan = collections.defaultdict(list)
Expand Down Expand Up @@ -447,6 +439,9 @@ def utils_create_test_vlans(duthost, cfg_facts, vlan_ports_list, vlan_intfs_dict
for permit_vlanid in vlan_port['permit_vlanid']:
if vlan_intfs_dict[int(permit_vlanid)]['orig']:
continue

if (check_switchport_cmd(duthost, vlan_port['dev']) is True):
cmds.append('config switchport mode trunk {port}'.format(port=vlan_port['dev']))
cmds.append('config vlan member add {tagged} {id} {port}'.format(
tagged=('--untagged' if vlan_port['pvid'] == permit_vlanid else ''),
id=permit_vlanid,
Expand All @@ -456,6 +451,15 @@ def utils_create_test_vlans(duthost, cfg_facts, vlan_ports_list, vlan_intfs_dict
duthost.shell_cmds(cmds=cmds)


def check_switchport_cmd(duthost, tport):
cmds = 'config switchport mode trunk {port}'.format(port=tport)
logger.info("Commands: {}".format(cmds))
output = duthost.shell(cmds, module_ignore_errors=True)
if (output['rc'] == 0):
return True
return False


def _dut_qos_map(dut):
"""
A helper function to get QoS map from DUT host.
Expand Down
8 changes: 3 additions & 5 deletions tests/generic_config_updater/test_dhcp_relay.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from tests.generic_config_updater.gu_utils import apply_patch, expect_op_success, expect_res_success, expect_op_failure
from tests.generic_config_updater.gu_utils import generate_tmpfile, delete_tmpfile
from tests.generic_config_updater.gu_utils import create_checkpoint, delete_checkpoint, rollback_or_reload, rollback

pytestmark = [
pytest.mark.topology('t0', 'm0'),
]
Expand Down Expand Up @@ -43,10 +42,7 @@ def first_avai_vlan_port(rand_selected_dut, tbinfo):
for v in list(mg_facts['minigraph_vlans'].values()):
for p in v['members']:
if p.startswith("Ethernet"):
if 'mode' not in mg_facts['minigraph_ports'][p]:
logger.info("trunk mode in Port added")
mg_facts['minigraph_ports'][p]['mode'] = 'trunk'
return p
return p

logger.error("No vlan port member ready for test")
pytest_assert(False, "No vlan port member ready for test")
Expand Down Expand Up @@ -156,13 +152,15 @@ def setup_vlan(duthosts, rand_one_dut_hostname, vlan_intfs_dict, first_avai_vlan

dhcp_relay_info_before_test = get_dhcp_relay_info_from_all_vlans(duthost)
create_checkpoint(duthost, SETUP_ENV_CP)

# --------------------- Testing -----------------------
yield

# --------------------- Teardown -----------------------
# Rollback twice. First rollback to checkpoint just before 'yield'
# Second rollback is to back to original setup
try:
# load first
output = rollback(duthost, SETUP_ENV_CP)
pytest_assert(
not output['rc'] and "Config rolled back successfull" in output['stdout'],
Expand Down