@BeforeGroups(groups = {"integration", "live"}) @Override public void setupContext() { super.setupContext(); gocontext = view.unwrap(); client = gocontext.getApi(); serverLatestJobCompleted = retry(new ServerLatestJobCompleted(client.getJobServices()), 800, 20, SECONDS); loadBalancerLatestJobCompleted = retry(new LoadBalancerLatestJobCompleted(client.getJobServices()), 800, 20, SECONDS); }
/** Tests server start, reboot and deletion. Also verifies IP services and job services. */ @Test(enabled = true) public void testServerLifecycle() { int serverCountBeforeTest = client.getServerServices().getServerList().size(); final String nameOfServer = "Server" + String.valueOf(new Date().getTime()).substring(6); serversToDeleteAfterTheTests.add(nameOfServer); Set<Ip> availableIps = client.getIpServices().getUnassignedPublicIpList(); Ip availableIp = Iterables.getLast(availableIps); String ram = Iterables.get(client.getServerServices().getRamSizes(), 0).getName(); Server createdServer = client .getServerServices() .addServer( nameOfServer, "GSI-f8979644-e646-4711-ad58-d98a5fa3612c", ram, availableIp.getIp()); assertNotNull(createdServer); assert serverLatestJobCompleted.apply(createdServer); // get server by name Set<Server> response = client.getServerServices().getServersByName(nameOfServer); assert (response.size() == 1); // restart the server client.getServerServices().power(nameOfServer, PowerCommand.RESTART); Set<Job> jobs = client.getJobServices().getJobsForObjectName(nameOfServer); assert ("RestartVirtualServer".equals(Iterables.getLast(jobs).getCommand().getName())); assert serverLatestJobCompleted.apply(createdServer); int serverCountAfterAddingOneServer = client.getServerServices().getServerList().size(); assert serverCountAfterAddingOneServer == serverCountBeforeTest + 1 : "There should be +1 increase in the number of servers since the test started"; // delete the server client.getServerServices().deleteByName(nameOfServer); jobs = client.getJobServices().getJobsForObjectName(nameOfServer); assert ("DeleteVirtualServer".equals(Iterables.getLast(jobs).getCommand().getName())); assert serverLatestJobCompleted.apply(createdServer); int serverCountAfterDeletingTheServer = client.getServerServices().getServerList().size(); assert serverCountAfterDeletingTheServer == serverCountBeforeTest : "There should be the same # of servers as since the test started"; // make sure that IP is put back to "unassigned" assert client.getIpServices().getUnassignedIpList().contains(availableIp); }
/** * Starts a servers, verifies that jobs are created correctly and an be retrieved from the job * services */ @Test(dependsOnMethods = "testServerLifecycle", enabled = true) public void testJobs() { final String nameOfServer = "Server" + String.valueOf(new Date().getTime()).substring(6); serversToDeleteAfterTheTests.add(nameOfServer); Set<Ip> availableIps = client.getIpServices().getUnassignedPublicIpList(); String ram = Iterables.get(client.getServerServices().getRamSizes(), 0).getName(); Server createdServer = client .getServerServices() .addServer( nameOfServer, "GSI-f8979644-e646-4711-ad58-d98a5fa3612c", ram, Iterables.getLast(availableIps).getIp()); assert serverLatestJobCompleted.apply(createdServer); // restart the server client.getServerServices().power(nameOfServer, PowerCommand.RESTART); Set<Job> jobs = client.getJobServices().getJobsForObjectName(nameOfServer); Job latestJob = Iterables.getLast(jobs); Long latestJobId = latestJob.getId(); Job latestJobFetched = Iterables.getOnlyElement(client.getJobServices().getJobsById(latestJobId)); assert latestJob.equals(latestJobFetched) : "Job and its representation found by ID don't match"; long[] idsOfAllJobs = new long[jobs.size()]; int i = 0; for (Job job : jobs) { idsOfAllJobs[i++] = job.getId(); } Set<Job> jobsFetched = client.getJobServices().getJobsById(idsOfAllJobs); assert jobsFetched.size() == jobs.size() : format( "Number of jobs fetched by ids doesn't match the number of jobs " + "requested. Requested/expected: %d. Found: %d.", jobs.size(), jobsFetched.size()); // delete the server client.getServerServices().deleteByName(nameOfServer); }
public void testSync() throws SecurityException, NoSuchMethodException, InterruptedException, ExecutionException { assert syncClient.getImageServices() != null; assert syncClient.getIpServices() != null; assert syncClient.getJobServices() != null; assert syncClient.getLoadBalancerServices() != null; assert syncClient.getServerServices() != null; }
/** Tests common load balancer operations. Also verifies IP services and job services. */ @Test(enabled = true) public void testLoadBalancerLifecycle() { int lbCountBeforeTest = client.getLoadBalancerServices().getLoadBalancerList().size(); final String nameOfLoadBalancer = "LoadBalancer" + String.valueOf(new Date().getTime()).substring(6); loadBalancersToDeleteAfterTest.add(nameOfLoadBalancer); Set<Ip> availableIps = client.getIpServices().getUnassignedPublicIpList(); if (availableIps.size() < 4) throw new SkipException("Not enough available IPs (4 needed) to run the test"); Iterator<Ip> ipIterator = availableIps.iterator(); Ip vip = ipIterator.next(); Ip realIp1 = ipIterator.next(); Ip realIp2 = ipIterator.next(); Ip realIp3 = ipIterator.next(); AddLoadBalancerOptions options = new AddLoadBalancerOptions.Builder() .create(LoadBalancerType.LEAST_CONNECTED, LoadBalancerPersistenceType.SOURCE_ADDRESS); LoadBalancer createdLoadBalancer = client .getLoadBalancerServices() .addLoadBalancer( nameOfLoadBalancer, IpPortPair.builder().ip(vip).port(80).build(), Arrays.asList( IpPortPair.builder().ip(realIp1).port(80).build(), IpPortPair.builder().ip(realIp2).port(80).build()), options); assertNotNull(createdLoadBalancer); assert loadBalancerLatestJobCompleted.apply(createdLoadBalancer); // get load balancer by name Set<LoadBalancer> response = client.getLoadBalancerServices().getLoadBalancersByName(nameOfLoadBalancer); assert (response.size() == 1); createdLoadBalancer = Iterables.getOnlyElement(response); assertNotNull(createdLoadBalancer.getRealIpList()); assertEquals(createdLoadBalancer.getRealIpList().size(), 2); assertNotNull(createdLoadBalancer.getVirtualIp()); assertEquals(createdLoadBalancer.getVirtualIp().getIp().getIp(), vip.getIp()); LoadBalancer editedLoadBalancer = client .getLoadBalancerServices() .editLoadBalancerNamed( nameOfLoadBalancer, Arrays.asList(IpPortPair.builder().ip(realIp3).port(8181).build())); assert loadBalancerLatestJobCompleted.apply(editedLoadBalancer); assertNotNull(editedLoadBalancer.getRealIpList()); assertEquals(editedLoadBalancer.getRealIpList().size(), 1); assertEquals( Iterables.getOnlyElement(editedLoadBalancer.getRealIpList()).getIp().getIp(), realIp3.getIp()); int lbCountAfterAddingOneServer = client.getLoadBalancerServices().getLoadBalancerList().size(); assert lbCountAfterAddingOneServer == lbCountBeforeTest + 1 : "There should be +1 increase in the number of load balancers since the test started"; // delete the load balancer client.getLoadBalancerServices().deleteByName(nameOfLoadBalancer); Set<Job> jobs = client.getJobServices().getJobsForObjectName(nameOfLoadBalancer); assert ("DeleteLoadBalancer".equals(Iterables.getLast(jobs).getCommand().getName())); assert loadBalancerLatestJobCompleted.apply(createdLoadBalancer); int lbCountAfterDeletingTheServer = client.getLoadBalancerServices().getLoadBalancerList().size(); assert lbCountAfterDeletingTheServer == lbCountBeforeTest : "There should be the same # of load balancers as since the test started"; }