Skip to content

Commit

Permalink
New SDK for 2018-06-30 changes and other nit fixes ver2 (Azure#4971)
Browse files Browse the repository at this point in the history
* Generated SDK using generate.ps1

* Added changes to RP.Props

* Added SDK for Automation.Python2Packages and re-recorded tests

* Reduced poll interval for modules and python2packages for faster playback

* new test python2 packages, DynamicGroup and Prepost

* Changed version for assembyinfo and csproj files

* Addressed PR comments
  • Loading branch information
D1v38om83r authored and Ashraf Hamad committed Oct 31, 2018
1 parent 43f39e5 commit 17c9bcb
Show file tree
Hide file tree
Showing 71 changed files with 11,477 additions and 4,513 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -344,15 +344,15 @@ public void CanCreateUpdateDeleteAutomationModules()

Assert.NotNull(module);
Assert.Equal(ModuleProvisioningState.Creating, module.ProvisioningState);
EnsureModuleReachesSuccessProvisioningState(moduleName, testFixture, out module);
module = EnsureModuleReachesSuccessProvisioningState(moduleName, testFixture);
Assert.Equal(moduleName, module.Name);
Assert.Equal("1.0", module.Version);

// Update the module
module = testFixture.CreateAutomationModule(moduleName, contentLink2);
Assert.NotNull(module);
Assert.Equal(ModuleProvisioningState.Creating, module.ProvisioningState);
EnsureModuleReachesSuccessProvisioningState(moduleName, testFixture, out module);
module = EnsureModuleReachesSuccessProvisioningState(moduleName, testFixture);
Assert.Equal(moduleName, module.Name);
Assert.Equal("2.0", module.Version);

Expand All @@ -373,6 +373,54 @@ public void CanCreateUpdateDeleteAutomationModules()
}
}

[Fact]
public void CanCreateUpdateDeletePython2Packages()
{
using (var context = MockContext.Start(GetType().FullName))
{
using (var testFixture = new AutomationTestBase(context))
{

var python2PackageName = "numpy";
// Content links don't have to be valid for playback. However, these are the actual module download locations used for recording.
var contentLink1 = "https://bhbrahmaprodtestingseau.blob.core.windows.net/module1/numpy-1.14.5-cp27-none-win_amd64.whl";
var contentLink2 = "https://bhbrahmaprodtestingseau.blob.core.windows.net/module2/numpy-1.15.2-cp27-none-win_amd64.whl";

testFixture.DeletePython2Package(python2PackageName, true);

var python2Package = testFixture.CreateAutomationPython2Package(python2PackageName, contentLink1);

Assert.NotNull(python2Package);
Assert.Equal(ModuleProvisioningState.Creating, python2Package.ProvisioningState);
python2Package = EnsurePython2PackageReachesSuccessProvisioningState(python2PackageName, testFixture);
Assert.Equal(python2PackageName, python2Package.Name);
Assert.Equal("1.14.5", python2Package.Version);

// Update the module
python2Package = testFixture.CreateAutomationPython2Package(python2PackageName, contentLink2);
Assert.NotNull(python2Package);
Assert.Equal(ModuleProvisioningState.Creating, python2Package.ProvisioningState);
python2Package = EnsurePython2PackageReachesSuccessProvisioningState(python2PackageName, testFixture);
Assert.Equal(python2PackageName, python2Package.Name);
Assert.Equal("1.15.2", python2Package.Version);

// Delete the module
bool deleteCompleted = false;
testFixture.DeletePython2Package(python2PackageName);
try
{
testFixture.GetAutomationPython2Package(python2PackageName);
}
catch (ErrorResponseException)
{
// Exception expected
deleteCompleted = true;
}
Assert.True(deleteCompleted);
}
}
}

[Fact]
public void CanCreateUpdateDeleteSourceControl()
{
Expand Down Expand Up @@ -479,23 +527,40 @@ public void CanCreateSourceControlSyncJob()
}
}

private void EnsureModuleReachesSuccessProvisioningState(string moduleName, AutomationTestBase testFixture, out Module module)
private Module EnsureModuleReachesSuccessProvisioningState(string moduleName, AutomationTestBase testFixture)
{
// Wait for the module Provisioing state to reach Succeeded
GetModuleAction getmoduleAction = () => testFixture.GetAutomationModule(moduleName);
return TestProvisioningStateSucceeded(getmoduleAction);
}

private Module EnsurePython2PackageReachesSuccessProvisioningState(string moduleName, AutomationTestBase testFixture)
{
GetModuleAction getPython2PackageAction = () => testFixture.GetAutomationPython2Package(moduleName);
return TestProvisioningStateSucceeded(getPython2PackageAction);
}

private delegate Module GetModuleAction();

private Module TestProvisioningStateSucceeded (GetModuleAction action)
{
var startTime = DateTime.Now;
var endTime = startTime.AddMinutes(5);
bool provisioningSucceeded = false;
bool success = false;
Module module;
do
{
Thread.Sleep(50); // Used 5 seconds polling delay in the record mode, using 50 ms in playback for test to complete fast
module = testFixture.GetAutomationModule(moduleName);
module = action();
if (module.ProvisioningState == ModuleProvisioningState.Succeeded)
{
provisioningSucceeded = true;
success = true;
break;
}

} while (DateTime.Now < endTime);
Assert.True(provisioningSucceeded);
Assert.True(success);
return module;
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public class BaseTest
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 const string VM_01 = "/subscriptions/422b6c61-95b0-4213-b3be-7282315df71d/resourceGroups/a-stasku-rg0/providers/Microsoft.Compute/virtualMachines/vmj-arm-01";
protected const string VM_02 = "/subscriptions/422b6c61-95b0-4213-b3be-7282315df71d/resourceGroups/a-stasku-rg0/providers/Microsoft.Compute/virtualMachines/vmj-arm-02";

protected AutomationClient automationClient;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class SoftwareUpdateConfigurationMachineRunTests : BaseTest
[Fact]
public void CanGetMachineRunById()
{
var runId = Guid.Parse("b56021cf-1643-4bfb-99d3-6b798db242f5");
var runId = Guid.Parse("da6493d0-de31-48d9-bc78-08e3c1d80d0a");
using (var context = MockContext.Start(GetType().FullName))
{
this.CreateAutomationClient(context);
Expand All @@ -32,14 +32,14 @@ public void CanGetAllMachineRuns()

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

[Fact]
public void CanGetAllRunsByCorrelationId()
{
Guid correlationId = Guid.Parse("595159c7-64cb-436f-892d-b44b31970f7a");
Guid correlationId = Guid.Parse("6ff49ee2-092a-48bf-841a-c3d645611689");
using (var context = MockContext.Start(GetType().FullName))
{
this.CreateAutomationClient(context);
Expand All @@ -53,14 +53,14 @@ public void CanGetAllRunsByCorrelationId()
[Fact]
public void CanGetAllRunsByStatus()
{
const string status = "Failed";
const string status = "Succeeded";
using (var context = MockContext.Start(GetType().FullName))
{
this.CreateAutomationClient(context);

var runs = this.automationClient.SoftwareUpdateConfigurationMachineRuns.ListByStatus(ResourceGroupName, AutomationAccountName, status);
Assert.NotNull(runs.Value);
Assert.Equal(4, runs.Value.Count);
Assert.Equal(16, runs.Value.Count);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class SoftwareUpdateConfigurationRunTests : BaseTest
[Fact]
public void CanGetRunById()
{
var runId = Guid.Parse("595159c7-64cb-436f-892d-b44b31970f7a");
var runId = Guid.Parse("6ff49ee2-092a-48bf-841a-c3d645611689");
using (var context = MockContext.Start(GetType().FullName))
{
this.CreateAutomationClient(context);
Expand All @@ -32,7 +32,7 @@ public void CanGetAllRuns()

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

Expand All @@ -46,7 +46,7 @@ public void CanGetAllRunsByConfigurationName()

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

Expand All @@ -60,7 +60,7 @@ public void CanGetAllRunsByOs()

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

Expand All @@ -74,21 +74,21 @@ public void CanGetAllRunsByStatus()

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

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

var runs = this.automationClient.SoftwareUpdateConfigurationRuns.ListByStartTime(ResourceGroupName, AutomationAccountName, startTime);
Assert.NotNull(runs.Value);
Assert.Equal(3, runs.Value.Count);
Assert.Equal(1, runs.Value.Count);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace Automation.Tests.ScenarioTests.UpdateManagement
{
using System;
using System.Collections.Generic;
using System.Linq;

using Microsoft.Azure.Management.Automation;
Expand Down Expand Up @@ -33,18 +34,32 @@ public void CanCreateGetAndDelete()

getResult = this.automationClient.SoftwareUpdateConfigurations.GetByName(ResourceGroupName, AutomationAccountName, updateConfigurationName_02);
Assert.NotNull(getResult);
Assert.NotNull(getResult.UpdateConfiguration);
Assert.NotNull(getResult.UpdateConfiguration.Targets);
Assert.NotNull(getResult.UpdateConfiguration.Targets.AzureQueries);
Assert.Equal(1, getResult.UpdateConfiguration.Targets.AzureQueries.Count);
Assert.Equal(2, getResult.UpdateConfiguration.Targets.AzureQueries.First().Scope.Count);
Assert.NotNull(getResult.Tasks);
Assert.NotNull(getResult.Tasks.PreTask);
Assert.Equal("preScript", getResult.Tasks.PreTask.Source);
Assert.NotNull(getResult.Tasks.PostTask);
Assert.NotNull(getResult.Tasks.PostTask.Source);
Assert.NotNull(getResult.Tasks.PostTask.Parameters);
Assert.Equal(1, getResult.Tasks.PostTask.Parameters.Count);
Assert.Equal("postScript", getResult.Tasks.PostTask.Source);

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


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

Expand Down Expand Up @@ -76,18 +91,71 @@ private SoftwareUpdateConfiguration CreateSoftwareUpdateConfigurationModel(strin
ExcludedKbNumbers = new[] { "KB123", "KB123" }
},
Duration = TimeSpan.FromHours(3),
AzureVirtualMachines = azureVirtualMachines
AzureVirtualMachines = azureVirtualMachines,
Targets = new TargetProperties
{
AzureQueries = new List<AzureQueryProperties>
{
new AzureQueryProperties
{
Locations = new List<string>
{
"Japan East",
"UK South"
},
Scope = new List<string>
{
"/subscriptions/422b6c61-95b0-4213-b3be-7282315df71d/resourceGroups/a-stasku-rg0",
"/subscriptions/422b6c61-95b0-4213-b3be-7282315df71d"
},
TagSettings = new TagSettingsProperties
{
Tags = new Dictionary<string, IList<string>>
{
{
"tag1" , new List<string>
{
"tag1Value1",
"tag1Value2"
}
},
{
"tag2" , new List<string>
{
"tag2Value1",
"tag2Value2"
}
},
},
FilterOperator = TagOperators.All
}
}
}
}
};

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

return new SoftwareUpdateConfiguration(updateConfiguration, scheduleInfo);
var tasks = new SoftwareUpdateConfigurationTasks
{
PreTask = new TaskProperties
{
Source = "preScript"
},
PostTask = new TaskProperties
{
Source = "postScript",
Parameters = new Dictionary<string, string>() { { "Num", "4" } }
}
};

return new SoftwareUpdateConfiguration(updateConfiguration, scheduleInfo, tasks: tasks);
}
}
}
Loading

0 comments on commit 17c9bcb

Please sign in to comment.