def runTest(self): tenant_name = 't1' segment_name = "s2" tenantData = Tenant(tenant_name) tenantData.delete_tenant(tenant_name) time.sleep(5) tenantData.build_tenant() segment_cfg = { "name": segment_name, "type": "vlan", "vlan_id": "2", "ip_address": [] } tenantData.segment(name=segment_cfg["name"], type=segment_cfg["type"], vlan_id=segment_cfg["vlan_id"], ip_address=segment_cfg["ip_address"]) tenantData.build_segment() segmentData = tenantData.get_segmentByTenant(tenant_name) segmentData = segmentData["tenantSegments"][0] assert (segment_cfg['name'] == segmentData['name']) assert (segment_cfg['type'] == segmentData['type']) assert (segment_cfg['vlan_id'] == str(segmentData['value'])) #print("debug: cfg.leaf0['portA'].name ", cfg.leaf0['portA'].name) SegmentMemberData = tenantData.segment_member( SegmentMember(segment_name, cfg.leaf0['id']).ports([cfg.leaf0['portA'].name])) ## SegmentMemberData = tenantData.segment_member(SegmentMemberData) tenantData.build_segment() actual_port = tenantData.get_segmentMemberById(tenant_name, segment_name, cfg.leaf0['id']) assert (cfg.leaf0['portA'].name == actual_port["segment_members"][0] ["ports"][0]) endpoint_cfg = {} endpoint_cfg['tenant'] = tenant_name endpoint_cfg['segment'] = segment_name endpoint_cfg['mac'] = "46:E4:3C:A4:17:C8" endpoint_cfg['ip_addresses'] = ["127.0.0.1"] endpoint_cfg['locations'] = [{ "device_id": cfg.leaf0['id'], "port": str(cfg.leaf0["front_port_A"]) }] endpointData = Endpoint(endpoint_cfg).build() time.sleep(5) actual_port = endpointData.get_configBySegment_Mac( segment_name, endpoint_cfg['mac']) chkData = actual_port["hosts"][0] assert (endpoint_cfg['mac'] == chkData["mac"] ), "Cannot get mac of endpoint config" assert (endpoint_cfg['ip_addresses'] == chkData["ip_addresses"] ), "Cannot get ip_addresses of endpoint config" tenantData.delete_tenant(tenant_name)
def runTest(self): ports = sorted(config["port_map"].keys()) d_ip = "192.168.1.111" t_ip = "192.168.1.10" vlan_id = 2 tenant_name = 't1' segment_name = "s1" tenantData = Tenant(tenant_name) tenantData.delete_tenant(tenant_name) time.sleep(3) tenantData.build_tenant() segment_cfg = { "name": segment_name, "type": "vlan", "vlan_id": "{}".format(vlan_id), "ip_address": ["{}".format(d_ip)] } tenantData.segment(name=segment_cfg["name"], type=segment_cfg["type"], vlan_id=segment_cfg["vlan_id"], ip_address=segment_cfg["ip_address"]) tenantData.build_segment() time.sleep(5) segmentData = tenantData.get_segmentByTenant(tenant_name) segmentData = segmentData["tenantSegments"][0] assert (segment_cfg['name'] == segmentData['name']) assert (segment_cfg['type'] == segmentData['type']) assert (segment_cfg['vlan_id'] == str(segmentData['value'])) a_name = cfg.leaf0['portA'].name.replace("untag", "tag") b_name = cfg.leaf0['portB'].name.replace("untag", "tag") SegmentMemberData = tenantData.segment_member( SegmentMember(segment_name, cfg.leaf0['id']).ports([a_name, b_name])) tenantData.build_segment() time.sleep(5) actual_port = tenantData.get_segmentMemberById(tenant_name, segment_name, cfg.leaf0['id']) assert ( a_name in actual_port["segment_members"][0]["ports"]), "Not found port A" assert ( b_name in actual_port["segment_members"][0]["ports"]), "Not found port A" # manual setup mac manualMac = "46:E4:3C:A4:17:C8" manualIp = ["127.0.0.1"] endpoint_cfg = {} endpoint_cfg['tenant'] = tenant_name endpoint_cfg['segment'] = segment_name endpoint_cfg['mac'] = manualMac endpoint_cfg['ip_addresses'] = manualIp endpoint_cfg['locations'] = [{ "device_id": cfg.leaf0['id'], "port": str(cfg.leaf0["front_port_A"]) }] endpointData = Endpoint(endpoint_cfg).build() time.sleep(3) actual_port = endpointData.get_configBySegment_Mac( segment_name, endpoint_cfg['mac']) chkData = actual_port["hosts"][0] assert (endpoint_cfg['mac'] == chkData["mac"] ), "Cannot get mac of endpoint config(before reboot)" assert (endpoint_cfg['ip_addresses'] == chkData["ip_addresses"] ), "Cannot get ip_addresses of endpoint config(before reboot)" tenant_logical_router_cfg = {"name": "r1", "interfaces": ["s1"]} tlr = TenantLogicalRouterApi( TenantLogicalRouterCfg(tenant_logical_router_cfg)) assert (tlr.retrieve() == []) tlr.create(tenant='t1') result = tlr.retrieve() assert (result[0]['name'] == tenant_logical_router_cfg['name']) assert ( result[0]['interfaces'] == tenant_logical_router_cfg['interfaces']) assert (result[0]['tenant'] == 't1') # tlr.delete() time.sleep(10) pkt_from_p0_to_dut = simple_arp_packet( pktlen=68, vlan_vid=vlan_id, eth_dst="ff:ff:ff:ff:ff:ff", eth_src=cfg.host0['mac'], ip_snd=t_ip, ip_tgt=d_ip, hw_snd=cfg.host0['mac'], hw_tgt='00:00:00:00:00:00', ) expected_pkt = simple_eth_vlan_type_packet( pktlen=12, eth_type=0x0806, vlan_vid=vlan_id, eth_dst=cfg.host0['mac'], eth_src=cfg.spine0['mac'], ) for i in range(15): self.dataplane.send(ports[0], str(pkt_from_p0_to_dut)) wait_for_seconds(1) verify_packet(self, str(expected_pkt), ports[0]) # verify_no_packet(self, str(expected_pkt), ports[1]) time.sleep(50) endpoint_cfg = {} endpointData = Endpoint(endpoint_cfg) actual_port = endpointData.get() for portNum in actual_port["hosts"]: if portNum["mac"] == cfg.host0['mac']: # assert(t_ip == portNum["ip_addresses"][0] # ), "Cannot get ip_addresses of endpoint config" if t_ip == portNum["ip_addresses"][0]: break elif portNum["mac"] == actual_port["hosts"][ len(actual_port["hosts"]) - 1]["mac"]: assert (False), "Not found endpoint mac error" expected_pkt = simple_eth_vlan_packet( pktlen=64, vlan_vid=vlan_id, eth_dst="ff:ff:ff:ff:ff:ff", eth_src=cfg.host1['mac'], ) for i in range(15): self.dataplane.send(ports[1], str(expected_pkt)) wait_for_seconds(1) verify_packet(self, str(expected_pkt), ports[0]) time.sleep(50) actual_port = endpointData.get() for portNum in actual_port["hosts"]: if portNum["mac"] == cfg.host1['mac']: # assert('0.0.0.0' == portNum["ip_addresses"][0] # ), "Cannot get ip_addresses of endpoint config" if '0.0.0.0' == portNum["ip_addresses"][0]: break elif portNum["mac"] == actual_port["hosts"][ len(actual_port["hosts"]) - 1]["mac"]: assert (False), "Not found endpoint mac error(no ip)" # reboot rebootTest = RebootSwitch(cfg.leaf0['id']) rebootTest.reboot() rebootTest = RebootSwitch(cfg.leaf1['id']) rebootTest.reboot() time.sleep(330) expected_pkt = simple_eth_vlan_packet( pktlen=64, vlan_vid=vlan_id, eth_dst="ff:ff:ff:ff:ff:ff", eth_src=cfg.host1['mac'], ) for i in range(15): self.dataplane.send(ports[1], str(expected_pkt)) wait_for_seconds(1) verify_packet(self, str(expected_pkt), ports[0]) time.sleep(50) actual_port = endpointData.get() for portNum in actual_port["hosts"]: if portNum["mac"] == cfg.host1['mac']: assert ('0.0.0.0' == portNum["ip_addresses"][0] ), "Cannot get ip_addresses of endpoint config" break elif portNum["mac"] == actual_port["hosts"][ len(actual_port["hosts"]) - 1]["mac"]: assert (False), "Not found endpoint mac error(no ip)" actual_port = endpointData.get_configBySegment_Mac( segment_name, manualMac) chkData = actual_port["hosts"][0] assert (manualMac == chkData["mac"] ), "Cannot get mac of endpoint config(after reboot)" assert (manualIp == chkData["ip_addresses"] ), "Cannot get ip_addresses of endpoint config(after reboot)" # sned packet pkt_from_p0_to_dut = simple_arp_packet( pktlen=68, vlan_vid=vlan_id, eth_dst="ff:ff:ff:ff:ff:ff", eth_src=cfg.host0['mac'], ip_snd=t_ip, ip_tgt=d_ip, hw_snd=cfg.host0['mac'], hw_tgt='00:00:00:00:00:00', ) expected_pkt = simple_eth_vlan_type_packet( pktlen=12, eth_type=0x0806, vlan_vid=vlan_id, eth_dst=cfg.host0['mac'], eth_src=cfg.spine0['mac'], ) for i in range(15): self.dataplane.send(ports[0], str(pkt_from_p0_to_dut)) wait_for_seconds(1) #verify_packet(self, str(expected_pkt), ports[0]) #verify_no_packet(self, str(expected_pkt), ports[1]) time.sleep(50) endpoint_cfg = {} endpointData = Endpoint(endpoint_cfg) actual_port = endpointData.get() for portNum in actual_port["hosts"]: if portNum["mac"] == cfg.host0['mac']: assert ( t_ip == portNum["ip_addresses"][0] ), "Cannot get ip_addresses of endpoint config(after reboot)" break elif portNum["mac"] == actual_port["hosts"][ len(actual_port["hosts"]) - 1]["mac"]: assert (False), "Not found endpoint mac error(after reboot)" endpoint_cfg = {} endpointData = Endpoint(endpoint_cfg) endpointData.delete_configByTenant_Segment_Mac(tenant_name, segment_name, cfg.host0['mac']) endpointData.delete_configByTenant_Segment_Mac(tenant_name, segment_name, cfg.host1['mac']) endpointData.delete_configByTenant_Segment_Mac("unknown", "unknown", cfg.host0['mac']) endpointData.delete_configByTenant_Segment_Mac("unknown", "unknown", cfg.host1['mac']) tlr.delete() tenantData = Tenant(tenant_name) tenantData.delete_segment(segment_name) tenantData.delete_tenant(tenant_name)