Implements VirtualMachineAPI deallocate operation

https://docs.microsoft.com/en-us/rest/api/compute/virtualmachines/deallocate

Adds missing mock test
Fixes returning codes from API methods to 202
This commit is contained in:
Dani Estevez 2018-06-29 16:42:38 -04:00 committed by Ignasi Barrera
parent 975aca5346
commit 1bd3b8f9df
3 changed files with 34 additions and 12 deletions

View File

@ -19,7 +19,6 @@ package org.jclouds.azurecompute.arm.features;
import java.net.URI;
import java.util.List;
import java.util.Map;
import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
@ -114,6 +113,11 @@ public interface VirtualMachineApi {
@Path("/{name}/powerOff")
void stop(@PathParam("name") String name);
@Named("DeallocateVirtualMachine")
@POST
@Path("/{name}/deallocate")
void deallocate(@PathParam("name") String name);
@Named("generalize")
@POST
@Path("/{name}/generalize")

View File

@ -156,13 +156,20 @@ public class VirtualMachineApiLiveTest extends BaseAzureComputeApiLiveTest {
assertEquals(vm.properties().storageProfile().dataDisks().size(), oldDataDisks.size() + 1);
}
@Test(dependsOnMethods = "testUpdate")
@Test(dependsOnMethods = "testRestart")
public void testStop() {
api().stop(vmName);
assertTrue(stateReached(vmName, PowerState.STOPPED), "stop operation did not complete in the configured timeout");
}
@Test(dependsOnMethods = "testStop")
@Test(dependsOnMethods = "testUpdate")
public void testDeallocate() {
api().deallocate(vmName);
assertTrue(stateReached(vmName, PowerState.DEALLOCATED),
"deallocate operation did not complete in the configured timeout");
}
@Test(dependsOnMethods = "testDeallocate")
public void testRestart() {
api().start(vmName);
assertTrue(stateReached(vmName, PowerState.RUNNING), "start operation did not complete in the configured timeout");

View File

@ -16,6 +16,12 @@
*/
package org.jclouds.azurecompute.arm.features;
import static com.google.common.collect.Iterables.isEmpty;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
import java.net.URI;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
@ -53,12 +59,6 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.squareup.okhttp.mockwebserver.MockResponse;
import static com.google.common.collect.Iterables.isEmpty;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
@Test(groups = "unit", testName = "VirtualMachineApiMockTest", singleThreaded = true)
public class VirtualMachineApiMockTest extends BaseAzureComputeApiMockTest {
@ -213,7 +213,7 @@ public class VirtualMachineApiMockTest extends BaseAzureComputeApiMockTest {
}
public void testStart() throws Exception {
server.enqueue(new MockResponse().setResponseCode(204));
server.enqueue(response202WithHeader());
final VirtualMachineApi vmAPI = api.getVirtualMachineApi("groupname");
@ -224,7 +224,7 @@ public class VirtualMachineApiMockTest extends BaseAzureComputeApiMockTest {
}
public void testRestart() throws Exception {
server.enqueue(new MockResponse().setResponseCode(204));
server.enqueue(response202WithHeader());
final VirtualMachineApi vmAPI = api.getVirtualMachineApi("groupname");
@ -235,7 +235,7 @@ public class VirtualMachineApiMockTest extends BaseAzureComputeApiMockTest {
}
public void testStop() throws Exception {
server.enqueue(new MockResponse().setResponseCode(204));
server.enqueue(response202WithHeader());
final VirtualMachineApi vmAPI = api.getVirtualMachineApi("groupname");
@ -245,6 +245,17 @@ public class VirtualMachineApiMockTest extends BaseAzureComputeApiMockTest {
+ "/virtualMachines/windowsmachine/powerOff?api-version=2016-04-30-preview");
}
public void testDeallocate() throws Exception {
server.enqueue(response202WithHeader());
final VirtualMachineApi vmAPI = api.getVirtualMachineApi("groupname");
vmAPI.deallocate("windowsmachine");
assertSent(server, "POST", "/subscriptions/SUBSCRIPTIONID/resourceGroups/groupname/providers/Microsoft.Compute"
+ "/virtualMachines/windowsmachine/deallocate?api-version=2016-04-30-preview");
}
public void testGeneralize() throws Exception {
server.enqueue(new MockResponse().setResponseCode(200));
final VirtualMachineApi vmAPI = api.getVirtualMachineApi("groupname");