Пример #1
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);
            }
        }
Пример #2
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);
            }
        }
Пример #3
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);
            }
        }
Пример #4
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();
            }
        }
Пример #5
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();
            }
        }
Пример #6
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);
            }
        }
Пример #7
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);
            }
        }
Пример #8
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);
            }
        }