@Test(expected = OpenStackException.class) public void testShouldDeployVMError() throws OpenStackException, IOException { String payload = ""; String content = "<badRequest code=\"400\" xmlns=\"http: + "<message>Invalid key_name provided.</message></badRequest>"; when(openOperationUtil.executeNovaRequest(any(HttpUriRequest.class))).thenReturn(content); String response = openStackUtil.createServer(payload, "region", "token", "vdc"); assertNotNull(response); }
public String createServer(String payload, String region, String token, String vdc) throws OpenStackException { log.debug("create server " + token + " vdc " + vdc); HttpUriRequest request; String response = null; String getResponse = ""; String id = ""; try { request = openOperationUtil.createNovaPostRequest(RESOURCE_SERVERS, payload, APPLICATION_JSON, APPLICATION_JSON, region, token, vdc); } catch (OpenStackException ex) { throw new OpenStackException(ex.getMessage()); } try { response = openOperationUtil.executeNovaRequest(request); log.debug(response); JSONObject serverJson = new JSONObject(response); id = serverJson.getJSONObject("server").getString("id"); while (!(getResponse.contains("ACTIVE") || getResponse.contains("ERROR"))) { getResponse = getServer(id, region, token, vdc); Thread.sleep(5000); } } catch (Exception e) { String errorMessage = "Error creating server: " + e.getMessage(); log.error(errorMessage); throw new OpenStackException(errorMessage); } if (getResponse.contains("ERROR")) { log.debug(getResponse); throw new OpenStackException("Error in parse response after deploy the VM " + id + " " + getResponse); } return id; }
OpenStackUtilImpl implements OpenStackUtil { public String createServer(String payload, String region, String token, String vdc) throws OpenStackException { log.debug("create server " + token + " vdc " + vdc); HttpUriRequest request; String response = null; String getResponse = ""; String id = ""; try { request = openOperationUtil.createNovaPostRequest(RESOURCE_SERVERS, payload, APPLICATION_JSON, APPLICATION_JSON, region, token, vdc); } catch (OpenStackException ex) { throw new OpenStackException(ex.getMessage()); } try { response = openOperationUtil.executeNovaRequest(request); log.debug(response); JSONObject serverJson = new JSONObject(response); id = serverJson.getJSONObject("server").getString("id"); while (!(getResponse.contains("ACTIVE") || getResponse.contains("ERROR"))) { getResponse = getServer(id, region, token, vdc); Thread.sleep(5000); } } catch (Exception e) { String errorMessage = "Error creating server: " + e.getMessage(); log.error(errorMessage); throw new OpenStackException(errorMessage); } if (getResponse.contains("ERROR")) { log.debug(getResponse); throw new OpenStackException("Error in parse response after deploy the VM " + id + " " + getResponse); } return id; } }
OpenStackUtilImpl implements OpenStackUtil { public String createServer(String payload, String region, String token, String vdc) throws OpenStackException { log.debug("create server " + token + " vdc " + vdc); HttpUriRequest request; String response = null; String getResponse = ""; String id = ""; try { request = openOperationUtil.createNovaPostRequest(RESOURCE_SERVERS, payload, APPLICATION_JSON, APPLICATION_JSON, region, token, vdc); } catch (OpenStackException ex) { throw new OpenStackException(ex.getMessage()); } try { response = openOperationUtil.executeNovaRequest(request); log.debug(response); JSONObject serverJson = new JSONObject(response); id = serverJson.getJSONObject("server").getString("id"); while (!(getResponse.contains("ACTIVE") || getResponse.contains("ERROR"))) { getResponse = getServer(id, region, token, vdc); Thread.sleep(5000); } } catch (Exception e) { String errorMessage = "Error creating server: " + e.getMessage(); log.error(errorMessage); throw new OpenStackException(errorMessage); } if (getResponse.contains("ERROR")) { log.debug(getResponse); throw new OpenStackException("Error in parse response after deploy the VM " + id + " " + getResponse); } return id; } OpenStackUtilImpl(); }
OpenStackUtilImpl implements OpenStackUtil { public String createServer(String payload, String region, String token, String vdc) throws OpenStackException { log.debug("create server " + token + " vdc " + vdc); HttpUriRequest request; String response = null; String getResponse = ""; String id = ""; try { request = openOperationUtil.createNovaPostRequest(RESOURCE_SERVERS, payload, APPLICATION_JSON, APPLICATION_JSON, region, token, vdc); } catch (OpenStackException ex) { throw new OpenStackException(ex.getMessage()); } try { response = openOperationUtil.executeNovaRequest(request); log.debug(response); JSONObject serverJson = new JSONObject(response); id = serverJson.getJSONObject("server").getString("id"); while (!(getResponse.contains("ACTIVE") || getResponse.contains("ERROR"))) { getResponse = getServer(id, region, token, vdc); Thread.sleep(5000); } } catch (Exception e) { String errorMessage = "Error creating server: " + e.getMessage(); log.error(errorMessage); throw new OpenStackException(errorMessage); } if (getResponse.contains("ERROR")) { log.debug(getResponse); throw new OpenStackException("Error in parse response after deploy the VM " + id + " " + getResponse); } return id; } OpenStackUtilImpl(); HttpClientConnectionManager getHttpConnectionManager(); void setHttpConnectionManager(HttpClientConnectionManager httpConnectionManager); String addInterface(String idRouter, NetworkInstance net, String region, String token, String vdc); String addInterfaceToPublicRouter(PaasManagerUser user, NetworkInstance net, String region); String addRouterInterface(String routerId, String subNetId, String region, String token, String vdc); String allocateFloatingIP(String payload, String region, String token, String vdc); String getFloatingIPs(String region, String token, String vdc, String dd); void disAllocateFloatingIP(String region, String token, String vdc, String floatingIp); String assignFloatingIP(String serverId, String floatingIP, String region, String token, String vdc); String createNetwork(String payload, String region, String token, String vdc); String createRouter(RouterInstance router, String region, String token, String vdc); String createServer(String payload, String region, String token, String vdc); String createSubNet(SubNetworkInstance subNet, String region, String token, String vdc); String deleteNetwork(String networkId, String region, String token, String vdc); String deleteRouter(String routerId, String region, String token, String vdc); String deleteServer(String serverId, String region, String token, String vdc); void deleteSubNetwork(String idSubNet, String region, String vdc, String token); String getFloatingIP(PaasManagerUser user, String region); String getNetworkDetails(String networkId, String region, String token, String vdc); String getSubNetworkDetails(String subNetworkId, String region, String token, String vdc); String getNetworks(String region, String token, String vdc); String getServer(String serverId, String region, String token, String vdc); boolean existsServerForDelete(String serverId, String region, String token, String vdc); String listServers(String region, String token, String vdc); String removeInterface(RouterInstance router, String net, String region, String token, String vdc); String getAbsoluteLimits(PaasManagerUser user, String region); String listNetworks(PaasManagerUser user, String region); String listSubNetworks(PaasManagerUser user, String region); String listPorts(PaasManagerUser user, String region); String deleteInterfaceToPublicRouter(PaasManagerUser user, NetworkInstance net, String region); OpenStackRegion getOpenStackRegion(); void setOpenStackRegion(OpenStackRegion openStackRegion); void setOpenOperationUtil(OpenOperationUtil openOperationUtil); void setOpenStackConfigUtil(OpenStackConfigUtil openStackConfigUtil); String joinNetworks(NetworkInstance networkInstance, NetworkInstance networkInstance2, String token); }
OpenStackUtilImpl implements OpenStackUtil { public String createServer(String payload, String region, String token, String vdc) throws OpenStackException { log.debug("create server " + token + " vdc " + vdc); HttpUriRequest request; String response = null; String getResponse = ""; String id = ""; try { request = openOperationUtil.createNovaPostRequest(RESOURCE_SERVERS, payload, APPLICATION_JSON, APPLICATION_JSON, region, token, vdc); } catch (OpenStackException ex) { throw new OpenStackException(ex.getMessage()); } try { response = openOperationUtil.executeNovaRequest(request); log.debug(response); JSONObject serverJson = new JSONObject(response); id = serverJson.getJSONObject("server").getString("id"); while (!(getResponse.contains("ACTIVE") || getResponse.contains("ERROR"))) { getResponse = getServer(id, region, token, vdc); Thread.sleep(5000); } } catch (Exception e) { String errorMessage = "Error creating server: " + e.getMessage(); log.error(errorMessage); throw new OpenStackException(errorMessage); } if (getResponse.contains("ERROR")) { log.debug(getResponse); throw new OpenStackException("Error in parse response after deploy the VM " + id + " " + getResponse); } return id; } OpenStackUtilImpl(); HttpClientConnectionManager getHttpConnectionManager(); void setHttpConnectionManager(HttpClientConnectionManager httpConnectionManager); String addInterface(String idRouter, NetworkInstance net, String region, String token, String vdc); String addInterfaceToPublicRouter(PaasManagerUser user, NetworkInstance net, String region); String addRouterInterface(String routerId, String subNetId, String region, String token, String vdc); String allocateFloatingIP(String payload, String region, String token, String vdc); String getFloatingIPs(String region, String token, String vdc, String dd); void disAllocateFloatingIP(String region, String token, String vdc, String floatingIp); String assignFloatingIP(String serverId, String floatingIP, String region, String token, String vdc); String createNetwork(String payload, String region, String token, String vdc); String createRouter(RouterInstance router, String region, String token, String vdc); String createServer(String payload, String region, String token, String vdc); String createSubNet(SubNetworkInstance subNet, String region, String token, String vdc); String deleteNetwork(String networkId, String region, String token, String vdc); String deleteRouter(String routerId, String region, String token, String vdc); String deleteServer(String serverId, String region, String token, String vdc); void deleteSubNetwork(String idSubNet, String region, String vdc, String token); String getFloatingIP(PaasManagerUser user, String region); String getNetworkDetails(String networkId, String region, String token, String vdc); String getSubNetworkDetails(String subNetworkId, String region, String token, String vdc); String getNetworks(String region, String token, String vdc); String getServer(String serverId, String region, String token, String vdc); boolean existsServerForDelete(String serverId, String region, String token, String vdc); String listServers(String region, String token, String vdc); String removeInterface(RouterInstance router, String net, String region, String token, String vdc); String getAbsoluteLimits(PaasManagerUser user, String region); String listNetworks(PaasManagerUser user, String region); String listSubNetworks(PaasManagerUser user, String region); String listPorts(PaasManagerUser user, String region); String deleteInterfaceToPublicRouter(PaasManagerUser user, NetworkInstance net, String region); OpenStackRegion getOpenStackRegion(); void setOpenStackRegion(OpenStackRegion openStackRegion); void setOpenOperationUtil(OpenOperationUtil openOperationUtil); void setOpenStackConfigUtil(OpenStackConfigUtil openStackConfigUtil); String joinNetworks(NetworkInstance networkInstance, NetworkInstance networkInstance2, String token);  }