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
46 changes: 32 additions & 14 deletions ansible/library/conn_graph_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,29 +233,49 @@ def main():
module = AnsibleModule(
argument_spec=dict(
host=dict(required=False),
hosts=dict(required=False, type='list'),
filename=dict(required=False),
),
mutually_exclusive=[['host', 'hosts']],
supports_check_mode=True
)
m_args = module.params
hostname = m_args['host']

hostnames = m_args['hosts']
if not hostnames:
hostnames = [m_args['host']]
try:
if m_args['filename']:
filename = m_args['filename']
else:
filename = LAB_GRAPHFILE_PATH + LAB_CONNECTION_GRAPH_FILE
lab_graph = Parse_Lab_Graph(filename)
lab_graph.parse_graph()
dev = lab_graph.get_host_device_info(hostname)
if dev is None:
module.fail_json(msg="cannot find info for "+hostname)
results = {}
results['device_info'] = lab_graph.get_host_device_info(hostname)
results['device_conn'] = lab_graph.get_host_connections(hostname)
if lab_graph.get_host_vlan(hostname):
results['device_vlan_range'] = lab_graph.get_host_vlan(hostname)['VlanRange']
results['device_vlan_list'] = lab_graph.get_host_vlan(hostname)['VlanList']
results['device_port_vlans'] = lab_graph.get_host_port_vlans(hostname)

device_info = []
device_conn = []
device_port_vlans = []
device_vlan_range = []
device_vlan_list = []
for hostname in hostnames:
dev = lab_graph.get_host_device_info(hostname)
if dev is None:
module.fail_json(msg="cannot find info for %s" % hostname)
device_info.append(dev)
device_conn.append(lab_graph.get_host_connections(hostname))
host_vlan = lab_graph.get_host_vlan(hostname)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonder how the vlan used to connect DUTs are configured. If DUT1 has port 0 connected to DUT2 port 0, then both should have the same vlan id. Also, vlans in trunk interfaces all the way up to the server will need to be updated.

Copy link
Copy Markdown
Collaborator Author

@lolyu lolyu Jul 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ports between DUTs are direct connections, this patch aims to connect PTF containers through fanout switches. The VLAN trunk interfaces connecting to the server is configured in playbook fanout_connect.yml.

# for multi-DUTs, must ensure all have vlan configured.
if host_vlan:
device_vlan_range.append(host_vlan["VlanRange"])
device_vlan_list.append(host_vlan["VlanList"])
device_port_vlans.append(lab_graph.get_host_port_vlans(hostname))
results = {k: v for k, v in locals().items()
if (k.startswith("device_") and v)}

# flatten the lists for single host
if m_args['hosts'] is None:
results = {k: v[0] for k, v in results.items()}

module.exit_json(ansible_facts=results)
except (IOError, OSError):
module.fail_json(msg="Can not find lab graph file "+LAB_CONNECTION_GRAPH_FILE)
Expand All @@ -264,7 +284,5 @@ def main():


from ansible.module_utils.basic import *
if __name__== "__main__":
if __name__ == "__main__":
main()


10 changes: 9 additions & 1 deletion ansible/roles/fanout/tasks/rootfanout_connect.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
delegate_to: localhost
tags: always
register: devinfo
when: dut.split(',')|length == 1

- name: Gathering connection facts about the DUTs or leaffanout device
conn_graph_facts: hosts={{ dut.split(',') }}
delegate_to: localhost
tags: always
register: devinfo
when: dut.split(',')|length > 1

- name: Gathering connection facts about the lab
conn_graph_facts:
Expand All @@ -20,7 +28,7 @@
register: lab

- set_fact:
dev_vlans: "{{ devinfo.ansible_facts.device_vlan_range }}"
dev_vlans: "{{ devinfo.ansible_facts.device_vlan_range|flatten(levels=1) }}"
lab_devices: "{{ lab.ansible_facts.device_info }}"

- name: Find the root fanout switch
Expand Down
25 changes: 20 additions & 5 deletions ansible/roles/vm_set/library/vlan_port.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/python

import itertools
import re
import sys
import time
Expand Down Expand Up @@ -121,29 +122,43 @@ def main():

module = AnsibleModule(argument_spec=dict(
cmd=dict(required=True, choices=['create', 'remove', 'list']),
external_port = dict(required=True, type='str'),
external_port=dict(required=True, type='str'),
vlan_ids=dict(required=True, type='list'),
is_multi_duts=dict(required=False, type='bool', default=False),
))

cmd = module.params['cmd']
external_port = module.params['external_port']
vlan_ids = module.params['vlan_ids']
vlan_ids.sort()
is_multi_duts = module.params['is_multi_duts']

_vlan_ids = vlan_ids
if is_multi_duts:
# flatten the list in the case of multi-DUTs
_vlan_ids = list(itertools.chain.from_iterable(_vlan_ids))
_vlan_ids.sort()

fp_ports = []

vp = VlanPort(external_port, vlan_ids)
vp = VlanPort(external_port, _vlan_ids)

vp.up_external_port()
if cmd == "create":
vp.create_vlan_ports()
elif cmd == "remove":
vp.remove_vlan_ports()

for vlan_id in vlan_ids:
fp_ports.append("%s.%d" % (external_port, vlan_id))
fp_port_templ = external_port + ".%s"
if is_multi_duts:
fp_ports = []
for dut_vlans in vlan_ids:
dut_vlans.sort()
fp_ports.append([fp_port_templ % vid for vid in dut_vlans])
else:
fp_ports = [fp_port_templ % vid for vid in vlan_ids]

module.exit_json(changed=False, ansible_facts={'dut_fp_ports': fp_ports})


if __name__ == "__main__":
main()
Loading