Esempio n. 1
0
        public void StartCrossAccountCopyWithMetaAndPropertiesTest()
        {
            if (lang == Language.PowerShell)
            {
                blobUtil.SetupTestContainerAndBlob();
            }
            else
            {
                blobUtil.SetupTestContainerAndBlob(blobNamePrefix: "blob");
            }

            try
            {
                CloudStorageAccount secondaryAccount = TestBase.GetCloudStorageAccountFromConfig("Secondary");
                object destContext = null;
                if (lang == Language.PowerShell)
                {
                    destContext = PowerShellAgent.GetStorageContext(secondaryAccount.ToString(true));
                }
                else
                {
                    destContext = secondaryAccount;
                }
                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();
            }
        }
Esempio n. 2
0
        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();
            }
        }
Esempio n. 3
0
        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);
            }
        }
Esempio n. 4
0
        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);
            }
        }
Esempio n. 5
0
        public static void TestClassInitialize(TestContext testContext)
        {
            Test.Info(string.Format("{0} Class Initialize", testContext.FullyQualifiedTestClassName));
            Test.FullClassName = testContext.FullyQualifiedTestClassName;

            //add the common initialization
            if (StorageAccount == null)
            {
                StorageAccount = GetCloudStorageAccountFromConfig(useHttps: useHttps);
                Test.Info("Got storage account from config: {0}", StorageAccount.ToString(true));
            }

            //init the blob helper for blob related operations
            blobUtil  = new CloudBlobUtil(StorageAccount);
            queueUtil = new CloudQueueUtil(StorageAccount);
            tableUtil = new CloudTableUtil(StorageAccount);
            fileUtil  = new CloudFileUtil(StorageAccount);
            random    = new Random();

            SetCLIEnv(testContext);

            if (null == CommandAgent)
            {
                CommandAgent = AgentFactory.CreateAgent(testContext.Properties);
            }
        }
Esempio n. 6
0
        internal void UploadBlobTestGB(Agent agent, StorageBlob.BlobType blobType)
        {
            string uploadFilePath = @".\" + Utility.GenNameString("gbupload");
            string containerName  = Utility.GenNameString("gbupload-");
            string blobName       = Path.GetFileName(uploadFilePath);

            // create the container
            CloudBlobContainer container = blobUtil.CreateContainer(containerName);

            // Generate a 512 bytes file which contains GB18030 characters
            File.WriteAllText(uploadFilePath, GB18030String);

            try
            {
                //--------------Upload operation--------------
                Test.Assert(agent.SetAzureStorageBlobContent(uploadFilePath, containerName, blobType),
                            Utility.GenComparisonData("SendAzureStorageBlob", true));

                ICloudBlob blob = CloudBlobUtil.GetBlob(container, blobName, blobType);
                Test.Assert(blob != null && blob.Exists(), "blob " + blobName + " should exist!");

                // Check MD5
                string localMd5 = Helper.GetFileContentMD5(uploadFilePath);
                blob.FetchAttributes();
                Test.Assert(localMd5 == blob.Properties.ContentMD5,
                            string.Format("blob content md5 should be {0}, and actualy it's {1}", localMd5, blob.Properties.ContentMD5));
            }
            finally
            {
                // cleanup
                container.DeleteIfExists();
                File.Delete(uploadFilePath);
            }
        }
Esempio n. 7
0
        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();
        }
Esempio n. 8
0
        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();
            }
        }
Esempio n. 9
0
        private ICloudBlob AssertCopyBlobCrossContainer(ICloudBlob srcBlob, CloudBlobContainer destContainer, string destBlobName, object destContext, Func <bool> StartFunc = null)
        {
            if (StartFunc == null)
            {
                Test.Assert(agent.StartAzureStorageBlobCopy(srcBlob.Container.Name, srcBlob.Name, destContainer.Name, destBlobName, destContext), "blob copy should start sucessfully");
            }
            else
            {
                Test.Assert(StartFunc(), "blob copy should start sucessfully");
            }

            int expectedBlobCount = 1;

            Test.Assert(agent.Output.Count == expectedBlobCount, String.Format("Expected get {0} copy state, and actually it's {1}", expectedBlobCount, agent.Output.Count));
            ICloudBlob destBlob         = (ICloudBlob)agent.Output[0]["ICloudBlob"];
            string     expectedBlobName = destBlobName;

            if (string.IsNullOrEmpty(expectedBlobName))
            {
                expectedBlobName = srcBlob.Name;
            }

            Test.Assert(expectedBlobName == destBlob.Name, string.Format("Expected destination blob name is {0}, and actually it's {1}", expectedBlobName, destBlob.Name));
            Test.Assert(CloudBlobUtil.WaitForCopyOperationComplete(destBlob), "Copy Operation should finished");
            destBlob.FetchAttributes();
            string expectedSourceUri = CloudBlobUtil.ConvertCopySourceUri(srcBlob.Uri.ToString());
            string sourceUri         = destBlob.CopyState.Source.ToString();

            Test.Assert(sourceUri.StartsWith(expectedSourceUri), String.Format("source uri should start with {0}, and actualy it's {1}", expectedSourceUri, sourceUri));
            Test.Assert(destBlob.Metadata.Count > 0, "destination blob should contain meta data");
            Test.Assert(destBlob.Metadata.SequenceEqual(srcBlob.Metadata), "Copied blob's meta data should be equal with origin metadata");
            Test.Assert(destBlob.Properties.ContentEncoding == srcBlob.Properties.ContentEncoding, String.Format("expected content encoding is {0}, and actually it's {1}", srcBlob.Properties.ContentEncoding, destBlob.Properties.ContentEncoding));

            return(destBlob);
        }
Esempio n. 10
0
        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);
        }
Esempio n. 11
0
        private void UploadBlobWithAccount(CloudStorageAccount storageAccount)
        {
            string uploadDirRoot = Test.Data.Get("UploadDir");

            Test.Verbose("Create Upload dir {0}", uploadDirRoot);
            FileUtil.CreateDirIfNotExits(uploadDirRoot);
            FileUtil.CleanDirectory(uploadDirRoot);
            CloudBlobUtil      blobUtil  = new CloudBlobUtil(storageAccount);
            CloudBlobContainer container = blobUtil.CreateContainer(Utility.GenNameString("container"));

            try
            {
                string filePath = Path.Combine(uploadDirRoot, Utility.GenNameString("fileName"));

                FileUtil.GenerateSmallFile(filePath, 1024);

                string blobName = Utility.GenNameString("BlobName");

                Test.Assert(CommandAgent.SetAzureStorageBlobContent(filePath, container.Name, Microsoft.WindowsAzure.Storage.Blob.BlobType.BlockBlob, blobName), "Upload blob should succeed.");

                ICloudBlob blob     = container.GetBlobReferenceFromServer(blobName);
                string     localMd5 = FileUtil.GetFileContentMD5(filePath);

                Test.Assert(localMd5 == blob.Properties.ContentMD5, string.Format("blob content md5 should be {0}, and actually it's {1}", localMd5, blob.Properties.ContentMD5));
            }
            finally
            {
                FileUtil.CleanDirectory(uploadDirRoot);
                blobUtil.RemoveContainer(container);
            }
        }
Esempio n. 12
0
        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();
            }
        }
Esempio n. 13
0
        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();
            }
        }
Esempio n. 14
0
        /// <summary>
        /// Parameters:
        ///     Block:
        ///         True for BlockBlob, false for PageBlob
        /// </summary>
        internal void UploadBlobTest(Agent agent, string UploadFilePath, Microsoft.WindowsAzure.Storage.Blob.BlobType Type)
        {
            string NEW_CONTAINER_NAME = Utility.GenNameString("upload-");
            string blobName           = Path.GetFileName(UploadFilePath);

            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 = CommonStorageAccount.CreateCloudBlobClient().GetContainerReference(NEW_CONTAINER_NAME);

            container.CreateIfNotExists();

            try
            {
                //--------------Upload operation--------------
                Test.Assert(agent.SetAzureStorageBlobContent(UploadFilePath, NEW_CONTAINER_NAME, Type), Utility.GenComparisonData("SendAzureStorageBlob", true));

                ICloudBlob blob = CommonBlobHelper.QueryBlob(NEW_CONTAINER_NAME, blobName);
                CloudBlobUtil.PackBlobCompareData(blob, dic);
                // Verification for returned values
                agent.OutputValidation(comp);
                Test.Assert(blob != null && blob.Exists(), "blob " + blobName + " should exist!");
            }
            finally
            {
                // cleanup
                container.DeleteIfExists();
            }
        }
Esempio n. 15
0
        public void GetCopyStateFromCrossAccountCopyTest()
        {
            CloudStorageAccount secondaryAccount = TestBase.GetCloudStorageAccountFromConfig("Secondary");
            object destContext;

            if (lang == Language.PowerShell)
            {
                destContext = PowerShellAgent.GetStorageContext(secondaryAccount.ToString(true));
            }
            else
            {
                destContext = secondaryAccount;
            }
            CloudBlobUtil      destBlobUtil      = new CloudBlobUtil(secondaryAccount);
            string             destContainerName = Utility.GenNameString("secondary");
            CloudBlobContainer destContainer     = destBlobUtil.CreateContainer(destContainerName);

            if (lang == Language.PowerShell)
            {
                blobUtil.SetupTestContainerAndBlob();
            }
            else
            {
                blobUtil.SetupTestContainerAndBlob(blobNamePrefix: "blob");
            }
            //remove the same name container in source storage account, so we could avoid some conflicts.
            if (!blobUtil.Blob.ServiceClient.BaseUri.Host.Equals(destContainer.ServiceClient.BaseUri.Host))
            {
                blobUtil.RemoveContainer(destContainer.Name);
            }

            try
            {
                Test.Assert(CommandAgent.StartAzureStorageBlobCopy(blobUtil.Blob, destContainer.Name, string.Empty, destContext), "Start cross account copy should succeed");
                int expectedBlobCount = 1;
                Test.Assert(CommandAgent.Output.Count == expectedBlobCount, String.Format("Expected get {0} copy blob, and actually it's {1}", expectedBlobCount, CommandAgent.Output.Count));

                CloudBlob destBlob;
                object    context;
                if (lang == Language.PowerShell)
                {
                    destBlob = (CloudBlob)CommandAgent.Output[0]["ICloudBlob"];
                    //make sure this context is different from the PowerShell.Context
                    context = CommandAgent.Output[0]["Context"];
                    Test.Assert(PowerShellAgent.Context != context, "make sure you are using different context for cross account copy");
                }
                else
                {
                    destBlob = StorageExtensions.GetBlobReferenceFromServer(destContainer, (string)CommandAgent.Output[0]["name"]);
                    context  = destContext;
                }
                Test.Assert(CommandAgent.GetAzureStorageBlobCopyState(destBlob, context, true), "Get copy state in dest container should succeed.");
                AssertFinishedCopyState(blobUtil.Blob.Uri);
            }
            finally
            {
                blobUtil.CleanupTestContainerAndBlob();
                destBlobUtil.RemoveContainer(destContainer.Name);
            }
        }
Esempio n. 16
0
        /// <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));
            ICloudBlob 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
            if (Type == Microsoft.WindowsAzure.Storage.Blob.BlobType.BlockBlob)
            {
                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);

            //--------------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(Helper.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);
        }
Esempio n. 17
0
        private void AssertFinishedCopyState(Uri SourceUri, int startIndex = 0)
        {
            string expectedSourceUri = CloudBlobUtil.ConvertCopySourceUri(SourceUri.ToString());

            Test.Assert(agent.Output.Count > startIndex, String.Format("Should contain the great than {0} copy state, and actually it's {1}", startIndex, agent.Output.Count));
            string sourceUri = ((Uri)agent.Output[startIndex]["Source"]).ToString();

            Test.Assert(sourceUri.StartsWith(expectedSourceUri), String.Format("source uri should start with {0}, and actualy it's {1}", expectedSourceUri, sourceUri));
            StorageBlob.CopyStatus status = (StorageBlob.CopyStatus)agent.Output[startIndex]["Status"];
            Test.Assert(status != StorageBlob.CopyStatus.Pending, String.Format("Copy status should not be Pending, actually it's {0}", status));
            string copyId = (string)agent.Output[startIndex]["CopyId"];

            Test.Assert(!String.IsNullOrEmpty(copyId), "Copy ID should be not empty");
        }
Esempio n. 18
0
        internal void CopyBlobTestGB(Agent agent, StorageBlob.BlobType blobType)
        {
            string uploadFilePath    = @".\" + Utility.GenNameString("gbupload");
            string srcContainerName  = Utility.GenNameString("gbupload-", 15);
            string destContainerName = Utility.GenNameString("gbupload-", 15);
            string blobName          = Path.GetFileName(uploadFilePath);

            // create the container
            CloudBlobContainer srcContainer  = blobUtil.CreateContainer(srcContainerName);
            CloudBlobContainer destContainer = blobUtil.CreateContainer(destContainerName);

            // Generate a 512 bytes file which contains GB18030 characters
            File.WriteAllText(uploadFilePath, GB18030String);

            string localMd5 = Helper.GetFileContentMD5(uploadFilePath);

            try
            {
                // create source blob
                ICloudBlob blob = CloudBlobUtil.GetBlob(srcContainer, blobName, blobType);

                // upload file data
                using (var fileStream = System.IO.File.OpenRead(uploadFilePath))
                {
                    blob.UploadFromStream(fileStream);
                    // need to set MD5 as for page blob, it won't set MD5 automatically
                    blob.Properties.ContentMD5 = localMd5;
                    blob.SetProperties();
                }

                //--------------Copy blob operation--------------
                Test.Assert(agent.StartAzureStorageBlobCopy(srcContainerName, blobName, destContainerName, blobName), Utility.GenComparisonData("Start copy blob using blob name", true));

                // Get destination blob
                blob = CloudBlobUtil.GetBlob(destContainer, blobName, blobType);

                // Check MD5
                blob.FetchAttributes();
                Test.Assert(localMd5 == blob.Properties.ContentMD5,
                            string.Format("blob content md5 should be {0}, and actualy it's {1}", localMd5, blob.Properties.ContentMD5));
            }
            finally
            {
                // cleanup
                srcContainer.DeleteIfExists();
                destContainer.DeleteIfExists();
                File.Delete(uploadFilePath);
            }
        }
Esempio n. 19
0
        /// <summary>
        /// Parameters:
        ///     Block:
        ///         True for BlockBlob, false for PageBlob
        /// </summary>
        internal void DownloadBlobTest(Agent agent, string UploadFilePath, string DownloadDirPath, Microsoft.WindowsAzure.Storage.Blob.BlobType Type)
        {
            string NEW_CONTAINER_NAME = Utility.GenNameString("upload-");
            string blobName           = Path.GetFileName(UploadFilePath);

            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 = CommonStorageAccount.CreateCloudBlobClient().GetContainerReference(NEW_CONTAINER_NAME);

            container.CreateIfNotExists();

            try
            {
                bool bSuccess = false;
                // upload the blob file
                if (Type == Microsoft.WindowsAzure.Storage.Blob.BlobType.BlockBlob)
                {
                    bSuccess = CommonBlobHelper.UploadFileToBlockBlob(NEW_CONTAINER_NAME, blobName, UploadFilePath);
                }
                else if (Type == Microsoft.WindowsAzure.Storage.Blob.BlobType.PageBlob)
                {
                    bSuccess = CommonBlobHelper.UploadFileToPageBlob(NEW_CONTAINER_NAME, blobName, UploadFilePath);
                }
                Test.Assert(bSuccess, "upload file {0} to container {1} should succeed", UploadFilePath, NEW_CONTAINER_NAME);

                //--------------Download operation--------------
                string downloadFilePath = Path.Combine(DownloadDirPath, blobName);
                Test.Assert(agent.GetAzureStorageBlobContent(blobName, downloadFilePath, NEW_CONTAINER_NAME),
                            Utility.GenComparisonData("GetAzureStorageBlobContent", true));
                ICloudBlob blob = CommonBlobHelper.QueryBlob(NEW_CONTAINER_NAME, blobName);
                CloudBlobUtil.PackBlobCompareData(blob, dic);
                // Verification for returned values
                agent.OutputValidation(comp);

                Test.Assert(Helper.CompareTwoFiles(downloadFilePath, UploadFilePath),
                            String.Format("File '{0}' should be bit-wise identicial to '{1}'", downloadFilePath, UploadFilePath));
            }
            finally
            {
                // cleanup
                container.DeleteIfExists();
            }
        }
Esempio n. 20
0
        /// <summary>
        /// Parameters:
        ///     Block:
        ///         True for BlockBlob, false for PageBlob
        /// </summary>
        internal void GetBlobTest(Agent agent, string UploadFilePath, Microsoft.WindowsAzure.Storage.Blob.BlobType Type)
        {
            string NEW_CONTAINER_NAME = Utility.GenNameString("upload-");
            string blobName           = Path.GetFileName(UploadFilePath);

            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 = CommonStorageAccount.CreateCloudBlobClient().GetContainerReference(NEW_CONTAINER_NAME);

            container.CreateIfNotExists();

            try
            {
                bool bSuccess = false;
                // upload the blob file
                if (Type == Microsoft.WindowsAzure.Storage.Blob.BlobType.BlockBlob)
                {
                    bSuccess = CommonBlobHelper.UploadFileToBlockBlob(NEW_CONTAINER_NAME, blobName, UploadFilePath);
                }
                else if (Type == Microsoft.WindowsAzure.Storage.Blob.BlobType.PageBlob)
                {
                    bSuccess = CommonBlobHelper.UploadFileToPageBlob(NEW_CONTAINER_NAME, blobName, UploadFilePath);
                }
                Test.Assert(bSuccess, "upload file {0} to container {1} should succeed", UploadFilePath, NEW_CONTAINER_NAME);

                //--------------Get operation--------------
                Test.Assert(agent.GetAzureStorageBlob(blobName, NEW_CONTAINER_NAME), Utility.GenComparisonData("GetAzureStorageBlob", true));

                // Verification for returned values
                // get blob object using XSCL
                ICloudBlob blob = CommonBlobHelper.QueryBlob(NEW_CONTAINER_NAME, blobName);
                blob.FetchAttributes();
                CloudBlobUtil.PackBlobCompareData(blob, dic);
                dic.Add("ICloudBlob", blob);

                agent.OutputValidation(comp);
            }
            finally
            {
                // cleanup
                container.DeleteIfExists();
            }
        }
Esempio n. 21
0
        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);
            }
        }
Esempio n. 22
0
        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();
            }
        }
Esempio n. 23
0
        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();
            }
        }
Esempio n. 24
0
        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);
        }
Esempio n. 25
0
        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();
            }
        }
Esempio n. 26
0
        internal void DownloadBlobTestGB(Agent agent, StorageBlob.BlobType blobType)
        {
            string uploadFilePath   = @".\" + Utility.GenNameString("gbupload");
            string downloadFilePath = @".\" + Utility.GenNameString("gbdownload");
            string containerName    = Utility.GenNameString("gbupload-");
            string blobName         = Path.GetFileName(uploadFilePath);

            // create the container
            CloudBlobContainer container = blobUtil.CreateContainer(containerName);

            // Generate a 512 bytes file which contains GB18030 characters
            File.WriteAllText(uploadFilePath, GB18030String);

            try
            {
                // create source blob
                ICloudBlob blob = CloudBlobUtil.GetBlob(container, blobName, blobType);

                // upload file data
                using (var fileStream = System.IO.File.OpenRead(uploadFilePath))
                {
                    blob.UploadFromStream(fileStream);
                }

                //--------------Download operation--------------
                Test.Assert(agent.GetAzureStorageBlobContent(blobName, downloadFilePath, containerName, true), "download blob should be successful");

                // Check MD5
                string localMd5  = Helper.GetFileContentMD5(downloadFilePath);
                string uploadMd5 = Helper.GetFileContentMD5(uploadFilePath);
                blob.FetchAttributes();
                Test.Assert(localMd5 == uploadMd5, string.Format("blob content md5 should be {0}, and actualy it's {1}", localMd5, uploadMd5));
            }
            finally
            {
                // cleanup
                container.DeleteIfExists();
                File.Delete(uploadFilePath);
                File.Delete(downloadFilePath);
            }
        }
Esempio n. 27
0
        public void UploadBlobWithZeroSize(StorageBlob.BlobType blobType)
        {
            string             filePath  = FileUtil.GenerateOneTempTestFile(0, 0);
            CloudBlobContainer container = blobUtil.CreateContainer();
            string             blobName  = Utility.GenNameString("blob");

            try
            {
                string localMD5 = FileUtil.GetFileContentMD5(filePath);
                Test.Assert(CommandAgent.SetAzureStorageBlobContent(filePath, container.Name, blobType, blobName, true), "upload blob with zero size should succeed");
                CloudBlob blob = CloudBlobUtil.GetBlob(container, blobName, blobType);
                blob.FetchAttributes();

                ExpectEqual(localMD5, blob.Properties.ContentMD5, "content md5");
            }
            finally
            {
                blobUtil.RemoveContainer(container.Name);
                FileUtil.RemoveFile(filePath);
            }
        }
Esempio n. 28
0
        public void UploadBlobWithSpeicialChars(StorageBlob.BlobType blobType)
        {
            string             filePath  = FileUtil.GenerateOneTempTestFile();
            CloudBlobContainer container = blobUtil.CreateContainer();
            string             blobName  = SpecialChars;

            try
            {
                string localMD5 = FileUtil.GetFileContentMD5(filePath);
                Test.Assert(CommandAgent.SetAzureStorageBlobContent(filePath, container.Name, blobType, blobName, true), "upload a blob name with special chars should succeed");
                CloudBlob blob = CloudBlobUtil.GetBlob(container, blobName, blobType);
                blob.FetchAttributes();

                ExpectEqual(localMD5, blob.Properties.ContentMD5, "content md5");
            }
            finally
            {
                blobUtil.RemoveContainer(container.Name);
                FileUtil.RemoveFile(filePath);
            }
        }
Esempio n. 29
0
        public void GetContainerFromMultipleStorageContext()
        {
            PowerShellAgent     psAgent  = (PowerShellAgent)CommandAgent;
            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");
            bool          savedParamValue = psAgent.UseContextParam;

            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);
                psAgent.UseContextParam = false;
                psAgent.AddPipelineScript(cmd);

                Test.Assert(CommandAgent.GetAzureStorageContainer(containerName), Utility.GenComparisonData("Get-AzureStorageContainer using multiple storage contexts", true));
                Test.Assert(CommandAgent.Output.Count == containerCount, String.Format("Want to retrieve {0} page blob, but retrieved {1} page blobs", containerCount, CommandAgent.Output.Count));

                CommandAgent.OutputValidation(new List <CloudBlobContainer>()
                {
                    container1, container2
                });
            }
            finally
            {
                psAgent.UseContextParam = savedParamValue;
                blobUtil1.RemoveContainer(containerName);
                blobUtil2.RemoveContainer(containerName);
            }
        }
Esempio n. 30
0
        public void SetBlobContentForExistsBlobWithForce()
        {
            string             filePath  = FileUtil.GenerateOneTempTestFile();
            CloudBlobContainer container = blobUtil.CreateContainer();
            string             blobName  = Utility.GenNameString("blob");
            CloudBlob          blob      = blobUtil.CreateRandomBlob(container, blobName);

            try
            {
                string localMD5 = FileUtil.GetFileContentMD5(filePath);
                Test.Assert(CommandAgent.SetAzureStorageBlobContent(filePath, container.Name, blob.BlobType, blob.Name, true), "set blob content with force parameter should succeed");
                blob = CloudBlobUtil.GetBlob(container, blobName, blob.BlobType);
                blob.FetchAttributes();

                ExpectEqual(localMD5, blob.Properties.ContentMD5, "content md5");
            }
            finally
            {
                blobUtil.RemoveContainer(container.Name);
                FileUtil.RemoveFile(filePath);
            }
        }
Esempio n. 31
0
        private void AssertFinishedCopyState(Uri SourceUri, int startIndex = 0)
        {
            string expectedSourceUri = CloudBlobUtil.ConvertCopySourceUri(SourceUri.ToString());

            Test.Assert(CommandAgent.Output.Count > startIndex, String.Format("Should contain the great than {0} copy state, and actually it's {1}", startIndex, CommandAgent.Output.Count));
            if (lang == Language.PowerShell)
            {
                string sourceUri = ((Uri)CommandAgent.Output[startIndex]["Source"]).ToString();
                Test.Assert(sourceUri.StartsWith(expectedSourceUri), String.Format("source uri should start with {0}, and actually it's {1}", expectedSourceUri, sourceUri));
                CopyStatus status = (CopyStatus)CommandAgent.Output[startIndex]["Status"];
                Test.Assert(status != CopyStatus.Pending, String.Format("Copy status should not be Pending, actually it's {0}", status));
                string copyId = (string)CommandAgent.Output[startIndex]["CopyId"];
                Test.Assert(!String.IsNullOrEmpty(copyId), "Copy ID should be not empty");
            }
            else
            {
                string status = ((JObject)CommandAgent.Output[0]["copy"])["status"].ToString();
                Test.Assert(status != "pending", String.Format("Copy status should not be Pending, actually it's {0}", status));
                string copyId = ((JObject)CommandAgent.Output[0]["copy"])["id"].ToString();
                Test.Assert(!String.IsNullOrEmpty(copyId), "Copy ID should be not empty");
            }
        }
Esempio n. 32
0
        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();
        }
Esempio n. 33
0
        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);
            }
        }
Esempio n. 34
0
 public abstract string SetContextWithSASToken(string accountName, CloudBlobUtil blobUtil, StorageObjectType objectType,
                                               string endpoint, string policy, string permission, DateTime?startTime = null, DateTime?expiryTime = null);
Esempio n. 35
0
        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();
            }
        }
Esempio n. 36
0
        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();
            }
        }
Esempio n. 37
0
        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;
        }
Esempio n. 38
0
        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();
            }
        }