Skip to content

Commit

Permalink
uncommented test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
hiaga committed May 16, 2022
1 parent 4ba3153 commit 63bddd3
Show file tree
Hide file tree
Showing 15 changed files with 442 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public partial class PolicyHelpers
// <summary>
/// Helper function to validate long term rentention policy and simple schedule policy.
/// </summary>
public static void ValidateLongTermRetentionPolicyWithSimpleRetentionPolicy(
public static void ValidateLongTermRetentionPolicyWithSimpleSchedulePolicy(
LongTermRetentionPolicy ltrPolicy,
SimpleSchedulePolicy schPolicy)
{
Expand Down Expand Up @@ -124,7 +124,7 @@ public static void ValidateLongTermRetentionPolicyWithSimpleRetentionPolicy(
// <summary>
/// Helper function to validate long term rentention policy and simple schedule policy.
/// </summary>
public static void ValidateLongTermRetentionPolicyWithSimpleRetentionPolicy(
public static void ValidateLongTermRetentionPolicyWithSimpleSchedulePolicy(
LongTermRetentionPolicy ltrPolicy,
SimpleSchedulePolicyV2 schPolicy)
{
Expand Down Expand Up @@ -226,7 +226,7 @@ public static void ValidateLongTermRetentionPolicyWithSimpleRetentionPolicy(
}
}

public static void ValidateLongTermRetentionPolicyWithSimpleRetentionPolicy(
public static void ValidateLongTermRetentionPolicyWithSimpleSchedulePolicy(
SQLRetentionPolicy ltrPolicy,
SQLSchedulePolicy schPolicy)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ public enum PolicyParams
ResourceName,
FixForInconsistentItems,
ScheduleRunFrequency,
PolicySubType
PolicySubType,
ExistingPolicy
}

public enum ItemParams
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,10 @@ private RestAzureNS.AzureOperationResponse<ProtectionPolicyResource> CreateorMod
string resourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName];
string policyName = ProviderData.ContainsKey(PolicyParams.PolicyName) ?
(string)ProviderData[PolicyParams.PolicyName] : null;
string auxiliaryAccessToken = (string)ProviderData[ResourceGuardParams.Token];

string auxiliaryAccessToken = ProviderData.ContainsKey(ResourceGuardParams.Token) ? (string)ProviderData[ResourceGuardParams.Token] : null;
bool isMUAOperation = ProviderData.ContainsKey(ResourceGuardParams.IsMUAOperation) ? (bool)ProviderData[ResourceGuardParams.IsMUAOperation] : false;
ProtectionPolicyResource existingPolicy = ProviderData.ContainsKey(PolicyParams.ExistingPolicy) ? (ProtectionPolicyResource)ProviderData[PolicyParams.ExistingPolicy] : null;

RetentionPolicyBase retentionPolicy =
ProviderData.ContainsKey(PolicyParams.RetentionPolicy) ?
Expand Down Expand Up @@ -400,7 +403,7 @@ private RestAzureNS.AzureOperationResponse<ProtectionPolicyResource> CreateorMod
Logger.Instance.WriteDebug("Copy of RetentionTime from with SchedulePolicy to RetentionPolicy is successful");

// Now validate both RetentionPolicy and SchedulePolicy matches or not
PolicyHelpers.ValidateLongTermRetentionPolicyWithSimpleRetentionPolicy(
PolicyHelpers.ValidateLongTermRetentionPolicyWithSimpleSchedulePolicy(
(CmdletModel.LongTermRetentionPolicy)((AzureFileSharePolicy)policy).RetentionPolicy,
(CmdletModel.SimpleSchedulePolicy)((AzureFileSharePolicy)policy).SchedulePolicy);
Logger.Instance.WriteDebug("Validation of Retention policy with Schedule policy is successful");
Expand Down Expand Up @@ -447,7 +450,7 @@ private RestAzureNS.AzureOperationResponse<ProtectionPolicyResource> CreateorMod
Logger.Instance.WriteDebug("Copy of RetentionTime from with SchedulePolicy to RetentionPolicy is successful");

// Now validate both RetentionPolicy and SchedulePolicy together
PolicyHelpers.ValidateLongTermRetentionPolicyWithSimpleRetentionPolicy(
PolicyHelpers.ValidateLongTermRetentionPolicyWithSimpleSchedulePolicy(
(CmdletModel.LongTermRetentionPolicy)retentionPolicy,
(CmdletModel.SimpleSchedulePolicy)schedulePolicy);
Logger.Instance.WriteDebug("Validation of Retention policy with Schedule policy is successful");
Expand All @@ -473,14 +476,22 @@ private RestAzureNS.AzureOperationResponse<ProtectionPolicyResource> CreateorMod
azureFileShareProtectionPolicy.WorkLoadType = ConversionUtils.GetServiceClientWorkloadType(workloadType.ToString());

serviceClientRequest.Properties = azureFileShareProtectionPolicy;
}
}

// check for MUA
bool isMUAProtected = false;
if (existingPolicy != null)
{
isMUAProtected = AzureWorkloadProviderHelper.checkMUAForModifyPolicy(existingPolicy, serviceClientRequest, isMUAOperation);
}

return ServiceClientAdapter.CreateOrUpdateProtectionPolicy(
policyName = policyName ?? policy.Name,
serviceClientRequest,
vaultName: vaultName,
resourceGroupName: resourceGroupName,
auxiliaryAccessToken);
auxiliaryAccessToken,
isMUAProtected);
}

public RPMountScriptDetails ProvisionItemLevelRecoveryAccess()
Expand Down Expand Up @@ -888,8 +899,6 @@ private RestAzureNS.AzureOperationResponse<ProtectedItemResource> EnableOrModify
(string)ProviderData[ItemParams.StorageAccountName] : null;
string parameterSetName = ProviderData.ContainsKey(ItemParams.ParameterSetName) ?
(string)ProviderData[ItemParams.ParameterSetName] : null;
string auxiliaryAccessToken = ProviderData.ContainsKey(ResourceGuardParams.Token) ? (string)ProviderData[ResourceGuardParams.Token] : null;
bool isMUAOperation = ProviderData.ContainsKey(ResourceGuardParams.IsMUAOperation) ? (bool)ProviderData[ResourceGuardParams.IsMUAOperation] : false;

PolicyBase policy = ProviderData.ContainsKey(ItemParams.Policy) ?
(PolicyBase)ProviderData[ItemParams.Policy] : null;
Expand All @@ -898,6 +907,31 @@ private RestAzureNS.AzureOperationResponse<ProtectedItemResource> EnableOrModify

AzureFileShareItem item = (AzureFileShareItem)ProviderData[ItemParams.Item];

string auxiliaryAccessToken = ProviderData.ContainsKey(ResourceGuardParams.Token) ? (string)ProviderData[ResourceGuardParams.Token] : null;
bool isMUAOperation = ProviderData.ContainsKey(ResourceGuardParams.IsMUAOperation) ? (bool)ProviderData[ResourceGuardParams.IsMUAOperation] : false;

ProtectionPolicyResource oldPolicy = null;
ProtectionPolicyResource newPolicy = null;
if (parameterSetName.Contains("Modify"))
{
Dictionary<UriEnums, string> keyValueDict = HelperUtils.ParseUri(item.PolicyId);
string oldPolicyName = HelperUtils.GetPolicyNameFromPolicyId(keyValueDict, item.PolicyId);

keyValueDict = HelperUtils.ParseUri(policy.Id);
string newPolicyName = HelperUtils.GetPolicyNameFromPolicyId(keyValueDict, policy.Id);

// fetch old and new Policy
oldPolicy = ServiceClientAdapter.GetProtectionPolicy(
oldPolicyName,
vaultName: vaultName,
resourceGroupName: vaultResourceGroupName);

newPolicy = ServiceClientAdapter.GetProtectionPolicy(
newPolicyName,
vaultName: vaultName,
resourceGroupName: vaultResourceGroupName);
}

string containerUri = "";
string protectedItemUri = "";
string sourceResourceId = null;
Expand Down Expand Up @@ -968,14 +1002,21 @@ private RestAzureNS.AzureOperationResponse<ProtectedItemResource> EnableOrModify
Properties = properties
};

// check for MUA
bool isMUAProtected = false;
if (parameterSetName.Contains("Modify") && oldPolicy != null && newPolicy != null)
{
isMUAProtected = AzureWorkloadProviderHelper.checkMUAForModifyPolicy(oldPolicy, newPolicy, isMUAOperation);
}

return ServiceClientAdapter.CreateOrUpdateProtectedItem(
containerUri,
protectedItemUri,
serviceClientRequest,
vaultName: vaultName,
resourceGroupName: vaultResourceGroupName,
auxiliaryAccessToken,
isMUAOperation);
isMUAProtected);
}

private void ValidateAzureStorageBackupManagementType(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,10 @@ private RestAzureNS.AzureOperationResponse<ProtectionPolicyResource> CreateorMod
(bool)ProviderData[PolicyParams.FixForInconsistentItems] : false;
ProtectionPolicyResource serviceClientRequest = new ProtectionPolicyResource();

string auxiliaryAccessToken = ProviderData.ContainsKey(ResourceGuardParams.Token) ? (string)ProviderData[ResourceGuardParams.Token] : null;
bool isMUAOperation = ProviderData.ContainsKey(ResourceGuardParams.IsMUAOperation) ? (bool)ProviderData[ResourceGuardParams.IsMUAOperation] : false;
ProtectionPolicyResource existingPolicy = ProviderData.ContainsKey(PolicyParams.ExistingPolicy) ? (ProtectionPolicyResource)ProviderData[PolicyParams.ExistingPolicy] : null;

if (policy != null)
{
// do validations
Expand Down Expand Up @@ -704,7 +708,7 @@ private RestAzureNS.AzureOperationResponse<ProtectionPolicyResource> CreateorMod
Logger.Instance.WriteDebug("Copy of RetentionTime from with SchedulePolicy to RetentionPolicy is successful");

// Now validate both RetentionPolicy and SchedulePolicy matches or not
PolicyHelpers.ValidateLongTermRetentionPolicyWithSimpleRetentionPolicy(
PolicyHelpers.ValidateLongTermRetentionPolicyWithSimpleSchedulePolicy(
(CmdletModel.LongTermRetentionPolicy)((AzureVmWorkloadPolicy)policy).FullBackupRetentionPolicy,
(CmdletModel.SimpleSchedulePolicy)((AzureVmWorkloadPolicy)policy).FullBackupSchedulePolicy);
Logger.Instance.WriteDebug("Validation of Retention policy with Schedule policy is successful");
Expand Down Expand Up @@ -740,7 +744,7 @@ private RestAzureNS.AzureOperationResponse<ProtectionPolicyResource> CreateorMod
Logger.Instance.WriteDebug("Copy of RetentionTime from with SchedulePolicy to RetentionPolicy is successful");

// Now validate both RetentionPolicy and SchedulePolicy together
PolicyHelpers.ValidateLongTermRetentionPolicyWithSimpleRetentionPolicy(
PolicyHelpers.ValidateLongTermRetentionPolicyWithSimpleSchedulePolicy(
(SQLRetentionPolicy)retentionPolicy,
(SQLSchedulePolicy)schedulePolicy);
Logger.Instance.WriteDebug("Validation of Retention policy with Schedule policy is successful");
Expand All @@ -758,11 +762,20 @@ private RestAzureNS.AzureOperationResponse<ProtectionPolicyResource> CreateorMod
serviceClientRequest.Properties = azureVmWorkloadProtectionPolicy;
}

// check for MUA
bool isMUAProtected = false;
if (existingPolicy != null)
{
isMUAProtected = AzureWorkloadProviderHelper.checkMUAForModifyPolicy(existingPolicy, serviceClientRequest, isMUAOperation);
}

return ServiceClientAdapter.CreateOrUpdateProtectionPolicy(
policyName = policyName ?? policy.Name,
serviceClientRequest,
vaultName: vaultName,
resourceGroupName: resourceGroupName);
resourceGroupName: resourceGroupName,
auxiliaryAccessToken,
isMUAProtected);
}

private RestAzureNS.AzureOperationResponse<ProtectedItemResource> EnableOrModifyProtection(bool disableWithRetentionData = false)
Expand All @@ -781,9 +794,6 @@ private RestAzureNS.AzureOperationResponse<ProtectedItemResource> EnableOrModify
ItemBase itemBase = ProviderData.ContainsKey(ItemParams.Item) ?
(ItemBase)ProviderData[ItemParams.Item] : null;

string auxiliaryAccessToken = ProviderData.ContainsKey(ResourceGuardParams.Token) ? (string)ProviderData[ResourceGuardParams.Token] : null;
bool isMUAOperation = ProviderData.ContainsKey(ResourceGuardParams.IsMUAOperation) ? (bool)ProviderData[ResourceGuardParams.IsMUAOperation] : false;

AzureItem item;
AzureVmWorkloadProtectedItem properties;
if (itemBase != null && itemBase.WorkloadType == CmdletModel.WorkloadType.SAPHanaDatabase)
Expand All @@ -800,7 +810,32 @@ private RestAzureNS.AzureOperationResponse<ProtectedItemResource> EnableOrModify

properties = new AzureVmWorkloadSQLDatabaseProtectedItem();
}


string auxiliaryAccessToken = ProviderData.ContainsKey(ResourceGuardParams.Token) ? (string)ProviderData[ResourceGuardParams.Token] : null;
bool isMUAOperation = ProviderData.ContainsKey(ResourceGuardParams.IsMUAOperation) ? (bool)ProviderData[ResourceGuardParams.IsMUAOperation] : false;

ProtectionPolicyResource oldPolicy = null;
ProtectionPolicyResource newPolicy = null;
if (isMUAOperation)
{
Dictionary<UriEnums, string> keyValueDict = HelperUtils.ParseUri(item.PolicyId);
string oldPolicyName = HelperUtils.GetPolicyNameFromPolicyId(keyValueDict, item.PolicyId);

keyValueDict = HelperUtils.ParseUri(policy.Id);
string newPolicyName = HelperUtils.GetPolicyNameFromPolicyId(keyValueDict, policy.Id);

// fetch old and new Policy
oldPolicy = ServiceClientAdapter.GetProtectionPolicy(
oldPolicyName,
vaultName: vaultName,
resourceGroupName: vaultResourceGroupName);

newPolicy = ServiceClientAdapter.GetProtectionPolicy(
newPolicyName,
vaultName: vaultName,
resourceGroupName: vaultResourceGroupName);
}

string containerUri = "";
string protectedItemUri = "";

Expand Down Expand Up @@ -847,14 +882,21 @@ private RestAzureNS.AzureOperationResponse<ProtectedItemResource> EnableOrModify
Properties = properties
};

// check for MUA
bool isMUAProtected = false;
if (isMUAOperation && oldPolicy != null && newPolicy != null)
{
isMUAProtected = AzureWorkloadProviderHelper.checkMUAForModifyPolicy(oldPolicy, newPolicy, isMUAOperation);
}

return ServiceClientAdapter.CreateOrUpdateProtectedItem(
containerUri,
protectedItemUri,
serviceClientRequest,
vaultName: vaultName,
resourceGroupName: vaultResourceGroupName,
auxiliaryAccessToken,
isMUAOperation);
isMUAProtected);
}

public void RegisterContainer()
Expand Down
Loading

0 comments on commit 63bddd3

Please sign in to comment.