/// <summary> /// Adds storage account in given resource group and applies required roles. /// </summary> /// <param name="context">StorageCacheTestContext.</param> /// <param name="resourceGroup">Object representing a resource group.</param> /// <param name="suffix">suffix.</param> /// <param name="addPermissions">Whether to add storage account contributor roles.</param> /// <param name="testOutputHelper">testOutputHelper.</param> /// <param name="sleep">Sleep time for permissions to get propagated.</param> /// <param name="waitForPermissions">Whether to wait for permissions to be propagated.</param> /// <returns>StorageAccount.</returns> public StorageAccount AddStorageAccount( StorageCacheTestContext context, ResourceGroup resourceGroup, string suffix = null, bool addPermissions = true, ITestOutputHelper testOutputHelper = null, int sleep = 300, bool waitForPermissions = true, bool blobNfs = false) { if (testOutputHelper != null) { testOutputHelper.WriteLine($"SAF Add Storage Account {resourceGroup.Name + suffix}"); testOutputHelper.WriteLine($"SAF Add Storage Account blobNfs {blobNfs}"); testOutputHelper.WriteLine($"SAF Add Storage Account addpermissions {addPermissions}"); } notes.Add("SAF AddStorageAccount"); if (this.storageAccountsCache.TryGetValue(resourceGroup.Name + suffix, out StorageAccount storageAccount)) { notes.Add("SAF AddStorageAccount Using Existing Storage Account."); if (testOutputHelper != null) { testOutputHelper.WriteLine($"Using existing storage account {resourceGroup.Name + suffix}"); } return(storageAccount); } notes.Add("SAF AddStorageAccount Need to create a storage account."); StorageManagementClient storageManagementClient = context.GetClient <StorageManagementClient>(); StorageAccountsHelper storageAccountsHelper = new StorageAccountsHelper(storageManagementClient, resourceGroup); string subnetUri = $"/subscriptions/{fixture.SubscriptionID}/resourcegroups/{fixture.ResourceGroup.Name}/providers/Microsoft.Network/virtualNetworks/{fixture.VirtualNetwork.Name}/subnets/{fixture.SubNet.Name}"; notes.Add($"SAF AddStroageAccount subnetUri: {subnetUri}"); storageAccount = storageAccountsHelper.CreateStorageAccount(resourceGroup.Name + suffix, blobNfs: blobNfs, subnetUri: subnetUri); if (storageAccount == null) { testOutputHelper.WriteLine("Failed to create storageAccount"); return(storageAccount); } if (addPermissions) { notes.Add("SAF AddStorageAccount Add SA Access Rules"); this.AddStorageAccountAccessRules(context, storageAccount); } if (waitForPermissions && HttpMockServer.Mode == HttpRecorderMode.Record) { testOutputHelper.WriteLine($"Sleeping {sleep.ToString()} seconds while permissions propagates."); TestUtilities.Wait(new TimeSpan(0, 0, sleep)); } this.storageAccountsCache.Add(storageAccount.Name, storageAccount); return(storageAccount); }
/// <summary> /// Adds storage account in given resource group and applies required roles. /// </summary> /// <param name="context">HpcCacheTestContext.</param> /// <param name="resourceGroup">Object representing a resource group.</param> /// <param name="storageAccountName">storage account name.</param> /// <param name="suffix">suffix.</param> /// <param name="addPermissions">Whether to add storage account contributor roles.</param> /// <param name="testOutputHelper">testOutputHelper.</param> /// <param name="sleep">Sleep time for permissions to get propagated.</param> /// <param name="waitForPermissions">Whether to wait for permissions to be propagated.</param> /// <returns>StorageAccount.</returns> public StorageAccount AddStorageAccount( HpcCacheTestContext context, ResourceGroup resourceGroup, string storageAccountName, string suffix = null, bool addPermissions = true, ITestOutputHelper testOutputHelper = null, int sleep = 300, bool waitForPermissions = true) { if (this.storageAccountsCache.TryGetValue(storageAccountName + suffix, out StorageAccount storageAccount)) { if (testOutputHelper != null) { testOutputHelper.WriteLine($"Using existing storage account {storageAccountName + suffix}"); } return(storageAccount); } StorageManagementClient storageManagementClient = context.GetClient <StorageManagementClient>(); StorageAccountsHelper storageAccountsHelper = new StorageAccountsHelper(storageManagementClient, resourceGroup); storageAccount = storageAccountsHelper.CreateStorageAccount(storageAccountName + suffix); if (addPermissions) { this.AddStorageAccountAccessRules(context, storageAccount); } if (waitForPermissions && HttpMockServer.Mode == HttpRecorderMode.Record) { if (testOutputHelper != null) { testOutputHelper.WriteLine($"Sleeping {sleep.ToString()} seconds while permissions propagates."); } TestUtilities.Wait(new TimeSpan(0, 0, sleep)); } this.storageAccountsCache.Add(storageAccount.Name, storageAccount); return(storageAccount); }