Skip to content

Commit

Permalink
Merge pull request #499 from khoale-azure/extension-img
Browse files Browse the repository at this point in the history
Adding VM extension image tests and payloads
  • Loading branch information
Jianghao Lu committed Aug 19, 2015
2 parents eaa5491 + 79329a5 commit 0b4853d
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
//
// Copyright (c) Microsoft. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

package com.microsoft.azure.utility.compute;

import com.microsoft.azure.management.compute.models.*;
import org.apache.commons.logging.LogFactory;
import org.junit.*;

import java.util.ArrayList;

public class VMExtensionImageTest extends ComputeTestBase {
private static String vmExtensionImageVersion = "2.0";
private static String vmExtensionImageType = "VMAccessAgent";

static {
log = LogFactory.getLog(VMExtensionImageTest.class);
}

@BeforeClass
public static void setup() throws Exception {
ensureClientsInitialized();
}

@AfterClass
public static void cleanup() throws Exception {
log.debug("after class, clean resource group: " + m_rgName);
cleanupResourceGroup();
}

@Before
public void beforeTest() throws Exception {
setupTest();
createOrUpdateResourceGroup(ComputeTestBase.m_rgName);
}

@After
public void afterTest() throws Exception {
resetTest();
}

private static VirtualMachineExtensionImageGetParameters parameters;

static {
parameters = new VirtualMachineExtensionImageGetParameters();
parameters.setLocation(m_location);
parameters.setPublisherName("Microsoft.Compute");
parameters.setType(vmExtensionImageType);
parameters.setVersion(vmExtensionImageVersion);
}

@Test
public void testExtensionImageGet() throws Exception {
VirtualMachineExtensionImageGetResponse vmExtensionImageResponse = computeManagementClient.getVirtualMachineExtensionImagesOperations().get(parameters);
Assert.assertEquals(vmExtensionImageVersion, vmExtensionImageResponse.getVirtualMachineExtensionImage().getName());
Assert.assertEquals(m_location.toLowerCase(), vmExtensionImageResponse.getVirtualMachineExtensionImage().getLocation().toLowerCase());
Assert.assertEquals("Windows", vmExtensionImageResponse.getVirtualMachineExtensionImage().getOperatingSystem());
Assert.assertEquals("IaaS", vmExtensionImageResponse.getVirtualMachineExtensionImage().getComputeRole());

Assert.assertEquals(false, vmExtensionImageResponse.getVirtualMachineExtensionImage().isVMScaleSetEnabled());
Assert.assertEquals(false, vmExtensionImageResponse.getVirtualMachineExtensionImage().isSupportsMultipleExtensions());
}

@Test
public void testExtensionImageListTypes() throws Exception {
VirtualMachineImageResourceList vmExtensionImgList = computeManagementClient.getVirtualMachineExtensionImagesOperations().listTypes(parameters);

Assert.assertTrue(vmExtensionImgList.getResources().size() > 0);
Assert.assertTrue(countVMExtensionImage(vmExtensionImgList, vmExtensionImageType) > 0);
}

@Test
public void testExtensionImageListVersionsNoFilter() throws Exception {
VirtualMachineImageResourceList vmExtensionImgList = computeManagementClient.getVirtualMachineExtensionImagesOperations().listVersions(parameters);

Assert.assertTrue(vmExtensionImgList.getResources().size() > 0);
Assert.assertTrue(countVMExtensionImage(vmExtensionImgList, vmExtensionImageVersion) > 0);
}

@Test
public void TestExtImgListVersionsFilters() throws Exception {
VirtualMachineExtensionImageListVersionsParameters listVersionsParamers = new VirtualMachineExtensionImageListVersionsParameters();
listVersionsParamers.setLocation(parameters.getLocation());
listVersionsParamers.setType(parameters.getType());
listVersionsParamers.setPublisherName(parameters.getPublisherName());

// Filter: startswith - Positive Test
listVersionsParamers.setFilterExpression(String.format("$filter=startswith(name,'%s')", vmExtensionImageVersion));
VirtualMachineImageResourceList vmExtensionImgList = computeManagementClient.getVirtualMachineExtensionImagesOperations().listVersions(listVersionsParamers);
Assert.assertTrue(vmExtensionImgList.getResources().size() > 0);
Assert.assertTrue(countVMExtensionImage(vmExtensionImgList, vmExtensionImageVersion) != 0);

// Filter: startswith - Negative Test
listVersionsParamers.setFilterExpression("$filter=startswith(name,'1.0')");
vmExtensionImgList = computeManagementClient.getVirtualMachineExtensionImagesOperations().listVersions(listVersionsParamers);
Assert.assertTrue(vmExtensionImgList.getResources().size() == 0);
Assert.assertTrue(countVMExtensionImage(vmExtensionImgList, vmExtensionImageVersion) == 0);

// Filter: top - Positive Test
listVersionsParamers.setFilterExpression("$top=1");
vmExtensionImgList = computeManagementClient.getVirtualMachineExtensionImagesOperations().listVersions(listVersionsParamers);
Assert.assertTrue(vmExtensionImgList.getResources().size() == 1);
Assert.assertTrue(countVMExtensionImage(vmExtensionImgList, vmExtensionImageVersion) != 0);

// Filter: top - Negative Test
listVersionsParamers.setFilterExpression("$top=0");
vmExtensionImgList = computeManagementClient.getVirtualMachineExtensionImagesOperations().listVersions(listVersionsParamers);
Assert.assertTrue(vmExtensionImgList.getResources().size() == 0);
}

private int countVMExtensionImage(VirtualMachineImageResourceList vmExtensionImgList, String vmExtensionImageType) {
int cnt = 0;
ArrayList<VirtualMachineImageResource> list = vmExtensionImgList.getResources();
for (VirtualMachineImageResource resource : list) {
if (resource.getName().equals(vmExtensionImageType)) {
cnt++;
}
}
return cnt;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"User-Agent":"Azure-SDK-For-Java","Method":"PUT","Uri":"/subscriptions/24fb23e3-6ba3-41f0-9b6e-e41131d5d61e/resourcegroups/javatestrgnamvwy?api-version=2014-04-01-preview","Content-Type":"application/json; charset=utf-8"},{"x-ms-ratelimit-remaining-subscription-writes":"1173","Pragma":"no-cache","StatusCode":"201","x-ms-correlation-request-id":"585fe662-20f6-46b9-b975-8f3d1091a5fd","Date":"Wed, 19 Aug 2015 01:05:04 GMT","Strict-Transport-Security":"max-age=31536000; includeSubDomains","Cache-Control":"no-cache","x-ms-routing-request-id":"WESTUS:20150819T010505Z:585fe662-20f6-46b9-b975-8f3d1091a5fd","Expires":"-1","Content-Length":"192","x-ms-request-id":"585fe662-20f6-46b9-b975-8f3d1091a5fd","Body":"{\"id\":\"/subscriptions/24fb23e3-6ba3-41f0-9b6e-e41131d5d61e/resourceGroups/javatestrgnamvwy\",\"name\":\"javatestrgnamvwy\",\"location\":\"southeastasia\",\"properties\":{\"provisioningState\":\"Succeeded\"}}","Content-Type":"application/json; charset=utf-8"},{"User-Agent":"Azure-SDK-For-Java","Method":"GET","Uri":"/subscriptions/24fb23e3-6ba3-41f0-9b6e-e41131d5d61e/providers/Microsoft.Compute/locations/SouthEastAsia/publishers/Microsoft.Compute/artifacttypes/vmextension/types/VMAccessAgent/versions?api-version=2015-06-15&$filter=startswith(name,'2.0')","Content-Type":"application/json"},{"Transfer-Encoding":"chunked","Server":"Microsoft-HTTPAPI/2.0","Pragma":"no-cache","x-ms-ratelimit-remaining-subscription-reads":"14972","StatusCode":"200","x-ms-correlation-request-id":"226d2dc9-0948-4b43-9f9e-0a03437a8a10","Date":"Wed, 19 Aug 2015 01:05:06 GMT","Strict-Transport-Security":"max-age=31536000; includeSubDomains","Cache-Control":"no-cache","x-ms-routing-request-id":"WESTUS:20150819T010506Z:226d2dc9-0948-4b43-9f9e-0a03437a8a10","Vary":"Accept-Encoding","Expires":"-1","Content-Length":"273","x-ms-request-id":"b85ae88c-ddfa-427c-a723-39a4df22772f","Body":"[\r\n {\r\n \"location\": \"southeastasia\",\r\n \"name\": \"2.0\",\r\n \"id\": \"/Subscriptions/24fb23e3-6ba3-41f0-9b6e-e41131d5d61e/Providers/Microsoft.Compute/Locations/southeastasia/Publishers/Microsoft.Compute/ArtifactTypes/VMExtension/Types/VMAccessAgent/Versions/2.0\"\r\n }\r\n]","Content-Type":"application/json; charset=utf-8"},{"User-Agent":"Azure-SDK-For-Java","Method":"GET","Uri":"/subscriptions/24fb23e3-6ba3-41f0-9b6e-e41131d5d61e/providers/Microsoft.Compute/locations/SouthEastAsia/publishers/Microsoft.Compute/artifacttypes/vmextension/types/VMAccessAgent/versions?api-version=2015-06-15&$filter=startswith(name,'1.0')","Content-Type":"application/json"},{"Transfer-Encoding":"chunked","Server":"Microsoft-HTTPAPI/2.0","Pragma":"no-cache","x-ms-ratelimit-remaining-subscription-reads":"14971","StatusCode":"200","x-ms-correlation-request-id":"1c7865ee-6dbf-4a47-b983-d78f5cbf797c","Date":"Wed, 19 Aug 2015 01:05:07 GMT","Strict-Transport-Security":"max-age=31536000; includeSubDomains","Cache-Control":"no-cache","x-ms-routing-request-id":"WESTUS:20150819T010507Z:1c7865ee-6dbf-4a47-b983-d78f5cbf797c","Vary":"Accept-Encoding","Expires":"-1","Content-Length":"2","x-ms-request-id":"5a552a7a-765c-49e9-9562-1577ca812397","Body":"[]","Content-Type":"application/json; charset=utf-8"},{"User-Agent":"Azure-SDK-For-Java","Method":"GET","Uri":"/subscriptions/24fb23e3-6ba3-41f0-9b6e-e41131d5d61e/providers/Microsoft.Compute/locations/SouthEastAsia/publishers/Microsoft.Compute/artifacttypes/vmextension/types/VMAccessAgent/versions?api-version=2015-06-15&$top=1","Content-Type":"application/json"},{"Transfer-Encoding":"chunked","Server":"Microsoft-HTTPAPI/2.0","Pragma":"no-cache","x-ms-ratelimit-remaining-subscription-reads":"14970","StatusCode":"200","x-ms-correlation-request-id":"a2793c2e-e072-4305-8481-c28e162f0a15","Date":"Wed, 19 Aug 2015 01:05:08 GMT","Strict-Transport-Security":"max-age=31536000; includeSubDomains","Cache-Control":"no-cache","x-ms-routing-request-id":"WESTUS:20150819T010508Z:a2793c2e-e072-4305-8481-c28e162f0a15","Vary":"Accept-Encoding","Expires":"-1","Content-Length":"273","x-ms-request-id":"ef7c37e4-81d7-4d79-b47c-1d6d695f33e0","Body":"[\r\n {\r\n \"location\": \"southeastasia\",\r\n \"name\": \"2.0\",\r\n \"id\": \"/Subscriptions/24fb23e3-6ba3-41f0-9b6e-e41131d5d61e/Providers/Microsoft.Compute/Locations/southeastasia/Publishers/Microsoft.Compute/ArtifactTypes/VMExtension/Types/VMAccessAgent/Versions/2.0\"\r\n }\r\n]","Content-Type":"application/json; charset=utf-8"},{"User-Agent":"Azure-SDK-For-Java","Method":"GET","Uri":"/subscriptions/24fb23e3-6ba3-41f0-9b6e-e41131d5d61e/providers/Microsoft.Compute/locations/SouthEastAsia/publishers/Microsoft.Compute/artifacttypes/vmextension/types/VMAccessAgent/versions?api-version=2015-06-15&$top=0","Content-Type":"application/json"},{"Transfer-Encoding":"chunked","Server":"Microsoft-HTTPAPI/2.0","Pragma":"no-cache","x-ms-ratelimit-remaining-subscription-reads":"14969","StatusCode":"200","x-ms-correlation-request-id":"cb12ac38-2631-48bd-bcdc-d2474468b814","Date":"Wed, 19 Aug 2015 01:05:09 GMT","Strict-Transport-Security":"max-age=31536000; includeSubDomains","Cache-Control":"no-cache","x-ms-routing-request-id":"WESTUS:20150819T010509Z:cb12ac38-2631-48bd-bcdc-d2474468b814","Vary":"Accept-Encoding","Expires":"-1","Content-Length":"2","x-ms-request-id":"c14fc4f5-ec9f-419e-b22a-302c397f5cc6","Body":"[]","Content-Type":"application/json; charset=utf-8"}]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"User-Agent":"Azure-SDK-For-Java","Method":"PUT","Uri":"/subscriptions/24fb23e3-6ba3-41f0-9b6e-e41131d5d61e/resourcegroups/javatestrgnybdfo?api-version=2014-04-01-preview","Content-Type":"application/json; charset=utf-8"},{"Transfer-Encoding":"chunked","x-ms-ratelimit-remaining-subscription-writes":"1184","Pragma":"no-cache","StatusCode":"200","x-ms-correlation-request-id":"3a8a654c-91af-4dae-b61f-6bf13c347b40","Date":"Wed, 19 Aug 2015 01:02:18 GMT","Strict-Transport-Security":"max-age=31536000; includeSubDomains","Cache-Control":"no-cache","x-ms-routing-request-id":"WESTUS:20150819T010219Z:3a8a654c-91af-4dae-b61f-6bf13c347b40","Vary":"Accept-Encoding","Expires":"-1","Content-Length":"192","x-ms-request-id":"3a8a654c-91af-4dae-b61f-6bf13c347b40","Body":"{\"id\":\"/subscriptions/24fb23e3-6ba3-41f0-9b6e-e41131d5d61e/resourceGroups/javatestrgnybdfo\",\"name\":\"javatestrgnybdfo\",\"location\":\"southeastasia\",\"properties\":{\"provisioningState\":\"Succeeded\"}}","Content-Type":"application/json; charset=utf-8"},{"User-Agent":"Azure-SDK-For-Java","Method":"GET","Uri":"/subscriptions/24fb23e3-6ba3-41f0-9b6e-e41131d5d61e/providers/Microsoft.Compute/locations/SouthEastAsia/publishers/Microsoft.Compute/artifacttypes/vmextension/types?api-version=2015-06-15","Content-Type":"application/json"},{"Transfer-Encoding":"chunked","Server":"Microsoft-HTTPAPI/2.0","Pragma":"no-cache","x-ms-ratelimit-remaining-subscription-reads":"14954","StatusCode":"200","x-ms-correlation-request-id":"b7e4b8d1-e47d-4681-a4e3-abc955b2cb11","Date":"Wed, 19 Aug 2015 01:02:20 GMT","Strict-Transport-Security":"max-age=31536000; includeSubDomains","Cache-Control":"no-cache","x-ms-routing-request-id":"WESTUS:20150819T010220Z:b7e4b8d1-e47d-4681-a4e3-abc955b2cb11","Vary":"Accept-Encoding","Expires":"-1","Content-Length":"553","x-ms-request-id":"2fbf610c-b2b6-4b2a-8a15-2f9f76bd3d19","Body":"[\r\n {\r\n \"location\": \"southeastasia\",\r\n \"name\": \"CustomScriptExtension\",\r\n \"id\": \"/Subscriptions/24fb23e3-6ba3-41f0-9b6e-e41131d5d61e/Providers/Microsoft.Compute/Locations/southeastasia/Publishers/Microsoft.Compute/ArtifactTypes/VMExtension/Types/CustomScriptExtension\"\r\n },\r\n {\r\n \"location\": \"southeastasia\",\r\n \"name\": \"VMAccessAgent\",\r\n \"id\": \"/Subscriptions/24fb23e3-6ba3-41f0-9b6e-e41131d5d61e/Providers/Microsoft.Compute/Locations/southeastasia/Publishers/Microsoft.Compute/ArtifactTypes/VMExtension/Types/VMAccessAgent\"\r\n }\r\n]","Content-Type":"application/json; charset=utf-8"}]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"User-Agent":"Azure-SDK-For-Java","Method":"PUT","Uri":"/subscriptions/24fb23e3-6ba3-41f0-9b6e-e41131d5d61e/resourcegroups/javatestrgnybdfo?api-version=2014-04-01-preview","Content-Type":"application/json; charset=utf-8"},{"Transfer-Encoding":"chunked","x-ms-ratelimit-remaining-subscription-writes":"1187","Pragma":"no-cache","StatusCode":"200","x-ms-correlation-request-id":"59222513-aadc-4ec2-a51f-ba44699e2d38","Date":"Wed, 19 Aug 2015 01:02:24 GMT","Strict-Transport-Security":"max-age=31536000; includeSubDomains","Cache-Control":"no-cache","x-ms-routing-request-id":"WESTUS:20150819T010224Z:59222513-aadc-4ec2-a51f-ba44699e2d38","Vary":"Accept-Encoding","Expires":"-1","Content-Length":"192","x-ms-request-id":"59222513-aadc-4ec2-a51f-ba44699e2d38","Body":"{\"id\":\"/subscriptions/24fb23e3-6ba3-41f0-9b6e-e41131d5d61e/resourceGroups/javatestrgnybdfo\",\"name\":\"javatestrgnybdfo\",\"location\":\"southeastasia\",\"properties\":{\"provisioningState\":\"Succeeded\"}}","Content-Type":"application/json; charset=utf-8"},{"User-Agent":"Azure-SDK-For-Java","Method":"GET","Uri":"/subscriptions/24fb23e3-6ba3-41f0-9b6e-e41131d5d61e/providers/Microsoft.Compute/locations/SouthEastAsia/publishers/Microsoft.Compute/artifacttypes/vmextension/types/VMAccessAgent/versions/2.0?api-version=2015-06-15","Content-Type":"application/json"},{"Transfer-Encoding":"chunked","Server":"Microsoft-HTTPAPI/2.0","Pragma":"no-cache","x-ms-ratelimit-remaining-subscription-reads":"14976","StatusCode":"200","x-ms-correlation-request-id":"3ac71b52-2249-4c95-a352-cb32c50b0683","Date":"Wed, 19 Aug 2015 01:02:25 GMT","Strict-Transport-Security":"max-age=31536000; includeSubDomains","Cache-Control":"no-cache","x-ms-routing-request-id":"WESTUS:20150819T010225Z:3ac71b52-2249-4c95-a352-cb32c50b0683","Vary":"Accept-Encoding","Expires":"-1","Content-Length":"419","x-ms-request-id":"6cff0e82-1135-46a2-9e37-cc868e975670","Body":"{\r\n \"properties\": {\r\n \"operatingSystem\": \"Windows\",\r\n \"computeRole\": \"IaaS\",\r\n \"vmScaleSetEnabled\": false,\r\n \"supportsMultipleExtensions\": false\r\n },\r\n \"location\": \"southeastasia\",\r\n \"name\": \"2.0\",\r\n \"id\": \"/Subscriptions/24fb23e3-6ba3-41f0-9b6e-e41131d5d61e/Providers/Microsoft.Compute/Locations/southeastasia/Publishers/Microsoft.Compute/ArtifactTypes/VMExtension/Types/VMAccessAgent/Versions/2.0\"\r\n}","Content-Type":"application/json; charset=utf-8"}]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"User-Agent":"Azure-SDK-For-Java","Method":"PUT","Uri":"/subscriptions/24fb23e3-6ba3-41f0-9b6e-e41131d5d61e/resourcegroups/javatestrgnybdfo?api-version=2014-04-01-preview","Content-Type":"application/json; charset=utf-8"},{"x-ms-ratelimit-remaining-subscription-writes":"1184","Pragma":"no-cache","StatusCode":"201","x-ms-correlation-request-id":"0cfeb59f-86ff-4296-ae4b-e0a133f879ae","Date":"Wed, 19 Aug 2015 01:02:16 GMT","Strict-Transport-Security":"max-age=31536000; includeSubDomains","Cache-Control":"no-cache","x-ms-routing-request-id":"WESTUS:20150819T010216Z:0cfeb59f-86ff-4296-ae4b-e0a133f879ae","Expires":"-1","Content-Length":"192","x-ms-request-id":"0cfeb59f-86ff-4296-ae4b-e0a133f879ae","Body":"{\"id\":\"/subscriptions/24fb23e3-6ba3-41f0-9b6e-e41131d5d61e/resourceGroups/javatestrgnybdfo\",\"name\":\"javatestrgnybdfo\",\"location\":\"southeastasia\",\"properties\":{\"provisioningState\":\"Succeeded\"}}","Content-Type":"application/json; charset=utf-8"},{"User-Agent":"Azure-SDK-For-Java","Method":"GET","Uri":"/subscriptions/24fb23e3-6ba3-41f0-9b6e-e41131d5d61e/providers/Microsoft.Compute/locations/SouthEastAsia/publishers/Microsoft.Compute/artifacttypes/vmextension/types/VMAccessAgent/versions?api-version=2015-06-15","Content-Type":"application/json"},{"Transfer-Encoding":"chunked","Server":"Microsoft-HTTPAPI/2.0","Pragma":"no-cache","x-ms-ratelimit-remaining-subscription-reads":"14892","StatusCode":"200","x-ms-correlation-request-id":"9cfce6cc-46b7-4ee8-a53a-99adb5058ba2","Date":"Wed, 19 Aug 2015 01:02:17 GMT","Strict-Transport-Security":"max-age=31536000; includeSubDomains","Cache-Control":"no-cache","x-ms-routing-request-id":"WESTUS:20150819T010217Z:9cfce6cc-46b7-4ee8-a53a-99adb5058ba2","Vary":"Accept-Encoding","Expires":"-1","Content-Length":"273","x-ms-request-id":"8e86fe65-a849-4fac-9653-ede7102c7a83","Body":"[\r\n {\r\n \"location\": \"southeastasia\",\r\n \"name\": \"2.0\",\r\n \"id\": \"/Subscriptions/24fb23e3-6ba3-41f0-9b6e-e41131d5d61e/Providers/Microsoft.Compute/Locations/southeastasia/Publishers/Microsoft.Compute/ArtifactTypes/VMExtension/Types/VMAccessAgent/Versions/2.0\"\r\n }\r\n]","Content-Type":"application/json; charset=utf-8"}]

0 comments on commit 0b4853d

Please sign in to comment.