Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automation 3.0.1-preview: Software Update Configuration #3992

Merged
merged 4 commits into from
Feb 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<PackageId>Automation.Tests</PackageId>
<AssemblyName>Automation.Tests</AssemblyName>
<VersionPrefix>3.0.0-preview</VersionPrefix>
<VersionPrefix>3.0.1-preview</VersionPrefix>
<Description>Test Project for Automation tests</Description>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace Automation.Tests.ScenarioTests.UpdateManagement
{
using Microsoft.Azure.Management.Automation;
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;

using Automation.Tests.Helpers;

public class BaseTest
{
protected const string ResourceGroupName = "to-delete-01";
protected const string AutomationAccountName = "fbs-aa-01";
protected const string updateConfigurationName_01 = "test-suc-001";
protected const string updateConfigurationName_02 = "test-suc-002";
protected const string VM_01 = "/subscriptions/05fd3142-4b8e-4b16-8da9-98b4bbfd722d/resourceGroups/compute-01/providers/Microsoft.Compute/virtualMachines/vm-arm-01";
protected const string VM_02 = "/subscriptions/05fd3142-4b8e-4b16-8da9-98b4bbfd722d/resourceGroups/to-delete/providers/Microsoft.Compute/virtualMachines/mo-arm-02";

protected AutomationClient automationClient;

protected void CreateAutomationClient(MockContext context)
{
if (this.automationClient == null)
{
var handler = new RecordedDelegatingHandler();
this.automationClient = context.GetServiceClient<AutomationClient>(false, handler);
this.automationClient.ResourceGroupName = ResourceGroupName;
this.automationClient.AutomationAccountName = AutomationAccountName;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
namespace Automation.Tests.ScenarioTests.UpdateManagement
{
using System;

using Microsoft.Azure.Management.Automation;
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;

using Xunit;

public class SoftwareUpdateConfigurationMachineRunTests : BaseTest
{
[Fact]
public void CanGetMachineRunById()
{
var runId = Guid.Parse("b56021cf-1643-4bfb-99d3-6b798db242f5");
using (var context = MockContext.Start(GetType().FullName))
{
this.CreateAutomationClient(context);

var run = this.automationClient.SoftwareUpdateConfigurationMachineRuns.GetById(runId);
Assert.NotNull(run);
Assert.Equal(runId.ToString(), run.Name);
}
}

[Fact]
public void CanGetAllMachineRuns()
{
using (var context = MockContext.Start(GetType().FullName))
{
this.CreateAutomationClient(context);

var runs = this.automationClient.SoftwareUpdateConfigurationMachineRuns.List();
Assert.NotNull(runs.Value);
Assert.Equal(27, runs.Value.Count);
}
}

[Fact]
public void CanGetAllRunsByCorrelationId()
{
Guid correlationId = Guid.Parse("595159c7-64cb-436f-892d-b44b31970f7a");
using (var context = MockContext.Start(GetType().FullName))
{
this.CreateAutomationClient(context);

var runs = this.automationClient.SoftwareUpdateConfigurationMachineRuns.ListByCorrelationId(correlationId);
Assert.NotNull(runs.Value);
Assert.Equal(2, runs.Value.Count);
}
}

[Fact]
public void CanGetAllRunsByStatus()
{
const string status = "Failed";
using (var context = MockContext.Start(GetType().FullName))
{
this.CreateAutomationClient(context);

var runs = this.automationClient.SoftwareUpdateConfigurationMachineRuns.ListByStatus(status);
Assert.NotNull(runs.Value);
Assert.Equal(4, runs.Value.Count);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
namespace Automation.Tests.ScenarioTests.UpdateManagement
{
using System;

using Microsoft.Azure.Management.Automation;
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;

using Xunit;

public class SoftwareUpdateConfigurationRunTests : BaseTest
{
[Fact]
public void CanGetRunById()
{
var runId = Guid.Parse("595159c7-64cb-436f-892d-b44b31970f7a");
using (var context = MockContext.Start(GetType().FullName))
{
this.CreateAutomationClient(context);

var run = this.automationClient.SoftwareUpdateConfigurationRuns.GetById(runId);
Assert.NotNull(run);
Assert.Equal(runId.ToString(), run.Name);
}
}

[Fact]
public void CanGetAllRuns()
{
using (var context = MockContext.Start(GetType().FullName))
{
this.CreateAutomationClient(context);

var runs = this.automationClient.SoftwareUpdateConfigurationRuns.List();
Assert.NotNull(runs.Value);
Assert.Equal(15, runs.Value.Count);
}
}

[Fact]
public void CanGetAllRunsByConfigurationName()
{
const string configName = "all-01";
using (var context = MockContext.Start(GetType().FullName))
{
this.CreateAutomationClient(context);

var runs = this.automationClient.SoftwareUpdateConfigurationRuns.ListByConfigurationName(configName);
Assert.NotNull(runs.Value);
Assert.Equal(6, runs.Value.Count);
}
}

[Fact]
public void CanGetAllRunsByOs()
{
const string os = "Windows";
using (var context = MockContext.Start(GetType().FullName))
{
this.CreateAutomationClient(context);

var runs = this.automationClient.SoftwareUpdateConfigurationRuns.ListByOsType(os);
Assert.NotNull(runs.Value);
Assert.Equal(17, runs.Value.Count);
}
}

[Fact]
public void CanGetAllRunsByStatus()
{
const string status = "Failed";
using (var context = MockContext.Start(GetType().FullName))
{
this.CreateAutomationClient(context);

var runs = this.automationClient.SoftwareUpdateConfigurationRuns.ListByStatus(status);
Assert.NotNull(runs.Value);
Assert.Equal(2, runs.Value.Count);
}
}

[Fact]
public void CanGetAllRunsByStartTime()
{
var startTime = DateTime.Parse("2017-12-03T22:01:00-8").ToUniversalTime();
using (var context = MockContext.Start(GetType().FullName))
{
this.CreateAutomationClient(context);

var runs = this.automationClient.SoftwareUpdateConfigurationRuns.ListByStartTime(startTime);
Assert.NotNull(runs.Value);
Assert.Equal(3, runs.Value.Count);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
namespace Automation.Tests.ScenarioTests.UpdateManagement
{
using System;
using System.Linq;

using Microsoft.Azure.Management.Automation;
using Microsoft.Azure.Management.Automation.Models;
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;

using Xunit;

public class SoftwareUpdateConfigurationTests : BaseTest
{
[Fact]
public void CanCreateGetAndDelete()
{
using (var context = MockContext.Start(GetType().FullName))
{
this.CreateAutomationClient(context);

// Create and get the first SUC (targeting 1 VMs)
var sucProperties = this.CreateSoftwareUpdateConfigurationModel(new[] { VM_01 });
var createResult = this.automationClient.SoftwareUpdateConfigurations.Create(updateConfigurationName_01, sucProperties);
Assert.NotNull(createResult);

var getResult = this.automationClient.SoftwareUpdateConfigurations.GetByName(updateConfigurationName_01);
Assert.NotNull(getResult);

// Create and get the second SUC (targeting 2 VMs)
sucProperties = this.CreateSoftwareUpdateConfigurationModel(new[] { VM_01, VM_02});
createResult = this.automationClient.SoftwareUpdateConfigurations.Create(updateConfigurationName_02, sucProperties);
Assert.NotNull(createResult);

getResult = this.automationClient.SoftwareUpdateConfigurations.GetByName(updateConfigurationName_02);
Assert.NotNull(getResult);

// List all SUCs
var listResult = this.automationClient.SoftwareUpdateConfigurations.List();
Assert.NotNull(listResult);
Assert.NotNull(listResult.Value);
Assert.Equal(9, listResult.Value.Count);

// List for specific VM
listResult = this.automationClient.SoftwareUpdateConfigurations.ListByAzureVirtualMachine(VM_01);
Assert.NotNull(listResult);
Assert.NotNull(listResult.Value);
Assert.Equal(6, listResult.Value.Count);
var suc = listResult.Value.Where(v => v.Name.Equals(updateConfigurationName_01, StringComparison.OrdinalIgnoreCase)).Single();
Assert.Equal(updateConfigurationName_01, suc.Name);

// Delete both
this.automationClient.SoftwareUpdateConfigurations.Delete(updateConfigurationName_01);
getResult = this.automationClient.SoftwareUpdateConfigurations.GetByName(updateConfigurationName_01);
Assert.Null(getResult);

this.automationClient.SoftwareUpdateConfigurations.Delete(updateConfigurationName_02);
getResult = this.automationClient.SoftwareUpdateConfigurations.GetByName(updateConfigurationName_02);
Assert.Null(getResult);
}
}

private SoftwareUpdateConfiguration CreateSoftwareUpdateConfigurationModel(string[] azureVirtualMachines)
{
var updateConfiguration = new UpdateConfiguration
{
OperatingSystem = OperatingSystemType.Windows,
Windows = new WindowsProperties
{
IncludedUpdateClassifications = WindowsUpdateClasses.Critical + ',' + WindowsUpdateClasses.Security,
ExcludedKbNumbers = new[] { "KB123", "KB123" }
},
Duration = TimeSpan.FromHours(3),
AzureVirtualMachines = azureVirtualMachines
};

var scheduleInfo = new ScheduleProperties
{
Frequency = ScheduleFrequency.Day,
StartTime = DateTime.Parse("2018-05-05T19:26:00.000"),
Interval = 1,
TimeZone = "America/Los_Angeles"
};

return new SoftwareUpdateConfiguration(updateConfiguration, scheduleInfo);
}
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"Entries": [
{
"RequestUri": "/subscriptions/05fd3142-4b8e-4b16-8da9-98b4bbfd722d/resourceGroups/to-delete-01/providers/Microsoft.Automation/automationAccounts/fbs-aa-01/softwareUpdateConfigurationMachineRuns?api-version=2017-05-15-preview&$filter=properties%2FcorrelationId%20eq%20595159c7-64cb-436f-892d-b44b31970f7a",
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnMvMDVmZDMxNDItNGI4ZS00YjE2LThkYTktOThiNGJiZmQ3MjJkL3Jlc291cmNlR3JvdXBzL3RvLWRlbGV0ZS0wMS9wcm92aWRlcnMvTWljcm9zb2Z0LkF1dG9tYXRpb24vYXV0b21hdGlvbkFjY291bnRzL2Zicy1hYS0wMS9zb2Z0d2FyZVVwZGF0ZUNvbmZpZ3VyYXRpb25NYWNoaW5lUnVucz9hcGktdmVyc2lvbj0yMDE3LTA1LTE1LXByZXZpZXcmJGZpbHRlcj1wcm9wZXJ0aWVzJTJGY29ycmVsYXRpb25JZCUyMGVxJTIwNTk1MTU5YzctNjRjYi00MzZmLTg5MmQtYjQ0YjMxOTcwZjdh",
"RequestMethod": "GET",
"RequestBody": "",
"RequestHeaders": {
"x-ms-client-request-id": [
"dde25426-d83b-47f5-8e86-2c330fe819d8"
],
"accept-language": [
"en-US"
],
"User-Agent": [
"FxVersion/4.6.25211.01",
"Microsoft.Azure.Management.Automation.AutomationClient/3.0.0.0"
]
},
"ResponseBody": "{\r\n \"value\": [\r\n {\r\n \"id\": \"/subscriptions/05fd3142-4b8e-4b16-8da9-98b4bbfd722d/resourceGroups/to-delete-01/providers/Microsoft.Automation/automationAccounts/fbs-aa-01/softwareUpdateConfigurationMachineRuns/b56021cf-1643-4bfb-99d3-6b798db242f5\",\r\n \"name\": \"b56021cf-1643-4bfb-99d3-6b798db242f5\",\r\n \"properties\": {\r\n \"targetComputer\": \"/subscriptions/05fd3142-4b8e-4b16-8da9-98b4bbfd722d/resourceGroups/compute-01/providers/Microsoft.Compute/virtualMachines/vm-arm-01\",\r\n \"targetComputerType\": \"AzureVirtualMachines\",\r\n \"softwareUpdateConfiguration\": {\r\n \"name\": \"all-01\"\r\n },\r\n \"status\": \"Failed\",\r\n \"osType\": \"Windows\",\r\n \"correlationId\": \"595159c7-64cb-436f-892d-b44b31970f7a\",\r\n \"sourceComputerId\": \"282452db-3afa-4538-9461-91f6361b1be1\",\r\n \"startTime\": \"2017-12-03T22:01:03.0427936-08:00\",\r\n \"endTime\": \"2017-12-03T22:35:44.8333333-08:00\",\r\n \"configuredDuration\": \"PT2H\",\r\n \"job\": null,\r\n \"creationTime\": \"2017-12-03T22:01:03.0427936-08:00\",\r\n \"lastModifiedBy\": null,\r\n \"lastModifiedTime\": \"2017-12-03T22:36:15.3566667-08:00\"\r\n }\r\n },\r\n {\r\n \"id\": \"/subscriptions/05fd3142-4b8e-4b16-8da9-98b4bbfd722d/resourceGroups/to-delete-01/providers/Microsoft.Automation/automationAccounts/fbs-aa-01/softwareUpdateConfigurationMachineRuns/cd9d9164-0268-438a-8d8a-dbca25ade827\",\r\n \"name\": \"cd9d9164-0268-438a-8d8a-dbca25ade827\",\r\n \"properties\": {\r\n \"targetComputer\": \"/subscriptions/05fd3142-4b8e-4b16-8da9-98b4bbfd722d/resourceGroups/to-delete/providers/Microsoft.Compute/virtualMachines/mo-arm-02\",\r\n \"targetComputerType\": \"AzureVirtualMachines\",\r\n \"softwareUpdateConfiguration\": {\r\n \"name\": \"all-01\"\r\n },\r\n \"status\": \"Succeeded\",\r\n \"osType\": \"Windows\",\r\n \"correlationId\": \"595159c7-64cb-436f-892d-b44b31970f7a\",\r\n \"sourceComputerId\": \"3a919404-fc45-4d2f-aaca-42ca398bbd21\",\r\n \"startTime\": \"2017-12-03T22:01:02.2462645-08:00\",\r\n \"endTime\": \"2017-12-03T22:01:30.9866667-08:00\",\r\n \"configuredDuration\": \"PT2H\",\r\n \"job\": null,\r\n \"creationTime\": \"2017-12-03T22:01:02.2462645-08:00\",\r\n \"lastModifiedBy\": null,\r\n \"lastModifiedTime\": \"2017-12-03T22:02:04.3933333-08:00\"\r\n }\r\n }\r\n ]\r\n}",
"ResponseHeaders": {
"Content-Type": [
"application/json; charset=utf-8"
],
"Expires": [
"-1"
],
"Cache-Control": [
"no-cache"
],
"Date": [
"Mon, 04 Dec 2017 07:23:32 GMT"
],
"Pragma": [
"no-cache"
],
"Transfer-Encoding": [
"chunked"
],
"Server": [
"Microsoft-IIS/8.5"
],
"Vary": [
"Accept-Encoding"
],
"x-ms-request-id": [
"dde25426-d83b-47f5-8e86-2c330fe819d8"
],
"Strict-Transport-Security": [
"max-age=31536000; includeSubDomains"
],
"X-AspNet-Version": [
"4.0.30319"
],
"X-Powered-By": [
"ASP.NET"
],
"x-ms-ratelimit-remaining-subscription-reads": [
"14994"
],
"x-ms-correlation-request-id": [
"5b6e13f8-4b6f-45de-9286-8b7ce7ef447f"
],
"x-ms-routing-request-id": [
"WESTUS2:20171204T072333Z:5b6e13f8-4b6f-45de-9286-8b7ce7ef447f"
]
},
"StatusCode": 200
}
],
"Names": {},
"Variables": {
"SubscriptionId": "05fd3142-4b8e-4b16-8da9-98b4bbfd722d"
}
}
Loading