Skip to content

Commit bc40a7d

Browse files
committed
minor bug fixes in policy
1 parent 0badd7d commit bc40a7d

File tree

5 files changed

+44
-26
lines changed

5 files changed

+44
-26
lines changed

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Helpers/Validations/PolicyValidations.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,28 @@ public static void ValidateLongTermRetentionPolicyWithSimpleRetentionPolicy(
3131
{
3232
// for daily schedule, daily retention policy is required
3333
if (schPolicy.ScheduleRunFrequency == ScheduleRunType.Daily &&
34-
ltrPolicy.DailySchedule == null)
34+
(ltrPolicy.DailySchedule == null || ltrPolicy.IsDailyScheduleEnabled == false))
3535
{
3636
throw new ArgumentException(Resources.DailyRetentionScheduleNullException);
3737
}
3838

3939
// for weekly schedule, daily retention policy should be NULL
4040
// AND weekly retention policy is required
4141
if (schPolicy.ScheduleRunFrequency == ScheduleRunType.Weekly &&
42-
(ltrPolicy.DailySchedule != null || ltrPolicy.WeeklySchedule == null))
42+
(ltrPolicy.IsDailyScheduleEnabled != false || ltrPolicy.WeeklySchedule == null ||
43+
(ltrPolicy.IsWeeklyScheduleEnabled == false)))
4344
{
4445
throw new ArgumentException(Resources.WeeklyRetentionScheduleNullException);
4546
}
4647

4748
// validate daily retention schedule with schPolicy
48-
if (ltrPolicy.DailySchedule != null)
49+
if (ltrPolicy.DailySchedule != null && ltrPolicy.IsDailyScheduleEnabled == true)
4950
{
5051
ValidateRetentionAndBackupTimes(schPolicy.ScheduleRunTimes, ltrPolicy.DailySchedule.RetentionTimes);
5152
}
5253

5354
// validate weekly retention schedule with schPolicy
54-
if (ltrPolicy.WeeklySchedule != null)
55+
if (ltrPolicy.WeeklySchedule != null && ltrPolicy.IsWeeklyScheduleEnabled == true)
5556
{
5657
ValidateRetentionAndBackupTimes(schPolicy.ScheduleRunTimes, ltrPolicy.WeeklySchedule.RetentionTimes);
5758

@@ -69,7 +70,7 @@ public static void ValidateLongTermRetentionPolicyWithSimpleRetentionPolicy(
6970
}
7071

7172
// validate monthly retention schedule with schPolicy
72-
if (ltrPolicy.MonthlySchedule != null)
73+
if (ltrPolicy.MonthlySchedule != null && ltrPolicy.IsMonthlyScheduleEnabled == true)
7374
{
7475
ValidateRetentionAndBackupTimes(schPolicy.ScheduleRunTimes, ltrPolicy.MonthlySchedule.RetentionTimes);
7576

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Models/Properties/Resources.Designer.cs

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Models/Properties/Resources.resx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@
202202
<value>RetentionTime in retention schedule should be same as backup time in SchedulePolicy</value>
203203
</data>
204204
<data name="DailyRetentionScheduleNullException" xml:space="preserve">
205-
<value>Daily Retention Schedule can't be null if Daily Backup Schedule is enabled</value>
205+
<value>Daily Retention Schedule can't be null (or) IsDailyScheduleEnabled should be 'true' if Daily Backup Schedule is enabled</value>
206206
</data>
207207
<data name="DailyScheduleEnabledButScheduleIsNullException" xml:space="preserve">
208208
<value>RetentionPolicy: IsDailyScheduleEnabled=true but DailySchedule is NULL</value>
@@ -226,7 +226,7 @@
226226
<value>RetentionDuration in Days/Weeks/Months/Years should be from 1 - 9999</value>
227227
</data>
228228
<data name="WeeklyRetentionScheduleNullException" xml:space="preserve">
229-
<value>If Weekly backup schedule is enabled, Daily retention schedule should be null and Weekly retention schedule should not be null</value>
229+
<value>If Weekly backup schedule is enabled, then IsDailyScheduleEnabled should be false and Weekly retention schedule should not be null, IsWeeklyScheduleEnabled should be true</value>
230230
</data>
231231
<data name="WeeklyScheduleEnabledButScheduleIsNullException" xml:space="preserve">
232232
<value>RetentionPolicy: IsWeeklyScheduleEnabled=true but WeeklySchedule is NULL</value>

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Providers/Providers/IaasVmPsBackupProvider.cs

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -201,25 +201,30 @@ public ProtectionPolicyResponse CreatePolicy()
201201
{
202202
string policyName = (string)ProviderData.ProviderParameters[PolicyParams.PolicyName];
203203
Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models.WorkloadType workloadType =
204-
(Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models.WorkloadType)ProviderData.ProviderParameters[PolicyParams.WorkloadType];
205-
AzureRmRecoveryServicesRetentionPolicyBase retentionPolicy = (AzureRmRecoveryServicesRetentionPolicyBase)
206-
ProviderData.ProviderParameters[PolicyParams.RetentionPolicy];
207-
AzureRmRecoveryServicesSchedulePolicyBase schedulePolicy = (AzureRmRecoveryServicesSchedulePolicyBase)
208-
ProviderData.ProviderParameters[PolicyParams.SchedulePolicy];
204+
(Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models.WorkloadType)ProviderData.ProviderParameters[PolicyParams.WorkloadType];
205+
AzureRmRecoveryServicesRetentionPolicyBase retentionPolicy =
206+
ProviderData.ProviderParameters.ContainsKey(PolicyParams.RetentionPolicy) ?
207+
(AzureRmRecoveryServicesRetentionPolicyBase)ProviderData.ProviderParameters[PolicyParams.RetentionPolicy] :
208+
null;
209+
AzureRmRecoveryServicesSchedulePolicyBase schedulePolicy =
210+
ProviderData.ProviderParameters.ContainsKey(PolicyParams.SchedulePolicy) ?
211+
(AzureRmRecoveryServicesSchedulePolicyBase)ProviderData.ProviderParameters[PolicyParams.SchedulePolicy] :
212+
null;
209213

210214
// do validations
211215
ValidateAzureVMWorkloadType(workloadType);
212216
ValidateAzureVMSchedulePolicy(schedulePolicy);
213217
Logger.Instance.WriteDebug("Validation of Schedule policy is successful");
214218

215-
// update the retention times from backupSchedule to retentionPolicy after converting to UTC
216-
CopyScheduleTimeToRetentionTimes((AzureRmRecoveryServicesLongTermRetentionPolicy)retentionPolicy,
217-
(AzureRmRecoveryServicesSimpleSchedulePolicy)schedulePolicy);
218-
219219
// validate RetentionPolicy
220220
ValidateAzureVMRetentionPolicy(retentionPolicy);
221221
Logger.Instance.WriteDebug("Validation of Retention policy is successful");
222222

223+
// update the retention times from backupSchedule to retentionPolicy after converting to UTC
224+
CopyScheduleTimeToRetentionTimes((AzureRmRecoveryServicesLongTermRetentionPolicy)retentionPolicy,
225+
(AzureRmRecoveryServicesSimpleSchedulePolicy)schedulePolicy);
226+
Logger.Instance.WriteDebug("Copy of RetentionTime from with SchedulePolicy to RetentionPolicy is successful");
227+
223228
// Now validate both RetentionPolicy and SchedulePolicy together
224229
PolicyHelpers.ValidateLongTermRetentionPolicyWithSimpleRetentionPolicy(
225230
(AzureRmRecoveryServicesLongTermRetentionPolicy)retentionPolicy,
@@ -248,15 +253,23 @@ public ProtectionPolicyResponse CreatePolicy()
248253

249254
public ProtectionPolicyResponse ModifyPolicy()
250255
{
251-
AzureRmRecoveryServicesRetentionPolicyBase retentionPolicy = (AzureRmRecoveryServicesRetentionPolicyBase)
252-
ProviderData.ProviderParameters[PolicyParams.RetentionPolicy];
253-
AzureRmRecoveryServicesSchedulePolicyBase schedulePolicy = (AzureRmRecoveryServicesSchedulePolicyBase)
254-
ProviderData.ProviderParameters[PolicyParams.SchedulePolicy];
255-
AzureRmRecoveryServicesPolicyBase policy = (AzureRmRecoveryServicesPolicyBase)
256-
ProviderData.ProviderParameters[PolicyParams.ProtectionPolicy];
256+
AzureRmRecoveryServicesRetentionPolicyBase retentionPolicy =
257+
ProviderData.ProviderParameters.ContainsKey(PolicyParams.RetentionPolicy) ?
258+
(AzureRmRecoveryServicesRetentionPolicyBase)ProviderData.ProviderParameters[PolicyParams.RetentionPolicy] :
259+
null;
260+
AzureRmRecoveryServicesSchedulePolicyBase schedulePolicy =
261+
ProviderData.ProviderParameters.ContainsKey(PolicyParams.SchedulePolicy) ?
262+
(AzureRmRecoveryServicesSchedulePolicyBase)ProviderData.ProviderParameters[PolicyParams.SchedulePolicy] :
263+
null;
264+
265+
AzureRmRecoveryServicesPolicyBase policy =
266+
ProviderData.ProviderParameters.ContainsKey(PolicyParams.ProtectionPolicy) ?
267+
(AzureRmRecoveryServicesPolicyBase)ProviderData.ProviderParameters[PolicyParams.ProtectionPolicy] :
268+
null;
257269

258270
// do validations
259271
ValidateAzureVMProtectionPolicy(policy);
272+
Logger.Instance.WriteDebug("Validation of Protection Policy is successful");
260273

261274
// RetentionPolicy and SchedulePolicy both should not be empty
262275
if (retentionPolicy == null && schedulePolicy == null)
@@ -269,22 +282,26 @@ public ProtectionPolicyResponse ModifyPolicy()
269282
{
270283
ValidateAzureVMSchedulePolicy(schedulePolicy);
271284
((AzureRmRecoveryServicesIaasVmPolicy)policy).SchedulePolicy = schedulePolicy;
285+
Logger.Instance.WriteDebug("Validation of Schedule policy is successful");
272286
}
273287
if (retentionPolicy != null)
274288
{
275289
ValidateAzureVMRetentionPolicy(retentionPolicy);
276290
((AzureRmRecoveryServicesIaasVmPolicy)policy).RetentionPolicy = retentionPolicy;
291+
Logger.Instance.WriteDebug("Validation of Retention policy is successful");
277292
}
278293

279294
// copy the backupSchedule time to retentionPolicy after converting to UTC
280295
CopyScheduleTimeToRetentionTimes(
281296
(AzureRmRecoveryServicesLongTermRetentionPolicy)((AzureRmRecoveryServicesIaasVmPolicy)policy).RetentionPolicy,
282297
(AzureRmRecoveryServicesSimpleSchedulePolicy)((AzureRmRecoveryServicesIaasVmPolicy)policy).SchedulePolicy);
298+
Logger.Instance.WriteDebug("Copy of RetentionTime from with SchedulePolicy to RetentionPolicy is successful");
283299

284300
// Now validate both RetentionPolicy and SchedulePolicy matches or not
285301
PolicyHelpers.ValidateLongTermRetentionPolicyWithSimpleRetentionPolicy(
286302
(AzureRmRecoveryServicesLongTermRetentionPolicy)((AzureRmRecoveryServicesIaasVmPolicy)policy).RetentionPolicy,
287303
(AzureRmRecoveryServicesSimpleSchedulePolicy)((AzureRmRecoveryServicesIaasVmPolicy)policy).SchedulePolicy);
304+
Logger.Instance.WriteDebug("Validation of Retention policy with Schedule policy is successful");
288305

289306
// construct Hydra policy request
290307
ProtectionPolicyRequest hydraRequest = new ProtectionPolicyRequest()

src/ResourceManager/RecoveryServices.Backup/Microsoft.Azure.Commands.RecoveryServices.Backup.format.ps1xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@
4242
<PropertyName>BackupManagementType</PropertyName>
4343
</TableColumnItem>
4444
<TableColumnItem>
45-
<PropertyName>SchedulePolicy.ScheduleRunTimes</PropertyName>
45+
<ScriptBlock>$_.SchedulePolicy.ScheduleRunTimes</ScriptBlock>
4646
</TableColumnItem>
4747
<TableColumnItem>
48-
<PropertyName>SchedulePolicy.ScheduleRunDays</PropertyName>
48+
<ScriptBlock>$_.SchedulePolicy.ScheduleRunDays</ScriptBlock>
4949
</TableColumnItem>
5050
</TableColumnItems>
5151
</TableRowEntry>

0 commit comments

Comments
 (0)