NovaApi novaApi = context.unwrapApi(NovaApi.class);VolumeApi volumeApi = novaApi.getVolumeExtensionForZone(region).get(); VolumeAttachmentApi volumeAttachmentApi = novaApi.getVolumeAttachmentExtensionForZone(region).get(); volumeAttachmentApi.listAttachmentsOnServer(serverId)
@Test(dependsOnMethods = "testGetAttachment") public void testDetachVolume() throws TimeoutException { volumeAttachmentApi.detachVolumeFromServer(volume.getId(), server.getId()); // Wait for the volume to become Detached (aka Available) before moving on if (!VolumePredicates.awaitAvailable(volumeApi).apply(volume)) { throw new TimeoutException("Timeout on volume: " + volume); } VolumeAttachment volumeAttachment = volumeAttachmentApi .getAttachmentForVolumeOnServer(volume.getId(), server.getId()); assertNull(volumeAttachment); } }
volumeAttachmentApi.get().listAttachmentsOnServer(serverId).toSet(); assertNotNull(attachments); final int before = attachments.size(); VolumeAttachment testAttachment = volumeAttachmentApi.get().attachVolumeToServerAsDevice( testVolume.getId(), serverId, "/dev/vdf"); assertNotNull(testAttachment.getId()); attachments = volumeAttachmentApi.get().listAttachmentsOnServer(serverId).toSet(); assertNotNull(attachments); assertEquals(attachments.size(), before + 1); for (VolumeAttachment att : attachments) { VolumeAttachment details = volumeAttachmentApi.get() .getAttachmentForVolumeOnServer(att.getVolumeId(), serverId); assertNotNull(details); assertNotNull(details.getId()); volumeAttachmentApi.get().detachVolumeFromServer(testVolume.getId(), serverId); assertTrue(retry(new Predicate<VolumeAttachmentApi>() { public boolean apply(VolumeAttachmentApi volumeAttachmentApi) {
public void testGetAttachmentFail() { URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/instance-1/os-volume_attachments/1"); VolumeAttachmentApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, authenticatedGET().endpoint(endpoint).build(), HttpResponse.builder().statusCode(404).build() ).getVolumeAttachmentExtensionForZone("az-1.region-a.geo-1").get(); assertNull(api.getAttachmentForVolumeOnServer("1", "instance-1")); }
@Test public void testAttachVolume() throws TimeoutException { VolumeAttachment volumeAttachment = volumeAttachmentApi .attachVolumeToServerAsDevice(volume.getId(), server.getId(), deviceId); // Wait for the volume to become Attached (aka In Use) before moving on if (!VolumePredicates.awaitInUse(volumeApi).apply(volume)) { throw new TimeoutException("Timeout on volume: " + volume); } assertEquals(volumeAttachment.getVolumeId(), volume.getId()); assertEquals(volumeAttachment.getServerId(), server.getId()); // we can't assert the device because, depending on the implementation, the passed in device may be ignored // and the implementation just picks a device itself }
public void testDetachVolumeFail() { URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/instance-1/os-volume_attachments/1"); VolumeAttachmentApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, authenticatedGET().endpoint(endpoint).method("DELETE").build(), HttpResponse.builder().statusCode(404).build() ).getVolumeAttachmentExtensionForZone("az-1.region-a.geo-1").get(); assertFalse(api.detachVolumeFromServer("1", "instance-1")); }
@Test(dependsOnMethods = "testListAttachments") public void testGetAttachment() { VolumeAttachment volumeAttachment = volumeAttachmentApi .getAttachmentForVolumeOnServer(volume.getId(), server.getId()); assertEquals(volumeAttachment.getVolumeId(), volume.getId()); assertEquals(volumeAttachment.getServerId(), server.getId()); }
@Test(expectedExceptions = ResourceNotFoundException.class) public void testAttachVolumeFail() { URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/instance-1/os-volume_attachments"); VolumeAttachmentApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, authenticatedGET().endpoint(endpoint).method("POST") .payload(payloadFromStringWithContentType("{\"volumeAttachment\":{\"volumeId\":\"1\",\"device\":\"/dev/vdc\"}}", MediaType.APPLICATION_JSON)).endpoint(endpoint).build(), HttpResponse.builder().statusCode(404).build() ).getVolumeAttachmentExtensionForZone("az-1.region-a.geo-1").get(); api.attachVolumeToServerAsDevice("1", "instance-1","/dev/vdc"); }
public void testDetachVolume() { URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/instance-1/os-volume_attachments/1"); VolumeAttachmentApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, authenticatedGET().endpoint(endpoint).method("DELETE").build(), HttpResponse.builder().statusCode(200).payload(payloadFromResource("/attachment_details.json")).build() ).getVolumeAttachmentExtensionForZone("az-1.region-a.geo-1").get(); assertTrue(api.detachVolumeFromServer("1", "instance-1")); }
public boolean apply(VolumeAttachmentApi volumeAttachmentApi) { return volumeAttachmentApi.listAttachmentsOnServer(serverId).size() > before; } }, 60 * 1000L).apply(volumeAttachmentApi.get()));
public void testGetAttachment() { URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v2/3456/servers/instance-1/os-volume_attachments/1"); VolumeAttachmentApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, authenticatedGET().endpoint(endpoint).build(), HttpResponse.builder().statusCode(200).payload(payloadFromResource("/attachment_details.json")).build() ).getVolumeAttachmentApi("az-1.region-a.geo-1").get(); VolumeAttachment attachment = api.getAttachmentForVolumeOnServer("1", "instance-1"); assertEquals(attachment, testAttachment()); }
public void testAttachVolume() { URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/instance-1/os-volume_attachments"); VolumeAttachmentApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, authenticatedGET().endpoint(endpoint).method("POST") .payload(payloadFromStringWithContentType("{\"volumeAttachment\":{\"volumeId\":\"1\",\"device\":\"/dev/vdc\"}}", MediaType.APPLICATION_JSON)).endpoint(endpoint).build(), HttpResponse.builder().statusCode(200).payload(payloadFromResource("/attachment_details.json")).build() ).getVolumeAttachmentExtensionForZone("az-1.region-a.geo-1").get(); VolumeAttachment result = api.attachVolumeToServerAsDevice("1", "instance-1", "/dev/vdc"); assertEquals(result, testAttachment()); }
public void testDetachVolume() { URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v2/3456/servers/instance-1/os-volume_attachments/1"); VolumeAttachmentApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, authenticatedGET().endpoint(endpoint).method("DELETE").build(), HttpResponse.builder().statusCode(200).payload(payloadFromResource("/attachment_details.json")).build() ).getVolumeAttachmentApi("az-1.region-a.geo-1").get(); assertTrue(api.detachVolumeFromServer("1", "instance-1")); }
public boolean apply(VolumeAttachmentApi volumeAttachmentApi) { return volumeAttachmentApi.listAttachmentsOnServer(serverId).size() == before; } }, 60 * 1000L).apply(volumeAttachmentApi.get()));
public void testGetAttachment() { URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/instance-1/os-volume_attachments/1"); VolumeAttachmentApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, authenticatedGET().endpoint(endpoint).build(), HttpResponse.builder().statusCode(200).payload(payloadFromResource("/attachment_details.json")).build() ).getVolumeAttachmentExtensionForZone("az-1.region-a.geo-1").get(); VolumeAttachment attachment = api.getAttachmentForVolumeOnServer("1", "instance-1"); assertEquals(attachment, testAttachment()); }
public void testAttachVolume() { URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v2/3456/servers/instance-1/os-volume_attachments"); VolumeAttachmentApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, authenticatedGET().endpoint(endpoint).method("POST") .payload(payloadFromStringWithContentType("{\"volumeAttachment\":{\"volumeId\":\"1\",\"device\":\"/dev/vdc\"}}", MediaType.APPLICATION_JSON)).endpoint(endpoint).build(), HttpResponse.builder().statusCode(200).payload(payloadFromResource("/attachment_details.json")).build() ).getVolumeAttachmentApi("az-1.region-a.geo-1").get(); VolumeAttachment result = api.attachVolumeToServerAsDevice("1", "instance-1", "/dev/vdc"); assertEquals(result, testAttachment()); }
@Test(expectedExceptions = AuthorizationException.class) public void testListAttachmentsFail() { URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/instance-2/os-volume_attachments"); VolumeAttachmentApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, authenticatedGET().endpoint(endpoint).build(), HttpResponse.builder().statusCode(401).build() ).getVolumeAttachmentExtensionForZone("az-1.region-a.geo-1").get(); api.listAttachmentsOnServer("instance-2"); }
@Test(dependsOnMethods = "testAttachVolume") public void testListAttachments() { FluentIterable<VolumeAttachment> volumeAttachments = volumeAttachmentApi .listAttachmentsOnServer(server.getId()); assertEquals(volumeAttachments.size(), 1); VolumeAttachment volumeAttachment = volumeAttachments.get(0); assertEquals(volumeAttachment.getVolumeId(), volume.getId()); assertEquals(volumeAttachment.getServerId(), server.getId()); }
public void testListAttachments() { URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/instance-1/os-volume_attachments"); VolumeAttachmentApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, authenticatedGET().endpoint(endpoint).build(), HttpResponse.builder().statusCode(200).payload(payloadFromResource("/attachment_list.json")).build() ).getVolumeAttachmentExtensionForZone("az-1.region-a.geo-1").get(); Set<? extends VolumeAttachment> attachments = api.listAttachmentsOnServer("instance-1").toSet(); assertEquals(attachments, ImmutableSet.of(testAttachment())); // double-check individual fields VolumeAttachment attachment = Iterables.getOnlyElement(attachments); assertEquals(attachment.getDevice(), "/dev/vdc"); assertEquals(attachment.getServerId(), "b4785058-cb80-491b-baa3-e4ee6546450e"); assertEquals(attachment.getId(), "1"); assertEquals(attachment.getVolumeId(), "1"); }
public void testListAttachments() { URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v2/3456/servers/instance-1/os-volume_attachments"); VolumeAttachmentApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, authenticatedGET().endpoint(endpoint).build(), HttpResponse.builder().statusCode(200).payload(payloadFromResource("/attachment_list.json")).build() ).getVolumeAttachmentApi("az-1.region-a.geo-1").get(); Set<? extends VolumeAttachment> attachments = api.listAttachmentsOnServer("instance-1").toSet(); assertEquals(attachments, ImmutableSet.of(testAttachment())); // double-check individual fields VolumeAttachment attachment = Iterables.getOnlyElement(attachments); assertEquals(attachment.getDevice(), "/dev/vdc"); assertEquals(attachment.getServerId(), "b4785058-cb80-491b-baa3-e4ee6546450e"); assertEquals(attachment.getId(), "1"); assertEquals(attachment.getVolumeId(), "1"); }