public void GetCopyStateFromCrossAccountCopyTest() { CloudStorageAccount secondaryAccount = TestBase.GetCloudStorageAccountFromConfig("Secondary"); object destContext = PowerShellAgent.GetStorageContext(secondaryAccount.ToString(true)); CloudBlobUtil destBlobUtil = new CloudBlobUtil(secondaryAccount); string destContainerName = Utility.GenNameString("secondary"); CloudBlobContainer destContainer = destBlobUtil.CreateContainer(destContainerName); blobUtil.SetupTestContainerAndBlob(); //remove the same name container in source storage account, so we could avoid some conflicts. blobUtil.RemoveContainer(destContainer.Name); try { Test.Assert(agent.StartAzureStorageBlobCopy(blobUtil.Blob, destContainer.Name, string.Empty, destContext), "Start cross account copy should successed"); int expectedBlobCount = 1; Test.Assert(agent.Output.Count == expectedBlobCount, String.Format("Expected get {0} copy blob, and actually it's {1}", expectedBlobCount, agent.Output.Count)); ICloudBlob destBlob = (ICloudBlob)agent.Output[0]["ICloudBlob"]; //make sure this context is different from the PowerShell.Context object context = agent.Output[0]["Context"]; Test.Assert(PowerShellAgent.Context != context, "make sure you are using different context for cross account copy"); Test.Assert(agent.GetAzureStorageBlobCopyState(destBlob, context, true), "Get copy state in dest container should be successed."); AssertFinishedCopyState(blobUtil.Blob.Uri); } finally { blobUtil.CleanupTestContainerAndBlob(); destBlobUtil.RemoveContainer(destContainer.Name); } }
public static void TestClassInitialize(TestContext testContext) { Test.Info(string.Format("{0} Class Initialize", testContext.FullyQualifiedTestClassName)); Test.FullClassName = testContext.FullyQualifiedTestClassName; StorageAccount = GetCloudStorageAccountFromConfig(); //init the blob helper for blob related operations blobUtil = new CloudBlobUtil(StorageAccount); queueUtil = new CloudQueueUtil(StorageAccount); tableUtil = new CloudTableUtil(StorageAccount); // import module string moduleFilePath = Test.Data.Get("ModuleFilePath"); PowerShellAgent.ImportModule(moduleFilePath); //set the default storage context PowerShellAgent.SetStorageContext(StorageAccount.ToString(true)); random = new Random(); ContainerInitCount = blobUtil.GetExistingContainerCount(); QueueInitCount = queueUtil.GetExistingQueueCount(); TableInitCount = tableUtil.GetExistingTableCount(); }
internal void StartCopyBlobTest(Agent agent, bool useUri) { CloudBlobUtil blobUtil = new CloudBlobUtil(CommonStorageAccount); blobUtil.SetupTestContainerAndBlob(); string copiedName = Utility.GenNameString("copied"); if(useUri) { //Set the blob permission, so the copy task could directly copy by uri BlobContainerPermissions permission = new BlobContainerPermissions(); permission.PublicAccess = BlobContainerPublicAccessType.Blob; blobUtil.Container.SetPermissions(permission); } try { if(useUri) { Test.Assert(agent.StartAzureStorageBlobCopy(blobUtil.Blob.Uri.ToString(), blobUtil.ContainerName, copiedName, PowerShellAgent.Context), Utility.GenComparisonData("Start copy blob using source uri", true)); } else { Test.Assert(agent.StartAzureStorageBlobCopy(blobUtil.ContainerName, blobUtil.BlobName, blobUtil.ContainerName, copiedName), Utility.GenComparisonData("Start copy blob using blob name", true)); } Test.Info("Get destination blob in copy task"); ICloudBlob blob = blobUtil.Container.GetBlobReferenceFromServer(copiedName); Test.Assert(blob != null, "Destination blob should exist after start copy. If not, please check it's a test issue or dev issue."); string sourceUri = CloudBlobUtil.ConvertCopySourceUri(blobUtil.Blob.Uri.ToString()); Test.Assert(blob.BlobType == blobUtil.Blob.BlobType, String.Format("The destination blob type should be {0}, actually {1}.", blobUtil.Blob.BlobType, blob.BlobType)); Test.Assert(blob.CopyState.Source.ToString().StartsWith(sourceUri), String.Format("The source of destination blob should start with {0}, and actually it's {1}", sourceUri, blob.CopyState.Source.ToString())); } finally { blobUtil.CleanupTestContainerAndBlob(); } }
internal ICloudBlob CopyBlobAndWaitForComplete(CloudBlobUtil blobUtil) { string destBlobName = Utility.GenNameString("copystate"); ICloudBlob destBlob = default(ICloudBlob); Test.Info("Copy Blob using storage client"); if (blobUtil.Blob.BlobType == StorageBlob.BlobType.BlockBlob) { CloudBlockBlob blockBlob = blobUtil.Container.GetBlockBlobReference(destBlobName); blockBlob.StartCopyFromBlob((CloudBlockBlob)blobUtil.Blob); destBlob = blockBlob; } else { CloudPageBlob pageBlob = blobUtil.Container.GetPageBlobReference(destBlobName); pageBlob.StartCopyFromBlob((CloudPageBlob)blobUtil.Blob); destBlob = pageBlob; } CloudBlobUtil.WaitForCopyOperationComplete(destBlob); Test.Assert(destBlob.CopyState.Status == CopyStatus.Success, String.Format("The blob copy using storage client should be success, actually it's {0}", destBlob.CopyState.Status)); return destBlob; }
public void StopCopyBlobTest() { CloudBlobUtil blobUtil = new CloudBlobUtil(CommonStorageAccount); blobUtil.SetupTestContainerAndBlob(); ICloudBlob destBlob = CopyBlobAndWaitForComplete(blobUtil); try { PowerShellAgent agent = new PowerShellAgent(); string copyId = Guid.NewGuid().ToString(); Test.Assert(!agent.StopAzureStorageBlobCopy(blobUtil.ContainerName, blobUtil.BlobName, copyId, true), "Stop copy operation should be fail since the specified blob don't have any copy operation"); Test.Assert(agent.ErrorMessages.Count > 0, "Should return error message"); string errorMessage = String.Format("Can not find copy task on specified blob '{0}' in container '{1}'", blobUtil.BlobName, blobUtil.ContainerName); Test.Assert(agent.ErrorMessages[0].IndexOf(errorMessage) != -1, String.Format("Error message should contain {0}, and actually it's {1}", errorMessage, agent.ErrorMessages[0])); errorMessage = "There is currently no pending copy operation."; Test.Assert(!agent.StopAzureStorageBlobCopy(blobUtil.ContainerName, destBlob.Name, copyId, true), "Stop copy operation should be fail since the specified copy operation has finished"); Test.Assert(agent.ErrorMessages.Count > 0, "Should return error message"); Test.Assert(agent.ErrorMessages[0].IndexOf(errorMessage) != -1, String.Format("Error message should contain {0}, and actually it's {1}", errorMessage, agent.ErrorMessages[0])); } finally { blobUtil.CleanupTestContainerAndBlob(); } }
public void GetBlobCopyStateTest() { CloudBlobUtil blobUtil = new CloudBlobUtil(CommonStorageAccount); blobUtil.SetupTestContainerAndBlob(); ICloudBlob destBlob = CopyBlobAndWaitForComplete(blobUtil); try { Test.Assert(destBlob.CopyState.Status == CopyStatus.Success, String.Format("The blob copy using storage client should be success, actually it's {0}", destBlob.CopyState.Status)); PowerShellAgent agent = new PowerShellAgent(); Test.Assert(agent.GetAzureStorageBlobCopyState(blobUtil.ContainerName, destBlob.Name, false), "Get copy state should be success"); int expectedStateCount = 1; Test.Assert(agent.Output.Count == expectedStateCount, String.Format("Expected to get {0} copy state, actually it's {1}", expectedStateCount, agent.Output.Count)); CopyStatus copyStatus = (CopyStatus)agent.Output[0]["Status"]; Test.Assert(copyStatus == CopyStatus.Success, String.Format("The blob copy should be success, actually it's {0}", copyStatus)); Uri sourceUri = (Uri)agent.Output[0]["Source"]; string expectedUri = CloudBlobUtil.ConvertCopySourceUri(blobUtil.Blob.Uri.ToString()); Test.Assert(sourceUri.ToString() == expectedUri, String.Format("Expected source uri is {0}, actully it's {1}", expectedUri, sourceUri.ToString())); Test.Assert(!agent.GetAzureStorageBlobCopyState(blobUtil.ContainerName, blobUtil.BlobName, false), "Get copy state should be fail since the specified blob don't have any copy operation"); Test.Assert(agent.ErrorMessages.Count > 0, "Should return error message"); string errorMessage = "Can not find copy task on specified blob"; Test.Assert(agent.ErrorMessages[0].StartsWith(errorMessage), String.Format("Error message should start with {0}, and actually it's {1}", errorMessage, agent.ErrorMessages[0])); } finally { blobUtil.CleanupTestContainerAndBlob(); } }
public void GetContainerFromMultipleStorageContext() { CloudStorageAccount account1 = TestBase.GetCloudStorageAccountFromConfig(); CloudStorageAccount account2 = TestBase.GetCloudStorageAccountFromConfig("Secondary"); string connectionString1 = account1.ToString(true); string connectionString2 = account2.ToString(true); Test.Assert(connectionString1 != connectionString2, "Use two different connection string {0} != {1}", connectionString1, connectionString2); CloudBlobUtil blobUtil1 = new CloudBlobUtil(account1); CloudBlobUtil blobUtil2 = new CloudBlobUtil(account2); string containerName = Utility.GenNameString("container"); try { CloudBlobContainer container1 = blobUtil1.CreateContainer(containerName); CloudBlobContainer container2 = blobUtil2.CreateContainer(containerName); int containerCount = 2; string cmd = String.Format("$context1 = new-azurestoragecontext -connectionstring '{0}';$context2 = new-azurestoragecontext -connectionstring '{1}';($context1, $context2)", connectionString1, connectionString2); agent.UseContextParam = false; ((PowerShellAgent)agent).AddPipelineScript(cmd); Test.Assert(agent.GetAzureStorageContainer(containerName), Utility.GenComparisonData("Get-AzureStorageContainer using multiple storage contexts", true)); Test.Assert(agent.Output.Count == containerCount, String.Format("Want to retrieve {0} page blob, but retrieved {1} page blobs", containerCount, agent.Output.Count)); agent.OutputValidation(new List<CloudBlobContainer>() { container1, container2 }); } finally { blobUtil1.RemoveContainer(containerName); blobUtil2.RemoveContainer(containerName); } }
public void StartCrossAccountCopyWithMetaAndPropertiesTest() { blobUtil.SetupTestContainerAndBlob(); try { CloudStorageAccount secondaryAccount = TestBase.GetCloudStorageAccountFromConfig("Secondary"); object destContext = PowerShellAgent.GetStorageContext(secondaryAccount.ToString(true)); CloudBlobUtil destBlobUtil = new CloudBlobUtil(secondaryAccount); string destContainerName = Utility.GenNameString("secondary"); CloudBlobContainer destContainer = destBlobUtil.CreateContainer(destContainerName); AssertCopyBlobCrossContainer(blobUtil.Blob, destContainer, string.Empty, destContext); destBlobUtil.RemoveContainer(destContainer.Name); } finally { blobUtil.CleanupTestContainerAndBlob(); } }