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

[CRP] Add assessmentMode to the VM Model #21357

Merged
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 @@ -23,7 +23,11 @@ public void TestVMWithSettingWindowsConfigurationPatchSettingsValueOfManual()
{
using (MockContext context = MockContext.Start(this.GetType()))
{
StartPatchSettingTest(context, "Manual", false);
var patchSetting = new PatchSettings
{
PatchMode = "Manual"
};
StartPatchSettingTest(context, patchSetting, false);
}
}

Expand All @@ -32,31 +36,49 @@ public void TestVMWithSettingWindowsConfigurationPatchSettingsValueOfAutomaticBy
{
using (MockContext context = MockContext.Start(this.GetType()))
{
StartPatchSettingTest(context, "AutomaticByOS", true);
var patchSetting = new PatchSettings
{
PatchMode = "AutomaticByOS",
};
StartPatchSettingTest(context, patchSetting, true);
}
}

[Fact()]
public void TestVMWithSettingWindowsConfigurationPatchSettingsValuesOfAutomaticByPlatform()
{
using (MockContext context = MockContext.Start(this.GetType()))
{
var patchSetting = new PatchSettings
{
PatchMode = "AutomaticByPlatform",
AssessmentMode = "AutomaticByPlatform",
};
StartPatchSettingTest(context, patchSetting, true);
}
}

[Fact()]
public void TestVMWithSettingWindowsConfigurationPatchSettingsValueOfAutomaticByPlatform()
public void TestVMWithSettingWindowsConfigurationPatchSettingsAssessmentModeOfImageDefault()
{
using (MockContext context = MockContext.Start(this.GetType()))
{
StartPatchSettingTest(context, "AutomaticByPlatform", true);
var patchSetting = new PatchSettings
{
AssessmentMode = "ImageDefault",
};
StartPatchSettingTest(context, patchSetting, false);
}
}

private void StartPatchSettingTest(MockContext context, string patchSettingMode, bool enableAutomaticUpdates)
private void StartPatchSettingTest(MockContext context, PatchSettings patchSetting, bool enableAutomaticUpdates)
{
EnsureClientsInitialized(context);

string rgName = ComputeManagementTestUtilities.GenerateName(TestPrefix);

// The following variables are defined here to allow validation
string autoLogonContent = null;
var patchSetting = new PatchSettings
{
PatchMode = patchSettingMode
};

Action<VirtualMachine> configureWindowsConfigurationPatchSetting = inputVM =>
{
Expand All @@ -65,7 +87,7 @@ private void StartPatchSettingTest(MockContext context, string patchSettingMode,
};

Action<VirtualMachine> validateWindowsConfigurationPatchSetting =
outputVM => ValidateWinPatchSetting(patchSetting.PatchMode, enableAutomaticUpdates, autoLogonContent, outputVM);
outputVM => ValidateWinPatchSetting(patchSetting, enableAutomaticUpdates, autoLogonContent, outputVM);

TestVMWithOSProfile(
rgName: rgName,
Expand All @@ -75,7 +97,7 @@ private void StartPatchSettingTest(MockContext context, string patchSettingMode,

}

private void ValidateWinPatchSetting(string patchSettingMode, bool enableAutomaticUpdates, string autoLogonContent, VirtualMachine outputVM)
private void ValidateWinPatchSetting(PatchSettings patchSetting, bool enableAutomaticUpdates, string autoLogonContent, VirtualMachine outputVM)
{
var osProfile = outputVM.OsProfile;

Expand All @@ -84,11 +106,32 @@ private void ValidateWinPatchSetting(string patchSettingMode, bool enableAutomat

Assert.True(osProfile.WindowsConfiguration.ProvisionVMAgent != null && osProfile.WindowsConfiguration.ProvisionVMAgent.Value);
Assert.True(osProfile.WindowsConfiguration.EnableAutomaticUpdates != null && osProfile.WindowsConfiguration.EnableAutomaticUpdates.Value == enableAutomaticUpdates);
// PatchSetting

// PatchSetting checks
Assert.NotNull(osProfile.WindowsConfiguration.PatchSettings);
Assert.NotNull(osProfile.WindowsConfiguration.PatchSettings.PatchMode);
Assert.Equal(osProfile.WindowsConfiguration.PatchSettings.PatchMode, patchSettingMode);
if (patchSetting.PatchMode != null)
{
Assert.NotNull(osProfile.WindowsConfiguration.PatchSettings.PatchMode);
Assert.Equal(osProfile.WindowsConfiguration.PatchSettings.PatchMode, patchSetting.PatchMode);
}
else
{
// By default in supported API versions, a value is provided in the VM model even if one is
// not specified by the user.
Assert.Equal("AutomaticByOS", osProfile.WindowsConfiguration.PatchSettings.PatchMode);
}

if (patchSetting.AssessmentMode != null)
{
Assert.NotNull(osProfile.WindowsConfiguration.PatchSettings.AssessmentMode);
Assert.Equal(osProfile.WindowsConfiguration.PatchSettings.AssessmentMode, patchSetting.AssessmentMode);
}
else
{
// By default in supported API versions, a value is provided in the VM model even if one is
// not specified by the user.
Assert.Equal("ImageDefault", osProfile.WindowsConfiguration.PatchSettings.AssessmentMode);
}
}

private void TestVMWithOSProfile(
Expand Down
Loading