-
Notifications
You must be signed in to change notification settings - Fork 1k
[Minigraph-Gen]create minigraph based on testbed_vm_topology #491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4d84b16
[minigraph-gen]unified generate minigraph from testbed topology defin…
maggiemsft 663b768
split minigraph template into sections; remove turned off interfaces …
maggiemsft ba11bd1
add missed test_fact file
maggiemsft ff1b103
add t0 topo file that with disabled host interfaces
maggiemsft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| # This Playbook run time generate matching configuration file for SONiC switch(Minigraph) based on a specific testbed topology specified in testbed.csv | ||
| # When user call testbed-cli to deploy a testbed topology, use this playbook to generate matching SONiC minigraph file and deploy it into SONiC switch under test. | ||
| # Or when you know your topology name, you may use this playbook alone to generate a minigraph matching your topology name without deploy it. | ||
| # | ||
| # VM Topologies are defined inside of vars/ directory in files vars/topo_{{ topology_name}}.yml | ||
| # Every topology should have a name to distinct one topology from another on the server | ||
| # Every topology contains a ptf container which will be used as placeholder for the injected interfaces from VMs, or direct connections to PTF host | ||
| # VMs inventory file is also required to have all VMs ready for generating the minigraph file | ||
| # VMs inventory is in file 'veos' | ||
| # | ||
| # Template files for generating minigraph.xml are defined in template/topo directory | ||
| # | ||
| # To generate and deploy minigraph for SONiC switch matching the VM topology please use following command | ||
| # ansible-playbook -i lab config_sonic_basedon_testbed_v2.yml -l sonic_dut_name -e vm_base=VM0300 -e topo=t0 [-e deploy=true -e save=true] | ||
| # ansible-playbook -i lab config_sonic_basedon_testbed_v2.yml -l sonic_dut_name -e testbed_name=vms1-1 [-e deploy=true -e save=true] | ||
| # | ||
| # Parameters | ||
| # -l str-msn2700-01 - the sonic_dut_name you are going to generate minigraph for | ||
| # -e vm_base=VM0300 - the VM name which is used to as base to calculate VM name for this set | ||
| # -e topo=t0 - the name of topology to generate minigraph file | ||
| # -e testbed_name=vms1-1 - the testbed name specified in testbed.csv file | ||
| # (if you give 'testbed_name' option, will use info from testbed and ignore topo and vm_base options) | ||
| # -e deploy=True - if deploy the newly generated minigraph to the targent DUT, default is false if not defined | ||
| # -e save=True - if save the newly generated minigraph to the targent DUT as starup-config, default is false if not defined | ||
| # | ||
| # After minigraph.xml is generated, the playbook will replace the original minigraph file under ansible/minigraph/ with the newly generated minigraph file for the SONiC device. | ||
| # The playbook will based on deploy=True or False to deside if load the SONiC device with new minigraph or not. | ||
| # If deploy=true, the playbook will apply the newly generated minigraph to the SONiC switch | ||
| # If save=true, the playbook will save the newly generated minigraph to SONiC switch as startup-config | ||
| # | ||
| #################################################################################################################################################################################### | ||
|
|
||
| - hosts: sonic | ||
| gather_facts: yes | ||
| tasks: | ||
|
|
||
| - block: | ||
| - name: Gathering testbed information | ||
| test_facts: testbed_name="{{ testbed_name }}" | ||
| connection: local | ||
|
|
||
| - fail: msg="The DUT you are trying to run test does not belongs to this testbed" | ||
| when: testbed_facts['dut'] != inventory_hostname | ||
|
|
||
| - name: set testbed_type | ||
| set_fact: | ||
| topo: "{{ testbed_facts['topo'] }}" | ||
|
|
||
| - name: set vm | ||
| set_fact: | ||
| vm_base: "{{ testbed_facts['vm_base'] }}" | ||
| when: "testbed_facts['vm_base'] != ''" | ||
| when: testbed_name is defined | ||
|
|
||
| - set_fact: | ||
| VM_topo: "{% if 'ptf' in topo %}False{% else %}True{% endif %}" | ||
| remote_dut: "{{ ansible_ssh_host }}" | ||
|
|
||
| - name: gather testbed VM informations | ||
| testbed_vm_info: base_vm={{ testbed_facts['vm_base'] }} topo={{ testbed_facts['topo'] }} | ||
| connection: local | ||
| when: "VM_topo | bool" | ||
|
|
||
| - name: find interface name mapping and indivisual interface speed if defined | ||
| port_alias: hwsku="{{ hwsku }}" | ||
| connection: local | ||
|
|
||
| - name: find all enalbed host_interfaces | ||
| set_fact: | ||
| host_if_indexes: "{{ vm_topo_config['host_interfaces'] | difference(vm_topo_config['off_host_interfaces']) }}" | ||
|
|
||
| - name: find all vlan interface names for T0 topology | ||
| set_fact: | ||
| vlan_intfs: "{{ vlan_intfs|default([])}} + ['{{ port_alias[item] }}' ]" | ||
| with_items: "{{ host_if_indexes }}" | ||
| when: ("'host_interfaces' in vm_topo_config") and ("'tor' in vm_topo_config['dut_type'] | lower") | ||
|
|
||
| - name: find all interface indexes connecting to VM | ||
| set_fact: | ||
| interface_to_vms: "{{ interface_to_vms|default({}) | combine({ item.key: item.value['interface_indexes'] }) }}" | ||
| with_dict: vm_topo_config['vm'] | ||
|
|
||
| - name: find all interface names | ||
| set_fact: | ||
| intf_names: "{{ intf_names | default({}) | combine({item.key: port_alias[item.value[0]|int:item.value[-1]|int+1] }) }}" | ||
| with_dict: interface_to_vms | ||
|
|
||
| - name: save original minigraph file of ansible (ignore errors when file doesnot exist) | ||
| shell: mv minigraph/{{ inventory_hostname }}.xml minigraph/{{ inventory_hostname }}.xml.orig | ||
| connection: local | ||
| ignore_errors: true | ||
|
|
||
| - name: create minigraph file in ansible minigraph folder | ||
| become: true | ||
| template: src=templates/minigraph_template.j2 | ||
| dest=minigraph/{{ inventory_hostname}}.xml | ||
| connection: local | ||
|
|
||
| - block: | ||
| - name: saved original minigraph file in SONiC DUT(ignore errors when file doesnot exist) | ||
| shell: mv /etc/sonic/minigraph.xml /etc/sonic/minigraph.xml.orig | ||
| become: true | ||
| ignore_errors: true | ||
|
|
||
| - name: create new minigraph file for SONiC device | ||
| template: src=templates/alltopo.j2 | ||
| dest=/etc/sonic/minigraph.xml | ||
| become: true | ||
|
|
||
| - name: disable automatic minigraph update if we are deploying new minigraph into SONiC | ||
| lineinfile: | ||
| name: /etc/sonic/updategraph.conf | ||
| regexp: '^enabled=' | ||
| line: 'enabled=false' | ||
| become: true | ||
|
|
||
| - name: execute cli "config load_minigraph -y" to apply new minigraph | ||
| become: true | ||
| shell: config load_minigraph -y | ||
|
|
||
| - name: execute cli "config bgp startup all" to bring up all bgp sessions for test | ||
| become: true | ||
| shell: config bgp startup all | ||
|
|
||
| - name: execute cli "config save -y" to save current minigraph as startup-config | ||
| become: true | ||
| shell: config save -y | ||
| when: save is defined and save|bool == true | ||
| when: deploy is defined and deploy|bool == true | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| <CpgDec> | ||
| <IsisRouters xmlns:a="http://schemas.datacontract.org/2004/07/Microsoft.Search.Autopilot.Evolution"/> | ||
| <PeeringSessions> | ||
| {% for index in range(vms_number) %} | ||
| {% set vm=vms[index] %} | ||
| {% if vm_topo_config['vm'][vm]['peer_ipv4'] %} | ||
| <BGPSession> | ||
| <MacSec>false</MacSec> | ||
| <StartRouter>{{ inventory_hostname }}</StartRouter> | ||
| <StartPeer>{{ vm_topo_config['vm'][vm]['bgp_ipv4'] }}</StartPeer> | ||
| <EndRouter>{{ vm }}</EndRouter> | ||
| <EndPeer>{{ vm_topo_config['vm'][vm]['peer_ipv4'] }}</EndPeer> | ||
| <Multihop>1</Multihop> | ||
| <HoldTime>10</HoldTime> | ||
| <KeepAliveTime>3</KeepAliveTime> | ||
| </BGPSession> | ||
| {% endif %} | ||
| {% if vm_topo_config['vm'][vm]['peer_ipv6'] %} | ||
| <BGPSession> | ||
| <StartRouter>{{ inventory_hostname }}</StartRouter> | ||
| <StartPeer>{{ vm_topo_config['vm'][vm]['bgp_ipv6'] }}</StartPeer> | ||
| <EndRouter>{{ vm }}</EndRouter> | ||
| <EndPeer>{{ vm_topo_config['vm'][vm]['peer_ipv6'] }}</EndPeer> | ||
| <Multihop>1</Multihop> | ||
| <HoldTime>10</HoldTime> | ||
| <KeepAliveTime>3</KeepAliveTime> | ||
| </BGPSession> | ||
| {% endif %} | ||
| {% endfor %} | ||
| </PeeringSessions> | ||
| <Routers xmlns:a="http://schemas.datacontract.org/2004/07/Microsoft.Search.Autopilot.Evolution"> | ||
| <a:BGPRouterDeclaration> | ||
| <a:ASN>{{ vm_topo_config['dut_asn'] }}</a:ASN> | ||
| <a:Hostname>{{ inventory_hostname }}</a:Hostname> | ||
| <a:Peers> | ||
| {% for index in range(vms_number) %} | ||
| <BGPPeer> | ||
| <Address>{{ vm_topo_config['vm'][vms[index]]['peer_ipv4'] }}</Address> | ||
| <RouteMapIn i:nil="true"/> | ||
| <RouteMapOut i:nil="true"/> | ||
| <Vrf i:nil="true"/> | ||
| </BGPPeer> | ||
| {% endfor %} | ||
| {% if 'tor' in vm_topo_config['dut_type'] | lower %} | ||
| <BGPPeer i:type="a:BGPPeerPassive"> | ||
| <ElementType>BGPPeer</ElementType> | ||
| <Address>10.1.0.32</Address> | ||
| <RouteMapIn i:nil="true"/> | ||
| <RouteMapOut i:nil="true"/> | ||
| <Vrf i:nil="true"/> | ||
| <a:Name>BGPSLBPassive</a:Name> | ||
| <a:PeersRange>10.255.0.0/25</a:PeersRange> | ||
| </BGPPeer> | ||
| <BGPPeer i:type="a:BGPPeerPassive"> | ||
| <ElementType>BGPPeer</ElementType> | ||
| <Address>10.1.0.32</Address> | ||
| <RouteMapIn i:nil="true"/> | ||
| <RouteMapOut i:nil="true"/> | ||
| <Vrf i:nil="true"/> | ||
| <a:Name>BGPVac</a:Name> | ||
| <a:PeersRange>192.168.0.0/25</a:PeersRange> | ||
| </BGPPeer> | ||
| {% endif %} | ||
| </a:Peers> | ||
| <a:RouteMaps/> | ||
| </a:BGPRouterDeclaration> | ||
| {% for index in range( vms_number) %} | ||
| <a:BGPRouterDeclaration> | ||
| <a:ASN>{{ vm_topo_config['vm'][vms[index]]['bgp_asn'] }}</a:ASN> | ||
| <a:Hostname>{{ vms[index] }}</a:Hostname> | ||
| <a:RouteMaps/> | ||
| </a:BGPRouterDeclaration> | ||
| {% endfor %} | ||
| </Routers> | ||
| </CpgDec> | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be connection: local
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed