private async Task <bool> MountStorageAccount(AzureStorageInfoValue storageInfoValue) { try { var storageConnectionString = Utility.BuildStorageConnectionString(storageInfoValue.AccountName, storageInfoValue.AccessKey, _environment.GetStorageSuffix()); await Utility.InvokeWithRetriesAsync(async() => { try { using (_metricsLogger.LatencyEvent($"{MetricEventNames.LinuxContainerSpecializationBYOSMountPrefix}.{storageInfoValue.Type.ToString().ToLowerInvariant()}.{storageInfoValue.Id?.ToLowerInvariant()}")) { switch (storageInfoValue.Type) { case AzureStorageType.AzureFiles: if (!await _meshServiceClient.MountCifs(storageConnectionString, storageInfoValue.ShareName, storageInfoValue.MountPath)) { throw new Exception($"Failed to mount BYOS fileshare {storageInfoValue.Id}"); } break; case AzureStorageType.AzureBlob: await _meshServiceClient.MountBlob(storageConnectionString, storageInfoValue.ShareName, storageInfoValue.MountPath); break; default: throw new NotSupportedException($"Unknown BYOS storage type {storageInfoValue.Type}"); } } } catch (Exception e) { // todo: Expose any failures here as a part of a health check api. _logger.LogError(e, $"Failed to mount BYOS storage account {storageInfoValue.Id}"); throw; } _logger.LogInformation( $"Successfully mounted BYOS storage account {storageInfoValue.Id}"); }, 1, TimeSpan.FromSeconds(0.5)); return(true); } catch (Exception e) { _logger.LogError(e, $"Failed to mount BYOS storage account {storageInfoValue.Id}"); return(false); } }
public void Builds_AzureStorageInfoValue(string id, AzureStorageType?type, string accountName, string shareName, string accessKey, string mountPath, bool isValid) { var key = id; var value = $"{accountName}|{shareName}|{accessKey}|{mountPath}"; var environmentVariable = new KeyValuePair <string, string>(key, value); var azureStorageInfoValue = AzureStorageInfoValue.FromEnvironmentVariable(environmentVariable); if (isValid) { Assert.NotNull(azureStorageInfoValue); Assert.Equal("storageid", azureStorageInfoValue.Id); Assert.Equal(type, azureStorageInfoValue.Type); Assert.Equal(accountName, azureStorageInfoValue.AccountName); Assert.Equal(shareName, azureStorageInfoValue.ShareName); Assert.Equal(accessKey, azureStorageInfoValue.AccessKey); Assert.Equal(mountPath, azureStorageInfoValue.MountPath); } else { Assert.Null(azureStorageInfoValue); } }