Skip to content

Commit 53fdcfe

Browse files
authored
[AzRecoveryServices.Backup] Adding null check for target storage account (#13681)
* Adding null check for target storage account * fixing the operations delay * re-recorded failed tests
1 parent 81e86e6 commit 53fdcfe

File tree

7 files changed

+2180
-1072
lines changed

7 files changed

+2180
-1072
lines changed

src/RecoveryServices/RecoveryServices.Backup.Helpers/TrackingHelpers.cs

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,15 @@ public static T GetOperationStatus<T>(RestAzureNS.AzureOperationResponse respons
4848
while (opStatusResponse.Body.Status ==
4949
ServiceClientModel.OperationStatusValues.InProgress)
5050
{
51-
if (String.Compare(testMode, "Playback", StringComparison.OrdinalIgnoreCase) != 0 && !TestMockSupport.RunningMocked)
51+
if (!TestMockSupport.RunningMocked)
52+
{
53+
TestMockSupport.Delay(_defaultSleepForOperationTracking * 1000);
54+
}
55+
if (String.Compare(testMode, "Record", StringComparison.OrdinalIgnoreCase) == 0)
5256
{
5357
Thread.Sleep(5000);
5458
}
59+
5560
opStatusResponse = getOpStatus(operationId);
5661
}
5762

@@ -79,7 +84,11 @@ public static T GetOperationStatus<T, S>(RestAzureNS.AzureOperationResponse<S> r
7984
while (opStatusResponse.Body.Status ==
8085
ServiceClientModel.OperationStatusValues.InProgress)
8186
{
82-
if (String.Compare(testMode, "Playback", StringComparison.OrdinalIgnoreCase) != 0 && !TestMockSupport.RunningMocked)
87+
if (!TestMockSupport.RunningMocked)
88+
{
89+
TestMockSupport.Delay(_defaultSleepForOperationTracking * 1000);
90+
}
91+
if (String.Compare(testMode, "Record", StringComparison.OrdinalIgnoreCase) == 0)
8392
{
8493
Thread.Sleep(5000);
8594
}
@@ -109,10 +118,15 @@ public static RestAzureNS.AzureOperationResponse GetOperationResult(
109118
string testMode = Environment.GetEnvironmentVariable("AZURE_TEST_MODE");
110119
while (opStatusResponse.Response.StatusCode == SystemNet.HttpStatusCode.Accepted)
111120
{
112-
if (String.Compare(testMode, "Playback", StringComparison.OrdinalIgnoreCase) != 0 && !TestMockSupport.RunningMocked)
121+
if (!TestMockSupport.RunningMocked)
122+
{
123+
TestMockSupport.Delay(_defaultSleepForOperationTracking * 1000);
124+
}
125+
if (String.Compare(testMode, "Record", StringComparison.OrdinalIgnoreCase) == 0)
113126
{
114127
Thread.Sleep(5000);
115128
}
129+
116130
opStatusResponse = getOpStatus(operationId);
117131
}
118132

@@ -139,10 +153,15 @@ public static RestAzureNS.AzureOperationResponse<T> GetOperationStatusDataMove<T
139153
string testMode = Environment.GetEnvironmentVariable("AZURE_TEST_MODE");
140154
while (opStatusResponse.Body.Status == "InProgress")
141155
{
142-
if (String.Compare(testMode, "Playback", StringComparison.OrdinalIgnoreCase) != 0 && !TestMockSupport.RunningMocked)
156+
if (!TestMockSupport.RunningMocked)
157+
{
158+
TestMockSupport.Delay(_defaultSleepForOperationTracking * 1000);
159+
}
160+
if (String.Compare(testMode, "Record", StringComparison.OrdinalIgnoreCase) == 0)
143161
{
144162
Thread.Sleep(5000);
145163
}
164+
146165
opStatusResponse = getOpStatus(operationId);
147166
}
148167
opStatusResponse = getOpStatus(operationId);
@@ -168,10 +187,15 @@ public static RestAzureNS.AzureOperationResponse<T> GetOperationResult<T>(
168187
string testMode = Environment.GetEnvironmentVariable("AZURE_TEST_MODE");
169188
while (opStatusResponse.Response.StatusCode == SystemNet.HttpStatusCode.Accepted)
170189
{
171-
if (String.Compare(testMode, "Playback", StringComparison.OrdinalIgnoreCase) != 0 && !TestMockSupport.RunningMocked)
190+
if (!TestMockSupport.RunningMocked)
191+
{
192+
TestMockSupport.Delay(_defaultSleepForOperationTracking * 1000);
193+
}
194+
if (String.Compare(testMode, "Record", StringComparison.OrdinalIgnoreCase) == 0)
172195
{
173196
Thread.Sleep(5000);
174197
}
198+
175199
opStatusResponse = getOpStatus(operationId);
176200
}
177201
opStatusResponse = getOpStatus(operationId);
@@ -212,10 +236,15 @@ public static RestAzureNS.AzureOperationResponse<T> GetOperationResult<T>(
212236
string testMode = Environment.GetEnvironmentVariable("AZURE_TEST_MODE");
213237
while (opStatusResponse.Response.StatusCode == SystemNet.HttpStatusCode.Accepted)
214238
{
215-
if (String.Compare(testMode, "Playback", StringComparison.OrdinalIgnoreCase) != 0 && !TestMockSupport.RunningMocked)
239+
if (!TestMockSupport.RunningMocked)
240+
{
241+
TestMockSupport.Delay(_defaultSleepForOperationTracking * 1000);
242+
}
243+
if (String.Compare(testMode, "Record", StringComparison.OrdinalIgnoreCase) == 0)
216244
{
217245
Thread.Sleep(5000);
218246
}
247+
219248
opStatusResponse = getOpStatus(operationId);
220249
}
221250

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

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

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,4 +613,7 @@ Please contact Microsoft for further assistance.</value>
613613
<data name="TargetResourcegroupNotSupported" xml:space="preserve">
614614
<value>Target ResourceGroup is not applicable and restore will proceed as unmanaged disk restore since this is unmanaged VM</value>
615615
</data>
616+
<data name="InvalidTargetStorageAccount" xml:space="preserve">
617+
<value>Please provide a vaild target storage account</value>
618+
</data>
616619
</root>

src/RecoveryServices/RecoveryServices.Backup.Providers/Providers/AzureFilesPsBackupProvider.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,14 @@ public RestAzureNS.AzureOperationResponse TriggerRestore()
199199
GenericResource targetStorageAccountResource = null;
200200
string targetStorageAccountLocation = null;
201201
if (targetStorageAccountName != null)
202-
{
202+
{
203203
targetStorageAccountResource = ServiceClientAdapter.GetStorageAccountResource(targetStorageAccountName);
204+
205+
if(targetStorageAccountResource == null)
206+
{
207+
throw new ArgumentException(string.Format(Resources.InvalidTargetStorageAccount));
208+
}
209+
204210
targetStorageAccountLocation = targetStorageAccountResource.Location;
205211
}
206212

@@ -209,6 +215,7 @@ public RestAzureNS.AzureOperationResponse TriggerRestore()
209215
RestoreFileSpecs restoreFileSpec = new RestoreFileSpecs();
210216
AzureFileShareRestoreRequest restoreRequest = new AzureFileShareRestoreRequest();
211217
restoreRequest.CopyOptions = copyOptions;
218+
212219
restoreRequest.SourceResourceId = storageAccountResource.Id;
213220
if (sourceFilePath != null)
214221
{

0 commit comments

Comments
 (0)