Skip to content

Commit 89dd272

Browse files
authored
Merge pull request Azure#4352 from vrdmr/vameru-nodeconfig-changes
Adding support for IncrementNodeConfigurationBuild
2 parents 884a396 + 2efa86e commit 89dd272

15 files changed

+317
-58
lines changed

src/ResourceManager/Automation/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
## Current Release
2121
* Made changes to AutomationDSC* cmdlets to pull more than 100 records
2222
* Resolved the issue where the Verbose streams stop working after calling some Automation cmdlets (for example Get-AzureRmAutomationVariable, Get-AzureRmAutomationJob).
23+
* Support for NodeConfiguration Build versioning added in StartAzureAutomationDscCompilationJob and ImportAzureAutomationDscNodeConfiguration.
2324
* Bug fixes for existing issues - Fixes the alias issue is #3775 and the runOn alias and support for HybridWorkers.
2425

2526
## Version 3.2.1

src/ResourceManager/Automation/Commands.Automation.Test/Commands.Automation.Test.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@
169169
<Compile Include="UnitTests\GetAzureAutomationScheduleTest.cs" />
170170
<Compile Include="UnitTests\GetAzureAutomationVariableTest.cs" />
171171
<Compile Include="UnitTests\GetAzureAutomationWebhookTest.cs" />
172+
<Compile Include="UnitTests\ImportAzureAutomationDscNodeConfigurationTest.cs" />
172173
<Compile Include="UnitTests\NewAzureAutomationAccountTest.cs" />
173174
<Compile Include="UnitTests\GetAzureAutomationAccountTest.cs" />
174175
<Compile Include="UnitTests\NewAzureAutomationCertificateTest.cs" />
@@ -194,6 +195,7 @@
194195
<Compile Include="UnitTests\SetAzureAutomationRunbookTest.cs" />
195196
<Compile Include="UnitTests\SetAzureAutomationScheduleTest.cs" />
196197
<Compile Include="UnitTests\SetAzureAutomationWebhookTest.cs" />
198+
<Compile Include="UnitTests\StartAzureAutomationDscCompilationJobTest.cs" />
197199
<Compile Include="UnitTests\StartAzureAutomationRunbookTest.cs" />
198200
<Compile Include="UnitTests\StopAzureAutomationJobTest.cs" />
199201
<Compile Include="UnitTests\SuspendAzureAutomationJobTest.cs" />
@@ -239,6 +241,7 @@
239241
<None Include="ScenarioTests\Resources\fastjob.ps1">
240242
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
241243
</None>
244+
<None Include="ScenarioTests\Resources\ContosoDscConfiguration.ps1" />
242245
<None Include="ScenarioTests\Resources\Test-Workflow.ps1">
243246
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
244247
</None>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Configuration ContosoDscConfiguration {
2+
3+
Node "TEST-PC1" {
4+
WindowsFeature MyFeatureInstance {
5+
Ensure = "Present"
6+
Name = "RSAT"
7+
}
8+
WindowsFeature My2ndFeatureInstance {
9+
Ensure = "Present"
10+
Name = "Bitlocker"
11+
}
12+
}
13+
}
14+
15+
ContosoDscConfiguration
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Commands.Automation.Cmdlet;
16+
using Microsoft.Azure.Commands.Automation.Common;
17+
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
18+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
19+
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
20+
using Moq;
21+
using Xunit;
22+
23+
namespace Microsoft.Azure.Commands.ResourceManager.Automation.Test.UnitTests
24+
{
25+
public class ImportAzureAutomationDscNodeConfigurationTest : RMTestBase
26+
{
27+
private Mock<IAutomationClient> mockAutomationClient;
28+
29+
private MockCommandRuntime mockCommandRuntime;
30+
31+
private ImportAzureAutomationDscNodeConfiguration cmdlet;
32+
33+
public ImportAzureAutomationDscNodeConfigurationTest()
34+
{
35+
this.mockAutomationClient = new Mock<IAutomationClient>();
36+
this.mockCommandRuntime = new MockCommandRuntime();
37+
38+
this.cmdlet = new ImportAzureAutomationDscNodeConfiguration
39+
{
40+
AutomationClient = this.mockAutomationClient.Object,
41+
CommandRuntime = this.mockCommandRuntime
42+
};
43+
}
44+
45+
[Fact]
46+
[Trait(Category.AcceptanceType, Category.CheckIn)]
47+
public void ImportAzureAutomationDscNodeConfigurationTestWithNullNodeConfiguration()
48+
{
49+
// Setup
50+
string resourceGroupName = "resourceGroup";
51+
string accountName = "automation";
52+
string configurationName = "runbook";
53+
string path = "/path/to/configuration";
54+
string nodeConfigurationName = "runbook.configuration";
55+
bool incrementNodeConfigBuild = false;
56+
57+
this.mockAutomationClient.Setup(
58+
f =>
59+
f.CreateNodeConfiguration(resourceGroupName, accountName, path, configurationName, incrementNodeConfigBuild, false)
60+
);
61+
62+
this.mockAutomationClient.Setup(
63+
f => f.GetNodeConfiguration(resourceGroupName, accountName, nodeConfigurationName, null)
64+
);
65+
66+
// Test
67+
this.cmdlet.ResourceGroupName = resourceGroupName;
68+
this.cmdlet.AutomationAccountName = accountName;
69+
this.cmdlet.ConfigurationName = configurationName;
70+
this.cmdlet.Path = path;
71+
this.cmdlet.IncrementNodeConfigurationBuild = incrementNodeConfigBuild;
72+
this.cmdlet.Force = false;
73+
74+
this.cmdlet.ExecuteCmdlet();
75+
76+
// Assert
77+
this.mockAutomationClient.Verify(f => f.CreateNodeConfiguration(resourceGroupName, accountName, path, configurationName, incrementNodeConfigBuild, false),
78+
Times.Once());
79+
}
80+
}
81+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System.Collections.Generic;
16+
using Microsoft.Azure.Commands.Automation.Cmdlet;
17+
using Microsoft.Azure.Commands.Automation.Common;
18+
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
19+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
20+
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
21+
using Moq;
22+
using Xunit;
23+
24+
namespace Microsoft.Azure.Commands.ResourceManager.Automation.Test.UnitTests
25+
{
26+
public class StartAzureAutomationDscCompilationJobTest : RMTestBase
27+
{
28+
private Mock<IAutomationClient> mockAutomationClient;
29+
30+
private MockCommandRuntime mockCommandRuntime;
31+
32+
private StartAzureAutomationDscCompilationJob cmdlet;
33+
34+
public StartAzureAutomationDscCompilationJobTest()
35+
{
36+
this.mockAutomationClient = new Mock<IAutomationClient>();
37+
this.mockCommandRuntime = new MockCommandRuntime();
38+
this.cmdlet = new StartAzureAutomationDscCompilationJob
39+
{
40+
AutomationClient = this.mockAutomationClient.Object,
41+
CommandRuntime = this.mockCommandRuntime
42+
};
43+
}
44+
45+
[Fact]
46+
[Trait(Category.AcceptanceType, Category.CheckIn)]
47+
public void StartAzureAutomationDscCompilationJobTestSuccessful()
48+
{
49+
// Setup
50+
string resourceGroupName = "resourceGroup";
51+
string accountName = "automation";
52+
string configurationName = "runbook";
53+
bool incrementNodeConfigurationBuild = true;
54+
var parameters = new Dictionary<string, string>()
55+
{
56+
{"Key1", "Value1"},
57+
{"Key2", "Value2"},
58+
};
59+
60+
61+
this.mockAutomationClient.Setup(
62+
f =>
63+
f.StartCompilationJob(resourceGroupName, accountName, configurationName, parameters, null, incrementNodeConfigurationBuild)
64+
);
65+
66+
//CompilationJob StartCompilationJob(string resourceGroupName,
67+
// string automationAccountName, string configurationName,
68+
// IDictionary parameters, IDictionary configurationData, bool incrementNodeConfigurationBuild = false);
69+
70+
// Test
71+
this.cmdlet.ResourceGroupName = resourceGroupName;
72+
this.cmdlet.AutomationAccountName = accountName;
73+
this.cmdlet.ConfigurationName = configurationName;
74+
this.cmdlet.Parameters = parameters;
75+
this.cmdlet.IncrementNodeConfigurationBuild = incrementNodeConfigurationBuild;
76+
this.cmdlet.ConfigurationData = null;
77+
78+
this.cmdlet.ExecuteCmdlet();
79+
80+
// Assert
81+
this.mockAutomationClient.Verify(f => f.StartCompilationJob(resourceGroupName, accountName, configurationName, parameters, null, incrementNodeConfigurationBuild),
82+
Times.Once());
83+
}
84+
}
85+
}

src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationDscNodeConfiguration.cs

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@
1515
using Microsoft.Azure.Commands.Automation.Model;
1616
using System.Management.Automation;
1717
using System.Security.Permissions;
18+
using Microsoft.Azure.Commands.Automation.Common;
19+
using Microsoft.Azure.Commands.Automation.Properties;
1820

1921
namespace Microsoft.Azure.Commands.Automation.Cmdlet
2022
{
2123
/// <summary>
2224
/// Imports dsc node configuration script
2325
/// </summary>
24-
[Cmdlet(VerbsData.Import, "AzureRmAutomationDscNodeConfiguration", SupportsShouldProcess = true)]
26+
[Cmdlet(VerbsData.Import, "AzureRmAutomationDscNodeConfiguration", SupportsShouldProcess = true, DefaultParameterSetName = AutomationCmdletParameterSets.ByAll)]
2527
[OutputType(typeof(NodeConfiguration))]
2628
public class ImportAzureAutomationDscNodeConfiguration : AzureAutomationBaseCmdlet
2729
{
@@ -33,27 +35,40 @@ public class ImportAzureAutomationDscNodeConfiguration : AzureAutomationBaseCmdl
3335
/// <summary>
3436
/// Gets or sets the source path.
3537
/// </summary>
36-
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Path to the node configuration .mof to import.")]
38+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true,
39+
HelpMessage = "Path to the node configuration .mof to import.")]
3740
[ValidateNotNullOrEmpty]
3841
public string Path { get; set; }
3942

4043
/// <summary>
4144
/// Gets or sets the configuration name for the node configuration.
4245
/// </summary>
43-
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The name of the DSC Configuration to import the Node Configuration under. All Node Configurations in Azure Automation must exist under a Configuration. The name of the Configuration will become the namespace of the imported Node Configuration, in the form of 'ConfigurationName.MofFileName'")]
46+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true,
47+
HelpMessage = "The name of the DSC Configuration to import the Node Configuration under. " +
48+
"All Node Configurations in Azure Automation must exist under a Configuration. " +
49+
"The name of the Configuration will become the namespace of the imported Node Configuration, " +
50+
"in the form of 'ConfigurationName.MofFileName'")]
4451
public string ConfigurationName { get; set; }
4552

4653

4754
/// <summary>
4855
/// Gets or sets switch parameter to confirm overwriting of existing configurations.
4956
/// </summary>
50-
[Parameter(Mandatory = false, HelpMessage = "Forces the command to overwrite an existing Node Configuration.")]
57+
[Parameter(Mandatory = false,
58+
HelpMessage = "Forces the command to overwrite an existing Node Configuration.")]
5159
public SwitchParameter Force
5260
{
5361
get { return this.overwriteExistingConfiguration; }
5462
set { this.overwriteExistingConfiguration = value; }
5563
}
5664

65+
/// <summary>
66+
/// Gets or sets switch parameter to confirm building a new build version of the NodeConfiguration.
67+
/// </summary>
68+
[Parameter(Mandatory = false,
69+
HelpMessage = "Creates a new Node Configuration build version.")]
70+
public SwitchParameter IncrementNodeConfigurationBuild;
71+
5772
/// <summary>
5873
/// Execute this cmdlet.
5974
/// </summary>
@@ -62,14 +77,38 @@ public override void ExecuteCmdlet()
6277
{
6378
if (ShouldProcess(Path, VerbsData.Import))
6479
{
65-
var nodeConfiguration = this.AutomationClient.CreateNodeConfiguration(
66-
this.ResourceGroupName,
67-
this.AutomationAccountName,
68-
this.Path,
69-
this.ConfigurationName,
70-
this.Force);
80+
var nodeName = System.IO.Path.GetFileNameWithoutExtension(Path);
81+
var nodeConfigurationName = ConfigurationName + "." + nodeName;
82+
83+
// if node configuration already exists, ensureuser knows about it.
84+
var nodeConfigurationModel = AutomationClient.GetNodeConfiguration(ResourceGroupName,
85+
AutomationAccountName,
86+
nodeConfigurationName,
87+
null);
88+
89+
if (nodeConfigurationModel != null && !IncrementNodeConfigurationBuild.IsPresent)
90+
{
91+
if (Force || ShouldContinue(Resources.NodeConfigurationAlreadyExistsConfirmation,
92+
Resources.NodeConfigurationAlreadyExistsCaption))
93+
{
94+
var nodeConfiguration = AutomationClient.CreateNodeConfiguration(
95+
ResourceGroupName, AutomationAccountName, Path, ConfigurationName, false, Force);
96+
97+
WriteObject(nodeConfiguration);
98+
}
99+
}
100+
else
101+
{
102+
var nodeConfiguration = AutomationClient.CreateNodeConfiguration(
103+
ResourceGroupName,
104+
AutomationAccountName,
105+
Path,
106+
ConfigurationName,
107+
IncrementNodeConfigurationBuild.IsPresent,
108+
false);
71109

72-
this.WriteObject(nodeConfiguration);
110+
WriteObject(nodeConfiguration);
111+
}
73112
}
74113
}
75114
}

src/ResourceManager/Automation/Commands.Automation/Cmdlet/StartAzureAutomationDscCompilationJob.cs

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ namespace Microsoft.Azure.Commands.Automation.Cmdlet
2525
/// <summary>
2626
/// starts azure automation compilation job
2727
/// </summary>
28-
[Cmdlet(VerbsLifecycle.Start, "AzureRmAutomationDscCompilationJob")]
28+
[Cmdlet(VerbsLifecycle.Start, "AzureRmAutomationDscCompilationJob", SupportsShouldProcess = true)]
2929
[OutputType(typeof(CompilationJob))]
3030
public class StartAzureAutomationDscCompilationJob : AzureAutomationBaseCmdlet
3131
{
32+
3233
/// <summary>
3334
/// Gets or sets the configuration name.
3435
/// </summary>
@@ -48,25 +49,38 @@ public class StartAzureAutomationDscCompilationJob : AzureAutomationBaseCmdlet
4849
[Parameter(Mandatory = false, HelpMessage = "The compilation job configuration data.")]
4950
public IDictionary ConfigurationData { get; set; }
5051

52+
/// <summary>
53+
/// Gets or sets switch parameter to confirm building a new build version of the NodeConfiguration.
54+
/// </summary>
55+
[Parameter(Mandatory = false, HelpMessage = "Creates a new Node Configuration build version.")]
56+
public SwitchParameter IncrementNodeConfigurationBuild;
57+
5158
/// <summary>
5259
/// Execute this cmdlet.
5360
/// </summary>
5461
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
5562
protected override void AutomationProcessRecord()
5663
{
57-
CompilationJob job = null;
58-
59-
if (this.Parameters != null && this.Parameters.Contains("ConfigurationData"))
64+
if (ShouldProcess(ConfigurationName, VerbsLifecycle.Start))
6065
{
61-
throw new ArgumentException(
62-
string.Format(
63-
CultureInfo.CurrentCulture,
64-
Resources.ConfigurationDataShouldNotBeInJobParameters, "-ConfigurationData"));
65-
}
66+
CompilationJob job = null;
6667

67-
job = this.AutomationClient.StartCompilationJob(this.ResourceGroupName, this.AutomationAccountName, this.ConfigurationName, this.Parameters, this.ConfigurationData);
68+
if (this.Parameters != null && this.Parameters.Contains("ConfigurationData"))
69+
{
70+
throw new ArgumentException(string.Format(
71+
CultureInfo.CurrentCulture, Resources.ConfigurationDataShouldNotBeInJobParameters,
72+
"-ConfigurationData"));
73+
}
6874

69-
this.WriteObject(job);
75+
job = this.AutomationClient.StartCompilationJob(this.ResourceGroupName,
76+
this.AutomationAccountName,
77+
this.ConfigurationName,
78+
this.Parameters,
79+
this.ConfigurationData,
80+
this.IncrementNodeConfigurationBuild.IsPresent);
81+
82+
this.WriteObject(job);
83+
}
7084
}
7185
}
7286
}

src/ResourceManager/Automation/Commands.Automation/Commands.Automation.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
</PropertyGroup>
5454
<ItemGroup>
5555
<Reference Include="Microsoft.Azure.Management.Automation, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
56-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Automation.2.0.1\lib\net40\Microsoft.Azure.Management.Automation.dll</HintPath>
56+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Automation.2.0.4\lib\net40\Microsoft.Azure.Management.Automation.dll</HintPath>
5757
<Private>True</Private>
5858
</Reference>
5959
<Reference Include="System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />

0 commit comments

Comments
 (0)