@Test public void testRouterDeleteWithBoundExteriorPort() throws Exception { // Add a router DtoRouter resRouter = topology.getRouter("router1"); // Add an exterior port. DtoRouterPort port = new DtoRouterPort(); port.setNetworkAddress("10.0.0.0"); port.setNetworkLength(24); port.setPortAddress("10.0.0.1"); DtoRouterPort resPort = dtoResource.postAndVerifyCreated( resRouter.getPorts(), APPLICATION_PORT_V2_JSON(), port, DtoRouterPort.class); // Get the host DTO. DtoHost[] hosts = dtoResource.getAndVerifyOk( topology.getApplication().getHosts(), APPLICATION_HOST_COLLECTION_JSON_V3(), DtoHost[].class); Assert.assertEquals(1, hosts.length); DtoHost resHost = hosts[0]; bindHostToTunnelZone(resHost.getId()); // Bind the exterior port to an interface on the host. DtoHostInterfacePort hostBinding = new DtoHostInterfacePort(); hostBinding.setHostId(resHost.getId()); hostBinding.setInterfaceName("eth0"); hostBinding.setPortId(resPort.getId()); dtoResource.postAndVerifyCreated( resHost.getPorts(), APPLICATION_HOST_INTERFACE_PORT_JSON(), hostBinding, DtoHostInterfacePort.class); dtoResource.deleteAndVerifyNoContent(resRouter.getUri(), APPLICATION_ROUTER_JSON_V3()); }
@Test public void testCreateWhenAlreadyBound() { DtoHost host = hostTopology.getHost(host1Id); DtoBridgePort port1 = topology.getBridgePort("bridgePort1"); bindHostToTunnelZone(host1Id); // List mappings. There should be none. DtoHostInterfacePort[] maps = dtoResource.getAndVerifyOk( host.getPorts(), APPLICATION_HOST_INTERFACE_PORT_COLLECTION_JSON(), DtoHostInterfacePort[].class); Assert.assertEquals(0, maps.length); DtoHostInterfacePort mapping = new DtoHostInterfacePort(); mapping.setPortId(port1.getId()); mapping.setInterfaceName("eth0"); dtoResource.postAndVerifyCreated( host.getPorts(), APPLICATION_HOST_INTERFACE_PORT_JSON(), mapping, DtoHostInterfacePort.class); mapping = new DtoHostInterfacePort(); mapping.setPortId(port1.getId()); mapping.setInterfaceName("eth1"); dtoResource.postAndVerifyBadRequest( host.getPorts(), APPLICATION_HOST_INTERFACE_PORT_JSON(), mapping); }
@Test public void testCreateWhenHostIsNotInAnyTunnelZone() { DtoHost host = hostTopology.getHost(host1Id); DtoBridgePort port = topology.getBridgePort("bridgePort1"); // Map a tunnel zone to a host DtoHostInterfacePort mapping = new DtoHostInterfacePort(); mapping.setPortId(port.getId()); mapping.setInterfaceName("eth0"); DtoError error = dtoResource.postAndVerifyBadRequest( host.getPorts(), APPLICATION_HOST_INTERFACE_PORT_JSON(), mapping); assertErrorMatchesLiteral(error, getMessage(HOST_IS_NOT_IN_ANY_TUNNEL_ZONE, host1Id)); }
@Test public void testCrud() throws Exception { DtoHost host = hostTopology.getHost(host1Id); DtoBridgePort port1 = topology.getBridgePort("bridgePort1"); bindHostToTunnelZone(host1Id); // List mappings. There should be none. DtoHostInterfacePort[] maps = dtoResource.getAndVerifyOk( host.getPorts(), APPLICATION_HOST_INTERFACE_PORT_COLLECTION_JSON(), DtoHostInterfacePort[].class); Assert.assertEquals(0, maps.length); // Map a tunnel zone to a host DtoHostInterfacePort mapping1 = new DtoHostInterfacePort(); mapping1.setPortId(port1.getId()); mapping1.setInterfaceName("eth0"); mapping1 = dtoResource.postAndVerifyCreated( host.getPorts(), APPLICATION_HOST_INTERFACE_PORT_JSON(), mapping1, DtoHostInterfacePort.class); // List bridge mapping and verify that there is one maps = dtoResource.getAndVerifyOk( host.getPorts(), APPLICATION_HOST_INTERFACE_PORT_COLLECTION_JSON(), DtoHostInterfacePort[].class); Assert.assertEquals(1, maps.length); // Remove mapping dtoResource.deleteAndVerifyNoContent( mapping1.getUri(), APPLICATION_HOST_INTERFACE_PORT_JSON()); // List mapping and verify that there is none maps = dtoResource.getAndVerifyOk( host.getPorts(), APPLICATION_HOST_INTERFACE_PORT_COLLECTION_JSON(), DtoHostInterfacePort[].class); Assert.assertEquals(0, maps.length); }
@Before public void setUp() throws StateAccessException, InterruptedException, KeeperException, SerializationException { WebResource resource = resource(); dtoResource = new DtoWebResource(resource); DtoHost host1 = new DtoHost(); host1.setName("host1"); DtoBridge bridge1 = new DtoBridge(); bridge1.setName("bridge1-name"); bridge1.setTenantId("tenant1-id"); DtoRouter router1 = new DtoRouter(); router1.setName("router1-name"); router1.setTenantId("tenant1-id"); DtoBridgePort bridgePort1 = new DtoBridgePort(); DtoBridgePort bridgePort2 = new DtoBridgePort(); DtoTunnelZone tunnelZone1 = new DtoTunnelZone(); tunnelZone1.setName("tz1-name"); topology = new Topology.Builder(dtoResource) .create("router1", router1) .create("bridge1", bridge1) .create("bridge1", "bridgePort1", bridgePort1) .create("bridge1", "bridgePort2", bridgePort2) .build(); hostTopology = new HostTopology.Builder(dtoResource) .create(host1Id, host1) .create("tz1", tunnelZone1) .build(); URI baseUri = resource().getURI(); api = new MidonetApi(baseUri.toString()); api.enableLogging(); }