internal void GetContainerTest(Agent agent) { string NEW_CONTAINER_NAME = Utility.GenNameString("astoria-"); Dictionary <string, object> dic = Utility.GenComparisonData(StorageObjectType.Container, NEW_CONTAINER_NAME); // create container if it does not exist CloudBlobContainer container = CommonStorageAccount.CreateCloudBlobClient().GetContainerReference(NEW_CONTAINER_NAME); container.CreateIfNotExists(); Collection <Dictionary <string, object> > comp = new Collection <Dictionary <string, object> > { dic }; try { //--------------Get operation-------------- Test.Assert(agent.GetAzureStorageContainer(NEW_CONTAINER_NAME), Utility.GenComparisonData("GetAzureStorageContainer", true)); // Verification for returned values container.FetchAttributes(); dic.Add("CloudBlobContainer", container); CloudBlobUtil.PackContainerCompareData(container, dic); agent.OutputValidation(comp); } finally { // clean up container.DeleteIfExists(); } }
internal void NewContainerTest(Agent agent) { string NEW_CONTAINER_NAME = Utility.GenNameString("astoria-"); Dictionary <string, object> dic = Utility.GenComparisonData(StorageObjectType.Container, NEW_CONTAINER_NAME); Collection <Dictionary <string, object> > comp = new Collection <Dictionary <string, object> > { dic }; // delete container if it exists CloudBlobContainer container = CommonStorageAccount.CreateCloudBlobClient().GetContainerReference(NEW_CONTAINER_NAME); container.DeleteIfExists(); try { //--------------New operation-------------- Test.Assert(agent.NewAzureStorageContainer(NEW_CONTAINER_NAME), Utility.GenComparisonData("NewAzureStorageContainer", true)); // Verification for returned values CloudBlobUtil.PackContainerCompareData(container, dic); agent.OutputValidation(comp); Test.Assert(container.Exists(), "container {0} should exist!", NEW_CONTAINER_NAME); } finally { // clean up container.DeleteIfExists(); } }
internal void SetContainerACLTest(Agent agent) { string NEW_CONTAINER_NAME = Utility.GenNameString("astoria-"); Collection <Dictionary <string, object> > comp = new Collection <Dictionary <string, object> >(); Dictionary <string, object> dic = Utility.GenComparisonData(StorageObjectType.Container, NEW_CONTAINER_NAME); comp.Add(dic); // create container if it does not exist CloudBlobContainer container = CommonStorageAccount.CreateCloudBlobClient().GetContainerReference(NEW_CONTAINER_NAME); container.CreateIfNotExists(); try { BlobContainerPublicAccessType[] accessTypes = new BlobContainerPublicAccessType[] { BlobContainerPublicAccessType.Blob, BlobContainerPublicAccessType.Container, BlobContainerPublicAccessType.Off }; // set PublicAccess as one value respetively foreach (var accessType in accessTypes) { //--------------Set operation-------------- Test.Assert(agent.SetAzureStorageContainerACL(NEW_CONTAINER_NAME, accessType), "SetAzureStorageContainerACL operation should succeed"); // Verification for returned values dic["PublicAccess"] = accessType; CloudBlobUtil.PackContainerCompareData(container, dic); agent.OutputValidation(comp); Test.Assert(container.GetPermissions().PublicAccess == accessType, "PublicAccess should be equal: {0} = {1}", container.GetPermissions().PublicAccess, accessType); } } finally { // clean up container.DeleteIfExists(); } }
public void ListContainerWithContianerPermission() { string containerName = Utility.GenNameString(ContainerPrefix); StorageBlob.CloudBlobContainer container = blobUtil.CreateContainer(containerName, StorageBlob.BlobContainerPublicAccessType.Container); try { Test.Assert(agent.GetAzureStorageContainer(containerName), Utility.GenComparisonData("GetAzureStorageContainer", true)); Dictionary <string, object> dic = Utility.GenComparisonData(StorageObjectType.Container, containerName); Collection <Dictionary <string, object> > comp = new Collection <Dictionary <string, object> > { dic }; //remove the permssion information for anonymous storage account CloudBlobUtil.PackContainerCompareData(container, dic); dic["PublicAccess"] = null; dic["Permission"] = null; // Verification for returned values agent.OutputValidation(comp); //check the http or https usage StorageBlob.CloudBlobContainer retrievedContainer = (StorageBlob.CloudBlobContainer)agent.Output[0]["CloudBlobContainer"];; string uri = retrievedContainer.Uri.ToString(); string uriPrefix = string.Empty; if (useHttps) { uriPrefix = "https"; } else { uriPrefix = "http"; } Test.Assert(uri.ToString().StartsWith(uriPrefix), string.Format("The prefix of container uri should be {0}, actually it's {1}", uriPrefix, uri)); } 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); }
/// <summary> /// Functional Cases: /// 1. Create the root container (New-AzureStorageContainer Positive 4) /// 2. Get the root container (Get-AzureStorageContainer Positive 4) /// 3. Remove the root container (Remove-AzureStorageContainer Positive 4) /// </summary> internal void RootContainerOperations(Agent agent) { const string ROOT_CONTAINER_NAME = "$root"; Dictionary <string, object> dic = Utility.GenComparisonData(StorageObjectType.Container, ROOT_CONTAINER_NAME); Collection <Dictionary <string, object> > comp = new Collection <Dictionary <string, object> > { dic }; // delete container if it not exists CloudBlobContainer container = StorageAccount.CreateCloudBlobClient().GetRootContainerReference(); bool bExists = container.Exists(); if (bExists) { container.Delete(); } try { //--------------New operation-------------- bool created = false; int retryCount = 0; int maxRetryCount = 60; //retry ten minutes do { if (retryCount > 0) { int sleepInterval = 10 * 1000; Test.Info("Sleep and wait for retry..."); Thread.Sleep(sleepInterval); Test.Info(string.Format("{0}th retry to create the $root container", retryCount)); } bool successed = agent.NewAzureStorageContainer(ROOT_CONTAINER_NAME); if (successed) { Test.Info("Create $root container successfully"); created = true; } else { if (agent.ErrorMessages.Count == 0) { Test.AssertFail("Can not create $root container and can't get any error messages"); break; } else if (agent.ErrorMessages[0].Contains("The remote server returned an error: (409) Conflict.")) { retryCount++; } else if (agent.ErrorMessages[0].Contains("The specified container is being deleted.")) { retryCount++; } else { Test.AssertFail(string.Format("Can not create $root container. Exception: {0}", agent.ErrorMessages[0])); break; } } }while (!created && retryCount < maxRetryCount); if (!created && retryCount == maxRetryCount) { Test.AssertFail(string.Format("Can not create $root container after {0} times retry", retryCount)); } container.FetchAttributes(); CloudBlobUtil.PackContainerCompareData(container, dic); // Verification for returned values agent.OutputValidation(comp); Test.Assert(container.Exists(), "container {0} should exist!", ROOT_CONTAINER_NAME); //--------------Get operation-------------- Test.Assert(agent.GetAzureStorageContainer(ROOT_CONTAINER_NAME), Utility.GenComparisonData("GetAzureStorageContainer", true)); // Verification for returned values agent.OutputValidation(comp); //--------------Remove operation-------------- Test.Assert(agent.RemoveAzureStorageContainer(ROOT_CONTAINER_NAME), Utility.GenComparisonData("RemoveAzureStorageContainer", true)); Test.Assert(!container.Exists(), "container {0} should not exist!", ROOT_CONTAINER_NAME); } finally { // Recover the environment try { if (bExists) { Test.Info("Sleep for 150 seconds to wait for removing the root container"); System.Threading.Thread.Sleep(150000); //The following statement often throw an 409 conflict exception container.Create(); } } catch { } } }