Skip to content

Commit

Permalink
Merge pull request Azure#1160 from anuchandy/custom-ext-sample-update
Browse files Browse the repository at this point in the history
test case to test enabling diagnostics profile in a virtual machine
  • Loading branch information
Martin Sawicki authored Oct 4, 2016
2 parents b3891ce + 29c2c7e commit a9364e6
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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"}]}}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<WadCfg><DiagnosticMonitorConfiguration overallQuotaInMB="4096"><DiagnosticInfrastructureLogs scheduledTransferPeriod="PT1M" scheduledTransferLogLevelFilter="Warning"/><PerformanceCounters scheduledTransferPeriod="PT1M"><PerformanceCounterConfiguration counterSpecifier="\Processor(_Total)\% Processor Time" sampleRate="PT15S" unit="Percent"><annotation displayName="CPU utilization" locale="en-us"/></PerformanceCounterConfiguration><PerformanceCounterConfiguration counterSpecifier="\Processor(_Total)\% Privileged Time" sampleRate="PT15S" unit="Percent"><annotation displayName="CPU privileged time" locale="en-us"/></PerformanceCounterConfiguration><PerformanceCounterConfiguration counterSpecifier="\Processor(_Total)\% User Time" sampleRate="PT15S" unit="Percent"><annotation displayName="CPU user time" locale="en-us"/></PerformanceCounterConfiguration><PerformanceCounterConfiguration counterSpecifier="\Processor Information(_Total)\Processor Frequency" sampleRate="PT15S" unit="Count"><annotation displayName="CPU frequency" locale="en-us"/></PerformanceCounterConfiguration><PerformanceCounterConfiguration counterSpecifier="\System\Processes" sampleRate="PT15S" unit="Count"><annotation displayName="Processes" locale="en-us"/></PerformanceCounterConfiguration><PerformanceCounterConfiguration counterSpecifier="\Process(_Total)\Thread Count" sampleRate="PT15S" unit="Count"><annotation displayName="Threads" locale="en-us"/></PerformanceCounterConfiguration><PerformanceCounterConfiguration counterSpecifier="\Process(_Total)\Handle Count" sampleRate="PT15S" unit="Count"><annotation displayName="Handles" locale="en-us"/></PerformanceCounterConfiguration><PerformanceCounterConfiguration counterSpecifier="\Memory\% Committed Bytes In Use" sampleRate="PT15S" unit="Percent"><annotation displayName="Memory usage" locale="en-us"/></PerformanceCounterConfiguration><PerformanceCounterConfiguration counterSpecifier="\Memory\Available Bytes" sampleRate="PT15S" unit="Bytes"><annotation displayName="Memory available" locale="en-us"/></PerformanceCounterConfiguration><PerformanceCounterConfiguration counterSpecifier="\Memory\Committed Bytes" sampleRate="PT15S" unit="Bytes"><annotation displayName="Memory committed" locale="en-us"/></PerformanceCounterConfiguration><PerformanceCounterConfiguration counterSpecifier="\Memory\Commit Limit" sampleRate="PT15S" unit="Bytes"><annotation displayName="Memory commit limit" locale="en-us"/></PerformanceCounterConfiguration><PerformanceCounterConfiguration counterSpecifier="\Memory\Pool Paged Bytes" sampleRate="PT15S" unit="Bytes"><annotation displayName="Memory paged pool" locale="en-us"/></PerformanceCounterConfiguration><PerformanceCounterConfiguration counterSpecifier="\Memory\Pool Nonpaged Bytes" sampleRate="PT15S" unit="Bytes"><annotation displayName="Memory non-paged pool" locale="en-us"/></PerformanceCounterConfiguration><PerformanceCounterConfiguration counterSpecifier="\PhysicalDisk(_Total)\% Disk Time" sampleRate="PT15S" unit="Percent"><annotation displayName="Disk active time" locale="en-us"/></PerformanceCounterConfiguration><PerformanceCounterConfiguration counterSpecifier="\PhysicalDisk(_Total)\% Disk Read Time" sampleRate="PT15S" unit="Percent"><annotation displayName="Disk active read time" locale="en-us"/></PerformanceCounterConfiguration><PerformanceCounterConfiguration counterSpecifier="\PhysicalDisk(_Total)\% Disk Write Time" sampleRate="PT15S" unit="Percent"><annotation displayName="Disk active write time" locale="en-us"/></PerformanceCounterConfiguration><PerformanceCounterConfiguration counterSpecifier="\PhysicalDisk(_Total)\Disk Transfers/sec" sampleRate="PT15S" unit="CountPerSecond"><annotation displayName="Disk operations" locale="en-us"/></PerformanceCounterConfiguration><PerformanceCounterConfiguration counterSpecifier="\PhysicalDisk(_Total)\Disk Reads/sec" sampleRate="PT15S" unit="CountPerSecond"><annotation displayName="Disk read operations" locale="en-us"/></PerformanceCounterConfiguration><PerformanceCounterConfiguration counterSpecifier="\PhysicalDisk(_Total)\Disk Writes/sec" sampleRate="PT15S" unit="CountPerSecond"><annotation displayName="Disk write operations" locale="en-us"/></PerformanceCounterConfiguration><PerformanceCounterConfiguration counterSpecifier="\PhysicalDisk(_Total)\Disk Bytes/sec" sampleRate="PT15S" unit="BytesPerSecond"><annotation displayName="Disk speed" locale="en-us"/></PerformanceCounterConfiguration><PerformanceCounterConfiguration counterSpecifier="\PhysicalDisk(_Total)\Disk Read Bytes/sec" sampleRate="PT15S" unit="BytesPerSecond"><annotation displayName="Disk read speed" locale="en-us"/></PerformanceCounterConfiguration><PerformanceCounterConfiguration counterSpecifier="\PhysicalDisk(_Total)\Disk Write Bytes/sec" sampleRate="PT15S" unit="BytesPerSecond"><annotation displayName="Disk write speed" locale="en-us"/></PerformanceCounterConfiguration><PerformanceCounterConfiguration counterSpecifier="\PhysicalDisk(_Total)\Avg. Disk Queue Length" sampleRate="PT15S" unit="Count"><annotation displayName="Disk average queue length" locale="en-us"/></PerformanceCounterConfiguration><PerformanceCounterConfiguration counterSpecifier="\PhysicalDisk(_Total)\Avg. Disk Read Queue Length" sampleRate="PT15S" unit="Count"><annotation displayName="Disk average read queue length" locale="en-us"/></PerformanceCounterConfiguration><PerformanceCounterConfiguration counterSpecifier="\PhysicalDisk(_Total)\Avg. Disk Write Queue Length" sampleRate="PT15S" unit="Count"><annotation displayName="Disk average write queue length" locale="en-us"/></PerformanceCounterConfiguration><PerformanceCounterConfiguration counterSpecifier="\LogicalDisk(_Total)\% Free Space" sampleRate="PT15S" unit="Percent"><annotation displayName="Disk free space (percentage)" locale="en-us"/></PerformanceCounterConfiguration><PerformanceCounterConfiguration counterSpecifier="\LogicalDisk(_Total)\Free Megabytes" sampleRate="PT15S" unit="Count"><annotation displayName="Disk free space (MB)" locale="en-us"/></PerformanceCounterConfiguration></PerformanceCounters><WindowsEventLog scheduledTransferPeriod="PT1M"><DataSource name="Application!*[System[(Level = 1 or Level = 2)]]"/><DataSource name="Security!*[System[(Level = 1 or Level = 2)]"/><DataSource name="System!*[System[(Level = 1 or Level = 2)]]"/></WindowsEventLog><Metrics resourceId="%VirtualMachineResourceId%"><MetricAggregation scheduledTransferPeriod="PT1H"/><MetricAggregation scheduledTransferPeriod="PT1M"/></Metrics></DiagnosticMonitorConfiguration></WadCfg>

0 comments on commit a9364e6

Please sign in to comment.