public void ShowBlobWithLease() { string containerName = Utility.GenNameString("container"); string pageBlobName = Utility.GenNameString("page"); string blockBlobName = Utility.GenNameString("block"); CloudBlobContainer container = blobUtil.CreateContainer(containerName); NodeJSAgent nodejsAgent = (NodeJSAgent)CommandAgent; try { CloudBlob pageBlob = blobUtil.CreatePageBlob(container, pageBlobName); CloudBlob blockBlob = blobUtil.CreateBlockBlob(container, blockBlobName); ((CloudPageBlob)pageBlob).AcquireLease(null, string.Empty); ((CloudBlockBlob)blockBlob).AcquireLease(null, string.Empty); pageBlob.FetchAttributes(); blockBlob.FetchAttributes(); Test.Assert(nodejsAgent.ShowAzureStorageBlob(pageBlobName, containerName), Utility.GenComparisonData("show blob with lease", true)); nodejsAgent.OutputValidation(new List <CloudBlob>() { pageBlob }); Test.Assert(nodejsAgent.ShowAzureStorageBlob(blockBlobName, containerName), Utility.GenComparisonData("show blob with lease", true)); nodejsAgent.OutputValidation(new List <CloudBlob>() { blockBlob }); } finally { blobUtil.RemoveContainer(containerName); } }
public void CopyFromFile2SASFile() { CopyFromFile2SASFile((sourceShare) => { string connectionString = (new CloudStorageAccount(sourceShare.ServiceClient.Credentials, null, null, null, sourceShare.ServiceClient.StorageUri.PrimaryUri)).ToString(true); if (lang == Language.PowerShell) { PowerShellAgent.SetStorageContext(connectionString); } else { NodeJSAgent.SetStorageContext(connectionString); } }); CopyFromFile2SASFile((sourceShare) => { string sasToken = sourceShare.GetSharedAccessSignature(new SharedAccessFilePolicy() { Permissions = SharedAccessFilePermissions.Read, SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddHours(1) }); CommandAgent.SetStorageContextWithSASToken(StorageAccount.Credentials.AccountName, sasToken); }); }
public void CopyFromBlob2SASFile() { CopyFromBlob2SASFile((sourceContainer) => { if (lang == Language.PowerShell) { PowerShellAgent.SetStorageContext(StorageAccount.ToString(true)); } else { NodeJSAgent.SetStorageContext(StorageAccount.ToString(true)); }; }); CopyFromBlob2SASFile((sourceContainer) => { string sasToken = sourceContainer.GetSharedAccessSignature(new SharedAccessBlobPolicy() { Permissions = SharedAccessBlobPermissions.Read, SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddHours(1) }); CommandAgent.SetStorageContextWithSASToken(StorageAccount.Credentials.AccountName, sasToken); }); }
/// <summary> /// on test setup /// the derived class could use it to run it owned set up settings. /// </summary> public virtual void OnTestSetup() { if (isResourceMode) { if (!isLogin) { if (Utility.GetAutoLogin()) { int retry = 0; do { if (CommandAgent.HadErrors) { Thread.Sleep(5000); Test.Info(string.Format("Retry login... Count:{0}", retry)); } if (!TestContext.FullyQualifiedTestClassName.Contains("SubScriptionBVT")) //For SubScriptionBVT, we already login and set current account, don't need re-login { CommandAgent.Logout(); CommandAgent.Login(); } }while (CommandAgent.HadErrors && retry++ < 5); } if (lang == Language.NodeJS) { SetActiveSubscription(); CommandAgent.ChangeCLIMode(Constants.Mode.arm); } isLogin = true; } } else { if (!accountImported) { if (lang == Language.NodeJS) { NodeJSAgent nodeAgent = (NodeJSAgent)CommandAgent; nodeAgent.Logout(); nodeAgent.ChangeCLIMode(Constants.Mode.asm); } string settingFile = Test.Data.Get("AzureSubscriptionPath"); string subscriptionId = Test.Data.Get("AzureSubscriptionID"); CommandAgent.ImportAzureSubscription(settingFile); string subscriptionID = Test.Data.Get("AzureSubscriptionID"); CommandAgent.SetActiveSubscription(subscriptionID); accountImported = true; } } }
public void GetCopyStateWithSAS() { string destShareName = Utility.GenNameString("destshare"); CloudFileShare destShare = fileUtil.EnsureFileShareExists(destShareName); try { string fileName = Utility.GenNameString("DestFile"); StorageFile.CloudFile destFile = fileUtil.GetFileReference(destShare.GetRootDirectoryReference(), fileName); object destContext; if (lang == Language.PowerShell) { destContext = PowerShellAgent.GetStorageContext(StorageAccount.ToString(true)); } else { destContext = NodeJSAgent.GetStorageContext(StorageAccount.ToString(true)); } string bigBlobUri = Test.Data.Get("BigBlobUri"); Test.Assert(CommandAgent.StartFileCopy(bigBlobUri, destShareName, fileName, destContext), "Copy to file should succeed."); string sasToken = destShare.GetSharedAccessSignature(new SharedAccessFilePolicy() { Permissions = SharedAccessFilePermissions.Read, SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddHours(1) }); CommandAgent.SetStorageContextWithSASToken(StorageAccount.Credentials.AccountName, sasToken); Test.Assert(CommandAgent.GetFileCopyState(destShareName, fileName, destContext), "Get copy state with sas token should succeed."); string copyId = null; if (lang == Language.NodeJS) { copyId = ((JObject)CommandAgent.Output[0]["copy"])["id"].ToString(); } NodeJSAgent.AgentConfig.ConnectionString = StorageAccount.ToString(true); Test.Assert(CommandAgent.StopFileCopy(destFile, copyId), "Stop file copy should succeed."); } finally { fileUtil.DeleteFileShareIfExists(destShareName); } }
public void ShowNonExistingContainer() { string containerName = Utility.GenNameString("nonexisting"); // Delete the container if it exists CloudBlobClient blobClient = StorageAccount.CreateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference(containerName); container.DeleteIfExists(); NodeJSAgent nodejsAgent = (NodeJSAgent)CommandAgent; //--------------Show operation-------------- Test.Assert(!nodejsAgent.ShowAzureStorageContainer(containerName), Utility.GenComparisonData("show container", false)); // Verification for returned values nodejsAgent.ValidateErrorMessage(MethodBase.GetCurrentMethod().Name, containerName); }
internal void StorageTest(string caseName) { NodeJSAgent nodeAgent = (NodeJSAgent)CommandAgent; string containerName = Utility.GenNameString("astoria-"); string blobName = Utility.GenNameString("astoria-"); Test.Assert(!nodeAgent.NewAzureStorageContainer(containerName), Utility.GenComparisonData("NewAzureStorageContainer", false)); nodeAgent.ValidateErrorMessage(caseName); Test.Assert(!nodeAgent.GetAzureStorageContainer(containerName), Utility.GenComparisonData("GetAzureStorageContainer", false)); nodeAgent.ValidateErrorMessage(caseName); Test.Assert(!nodeAgent.SetAzureStorageContainerACL(containerName, BlobContainerPublicAccessType.Container), Utility.GenComparisonData("SetAzureStorageContainerACL", false)); nodeAgent.ValidateErrorMessage(caseName); Test.Assert(!nodeAgent.RemoveAzureStorageContainer(containerName), Utility.GenComparisonData("RemoveAzureStorageContainer", false)); nodeAgent.ValidateErrorMessage(caseName); Test.Assert(!nodeAgent.ShowAzureStorageContainer(containerName), Utility.GenComparisonData("ShowAzureStorageContainer", false)); nodeAgent.ValidateErrorMessage(caseName); Test.Assert(!nodeAgent.SetAzureStorageBlobContent(TempTestFile, containerName, BlobType.BlockBlob, blobName), Utility.GenComparisonData("SetAzureStorageBlobContent", false)); nodeAgent.ValidateErrorMessage(caseName); Test.Assert(!nodeAgent.SetAzureStorageBlobContent(TempTestFile, containerName, BlobType.PageBlob, blobName), Utility.GenComparisonData("SetAzureStorageBlobContent", false)); nodeAgent.ValidateErrorMessage(caseName); Test.Assert(!nodeAgent.GetAzureStorageBlobContent(blobName, TempTestFile, containerName), Utility.GenComparisonData("GetAzureStorageBlobContent", false)); nodeAgent.ValidateErrorMessage(caseName); Test.Assert(!nodeAgent.GetAzureStorageBlob(blobName, containerName), Utility.GenComparisonData("GetAzureStorageBlob", false)); nodeAgent.ValidateErrorMessage(caseName); Test.Assert(!nodeAgent.ShowAzureStorageBlob(blobName, containerName), Utility.GenComparisonData("ShowAzureStorageBlob", false)); nodeAgent.ValidateErrorMessage(caseName); Test.Assert(!nodeAgent.RemoveAzureStorageBlob(blobName, containerName), Utility.GenComparisonData("RemoveAzureStorageBlob", false)); nodeAgent.ValidateErrorMessage(caseName); }
protected void SetActiveSubscription() { NodeJSAgent nodeAgent = (NodeJSAgent)CommandAgent; string subscriptionID = Test.Data.Get("AzureSubscriptionID"); if (!string.IsNullOrEmpty(subscriptionID)) { nodeAgent.SetActiveSubscription(subscriptionID); } else { string subscriptionName = Test.Data.Get("AzureSubscriptionName"); if (!string.IsNullOrEmpty(subscriptionName)) { nodeAgent.SetActiveSubscription(subscriptionName); } } }
protected static void SetCLIEnv(TestContext testContext) { //add the language specific initialization lang = AgentFactory.GetLanguage(testContext.Properties); isMooncake = Utility.GetTargetEnvironment().Name == "AzureChinaCloud"; string mode = Test.Data.Get("IsResourceMode"); if (!string.IsNullOrEmpty(mode)) { isResourceMode = bool.Parse(mode); } if (lang == Language.PowerShell) { if (isResourceMode) { PowerShellAgent.ImportModules(Constants.ResourceModulePaths);; } else { PowerShellAgent.ImportModules(Constants.ServiceModulePaths); } string snapInName = Test.Data.Get("PSSnapInName"); if (!string.IsNullOrWhiteSpace(snapInName)) { PowerShellAgent.AddSnapIn(snapInName); } //set the default storage context PowerShellAgent.SetStorageContext(StorageAccount.ToString(true)); } else if (lang == Language.NodeJS) { NodeJSAgent.GetOSConfig(Test.Data); // use ConnectionString parameter by default in function test NodeJSAgent.AgentConfig.ConnectionString = StorageAccount.ToString(true); FileUtil.GetOSConfig(Test.Data); } }
public void ShowBlobWithMetadata() { string containerName = Utility.GenNameString("container"); string pageBlobName = Utility.GenNameString("page"); string blockBlobName = Utility.GenNameString("block"); CloudBlobContainer container = blobUtil.CreateContainer(containerName); NodeJSAgent nodejsAgent = (NodeJSAgent)CommandAgent; try { CloudBlob pageBlob = blobUtil.CreatePageBlob(container, pageBlobName); CloudBlob blockBlob = blobUtil.CreateBlockBlob(container, blockBlobName); int count = Utility.GetRandomTestCount(); for (int i = 0; i < count; i++) { pageBlob.Metadata.Add(Utility.GenNameString("ShowBlobWithMetadata"), Utility.GenNameString("ShowBlobWithMetadata")); pageBlob.SetMetadata(); blockBlob.Metadata.Add(Utility.GenNameString("ShowBlobWithMetadata"), Utility.GenNameString("ShowBlobWithMetadata")); blockBlob.SetMetadata(); } Test.Assert(nodejsAgent.ShowAzureStorageBlob(pageBlobName, containerName), Utility.GenComparisonData("show blob with metadata", true)); Test.Assert(nodejsAgent.Output.Count == 1, String.Format("Expect to retrieve {0} blobs, but retrieved {1} blobs", 1, nodejsAgent.Output.Count)); nodejsAgent.OutputValidation(new List <CloudBlob>() { pageBlob }); Test.Assert(nodejsAgent.ShowAzureStorageBlob(blockBlobName, containerName), Utility.GenComparisonData("show blob with metadata", true)); Test.Assert(nodejsAgent.Output.Count == 1, String.Format("Expect to retrieve {0} blobs, but retrieved {1} blobs", 1, nodejsAgent.Output.Count)); nodejsAgent.OutputValidation(new List <CloudBlob>() { blockBlob }); } finally { blobUtil.RemoveContainer(containerName); } }
public void ShowLogsContainer() { const string containerName = "$logs"; Dictionary <string, object> dic = Utility.GenComparisonData(StorageObjectType.Container, containerName); Collection <Dictionary <string, object> > comp = new Collection <Dictionary <string, object> > { dic }; CloudBlobContainer container = StorageAccount.CreateCloudBlobClient().GetContainerReference(containerName); NodeJSAgent nodejsAgent = (NodeJSAgent)CommandAgent; //--------------Show operation-------------- Test.Assert(nodejsAgent.ShowAzureStorageContainer(containerName), Utility.GenComparisonData("show $logs container", true)); container.FetchAttributes(); CloudBlobUtil.PackContainerCompareData(container, dic); // Verification for returned values nodejsAgent.OutputValidation(comp); }
public void StartCopyFromInvalidContext() { string destShareName = Utility.GenNameString("destshare"); CloudFileShare destShare = fileUtil.EnsureFileShareExists(destShareName); string sourceShareName = Utility.GenNameString("sourceshare"); CloudFileShare sourceShare = fileUtil.EnsureFileShareExists(sourceShareName); try { StorageFile.CloudFile sourceFile = fileUtil.CreateFile(sourceShare.GetRootDirectoryReference(), Utility.GenNameString("SourceFile")); object destContext; if (lang == Language.PowerShell) { destContext = PowerShellAgent.GetStorageContext(StorageAccount.ToString(true)); } else { destContext = NodeJSAgent.GetStorageContext(StorageAccount.ToString(true)); } string sasToken = sourceShare.GetSharedAccessSignature(new SharedAccessFilePolicy() { Permissions = SharedAccessFilePermissions.Write, SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddHours(1) }); CommandAgent.SetStorageContextWithSASToken(StorageAccount.Credentials.AccountName, sasToken); string destFileName = Utility.GenNameString("destfile"); Test.Assert(!CommandAgent.StartFileCopyFromFile(sourceShareName, sourceFile.Name, destShareName, destFileName, destContext), "Copy to file with invalid sas token credential should fail."); ExpectedContainErrorMessage("This request is not authorized to perform this operation using this permission."); } finally { fileUtil.DeleteFileShareIfExists(sourceShareName); fileUtil.DeleteFileShareIfExists(destShareName); } }
public void ShowNonExistingBlob() { string containerName = Utility.GenNameString("container"); string blobName = Utility.GenNameString("blob", 12); CloudBlobContainer container = blobUtil.CreateContainer(containerName); NodeJSAgent nodejsAgent = (NodeJSAgent)CommandAgent; try { string notExistingBlobName = "notexistingblob"; string BLOB_NAME = Utility.GenNameString("nonexisting"); Test.Assert(!nodejsAgent.ShowAzureStorageBlob(notExistingBlobName, containerName), Utility.GenComparisonData("show blob with not existing blob", false)); nodejsAgent.ValidateErrorMessage(MethodBase.GetCurrentMethod().Name, notExistingBlobName, containerName); } finally { blobUtil.RemoveContainer(containerName); } }
private void CopyFromBlob2File(Action <CloudBlobContainer> SetSourceContext) { string destShareName = Utility.GenNameString("destshare"); CloudFileShare destShare = fileUtil.EnsureFileShareExists(destShareName); string sourceContainerName = Utility.GenNameString("container"); CloudBlobContainer container = blobUtil.CreateContainer(sourceContainerName); try { CloudBlob sourceBlob = blobUtil.CreateRandomBlob(container, Utility.GenNameString("BlobName")); object destContext; if (lang == Language.PowerShell) { destContext = PowerShellAgent.GetStorageContext(StorageAccount.ToString(true)); } else { destContext = NodeJSAgent.GetStorageContext(StorageAccount.ToString(true)); } SetSourceContext(container); string destFileName = Utility.GenNameString("destfile"); Test.Assert(CommandAgent.StartFileCopyFromBlob(sourceContainerName, sourceBlob.Name, destShareName, destFileName, destContext), "Copy to file with sas token credential should succeed."); var destFile = fileUtil.GetFileReference(destShare.GetRootDirectoryReference(), destFileName); Test.Assert(CommandAgent.GetFileCopyState(destFile, destContext, true), "Get file copy state should succeed."); CloudFileUtil.ValidateCopyResult(sourceBlob, destFile); } finally { blobUtil.RemoveContainer(sourceContainerName); fileUtil.DeleteFileShareIfExists(destShareName); } }
public void ShowBlobWithSpecialChars(BlobType blobType) { CloudBlobContainer container = blobUtil.CreateContainer(); string blobName = SpecialChars; CloudBlob blob = blobUtil.CreateBlob(container, blobName, blobType); NodeJSAgent nodejsAgent = (NodeJSAgent)CommandAgent; try { Test.Assert(nodejsAgent.ShowAzureStorageBlob(blobName, container.Name), "show blob name with special chars should succeed"); blob.FetchAttributes(); nodejsAgent.OutputValidation(new List <CloudBlob>() { blob }); } finally { blobUtil.RemoveContainer(container.Name); } }
public void ShowContainerWithSasPolicy() { string containerName = Utility.GenNameString("container"); CloudBlobContainer container = blobUtil.CreateContainer(containerName); NodeJSAgent nodejsAgent = (NodeJSAgent)CommandAgent; try { TimeSpan sasLifeTime = TimeSpan.FromMinutes(10); BlobContainerPermissions permission = new BlobContainerPermissions(); int count = random.Next(1, 5); for (int i = 0; i < count; i++) { permission.SharedAccessPolicies.Add(Utility.GenNameString("saspolicy"), new SharedAccessBlobPolicy { SharedAccessExpiryTime = DateTime.Now.Add(sasLifeTime), Permissions = SharedAccessBlobPermissions.Read, }); } container.SetPermissions(permission); Test.Assert(nodejsAgent.ShowAzureStorageContainer(containerName), Utility.GenComparisonData("show container", true)); Test.Assert(nodejsAgent.Output.Count == 1, String.Format("Create {0} containers, actually retrieved {1} containers", 1, nodejsAgent.Output.Count)); nodejsAgent.OutputValidation(new List <BlobContainerPermissions>() { permission }); } finally { blobUtil.RemoveContainer(containerName); } }
/// <summary> /// Functional Cases: /// 1. Upload a new blob file in the root container (Set-AzureStorageBlobContent Positive 2) /// 2. Get an existing blob in the root container (Get-AzureStorageBlob Positive 2) /// 3. Download an existing blob in the root container (Get-AzureStorageBlobContent Positive 2) /// 4. Remove an existing blob in the root container (Remove-AzureStorageBlob Positive 2) /// </summary> internal void RootBlobOperations(Agent agent, string UploadFilePath, string DownloadDirPath, Microsoft.WindowsAzure.Storage.Blob.BlobType Type) { const string ROOT_CONTAINER_NAME = "$root"; string blobName = Path.GetFileName(UploadFilePath); string downloadFilePath = Path.Combine(DownloadDirPath, blobName); Collection <Dictionary <string, object> > comp = new Collection <Dictionary <string, object> >(); Dictionary <string, object> dic = Utility.GenComparisonData(StorageObjectType.Blob, blobName); dic["BlobType"] = Type; comp.Add(dic); // create the container CloudBlobContainer container = StorageAccount.CreateCloudBlobClient().GetRootContainerReference(); container.CreateIfNotExists(); //--------------Upload operation-------------- Test.Assert(agent.SetAzureStorageBlobContent(UploadFilePath, ROOT_CONTAINER_NAME, Type), Utility.GenComparisonData("SendAzureStorageBlob", true)); CloudBlob blob = BlobHelper.QueryBlob(ROOT_CONTAINER_NAME, blobName); blob.FetchAttributes(); // Verification for returned values CloudBlobUtil.PackBlobCompareData(blob, dic); agent.OutputValidation(comp); Test.Assert(blob.Exists(), "blob " + blobName + " should exist!"); // validate the ContentType value for GetAzureStorageBlob operation // Remove the ContentType validation since it's not set/control by PowerShell, and is totally server behavior, and can change with server behavior change. //dic["ContentType"] = "application/octet-stream"; //--------------Get operation-------------- Test.Assert(agent.GetAzureStorageBlob(blobName, ROOT_CONTAINER_NAME), Utility.GenComparisonData("GetAzureStorageBlob", true)); // Verification for returned values agent.OutputValidation(comp); if (agent is NodeJSAgent) { NodeJSAgent nodejsAgent = (NodeJSAgent)agent; //--------------Show operation-------------- Test.Assert(nodejsAgent.ShowAzureStorageBlob(blobName, ROOT_CONTAINER_NAME), Utility.GenComparisonData("ShowAzureStorageBlob", true)); // Verification for returned values nodejsAgent.OutputValidation(comp); } //--------------Download operation-------------- downloadFilePath = Path.Combine(DownloadDirPath, blobName); Test.Assert(agent.GetAzureStorageBlobContent(blobName, downloadFilePath, ROOT_CONTAINER_NAME), Utility.GenComparisonData("GetAzureStorageBlobContent", true)); // Verification for returned values agent.OutputValidation(comp); Test.Assert(FileUtil.CompareTwoFiles(downloadFilePath, UploadFilePath), String.Format("File '{0}' should be bit-wise identicial to '{1}'", downloadFilePath, UploadFilePath)); //--------------Remove operation-------------- Test.Assert(agent.RemoveAzureStorageBlob(blobName, ROOT_CONTAINER_NAME), Utility.GenComparisonData("RemoveAzureStorageBlob", true)); blob = BlobHelper.QueryBlob(ROOT_CONTAINER_NAME, blobName); Test.Assert(blob == null, "blob {0} should not exist!", blobName); }