@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); }