@Test( dependsOnMethods = { "testAddPublicKey", "testAllocateIpAddress", "testCreateVolume", "resolveImageAndInstanceType" }) public void testCreateInstanceWithIpAndVolume() throws Exception { String name = TAG + "1"; killInstance(name); instance2 = connection.createInstanceInLocation( location.getId(), name, image.getId(), instanceType.getId(), attachIp(ip.getId()) .authorizePublicKey(key.getName()) .mountVolume(volume.getId(), "/mnt")); assertBeginState(instance2, name); assertIpHostAndStatusNEW(instance2); blockUntilRunning(instance2); instance2 = assertRunning(instance2, name); volume = connection.getVolume(volume.getId()); assertEquals(volume.getInstanceId(), instance2.getId()); refreshIpAndReturnAllAddresses(); assertEquals(ip.getInstanceId(), instance2.getId()); assertEquals(ip.getIp(), instance2.getIp()); sshAndDf( new IPSocket(instance2.getIp(), 22), new Credentials("idcuser", keyPair.get("private"))); }
@Test public void testGetVolume() throws Exception { Set<? extends Volume> response = connection.listVolumes(); assertNotNull(response); if (response.size() > 0) { Volume image = Iterables.get(response, 0); assertEquals(connection.getVolume(image.getId()).getId(), image.getId()); } }
@Test(dependsOnMethods = "testResolveVolumeOffering") public void testCreateVolume() throws Exception { try { volume = connection.createVolumeInLocation( location.getId(), TAG, FORMAT, cheapestStorage.getName(), cheapestStorage.getId()); // wait up to 5 minutes for this to become "unmounted" assert new RetryablePredicate<Volume>( new VolumeUnmounted(connection), 300, 5, TimeUnit.SECONDS) .apply(volume); } catch (IllegalStateException e) { int code = HttpResponseException.class.cast(e.getCause()).getResponse().getStatusCode(); if (code == 409 || code == 500) { Set<? extends Volume> volumes = connection.listVolumes(); try { volume = Iterables.find( volumes, new Predicate<Volume>() { @Override public boolean apply(Volume input) { return input.getState() == Volume.State.UNMOUNTED; } }); } catch (NoSuchElementException ex) { killInstance(TAG + 1); } } else { throw e; } } assertEquals(volume.getInstanceId(), null); assertEquals(volume.getLocation(), location.getId()); final String id = volume.getId(); Set<? extends Volume> allVolumes = connection.listVolumes(); // refresh volume as it may have been just created volume = Iterables.find( allVolumes, new Predicate<Volume>() { @Override public boolean apply(Volume input) { return input.getId().equals(id); } }); assert (allVolumes.contains(volume)) : String.format("volume %s not in %s", volume, volume); }
@AfterTest(groups = {"live"}) void tearDown() { if (volume != null) try { connection.deleteVolume(volume.getId()); } catch (Exception e) { } if (ip != null) try { connection.releaseAddress(ip.getId()); } catch (Exception e) { } if (key != null) try { connection.deleteKey(key.getName()); } catch (Exception e) { } if (instance != null) try { connection.deleteInstance(instance.getId()); } catch (Exception e) { } if (instance2 != null) try { connection.deleteInstance(instance2.getId()); } catch (Exception e) { } }
@Override public boolean apply(Volume input) { if ("0".equals(input.getInstanceId())) input.setInstanceId(null); if (emptyString.equals(input.getProductCodes())) input.getProductCodes().clear(); return true; }