Skip to content

Commit ed0c43f

Browse files
matthew-soulsbynnelluri-cisco
authored andcommitted
[QOS - Test PFC Pause] Multi VLAN Support (sonic-net#16725)
What is the motivation for this PR? As new testbeds are being created with more VLANs, the assumption that a device should only contain 1 VLAN no longer holds. As such, certain helpers/parts of the framework need to be modified to allow for multiple VLANs to be present and tested. How did you do it? Added a get_all_vlans function to extract all vlans from the duthost object The functions which get information related to vlans (get_active_vlan_members and get_vlan_subnet) now take a vlan configuration dictionary (which itself is taken from the get_all_vlans function) pfc_test_setup now returns a list of VLAN configurations, instead of just one The run_test wrapper now runs the relevant test for each VLAN supplied Also removed gen_testbed_t0, which is not used anywhere (validated with grep) How did you verify/test it? Before this change, running the qos/test_pfc_pause.py on a testbed with multiple VLANs produced the following output: @pytest.fixture(scope="module", autouse=True) def pfc_test_setup(duthosts, rand_one_dut_hostname, tbinfo, ptfhost): """ Generate configurations for the tests Args: duthosts(AnsibleHost) : multi dut instance rand_one_dut_hostname(string) : one of the dut instances from the multi dut Yields: setup(dict): DUT interfaces, PTF interfaces, PTF IP addresses, and PTF MAC addresses """ """ Get all the active physical interfaces enslaved to the Vlan """ """ These interfaces are actually server-faced interfaces at T0 """ duthost = duthosts[rand_one_dut_hostname] > vlan_members, vlan_id = get_active_vlan_members(duthost) E TypeError: cannot unpack non-iterable NoneType object With these changes, it is now successfully running: image Any platform specific information? Any platform with only one VLAN - as each of the new lists/dicts will only contain one VLAN, iterating through them will cause the same behaviour as before.
1 parent 09494dc commit ed0c43f

File tree

2 files changed

+163
-179
lines changed

2 files changed

+163
-179
lines changed

tests/qos/qos_helpers.py

Lines changed: 20 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from .qos_fixtures import lossless_prio_dscp_map, leaf_fanouts # noqa F401
33
import re
44
import os
5-
import random
65

76
PFC_GEN_FILE = 'pfc_gen.py'
87
PFC_GEN_LOCAL_PATH = '../../ansible/roles/test/files/helpers/pfc_gen.py'
@@ -148,27 +147,32 @@ def stop_pause(host_ans, pkt_gen_path):
148147
host_ans.host.shell(cmd)
149148

150149

151-
def get_active_vlan_members(host_ans):
150+
def get_all_vlans(host_ans):
152151
"""
153-
@Summary: Get all the active physical interfaces enslaved to a Vlan
152+
@Summary: Get all vlans active on a DUT from the device's minigraph facts
154153
@param host_ans: Ansible host instance of the device
155-
@return: Return the list of active physical interfaces
154+
@return: Dictionary, mapping dictionaries representing each vlan's values to the vlan name
156155
"""
157156
mg_facts = host_ans.minigraph_facts(
158157
host=host_ans.hostname)['ansible_facts']
159158
mg_vlans = mg_facts['minigraph_vlans']
160159

161-
if len(mg_vlans) != 1:
162-
print('There should be only one Vlan at the DUT')
163-
return None
160+
return mg_vlans
161+
164162

163+
def get_active_vlan_members(host_ans, vlan):
164+
"""
165+
@Summary: Get all the active physical interfaces enslaved to a Vlan
166+
@param host_ans: Ansible host instance of the device
167+
@param vlan: Dictionary containing a single vlan's `name`, `members` and `vlanid`
168+
@return: Return the list of active physical interfaces
169+
"""
165170
""" Get all the Vlan memebrs """
166-
vlan_intf = list(mg_vlans.keys())[0]
167-
vlan_members = mg_vlans[vlan_intf]['members']
171+
vlan_members = vlan['members']
168172
vlan_id = None
169-
if 'type' in mg_vlans[vlan_intf] and mg_vlans[vlan_intf]['type'] is not None \
170-
and 'Tagged' in mg_vlans[vlan_intf]['type']:
171-
vlan_id = mg_vlans[vlan_intf]['vlanid']
173+
if 'type' in vlan and vlan['type'] is not None \
174+
and 'Tagged' in vlan['type']:
175+
vlan_id = vlan['vlanid']
172176

173177
""" Filter inactive Vlan members """
174178
active_intfs = get_active_intfs(host_ans)
@@ -177,56 +181,22 @@ def get_active_vlan_members(host_ans):
177181
return vlan_members, vlan_id
178182

179183

180-
def get_vlan_subnet(host_ans):
184+
def get_vlan_subnet(host_ans, vlan):
181185
"""
182186
@Summary: Get Vlan subnet of a T0 device
183187
@param host_ans: Ansible host instance of the device
188+
@param vlan: Dictionary containing a single vlan's `name`, `members` and `vlanid`
184189
@return: Return Vlan subnet, e.g., "192.168.1.1/24"
185190
"""
186191
mg_facts = host_ans.minigraph_facts(
187192
host=host_ans.hostname)['ansible_facts']
188-
mg_vlans = mg_facts['minigraph_vlans']
189-
190-
if len(mg_vlans) != 1:
191-
print('There should be only one Vlan at the DUT')
192-
return None
193193

194194
mg_vlan_intfs = mg_facts['minigraph_vlan_interfaces']
195-
vlan_subnet = ansible_stdout_to_str(mg_vlan_intfs[0]['subnet'])
195+
vlan_intf = [curr_intf for curr_intf in mg_vlan_intfs if curr_intf['attachto'] == vlan['name']][0]
196+
vlan_subnet = ansible_stdout_to_str(vlan_intf['subnet'])
196197
return vlan_subnet
197198

198199

199-
def gen_testbed_t0(duthost):
200-
"""
201-
@Summary: Generate a T0 testbed configuration
202-
@param duthost: The object for interacting with DUT through ansible
203-
@return: Return four values: DUT interfaces, PTF interfaces, PTF IP addresses, and PTF MAC addresses,
204-
"""
205-
206-
""" Get all the active physical interfaces enslaved to the Vlan """
207-
""" These interfaces are actually server-faced interfaces at T0 """
208-
vlan_members = get_active_vlan_members(duthost)
209-
210-
""" Get Vlan subnet """
211-
vlan_subnet = get_vlan_subnet(duthost)
212-
213-
""" Generate IP addresses for servers in the Vlan """
214-
vlan_ip_addrs = get_addrs_in_subnet(vlan_subnet, len(vlan_members))
215-
216-
""" Generate MAC addresses 00:00:00:00:00:XX for servers in the Vlan """
217-
vlan_mac_addrs = [5 * '00:' + format(k, '02x')
218-
for k in random.sample(list(range(1, 256)), len(vlan_members))]
219-
220-
""" Find correspoinding interfaces on PTF """
221-
phy_intfs = get_phy_intfs(duthost)
222-
phy_intfs.sort(key=natural_keys)
223-
vlan_members.sort(key=natural_keys)
224-
vlan_members_index = [phy_intfs.index(intf) for intf in vlan_members]
225-
ptf_intfs = ['eth' + str(i) for i in vlan_members_index]
226-
227-
return vlan_members, ptf_intfs, vlan_ip_addrs, vlan_mac_addrs
228-
229-
230200
def setup_testbed(fanouthosts, ptfhost, leaf_fanouts): # noqa F811
231201
"""
232202
@Summary: Set up the testbed

0 commit comments

Comments
 (0)