Skip to content

Commit 7219731

Browse files
KalpeshChavan12Kalpesh Chavan
andauthored
[MaintenanceService] Added Support for InGuestPatch maintenance scope. (#15827)
Co-authored-by: Kalpesh Chavan <[email protected]>
1 parent b7cba09 commit 7219731

17 files changed

+2551
-1072
lines changed

src/Maintenance/Maintenance.Test/Maintenance.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</PropertyGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="Microsoft.Azure.Management.Maintenance" Version="1.3.0" />
14+
<PackageReference Include="Microsoft.Azure.Management.Maintenance" Version="1.4.0-preview" />
1515
</ItemGroup>
1616

1717
<ItemGroup>

src/Maintenance/Maintenance.Test/ScenarioTests/Common.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,17 @@ function Get-ProviderLocation($provider)
6464

6565
if ($location -eq $null)
6666
{
67-
return "westus"
67+
return "eastus2euap"
6868
} else
6969
{
7070
return $location.Locations[0].ToLower() -replace '\s',''
7171
}
7272
}
7373

74-
return "westus"
74+
return "eastus2euap"
7575
}
7676

77-
return "westus"
77+
return "eastus2euap"
7878
}
7979

8080
<#

src/Maintenance/Maintenance.Test/ScenarioTests/MaintenanceTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ public void TestMaintenanceConfiguration()
3939
TestController.NewInstance.RunPowerShellTest(_logger, "Test-AzMaintenanceConfiguration");
4040
}
4141

42+
[Fact]
43+
[Trait(Category.AcceptanceType, Category.CheckIn)]
44+
public void TestMaintenanceConfigurationInGuestPatch()
45+
{
46+
TestController.NewInstance.RunPowerShellTest(_logger, "Test-AzMaintenanceConfigurationInGuestPatch");
47+
}
48+
4249
[Fact]
4350
[Trait(Category.AcceptanceType, Category.CheckIn)]
4451
public void TestConfigurationAssignment()

src/Maintenance/Maintenance.Test/ScenarioTests/MaintenanceTests.ps1

Lines changed: 148 additions & 18 deletions
Large diffs are not rendered by default.

src/Maintenance/Maintenance.Test/SessionRecords/Microsoft.Azure.Commands.Maintenance.Test.ScenarioTests.MaintenanceTests/TestConfigurationAssignment.json

Lines changed: 137 additions & 137 deletions
Large diffs are not rendered by default.

src/Maintenance/Maintenance.Test/SessionRecords/Microsoft.Azure.Commands.Maintenance.Test.ScenarioTests.MaintenanceTests/TestMaintenanceConfiguration.json

Lines changed: 232 additions & 528 deletions
Large diffs are not rendered by default.

src/Maintenance/Maintenance.Test/SessionRecords/Microsoft.Azure.Commands.Maintenance.Test.ScenarioTests.MaintenanceTests/TestMaintenanceConfigurationInGuestPatch.json

Lines changed: 1398 additions & 0 deletions
Large diffs are not rendered by default.

src/Maintenance/Maintenance.Test/SessionRecords/Microsoft.Azure.Commands.Maintenance.Test.ScenarioTests.MaintenanceTests/TestMaintenanceUpdate.json

Lines changed: 138 additions & 252 deletions
Large diffs are not rendered by default.

src/Maintenance/Maintenance.Test/SessionRecords/Microsoft.Azure.Commands.Maintenance.Test.ScenarioTests.MaintenanceTests/TestPublicMaintenanceConfiguration.json

Lines changed: 119 additions & 119 deletions
Large diffs are not rendered by default.

src/Maintenance/Maintenance.sln

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
21
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 15
4-
VisualStudioVersion = 15.0.27703.2042
2+
# Visual Studio Version 16
3+
VisualStudioVersion = 16.0.31328.270
54
MinimumVisualStudioVersion = 10.0.40219.1
65
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Maintenance", "Maintenance\Maintenance.csproj", "{0E11B67A-1257-40D0-BD33-8315759FDB01}"
76
EndProject
@@ -39,6 +38,10 @@ Global
3938
{142D7B0B-388A-4CEB-A228-7F6D423C5C2E}.Debug|Any CPU.Build.0 = Debug|Any CPU
4039
{142D7B0B-388A-4CEB-A228-7F6D423C5C2E}.Release|Any CPU.ActiveCfg = Release|Any CPU
4140
{142D7B0B-388A-4CEB-A228-7F6D423C5C2E}.Release|Any CPU.Build.0 = Release|Any CPU
41+
{6BD6B80A-06AF-4B5B-9230-69CCFC6C8D64}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
42+
{6BD6B80A-06AF-4B5B-9230-69CCFC6C8D64}.Debug|Any CPU.Build.0 = Debug|Any CPU
43+
{6BD6B80A-06AF-4B5B-9230-69CCFC6C8D64}.Release|Any CPU.ActiveCfg = Release|Any CPU
44+
{6BD6B80A-06AF-4B5B-9230-69CCFC6C8D64}.Release|Any CPU.Build.0 = Release|Any CPU
4245
{FF81DC73-B8EC-4082-8841-4FBF2B16E7CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
4346
{FF81DC73-B8EC-4082-8841-4FBF2B16E7CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
4447
{FF81DC73-B8EC-4082-8841-4FBF2B16E7CE}.Release|Any CPU.ActiveCfg = Release|Any CPU

src/Maintenance/Maintenance/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
-->
2020

2121
## Upcoming Release
22+
* Added Guest patch maintenance support.
2223

2324
## Version 1.1.1
2425
* Bumped API version to stable 2021-05-01.

src/Maintenance/Maintenance/Maintenance.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
<ItemGroup>
1414
<PackageReference Include="AutoMapper" Version="6.2.2" />
15-
<PackageReference Include="Microsoft.Azure.Management.Maintenance" Version="1.3.0" />
15+
<PackageReference Include="Microsoft.Azure.Management.Maintenance" Version="1.4.0-preview" />
1616
</ItemGroup>
1717

1818
<ItemGroup>

src/Maintenance/Maintenance/MaintenanceConfiguration/MaintenanceConfigurationCreateOrUpdateMethod.cs

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
1717
using Microsoft.Azure.Management.Maintenance;
1818
using Microsoft.Azure.Management.Maintenance.Models;
19+
using Newtonsoft.Json;
1920
using System;
2021
using System.Collections;
2122
using System.Collections.Generic;
@@ -85,6 +86,74 @@ public override void ExecuteCmdlet()
8586
{
8687
configuration.Visibility = this.Visibility;
8788
}
89+
90+
if (this.InstallPatchRebootSetting != null)
91+
{
92+
configuration.InstallPatches = configuration.InstallPatches ?? new InputPatchConfiguration();
93+
configuration.InstallPatches.RebootSetting = this.InstallPatchRebootSetting;
94+
}
95+
96+
if (this.WindowParameterClassificationToInclude != null)
97+
{
98+
configuration.InstallPatches = configuration.InstallPatches ?? new InputPatchConfiguration();
99+
configuration.InstallPatches.WindowsParameters = configuration.InstallPatches.WindowsParameters ?? new InputWindowsParameters();
100+
configuration.InstallPatches.WindowsParameters.ClassificationsToInclude = this.WindowParameterClassificationToInclude.ToList();
101+
}
102+
103+
if (this.WindowParameterExcludeKbRequiringReboot.HasValue)
104+
{
105+
configuration.InstallPatches = configuration.InstallPatches ?? new InputPatchConfiguration();
106+
configuration.InstallPatches.WindowsParameters = configuration.InstallPatches.WindowsParameters ?? new InputWindowsParameters();
107+
configuration.InstallPatches.WindowsParameters.ExcludeKbsRequiringReboot = this.WindowParameterExcludeKbRequiringReboot;
108+
}
109+
110+
if (this.WindowParameterKbNumberToExclude != null)
111+
{
112+
configuration.InstallPatches = configuration.InstallPatches ?? new InputPatchConfiguration();
113+
configuration.InstallPatches.WindowsParameters = configuration.InstallPatches.WindowsParameters ?? new InputWindowsParameters();
114+
configuration.InstallPatches.WindowsParameters.KbNumbersToExclude = this.WindowParameterKbNumberToExclude.ToList();
115+
}
116+
117+
if (this.WindowParameterKbNumberToInclude != null)
118+
{
119+
configuration.InstallPatches = configuration.InstallPatches ?? new InputPatchConfiguration();
120+
configuration.InstallPatches.WindowsParameters = configuration.InstallPatches.WindowsParameters ?? new InputWindowsParameters();
121+
configuration.InstallPatches.WindowsParameters.KbNumbersToInclude = this.WindowParameterKbNumberToInclude.ToList();
122+
}
123+
124+
if (this.LinuxParameterClassificationToInclude!= null)
125+
{
126+
configuration.InstallPatches = configuration.InstallPatches ?? new InputPatchConfiguration();
127+
configuration.InstallPatches.LinuxParameters = configuration.InstallPatches.LinuxParameters ?? new InputLinuxParameters();
128+
configuration.InstallPatches.LinuxParameters.ClassificationsToInclude = this.LinuxParameterClassificationToInclude.ToList();
129+
}
130+
131+
if (this.LinuxParameterPackageNameMaskToExclude != null)
132+
{
133+
configuration.InstallPatches = configuration.InstallPatches ?? new InputPatchConfiguration();
134+
configuration.InstallPatches.LinuxParameters = configuration.InstallPatches.LinuxParameters ?? new InputLinuxParameters();
135+
configuration.InstallPatches.LinuxParameters.PackageNameMasksToExclude= this.LinuxParameterPackageNameMaskToExclude.ToList();
136+
}
137+
138+
if (this.LinuxParameterPackageNameMaskToInclude != null)
139+
{
140+
configuration.InstallPatches = configuration.InstallPatches ?? new InputPatchConfiguration();
141+
configuration.InstallPatches.LinuxParameters = configuration.InstallPatches.LinuxParameters ?? new InputLinuxParameters();
142+
configuration.InstallPatches.LinuxParameters.PackageNameMasksToInclude= this.LinuxParameterPackageNameMaskToInclude.ToList();
143+
}
144+
145+
if (this.PreTask != null)
146+
{
147+
configuration.InstallPatches = configuration.InstallPatches ?? new InputPatchConfiguration();
148+
configuration.InstallPatches.PreTasks = JsonConvert.DeserializeObject<List<TaskProperties>>(this.PreTask);
149+
}
150+
151+
if (this.PostTask != null)
152+
{
153+
configuration.InstallPatches = configuration.InstallPatches ?? new InputPatchConfiguration();
154+
configuration.InstallPatches.PreTasks = JsonConvert.DeserializeObject<List<TaskProperties>>(this.PostTask);
155+
}
156+
88157
var result = MaintenanceConfigurationsClient.CreateOrUpdate(resourceGroupName, resourceName, configuration);
89158
var psObject = new PSMaintenanceConfiguration();
90159
MaintenanceAutomationAutoMapperProfile.Mapper.Map<MaintenanceConfiguration, PSMaintenanceConfiguration>(result, psObject);
@@ -163,6 +232,55 @@ public override void ExecuteCmdlet()
163232
HelpMessage = "The Recurrence interval.")]
164233
public string RecurEvery { get; set; }
165234

235+
[Parameter(
236+
Mandatory = false,
237+
HelpMessage = "List of packages to include during vm patch operation")]
238+
public HashSet<string> LinuxParameterPackageNameMaskToInclude { get; set; }
239+
240+
[Parameter(
241+
Mandatory = false,
242+
HelpMessage = "List of packages to exclude during vm patch operation")]
243+
public HashSet<string> LinuxParameterPackageNameMaskToExclude { get; set; }
244+
245+
[Parameter(
246+
Mandatory = false,
247+
HelpMessage = "List of linux patch classifications")]
248+
public HashSet<string> LinuxParameterClassificationToInclude { get; set; }
249+
250+
[Parameter(
251+
Mandatory = false,
252+
HelpMessage = "List of KBs to include during vm patch operation")]
253+
public HashSet<string> WindowParameterKbNumberToInclude { get; set; }
254+
255+
[Parameter(
256+
Mandatory = false,
257+
HelpMessage = "List of KBs to exclude during vm patch operationn")]
258+
public HashSet<string> WindowParameterKbNumberToExclude { get; set; }
259+
260+
[Parameter(
261+
Mandatory = false,
262+
HelpMessage = "List of windows patch classification")]
263+
public HashSet<string> WindowParameterClassificationToInclude { get; set; }
264+
265+
[Parameter(
266+
Mandatory = false,
267+
HelpMessage = "Exclude KBs which require reboot")]
268+
public bool? WindowParameterExcludeKbRequiringReboot { get; set; }
269+
270+
[Parameter(
271+
Mandatory = false,
272+
HelpMessage = "List of tasks executed before schedule. e.g. [{'source' :'runbook', 'taskScope': 'Global', 'parameters': { 'arg1': 'value1'}}]")]
273+
public string PreTask { get; set; }
274+
275+
[Parameter(
276+
Mandatory = false,
277+
HelpMessage = "List of tasks executed after schedule. [{'source' :'runbook', 'taskScope': 'Resource', 'parameters': { 'arg1': 'value1'}}]")]
278+
public string PostTask { get; set; }
279+
280+
[Parameter(
281+
Mandatory = false,
282+
HelpMessage = "Install Patch Reboot Option. Allowed values Never, IfRequired, Always")]
283+
public string InstallPatchRebootSetting { get; set; }
166284

167285
[Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")]
168286
public SwitchParameter AsJob { get; set; }

src/Maintenance/Maintenance/MaintenanceConfiguration/MaintenanceConfigurationGetMethod.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ public override void ExecuteCmdlet()
4040
if (!string.IsNullOrEmpty(resourceGroupName) && !string.IsNullOrEmpty(name))
4141
{
4242
var result = MaintenanceConfigurationsClient.Get(resourceGroupName, name);
43-
WriteObject(result);
43+
PSMaintenanceConfiguration psMaintenanceConfiguration = new PSMaintenanceConfiguration();
44+
MaintenanceAutomationAutoMapperProfile.Mapper.Map<MaintenanceConfiguration, PSMaintenanceConfiguration>(result, psMaintenanceConfiguration);
45+
WriteObject(psMaintenanceConfiguration);
4446
}
4547

4648
else

src/Maintenance/Maintenance/Models/MaintenanceAutoMapperProfile.cs

Lines changed: 71 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
// ----------------------------------------------------------------------------------
1414

1515
using AutoMapper;
16+
using System.Collections.Generic;
17+
using System.Linq;
1618
using FROM = Microsoft.Azure.Management.Maintenance.Models;
1719
using TO = Microsoft.Azure.Commands.Maintenance.Models;
1820

@@ -50,16 +52,81 @@ private static void Initialize()
5052
var config = new MapperConfiguration(cfg =>
5153
{
5254
cfg.CreateMap<FROM.ApplyUpdate, TO.PSApplyUpdate>();
53-
cfg.CreateMap<TO.PSApplyUpdate, FROM.ApplyUpdate>();
55+
cfg.CreateMap<TO.PSApplyUpdate, FROM.ApplyUpdate>()
56+
.ForMember(src => src.SystemData, s => s.Ignore());
5457
cfg.CreateMap<FROM.ConfigurationAssignment, TO.PSConfigurationAssignment>();
55-
cfg.CreateMap<TO.PSConfigurationAssignment, FROM.ConfigurationAssignment>();
56-
cfg.CreateMap<FROM.MaintenanceConfiguration, TO.PSMaintenanceConfiguration>();
57-
cfg.CreateMap<TO.PSMaintenanceConfiguration, FROM.MaintenanceConfiguration>();
58+
cfg.CreateMap<TO.PSConfigurationAssignment, FROM.ConfigurationAssignment>()
59+
.ForMember(src => src.SystemData, s => s.Ignore());
60+
cfg.CreateMap<FROM.MaintenanceConfiguration, TO.PSMaintenanceConfiguration>()
61+
.ForMember(dest => dest.InstallPatchRebootSetting, opt => opt.MapFrom(src => src.InstallPatches.RebootSetting))
62+
.ForMember(dest => dest.LinuxParameterClassificationToInclude, opt => opt.MapFrom(src => src.InstallPatches.LinuxParameters.ClassificationsToInclude))
63+
.ForMember(dest => dest.LinuxParameterPackageNameMaskToExclude, opt => opt.MapFrom(src => src.InstallPatches.LinuxParameters.PackageNameMasksToExclude))
64+
.ForMember(dest => dest.LinuxParameterPackageNameMaskToInclude, opt => opt.MapFrom(src => src.InstallPatches.LinuxParameters.PackageNameMasksToInclude))
65+
.ForMember(dest => dest.WindowParameterClassificationToInclude, opt => opt.MapFrom(src => src.InstallPatches.WindowsParameters.ClassificationsToInclude))
66+
.ForMember(dest => dest.WindowParameterExcludeKbRequiringReboot, opt => opt.MapFrom(src => src.InstallPatches.WindowsParameters.ExcludeKbsRequiringReboot))
67+
.ForMember(dest => dest.WindowParameterKbNumberToExclude, opt => opt.MapFrom(src => src.InstallPatches.WindowsParameters.KbNumbersToExclude))
68+
.ForMember(dest => dest.WindowParameterKbNumberToInclude, opt => opt.MapFrom(src => src.InstallPatches.WindowsParameters.KbNumbersToInclude))
69+
.ForMember(dest => dest.PreTask, opt => opt.MapFrom(src => src.InstallPatches.PreTasks))
70+
.ForMember(dest => dest.PostTask, opt => opt.MapFrom(src => src.InstallPatches.PostTasks))
71+
.ForMember(dest => dest.InstallPatchRebootSetting, opt => opt.MapFrom(src => src.InstallPatches.RebootSetting))
72+
.ForSourceMember(src => src.SystemData, s => s.Ignore())
73+
.ForSourceMember(src => src.InstallPatches, s => s.Ignore())
74+
.ForPath(dst => dst.PostTask, s => s.Ignore())
75+
.ForPath(dst => dst.PreTask, s => s.Ignore())
76+
.AfterMap((src, dst) => {
77+
if (src?.InstallPatches?.PreTasks?.Any() ?? false)
78+
{
79+
dst.PreTask = Newtonsoft.Json.JsonConvert.SerializeObject(src.InstallPatches.PreTasks);
80+
}
81+
if (src?.InstallPatches?.PostTasks?.Any() ?? false)
82+
{
83+
dst.PostTask = Newtonsoft.Json.JsonConvert.SerializeObject(src.InstallPatches.PostTasks);
84+
}
85+
});
86+
cfg.CreateMap<TO.PSMaintenanceConfiguration, FROM.MaintenanceConfiguration>()
87+
.ForPath(dest => dest.InstallPatches.LinuxParameters.ClassificationsToInclude, src => src.MapFrom(o => o.LinuxParameterClassificationToInclude))
88+
.ForPath(dest => dest.InstallPatches.LinuxParameters.PackageNameMasksToInclude, src => src.MapFrom(o => o.LinuxParameterPackageNameMaskToInclude))
89+
.ForPath(dest => dest.InstallPatches.LinuxParameters.PackageNameMasksToExclude, src => src.MapFrom(o => o.LinuxParameterPackageNameMaskToExclude))
90+
.ForPath(dest => dest.InstallPatches.WindowsParameters.ClassificationsToInclude, src => src.MapFrom(o => o.WindowParameterClassificationToInclude))
91+
.ForPath(dest => dest.InstallPatches.WindowsParameters.ExcludeKbsRequiringReboot, src => src.MapFrom(o => o.WindowParameterExcludeKbRequiringReboot))
92+
.ForPath(dest => dest.InstallPatches.WindowsParameters.KbNumbersToExclude, src => src.MapFrom(o => o.WindowParameterKbNumberToExclude))
93+
.ForPath(dest => dest.InstallPatches.WindowsParameters.KbNumbersToInclude, src => src.MapFrom(o => o.WindowParameterKbNumberToInclude))
94+
.AfterMap((src, dst) => {
95+
if (string.IsNullOrEmpty(src.InstallPatchRebootSetting) &&
96+
string.IsNullOrEmpty(src.PostTask) &&
97+
string.IsNullOrEmpty(src.PreTask) &&
98+
!src.WindowParameterExcludeKbRequiringReboot.HasValue &&
99+
IsEmpty(src.LinuxParameterClassificationToInclude) &&
100+
IsEmpty(src.LinuxParameterPackageNameMaskToExclude) &&
101+
IsEmpty(src.LinuxParameterPackageNameMaskToInclude) &&
102+
IsEmpty(src.WindowParameterClassificationToInclude) &&
103+
IsEmpty(src.WindowParameterKbNumberToExclude) &&
104+
IsEmpty(src.WindowParameterKbNumberToInclude))
105+
{
106+
dst.InstallPatches = null;
107+
}
108+
else
109+
{
110+
if(string.IsNullOrEmpty(src.PreTask))
111+
{
112+
dst.InstallPatches.PreTasks = Newtonsoft.Json.JsonConvert.DeserializeObject<List<FROM.TaskProperties>>(src.PreTask);
113+
dst.InstallPatches.PostTasks = Newtonsoft.Json.JsonConvert.DeserializeObject<List<FROM.TaskProperties>>(src.PostTask);
114+
}
115+
}
116+
})
117+
.ForPath(dest => dest.InstallPatches.PostTasks, s => s.Ignore())
118+
.ForPath(dest => dest.InstallPatches.PreTasks, s => s.Ignore())
119+
.ForMember(dest => dest.SystemData, s => s.Ignore());
58120
cfg.CreateMap<FROM.Update, TO.PSUpdate>();
59121
cfg.CreateMap<TO.PSUpdate, FROM.Update>();
60122

61123
});
62124
_mapper = config.CreateMapper();
125+
config.AssertConfigurationIsValid();
126+
}
127+
public static bool IsEmpty<T>(IEnumerable<T> collection)
128+
{
129+
return !(collection != null && collection.Any());
63130
}
64131
}
65132
}

src/Maintenance/Maintenance/Models/PSMaintenanceConfiguration.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ public partial class PSMaintenanceConfiguration
3333
public string Timezone { get; set; }
3434
public string Visibility { get; set; }
3535
public string RecurEvery { get; set; }
36+
public HashSet<string> LinuxParameterClassificationToInclude { get; set; }
37+
public HashSet<string> LinuxParameterPackageNameMaskToExclude { get; set; }
38+
public HashSet<string> LinuxParameterPackageNameMaskToInclude { get; set; }
39+
public HashSet<string> WindowParameterKbNumberToInclude { get; set; }
40+
public HashSet<string> WindowParameterKbNumberToExclude { get; set; }
41+
public HashSet<string> WindowParameterClassificationToInclude { get; set; }
42+
public bool? WindowParameterExcludeKbRequiringReboot { get; set; }
43+
public string PreTask { get; set; }
44+
public string PostTask { get; set; }
45+
public string InstallPatchRebootSetting { get; set; }
3646

3747
}
3848
}

0 commit comments

Comments
 (0)