def test_7_from_list_and_update_and_dups(): ########################################### # Test graph load from list and # edge update method and node_duplicates update # behavior ########################################### with open("./yed.test_7_from_list_and_update_and_dups.graphml", "r") as f: expected_output = f.read() yed_diagram = create_yed_diagram() sample_list_graph = [ {'source': 'a', 'src_label': 'Gig0/0\nUP', 'label': 'DF', 'target': 'b', 'trgt_label': 'Gig0/1', 'description': 'vlans_trunked: 1,2,3\nstate: up'}, {'source': {'id':'b'}, 'src_label': 'Gig0/0', 'label': 'Copper', 'target': 'c', 'trgt_label': 'Gig0/2'}, {'source': {'id':'b', 'bottom_label': 'node_b'}, 'src_label': 'Gig0/0', 'label': 'Copper', 'target': 'e', 'trgt_label': 'Gig0/2'} ] yed_diagram.node_duplicates="update" yed_diagram.from_list(sample_list_graph) new_edges={ "LineStyle": {"color": "#00FF00", "width": "1.0"}, "EdgeLabel": {"textColor": "#00FF00"}, } yed_diagram.update_link( label="Copper", src_label="Gig0/0", trgt_label="Gig0/2", source="b", target="c", new_label="UTP", new_src_label="Gi0/0", new_trgt_label="Gi0/3", description="some additional data", attributes=new_edges ) yed_diagram.update_node( id="a", width=300, height=300, top_label="top llbl" ) yed_diagram.update_node( id="b", width=200, height=150, top_label="top llbl2" ) ret = yed_diagram.dump_xml() assert ret == expected_output
def test_4_dups_handling(): ########################################### # Test graph compare ########################################### with open("./yed.test_4_dups_handling.graphml", "r") as f: expected_output = f.read() sample_graph={ 'nodes': [ {'id': 'a', 'pic': 'router_1', 'label': 'R1' }, {'id': 'b', 'bottom_label':'some', 'top_label':'top_some'}, {'id': 'c', 'label': 'somelabel', 'bottom_label':'botlabel', 'top_label':'toplabel', 'description': 'some node description'}, {'id': 'd', 'pic':'firewall.svg', 'label': 'somelabel1', 'description': 'some node description'}, {'id': 'e', 'pic': 'router_2', 'label': 'R1' }], 'edges': [ {'source': 'a', 'src_label': 'Gig0/0\nUP', 'label': 'DF', 'target': 'b', 'trgt_label': 'Gig0/1', 'description': 'vlans_trunked: 1,2,3\nstate: up'}, {'source': 'b', 'src_label': 'Gig0/0', 'label': 'Copper', 'target': 'c', 'trgt_label': 'Gig0/2'}, {'source': 'c', 'src_label': 'Gig0/0', 'label': 'ZR', 'target': 'a', 'trgt_label': 'Gig0/3'}, {'source': 'd', 'src_label': 'Gig0/10', 'label': 'LR', 'target': 'c', 'trgt_label': 'Gig0/8'} # new link ]} yed_diagram = create_yed_diagram() yed_diagram.from_file("./test_load.graphml") yed_diagram.add_node(id = 'e', label = 'R101', top_label = 'top', bottom_label = 'bot', description='some node description') yed_diagram.add_link('e', 'c', label="some blabla") # new link yed_diagram.add_link('a', 'd') yed_diagram.from_dict(sample_graph) ret = yed_diagram.dump_xml() assert ret == expected_output
def test8_test_from_csv(): ########################################### # Test graph load from csv ########################################### with open("./yed.test8_test_from_csv.graphml", "r") as f: expected_output = f.read() yed_diagram = create_yed_diagram() csv_links_data = """"source","src_label","label","target","trgt_label","description" "a","Gig0/0\nUP","DF","b","Gig0/1","vlans_trunked: 1,2,3\nstate: up" "b","Gig0/0","Copper","c","Gig0/2", "b","Gig0/0","Copper","e","Gig0/2", d,Gig0/21,FW,e,Gig0/23, """ csv_nodes_data=""""id","pic","label","bottom_label","top_label","description" a,router_1,"R1,2",,, "b",,,"some","top_some", "c",,"somelabel","botlabel","toplabel","some node description" "d","firewall.svg","somelabel1",,,"some node description" "e","router_2","R1",,, """ yed_diagram.from_csv(csv_nodes_data) yed_diagram.from_csv(csv_links_data) yed_diagram.layout() ret = yed_diagram.dump_xml() assert ret == expected_output
def test_1_add_elements_one_by_one(): ########################################### # Test adding elements one by one ########################################### with open("./Output/should_be_yed.test_1_add_elements.graphml", "r") as f: expected_output = f.read() yed_diagram = create_yed_diagram() yed_diagram.add_node('a', top_label='top', bottom_label='bot') yed_diagram.add_node('b', label='somelabel', top_label='top', bottom_label='bot') yed_diagram.add_link('a', 'b', label='DF', src_label='Gi0/1', trgt_label='Fas1/2') yed_diagram.add_node('XR12', pic='router_3.svg') yed_diagram.add_node('XR13', pic='router_2.svg') yed_diagram.add_node('XR14', pic='router_1') yed_diagram.add_link('XR12', 'a', description=""" vlans_trunked: 1,22,33,44,55 state: up """) yed_diagram.add_link('XR14', 'XR12') yed_diagram.add_link('a', 'XR13', label='LLDP', src_label='Gi0/21', trgt_label='Fas1/22') yed_diagram.layout() ret = yed_diagram.dump_xml() assert ret == expected_output
def test_10_test_explicit_link_id(): yed_diagram = create_yed_diagram() data = { "nodes": [{ "id": "node-1" }, { "id": "node-2" }], "links": [{ "source": "node-1", "target": "node-2", "link_id": 1 }, { "source": "node-2", "target": "node-1", "link_id": 2 }] } yed_diagram.from_dict(data) yed_diagram.dump_file(filename="yed.test_10_test_explicit_link_id.graphml", folder="./Output/") with open( "./Output/yed.test_10_test_explicit_link_id.graphml") as produced: with open( "./Output/should_be_yed.test_10_test_explicit_link_id.graphml" ) as should_be: assert produced.read() == should_be.read() # test_10_test_explicit_link_id()
def test9_test_from_list_with_update(): """ Test that data2 will update switch-1 with top label """ with open("./yed.test9_test_from_list_with_update.graphml", "r") as f: expected_output = f.read() yed_diagram = create_yed_diagram(node_duplicates="update") data1 = [ { "source": "switch-1", "src_label": "GigabitEthernet4/6", "target": { "bottom_label": "", "id": "switch-2", "top_label": "10.13.1.7" }, "trgt_label": "GigabitEthernet1/5" }, { "source": "switch-1", "src_label": "GigabitEthernet1/1", "target": { "bottom_label": "", "id": "switch-3", "top_label": "10.17.14.1" }, "trgt_label": "GigabitEthernet0/1" }, { "source": "switch-1", "src_label": "GigabitEthernet1/2", "target": { "bottom_label": "", "id": "switch-4", "top_label": "10.17.14.2" }, "trgt_label": "GigabitEthernet0/10" } ] data2 = [ { "source": "switch-2", "src_label": "GigabitEthernet1/5", "target": { "bottom_label": "", "id": "switch-1", "top_label": "10.13.1.17" }, "trgt_label": "GigabitEthernet4/6" } ] yed_diagram.from_list(data1) yed_diagram.from_list(data2) ret = yed_diagram.dump_xml() assert ret == expected_output
def test_5_delete_nodes(): ########################################### # Test delete_node method ########################################### with open("./yed.test_5_delete_nodes.graphml", "r") as f: expected_output = f.read() yed_diagram = create_yed_diagram() yed_diagram.from_file("./test_load.graphml") yed_diagram.add_node(id="bb") yed_diagram.add_node(id="cc") yed_diagram.delete_node(id="e", ids=["a", "cc"]) ret = yed_diagram.dump_xml() assert ret == expected_output
def test_6_delete_links(): ########################################### # Test delete_link method ########################################### with open("./yed.test_6_delete_links.graphml", "r") as f: expected_output = f.read() yed_diagram = create_yed_diagram() yed_diagram.from_file("./test_load.graphml") yed_diagram.add_node(id="bb") yed_diagram.add_node(id="cc") yed_diagram.add_node(id="dd") yed_diagram.add_link('bb', 'cc') yed_diagram.add_link('cc', 'dd') yed_diagram.delete_link(id="e0", ids=["e1", "e2"]) yed_diagram.delete_link(source="cc", target="dd") ret = yed_diagram.dump_xml() assert ret == expected_output
def test_3_graph_compare(): ########################################### # Test graph compare ########################################### with open("./yed.test_3_graph_compare.graphml", "r") as f: expected_output = f.read() yed_diagram = create_yed_diagram() compare_graph = { 'nodes': [ {'id': 'a', 'pic': 'router_round', 'label': 'R1' }, {'id': 'b', 'bottom_label':'some', 'top_label':'top_some'}, {'id': 'f', 'bottom_label':'new_node', 'top_label':'new_node_f'}, {'id': 'e', 'pic': 'router_angles', 'label': 'R1' }], 'edges': [ {'source': 'a', 'src_label': 'Gig0/0\nUP', 'label': 'DF', 'target': 'b', 'trgt_label': 'Gig0/1', 'description': 'vlans_trunked: 1,2,3\nstate: up'}, {'source': 'b', 'src_label': 'Gig0/0', 'label': 'Copper', 'target': 'c', 'trgt_label': 'Gig0/2'}, {'source': 'c', 'src_label': 'Gig0/0', 'label': 'ZR', 'target': 'a', 'trgt_label': 'Gig0/3'}, {'source': 'e', 'src_label': 'Gig0/11', 'label': 'ed', 'target': 'b', 'trgt_label': 'Gig0/8'}, {'source': 'f', 'src_label': 'Gig0/21', 'label': 'DF', 'target': 'b', 'trgt_label': 'Gig0/18'} ]} yed_diagram.from_file("./test_load.graphml") yed_diagram.compare(compare_graph) ret = yed_diagram.dump_xml() assert ret == expected_output
def test_2_from_dict(): ########################################### # Test from dict method ########################################### with open("./yed.test_2_from_dict.graphml", "r") as f: expected_output = f.read() yed_diagram = create_yed_diagram() sample_graph={ 'nodes': [ {'id': 'a', 'pic': 'router_2', 'label': 'R1' }, {'id': 'b', 'bottom_label':'some', 'top_label':'top_some'}, {'id': 'c', 'label': 'somelabel', 'bottom_label':'botlabel', 'top_label':'toplabel', 'description': 'some node description'}, {'id': 'd', 'pic':'firewall.svg', 'label': 'somelabel1', 'description': 'some node description'}, {'id': 'e', 'pic': 'router_1', 'label': 'R1' }], 'edges': [ {'source': 'a', 'src_label': 'Gig0/0\nUP', 'label': 'DF', 'target': 'b', 'trgt_label': 'Gig0/1', 'description': 'vlans_trunked: 1,2,3\nstate: up'}, {'source': 'b', 'src_label': 'Gig0/0', 'label': 'Copper', 'target': 'c', 'trgt_label': 'Gig0/2'}, {'source': 'c', 'src_label': 'Gig0/0', 'label': 'ZR', 'target': 'a', 'trgt_label': 'Gig0/3'}, {'source': 'd', 'src_label': 'Gig0/10', 'label': 'LR', 'target': 'c', 'trgt_label': 'Gig0/8'} ]} yed_diagram.from_dict(sample_graph) yed_diagram.layout() ret = yed_diagram.dump_xml() assert ret == expected_output
def test_ip_drawing_yed_data_dict_group_links(): data = { "Cisco_IOS": [ """ switch_1# show run interfaces interface Loopback0 description Routing Loopback ip address 10.123.0.4 255.255.255.255 ! interface TenGigabitEthernet1/1/3 description to SWITCH_2 vrf VRF1 link 1 vrf forwarding VRF2 ip address 10.123.2.3 255.255.255.254 ! interface TenGigabitEthernet1/1/4 description to SWITCH_2 vrf VRF1 link 2 vrf forwarding VRF2 ip address 10.123.2.4 255.255.255.254 ! interface TenGigabitEthernet1/1/5 description to SWITCH_3 ip address 10.1.33.1 255.255.255.0 ! interface TenGigabitEthernet1/1/7 description to SWITCH_2 shared subnet ip address 10.1.234.1 255.255.255.0 ! interface Vlan123 description Workstations Vlan vrf forwarding CORP ip address 10.123.111.1 255.255.255.0 ip address 10.123.222.1 255.255.255.0 secondary ip address 10.123.233.1 255.255.255.0 secondary """, """ switch_2# show run interfaces interface Loopback0 description Routing Loopback ip address 10.123.0.5 255.255.255.255 ! interface GigabitEthernet1/3 description to SWITCH_1 link 1 vrf forwarding VRF1 ip address 10.123.2.2 255.255.255.254 ! interface GigabitEthernet1/4 description to SWITCH_1 links 2 vrf forwarding VRF1 ip address 10.123.2.5 255.255.255.254 ! interface TenGigabitEthernet1/1/71 description to SWITCH_2 shared subnet ip address 10.1.234.2 255.255.255.0 ! interface Vlan11 description Workstations Vlan vrf forwarding Staff Workstations ip address 10.11.11.1 255.255.255.0 ! interface Vlan22 description Workstations Vlan vrf forwarding Staff Phones ip address 10.22.22.1 255.255.255.0 """ ] } config = {"group_links": True} drawing = create_yed_diagram() drawer = ip_drawer(drawing, config) drawer.work(data) drawer.drawing.dump_file( filename="test_ip_drawing_yed_data_dict_group_links.graphml", folder="./Output/") with open("./Output/test_ip_drawing_yed_data_dict_group_links.graphml" ) as produced: with open( "./Output/should_be_test_ip_drawing_yed_data_dict_group_links.graphml" ) as should_be: assert produced.read() == should_be.read()
def test_ip_drawing_yed_data_dict_add_arp_and_fhrp(): data = { "Cisco_IOS": [ """ switch_1# show run interfaces interface TenGigabitEthernet1/1/5 description to SWITCH_3 ip address 10.1.33.1 255.255.255.0 ! interface TenGigabitEthernet1/1/3 description to SWITCH_2 vrf VRF1 link 1 vrf forwarding VRF2 ip address 10.123.2.3 255.255.255.254 ! interface TenGigabitEthernet1/1/4 description to SWITCH_2 vrf VRF1 link 2 vrf forwarding VRF2 ip address 10.123.2.4 255.255.255.254 ! interface TenGigabitEthernet1/1/7 description to SWITCH_2 shared subnet ip address 10.1.234.1 255.255.255.0 standby 1 10.1.234.99 ! interface Vlan123 description Workstations Vlan vrf forwarding CORP ip address 10.123.111.1 255.255.255.0 ip address 10.123.222.1 255.255.255.0 secondary ip address 10.123.233.1 255.255.255.0 secondary switch_1# show ip arp Internet 10.123.111.1 - d094.6643.1111 ARPA Vlan123 Internet 10.123.111.3 0 0008.e3ff.1333 ARPA Vlan123 Internet 10.123.111.4 106 d867.d9b7.1444 ARPA Vlan123 Internet 10.123.111.5 106 d867.d9b7.1555 ARPA Vlan123 Internet 10.123.233.1 - 0008.e3ff.2111 ARPA Vlan123 Internet 10.123.233.3 166 d867.d9b7.2333 ARPA Vlan123 Internet 10.123.233.4 31 0008.e3ff.2444 ARPA Vlan123 Internet 10.123.233.6 31 0008.e3ff.2666 ARPA Vlan123 Internet 10.1.234.1 - d867.d9b7.1111 ARPA TenGigabitEthernet1/1/7 Internet 10.1.234.2 31 0008.e3ff.1234 ARPA TenGigabitEthernet1/1/7 Internet 10.1.234.3 31 0008.e3ff.4321 ARPA TenGigabitEthernet1/1/7 Internet 10.1.234.99 - 00ac.0007.001a ARPA TenGigabitEthernet1/1/7 """, """ switch_2# show run interfaces interface TenGigabitEthernet1/1/71 description to SWITCH_2 shared subnet ip address 10.1.234.2 255.255.255.0 standby 1 10.1.234.99 ! interface GigabitEthernet1/3 description to SWITCH_1 link 1 vrf forwarding VRF1 ip address 10.123.2.2 255.255.255.254 ! interface GigabitEthernet1/4 description to SWITCH_1 links 2 vrf forwarding VRF1 ip address 10.123.2.5 255.255.255.254 ! interface Vlan11 description Workstations Vlan vrf forwarding Staff Workstations ip address 10.11.11.1 255.255.255.0 ! interface Vlan22 description Workstations Vlan vrf forwarding Staff Phones ip address 10.22.22.1 255.255.255.0 switch_2# show ip arp Internet 10.22.22.1 - d094.7890.1111 ARPA Vlan22 Internet 10.22.22.3 0 0008.7890.1333 ARPA Vlan22 Internet 10.22.22.4 106 d867.7890.1444 ARPA Vlan22 Internet 10.1.234.1 5 d867.d9b7.1111 ARPA TenGigabitEthernet1/1/71 Internet 10.1.234.2 - 0008.e3ff.1234 ARPA TenGigabitEthernet1/1/71 Internet 10.1.234.3 78 0008.e3ff.4321 ARPA TenGigabitEthernet1/1/71 Internet 10.1.234.99 5 00ac.0007.001a ARPA TenGigabitEthernet1/1/71 """ ] } config = { "add_arp": True, "add_fhrp": True, # "collapse_ptp": True } drawing = create_yed_diagram() drawer = ip_drawer(drawing, config) drawer.work(data) drawer.drawing.dump_file( filename="test_ip_drawing_yed_data_dict_add_arp_and_fhrp.graphml", folder="./Output/") with open("./Output/test_ip_drawing_yed_data_dict_add_arp_and_fhrp.graphml" ) as produced: with open( "./Output/should_be_test_ip_drawing_yed_data_dict_add_arp_and_fhrp.graphml" ) as should_be: assert produced.read() == should_be.read() # test_ip_drawing_yed_data_dict_add_arp_and_fhrp()
def test_ip_drawing_yed_data_dict_fortigate(): data = { "Fortigate": [ """ forti-fw-01 (Corporate) # get system config config system interface edit "vms_vlan" set vdom "root" set ip 1.1.1.1 255.255.255.0 set allowaccess ping https ssh snmp set description "VMs data vlan" set alias "vms_vlan" config secondaryip edit 1 set ip 10.38.1.152 255.255.255.0 set allowaccess ping next end next edit "NMS_mgmt" set vdom "root" set ip 10.0.0.1 255.255.255.0 set allowaccess ping https ssh snmp set description "NMS management access" set alias "NMS_mgmt" next edit "uplink_1" set vdom "root" set ip 10.1.0.1 255.255.255.252 set description "bgp to upstream FW" next forti-fw-01 (Corporate) # get system arp Address Age(min) Hardware Addr Interface 1.1.1.10 0 22:31:5e:00:34:d1 vms_vlan 10.0.0.10 0 22:31:5e:00:34:c2 NMS_mgmt 10.0.0.31 0 22:31:5e:00:34:31 NMS_mgmt """, """ forti-fw-02 (Corporate) # get system config config system interface edit "fw_1" set vdom "root" set ip 10.1.0.2 255.255.255.252 set description "bgp to forti-fw-01" next """ ] } config = {"add_arp": True} drawing = create_yed_diagram() drawer = ip_drawer(drawing, config) drawer.work(data) drawer.drawing.dump_file( filename="test_ip_drawing_yed_data_dict_fortigate.graphml", folder="./Output/") with open("./Output/test_ip_drawing_yed_data_dict_fortigate.graphml" ) as produced: with open( "./Output/should_be_test_ip_drawing_yed_data_dict_fortigate.graphml" ) as should_be: assert produced.read() == should_be.read()
def test_ip_drawing_yed_data_dict_huawei(): data = { "Huawei": [ """ <hua_sw1>dis current-configuration interface # interface Vlanif140 ip binding vpn-instance VRF_MGMT ip address 10.1.1.2 255.255.255.0 vrrp vrid 200 virtual-ip 10.1.1.1 # interface Eth-Trunk5.123 vlan-type dot1q 123 description hua_sw2 BGP peering ip binding vpn-instance VRF_MGMT ip address 10.0.0.1 255.255.255.252 ipv6 address FD00:1::1/126 # interface Eth-Trunk5.200 vlan-type dot1q 200 description hua_sw3 OSPF peering ip address 192.168.2.2 255.255.255.252 <hua_sw1>dis arp all 10.1.1.2 a008-6fc1-1101 I Vlanif140 VRF_MGMT 10.1.1.1 a008-6fc1-1102 0 D Vlanif140 VRF_MGMT 10.1.1.3 a008-6fc1-1103 10 D/200 Vlanif140 VRF_MGMT 10.1.1.9 a008-6fc1-1104 10 D/200 Vlanif140 VRF_MGMT 10.0.0.2 a008-6fc1-1105 10 D/200 Eth-Trunk5.123 VRF_MGMT """, """ <hua_sw2>dis current-configuration interface # interface Vlanif140 ip binding vpn-instance VRF_MGMT ip address 10.1.1.3 255.255.255.0 vrrp vrid 200 virtual-ip 10.1.1.1 # interface Eth-Trunk5.123 vlan-type dot1q 123 description hua_sw1 BGP peering ip binding vpn-instance VRF_MGMT ip address 10.0.0.2 255.255.255.252 ipv6 address FD00:1::2/126 """, """ <hua_sw3>dis current-configuration interface # interface Vlanif200 ip binding vpn-instance VRF_CUST1 ip address 192.168.1.1 255.255.255.0 # interface Eth-Trunk5.200 vlan-type dot1q 200 description hua_sw1 OSPF peering ip address 192.168.2.1 255.255.255.252 <hua_sw3>dis arp 192.168.1.1 a008-6fc1-1111 I Vlanif200 192.168.1.10 a008-6fc1-1110 30 D/300 Vlanif200 """ ] } config = {"add_arp": True, "add_fhrp": True} drawing = create_yed_diagram() drawer = ip_drawer(drawing, config) drawer.work(data) drawer.drawing.dump_file( filename="test_ip_drawing_yed_data_dict_huawei.graphml", folder="./Output/") with open("./Output/test_ip_drawing_yed_data_dict_huawei.graphml" ) as produced: with open( "./Output/should_be_test_ip_drawing_yed_data_dict_huawei.graphml" ) as should_be: assert produced.read() == should_be.read()
def test_ip_drawing_yed_data_dict_nxos(): data = { "Cisco_NXOS": [ """ switch_1# show run | sec interface interface Vlan133 description OOB vrf member MGMT_OOB ip address 10.133.137.2/24 hsrp 133 preempt ip 10.133.137.1 ! interface Vlan134 description OOB-2 vrf member MGMT_OOB ip address 10.134.137.2/24 vrrpv3 1334 address-family ipv4 address 10.134.137.1 primary ! interface Vlan222 description PTP OSPF Routing pat to siwtch2 ip address 10.222.137.1/30 ! interface Vlan223 description PTP OSPF Routing pat to siwtch3 ip address 10.223.137.1/30 switch_1# show ip arp vrf all 10.133.137.2 - d094.7890.1111 Vlan133 10.133.137.1 - d094.7890.1111 Vlan133 10.133.137.30 - d094.7890.1234 Vlan133 10.133.137.91 - d094.7890.4321 Vlan133 10.134.137.1 - d094.7890.1111 Vlan134 10.134.137.2 - d094.7890.1111 Vlan134 10.134.137.3 90 d094.7890.2222 Vlan134 10.134.137.31 91 d094.7890.beef Vlan134 10.134.137.81 81 d094.7890.feeb Vlan134 10.222.137.2 21 d094.7890.2222 Vlan222 """, """ switch_2# show run | sec interface interface Vlan134 description OOB-2 vrf member MGMT_OOB ip address 10.134.137.3/24 vrrpv3 1334 address-family ipv4 address 10.134.137.1 primary ! interface Vlan222 description PTP OSPF Routing pat to siwtch1 ip address 10.222.137.2/30 """, """ switch_3# show run | sec interface interface Vlan223 description PTP OSPF Routing pat to siwtch1 ip address 10.223.137.2/30 """ ] } config = {"add_arp": True, "add_fhrp": True} drawing = create_yed_diagram() drawer = ip_drawer(drawing, config) drawer.work(data) drawer.drawing.dump_file( filename="test_ip_drawing_yed_data_dict_nxos.graphml", folder="./Output/") with open( "./Output/test_ip_drawing_yed_data_dict_nxos.graphml") as produced: with open( "./Output/should_be_test_ip_drawing_yed_data_dict_nxos.graphml" ) as should_be: assert produced.read() == should_be.read()