OpenStackConfigUtilImpl implements OpenStackConfigUtil { public String getPublicAdminNetwork(PaasManagerUser user, String region) throws OpenStackException { log.debug("Obtain public admin network "); String type = "net"; String networkId = regionCache.getUrl(region, type); if (networkId != null) { log.debug("in cache " + networkId); return networkId; } NetworkInstance net = this.getPublicAdmin(user, region); if (net != null) { log.debug("net " + net.getNetworkName() + " " + net.getIdNetwork()); regionCache.putUrl(region, type, net.getNetworkName()); return net.getIdNetwork(); } return null; } OpenStackConfigUtilImpl(); HttpClientConnectionManager getHttpConnectionManager(); void setHttpConnectionManager(HttpClientConnectionManager httpConnectionManager); String getPublicAdminNetwork(PaasManagerUser user, String region); String getPublicFloatingPool(PaasManagerUser user, String region); NetworkInstance getPublicAdmin(PaasManagerUser user, String region); String getPublicRouter(PaasManagerUser user, String region, String publicNetworkId); String getPublicRouterId(String response, String vdc, String publicNetworkId); OpenStackRegion getOpenStackRegion(); void setOpenStackRegion(OpenStackRegion openStackRegion); void setOpenOperationUtil(OpenOperationUtil openOperationUtil);  }
@Test public void shouldObtainDefaultNetwork() throws OpenStackException, IOException { String region = "RegionOne"; OpenStackAccess openStackAccess = new OpenStackAccess(); openStackAccess.setToken("1234567891234567989"); openStackAccess.setTenantId("08bed031f6c54c9d9b35b42aa06b51c0"); when(openStackRegion.getTokenAdmin()).thenReturn(openStackAccess); when(openOperationUtil.executeNovaRequest(any(HttpUriRequest.class))).thenReturn(CONTENT_NETWORKS); String net = openStackUtil.getPublicAdminNetwork(paasManagerUser, region); assertNotNull(net); assertEquals(net, "83c3d979-4a43-4ce3-ac39-ef7bfb0b89e5"); }
@Test public void testObtainPublicNetworkSeveralExternalNetworks() throws OpenStackException { String CONTENT_NETWORKS = "{\"networks\": [{\"status\": \"ACTIVE\", " + "\"subnets\": [\"eb602a2b-13cd-46c8-9055-99ad45180730\"]," + "\"name\": \"net04_ext\", \"provider:physical_network\": null, " + "\"admin_state_up\": true, \"tenant_id\": " + "\"eab8403e83e048719ab220353c10806f\", \"provider:network_type\": " + "\"gre\", \"router:external\": true, \"shared\": " + "true, \"id\": \"04c9aedf-aeb6-4553-8ddb-845701da71bd\", " + "\"provider:segmentation_id\": 3}, " + "{\"status\": \"ACTIVE\", \"subnets\": [\"6ba86d6b-b7ad-4d0b-b552-cb63b36c9ef2\"], " + "\"name\": \"sec_ext_net\", " + "\"provider:physical_network\": \"physnet1\", \"admin_state_up\": true, \"tenant_id\":" + "\"eab8403e83e048719ab220353c10806f\", " + "\"provider:network_type\": \"flat\", \"router:external\": true, \"shared\": false," + " \"id\": \"063f1075-77eb-45f9-be7a-205a591840ee\"," + "\"provider:segmentation_id\": null}]}"; System.out.print(CONTENT_NETWORKS); String region = "RegionOne5"; OpenStackAccess openStackAccess = new OpenStackAccess(); openStackAccess.setToken("1234567891234567989"); openStackAccess.setTenantId("08bed031f6c54c9d9b35b42aa06b51c0"); when(openStackRegion.getTokenAdmin()).thenReturn(openStackAccess); when(openOperationUtil.executeNovaRequest(any(HttpUriRequest.class))).thenReturn(CONTENT_NETWORKS); String net = openStackUtil.getPublicAdminNetwork(paasManagerUser, region); assertNotNull(net); assertEquals(net, "04c9aedf-aeb6-4553-8ddb-845701da71bd"); }