Skip to content

Commit

Permalink
[AzRecoveryServices.Backup] Adding null check for target storage acco…
Browse files Browse the repository at this point in the history
…unt (#13681)

* Adding null check for target storage account

* fixing the operations delay

* re-recorded failed tests
  • Loading branch information
hiaga authored Feb 19, 2021
1 parent 81e86e6 commit 53fdcfe
Show file tree
Hide file tree
Showing 7 changed files with 2,180 additions and 1,072 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,15 @@ public static T GetOperationStatus<T>(RestAzureNS.AzureOperationResponse respons
while (opStatusResponse.Body.Status ==
ServiceClientModel.OperationStatusValues.InProgress)
{
if (String.Compare(testMode, "Playback", StringComparison.OrdinalIgnoreCase) != 0 && !TestMockSupport.RunningMocked)
if (!TestMockSupport.RunningMocked)
{
TestMockSupport.Delay(_defaultSleepForOperationTracking * 1000);
}
if (String.Compare(testMode, "Record", StringComparison.OrdinalIgnoreCase) == 0)
{
Thread.Sleep(5000);
}

opStatusResponse = getOpStatus(operationId);
}

Expand Down Expand Up @@ -79,7 +84,11 @@ public static T GetOperationStatus<T, S>(RestAzureNS.AzureOperationResponse<S> r
while (opStatusResponse.Body.Status ==
ServiceClientModel.OperationStatusValues.InProgress)
{
if (String.Compare(testMode, "Playback", StringComparison.OrdinalIgnoreCase) != 0 && !TestMockSupport.RunningMocked)
if (!TestMockSupport.RunningMocked)
{
TestMockSupport.Delay(_defaultSleepForOperationTracking * 1000);
}
if (String.Compare(testMode, "Record", StringComparison.OrdinalIgnoreCase) == 0)
{
Thread.Sleep(5000);
}
Expand Down Expand Up @@ -109,10 +118,15 @@ public static RestAzureNS.AzureOperationResponse GetOperationResult(
string testMode = Environment.GetEnvironmentVariable("AZURE_TEST_MODE");
while (opStatusResponse.Response.StatusCode == SystemNet.HttpStatusCode.Accepted)
{
if (String.Compare(testMode, "Playback", StringComparison.OrdinalIgnoreCase) != 0 && !TestMockSupport.RunningMocked)
if (!TestMockSupport.RunningMocked)
{
TestMockSupport.Delay(_defaultSleepForOperationTracking * 1000);
}
if (String.Compare(testMode, "Record", StringComparison.OrdinalIgnoreCase) == 0)
{
Thread.Sleep(5000);
}

opStatusResponse = getOpStatus(operationId);
}

Expand All @@ -139,10 +153,15 @@ public static RestAzureNS.AzureOperationResponse<T> GetOperationStatusDataMove<T
string testMode = Environment.GetEnvironmentVariable("AZURE_TEST_MODE");
while (opStatusResponse.Body.Status == "InProgress")
{
if (String.Compare(testMode, "Playback", StringComparison.OrdinalIgnoreCase) != 0 && !TestMockSupport.RunningMocked)
if (!TestMockSupport.RunningMocked)
{
TestMockSupport.Delay(_defaultSleepForOperationTracking * 1000);
}
if (String.Compare(testMode, "Record", StringComparison.OrdinalIgnoreCase) == 0)
{
Thread.Sleep(5000);
}

opStatusResponse = getOpStatus(operationId);
}
opStatusResponse = getOpStatus(operationId);
Expand All @@ -168,10 +187,15 @@ public static RestAzureNS.AzureOperationResponse<T> GetOperationResult<T>(
string testMode = Environment.GetEnvironmentVariable("AZURE_TEST_MODE");
while (opStatusResponse.Response.StatusCode == SystemNet.HttpStatusCode.Accepted)
{
if (String.Compare(testMode, "Playback", StringComparison.OrdinalIgnoreCase) != 0 && !TestMockSupport.RunningMocked)
if (!TestMockSupport.RunningMocked)
{
TestMockSupport.Delay(_defaultSleepForOperationTracking * 1000);
}
if (String.Compare(testMode, "Record", StringComparison.OrdinalIgnoreCase) == 0)
{
Thread.Sleep(5000);
}

opStatusResponse = getOpStatus(operationId);
}
opStatusResponse = getOpStatus(operationId);
Expand Down Expand Up @@ -212,10 +236,15 @@ public static RestAzureNS.AzureOperationResponse<T> GetOperationResult<T>(
string testMode = Environment.GetEnvironmentVariable("AZURE_TEST_MODE");
while (opStatusResponse.Response.StatusCode == SystemNet.HttpStatusCode.Accepted)
{
if (String.Compare(testMode, "Playback", StringComparison.OrdinalIgnoreCase) != 0 && !TestMockSupport.RunningMocked)
if (!TestMockSupport.RunningMocked)
{
TestMockSupport.Delay(_defaultSleepForOperationTracking * 1000);
}
if (String.Compare(testMode, "Record", StringComparison.OrdinalIgnoreCase) == 0)
{
Thread.Sleep(5000);
}

opStatusResponse = getOpStatus(operationId);
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -613,4 +613,7 @@ Please contact Microsoft for further assistance.</value>
<data name="TargetResourcegroupNotSupported" xml:space="preserve">
<value>Target ResourceGroup is not applicable and restore will proceed as unmanaged disk restore since this is unmanaged VM</value>
</data>
<data name="InvalidTargetStorageAccount" xml:space="preserve">
<value>Please provide a vaild target storage account</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,14 @@ public RestAzureNS.AzureOperationResponse TriggerRestore()
GenericResource targetStorageAccountResource = null;
string targetStorageAccountLocation = null;
if (targetStorageAccountName != null)
{
{
targetStorageAccountResource = ServiceClientAdapter.GetStorageAccountResource(targetStorageAccountName);

if(targetStorageAccountResource == null)
{
throw new ArgumentException(string.Format(Resources.InvalidTargetStorageAccount));
}

targetStorageAccountLocation = targetStorageAccountResource.Location;
}

Expand All @@ -209,6 +215,7 @@ public RestAzureNS.AzureOperationResponse TriggerRestore()
RestoreFileSpecs restoreFileSpec = new RestoreFileSpecs();
AzureFileShareRestoreRequest restoreRequest = new AzureFileShareRestoreRequest();
restoreRequest.CopyOptions = copyOptions;

restoreRequest.SourceResourceId = storageAccountResource.Id;
if (sourceFilePath != null)
{
Expand Down
Loading

0 comments on commit 53fdcfe

Please sign in to comment.