diff --git a/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/VirtualMachineExtensionOperationsTests.java b/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/VirtualMachineExtensionOperationsTests.java index 2c8423b840647..52f5d85c0a26f 100644 --- a/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/VirtualMachineExtensionOperationsTests.java +++ b/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/VirtualMachineExtensionOperationsTests.java @@ -1,10 +1,14 @@ package com.microsoft.azure.management.compute; +import com.fasterxml.jackson.databind.ObjectMapper; import com.microsoft.azure.management.resources.fluentcore.utils.ResourceNamer; +import com.microsoft.azure.management.storage.StorageAccount; +import org.apache.commons.codec.binary.Base64; import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; +import java.io.InputStream; import java.util.ArrayList; import java.util.List; @@ -18,6 +22,56 @@ public static void setup() throws Exception { public static void cleanup() throws Exception { } + @Test + public void canEnableDiagnosticsExtension() throws Exception { + final String RG_NAME = ResourceNamer.randomResourceName("vmexttest", 15); + final String STORAGEACCOUNTNAME = ResourceNamer.randomResourceName("stg", 15); + final String LOCATION = "eastus"; + final String VMNAME = "javavm"; + + // Creates a storage account + StorageAccount storageAccount = storageManager.storageAccounts() + .define(STORAGEACCOUNTNAME) + .withRegion(LOCATION) + .withNewResourceGroup(RG_NAME) + .create(); + + // Create a Linux VM + // + VirtualMachine vm = computeManager.virtualMachines() + .define(VMNAME) + .withRegion(LOCATION) + .withExistingResourceGroup(RG_NAME) + .withNewPrimaryNetwork("10.0.0.0/28") + .withPrimaryPrivateIpAddressDynamic() + .withoutPrimaryPublicIpAddress() + .withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_14_04_LTS) + .withRootUserName("Foo12") + .withPassword("BaR@12abc!") + .withSize(VirtualMachineSizeTypes.STANDARD_D3) + .withExistingStorageAccount(storageAccount) + .create(); + + final InputStream embeddedJsonConfig = VirtualMachineExtensionOperationsTests.class.getResourceAsStream("/linux_diagnostics_public_config.json"); + String jsonConfig = ((new ObjectMapper()).readTree(embeddedJsonConfig)).toString(); + jsonConfig = jsonConfig.replace("%VirtualMachineResourceId%", vm.id()); + + // Update Linux VM to enable Diagnostics + vm.update() + .defineNewExtension("LinuxDiagnostic") + .withPublisher("Microsoft.OSTCExtensions") + .withType("LinuxDiagnostic") + .withVersion("2.3") + .withPublicSetting("ladCfg", new String(Base64.encodeBase64(jsonConfig.getBytes()))) + .withPublicSetting("storageAccount", storageAccount.name()) + .withProtectedSetting("storageAccountName", storageAccount.name()) + .withProtectedSetting("storageAccountKey", storageAccount.getKeys().get(0).value()) + .withProtectedSetting("storageAccountEndPoint", "https://core.windows.net:443/") + .attach() + .apply(); + } + + @Test public void canResetPasswordUsingVMAccessExtension() throws Exception { final String RG_NAME = ResourceNamer.randomResourceName("vmexttest", 15); diff --git a/azure-mgmt-compute/src/test/resources/linux_diagnostics_public_config.json b/azure-mgmt-compute/src/test/resources/linux_diagnostics_public_config.json new file mode 100644 index 0000000000000..13e200af600d1 --- /dev/null +++ b/azure-mgmt-compute/src/test/resources/linux_diagnostics_public_config.json @@ -0,0 +1 @@ +{"diagnosticMonitorConfiguration":{"metrics":{"resourceId":"%VirtualMachineResourceId%","metricAggregation":[{"scheduledTransferPeriod":"PT1H"},{"scheduledTransferPeriod":"PT1M"}]},"performanceCounters":{"performanceCounterConfiguration":[{"class":"Memory","counterSpecifier":"PercentAvailableMemory","table":"LinuxMemory"},{"class":"Memory","counterSpecifier":"AvailableMemory","table":"LinuxMemory"},{"class":"Memory","counterSpecifier":"UsedMemory","table":"LinuxMemory"},{"class":"Memory","counterSpecifier":"PercentUsedSwap","table":"LinuxMemory"},{"class":"Processor","counterSpecifier":"PercentProcessorTime","table":"LinuxCpu"},{"class":"Processor","counterSpecifier":"PercentIOWaitTime","table":"LinuxCpu"},{"class":"Processor","counterSpecifier":"PercentIdleTime","table":"LinuxCpu"},{"class":"PhysicalDisk","counterSpecifier":"AverageWriteTime","table":"LinuxDisk"},{"class":"PhysicalDisk","counterSpecifier":"AverageReadTime","table":"LinuxDisk"},{"class":"PhysicalDisk","counterSpecifier":"ReadBytesPerSecond","table":"LinuxDisk"},{"class":"PhysicalDisk","counterSpecifier":"WriteBytesPerSecond","table":"LinuxDisk"}]}}} \ No newline at end of file diff --git a/azure-mgmt-compute/src/test/resources/windows_diagnostics_public_config.xml b/azure-mgmt-compute/src/test/resources/windows_diagnostics_public_config.xml new file mode 100644 index 0000000000000..72d1eb7cef741 --- /dev/null +++ b/azure-mgmt-compute/src/test/resources/windows_diagnostics_public_config.xml @@ -0,0 +1 @@ + \ No newline at end of file