Пример #1
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);
            }
        }
Пример #2
0
        public void GetCopyStateFromMultiBlobsTest()
        {
            CloudBlobContainer srcContainer  = blobUtil.CreateContainer();
            CloudBlobContainer destContainer = blobUtil.CreateContainer();

            List <CloudBlob> blobs = blobUtil.CreateRandomBlob(srcContainer);

            try
            {
                ((PowerShellAgent)CommandAgent).AddPipelineScript(String.Format("Get-AzureStorageBlob -Container {0}", srcContainer.Name));
                ((PowerShellAgent)CommandAgent).AddPipelineScript(String.Format("Start-AzureStorageBlobCopy -DestContainer {0}", destContainer.Name));

                Test.Assert(CommandAgent.GetAzureStorageBlobCopyState(string.Empty, string.Empty, true), "Get copy state for many blobs should succeed.");
                Test.Assert(CommandAgent.Output.Count == blobs.Count, String.Format("Expected get {0} copy state, and actually get {1} copy state", blobs.Count, CommandAgent.Output.Count));
                List <IListBlobItem> destBlobs = destContainer.ListBlobs().ToList();
                Test.Assert(destBlobs.Count == blobs.Count, String.Format("Expected get {0} copied blobs, and actually get {1} copy state", blobs.Count, destBlobs.Count));

                for (int i = 0, count = CommandAgent.Output.Count; i < count; i++)
                {
                    AssertFinishedCopyState(blobs[i].Uri, i);
                }
            }
            finally
            {
                blobUtil.RemoveContainer(srcContainer.Name);
                blobUtil.RemoveContainer(destContainer.Name);
            }
        }
Пример #3
0
        public void GetCopyStateFromRootContainerTest()
        {
            CloudBlobContainer rootContainer = blobUtil.CreateContainer("$root");

            string    srcBlobName = Utility.GenNameString("src");
            CloudBlob srcBlob     = blobUtil.CreateRandomBlob(rootContainer, srcBlobName);
            CloudBlob destBlob    = blobUtil.CreateBlob(rootContainer, Utility.GenNameString("dest"), srcBlob.BlobType);

            if (destBlob.BlobType == StorageBlob.BlobType.BlockBlob)
            {
                ((CloudBlockBlob)destBlob).StartCopy((CloudBlockBlob)srcBlob);
            }
            else if (destBlob.BlobType == StorageBlob.BlobType.PageBlob)
            {
                ((CloudPageBlob)destBlob).StartCopy((CloudPageBlob)srcBlob);
            }
            else if (destBlob.BlobType == StorageBlob.BlobType.AppendBlob)
            {
                ((CloudAppendBlob)destBlob).StartCopy((CloudAppendBlob)srcBlob);
            }
            else
            {
                Test.Error(string.Format("Invalid blob type: {0}", destBlob.BlobType));
                return;
            }

            Test.Assert(CommandAgent.GetAzureStorageBlobCopyState("$root", destBlob.Name, true), "Get copy state in $root container should succeed.");
            AssertFinishedCopyState(srcBlob.Uri);
        }
Пример #4
0
        public void GetCopyStateWithNotExistContainerAndBlobTest()
        {
            string srcContainerName = Utility.GenNameString("copy");
            string blobName         = Utility.GenNameString("blob");

            string    errorMessage = string.Empty;
            Validator validator;

            if (lang == Language.PowerShell)
            {
                errorMessage = string.Format("Can not find blob '{0}' in container '{1}', or the blob type is unsupported.", blobName, srcContainerName);
                validator    = ExpectedContainErrorMessage;
            }
            else
            {
                errorMessage = string.Format("Blob {0} in Container {1} doesn't exist", blobName, srcContainerName);
                validator    = ExpectedStartsWithErrorMessage;
            }
            Test.Assert(!CommandAgent.GetAzureStorageBlobCopyState(srcContainerName, blobName, false), "Get copy state should fail with not existing container");
            validator(errorMessage);

            try
            {
                CloudBlobContainer srcContainer = blobUtil.CreateContainer(srcContainerName);
                Test.Assert(!CommandAgent.GetAzureStorageBlobCopyState(srcContainerName, blobName, false), "Get copy state should fail with not existing blob");
                validator(errorMessage);
            }
            finally
            {
                blobUtil.RemoveContainer(srcContainerName);
            }
        }
Пример #5
0
        public void StartIncrementalCopy()
        {
            CloudBlobContainer container     = blobUtil.CreateContainer();
            CloudBlobContainer destContainer = blobUtil.CreateContainer();
            string             srcBlobName   = Utility.GenNameString("src");
            CloudBlob          srcBlob       = blobUtil.CreateRandomBlob(container, srcBlobName, Microsoft.WindowsAzure.Storage.Blob.BlobType.PageBlob);
            CloudBlob          snapshot1     = srcBlob.Snapshot();
            CloudBlob          snapshot2     = srcBlob.Snapshot();
            CloudBlob          snapshot3     = srcBlob.Snapshot();
            CloudBlob          snapshot4     = srcBlob.Snapshot();
            CloudBlob          snapshot5     = srcBlob.Snapshot();
            CloudBlob          snapshot6     = srcBlob.Snapshot();

            string        destBlobName = Utility.GenNameString("dest");
            CloudPageBlob destBlob     = destContainer.GetPageBlobReference(destBlobName);

            try
            {
                int i = 1;
                Test.Assert(CommandAgent.StartAzureStorageBlobIncrementalCopy(container.GetPageBlobReference(snapshot1.Name, snapshot1.SnapshotTime), destContainer.Name, destBlob.Name), "copy snapshot1 should success");
                Test.Assert(CommandAgent.GetAzureStorageBlobCopyState(destBlob, PowerShellAgent.Context, true), "Get copy status for snapshot1 should success");
                int blobCount = destContainer.ListBlobs(destBlobName, true, blobListingDetails: BlobListingDetails.Snapshots).Count();
                Test.Assert(blobCount == ++i, string.Format("After IncrementalCopy, blob count: {0} = {1}.", blobCount, i));

                Test.Assert(CommandAgent.StartAzureStorageBlobIncrementalCopy(container.GetPageBlobReference(snapshot2.Name, snapshot2.SnapshotTime), destBlob), "copy snapshot2 should success");
                Test.Assert(CommandAgent.GetAzureStorageBlobCopyState(destBlob, PowerShellAgent.Context, true), "Get copy status for snapshot2 should success");
                blobCount = destContainer.ListBlobs(destBlobName, true, blobListingDetails: BlobListingDetails.Snapshots).Count();
                Test.Assert(blobCount == ++i, string.Format("After IncrementalCopy, blob count: {0} = {1}.", blobCount, i));

                Test.Assert(CommandAgent.StartAzureStorageBlobIncrementalCopy(container, srcBlobName, snapshot3.SnapshotTime, destContainer.Name, destBlobName), "copy snapshot3 should success");
                Test.Assert(CommandAgent.GetAzureStorageBlobCopyState(destBlob, PowerShellAgent.Context, true), "Get copy status for snapshot3 should success");
                blobCount = destContainer.ListBlobs(destBlobName, true, blobListingDetails: BlobListingDetails.Snapshots).Count();
                Test.Assert(blobCount == ++i, string.Format("After IncrementalCopy, blob count: {0} = {1}.", blobCount, i));

                Test.Assert(CommandAgent.StartAzureStorageBlobIncrementalCopy(container.Name, srcBlobName, snapshot4.SnapshotTime, destContainer.Name, destBlobName), "copy snapshot4 should success");
                Test.Assert(CommandAgent.GetAzureStorageBlobCopyState(destBlob, PowerShellAgent.Context, true), "Get copy status for snapshot4 should success");
                blobCount = destContainer.ListBlobs(destBlobName, true, blobListingDetails: BlobListingDetails.Snapshots).Count();
                Test.Assert(blobCount == ++i, string.Format("After IncrementalCopy, blob count: {0} = {1}.", blobCount, i));

                Test.Assert(CommandAgent.StartAzureStorageBlobIncrementalCopy(snapshot5.SnapshotQualifiedUri.ToString(), destContainer.Name, destBlobName, PowerShellAgent.Context), "copy snapshot5 should success");
                Test.Assert(CommandAgent.GetAzureStorageBlobCopyState(destBlob, PowerShellAgent.Context, true), "Get copy status for snapshot5 should success");
                blobCount = destContainer.ListBlobs(destBlobName, true, blobListingDetails: BlobListingDetails.Snapshots).Count();
                Test.Assert(blobCount == ++i, string.Format("After IncrementalCopy, blob count: {0} = {1}.", blobCount, i));

                SharedAccessBlobPolicy bp = new SharedAccessBlobPolicy();
                bp.Permissions            = SharedAccessBlobPermissions.Read;
                bp.SharedAccessExpiryTime = DateTime.Now.AddDays(1);
                string sasToken = snapshot6.GetSharedAccessSignature(bp);

                Test.Assert(CommandAgent.StartAzureStorageBlobIncrementalCopy(string.Format(CultureInfo.InvariantCulture, "{0}&{1}", snapshot6.SnapshotQualifiedUri.AbsoluteUri, sasToken.Substring(1)), destContainer.Name, destBlobName, PowerShellAgent.Context), "copy snapshot6 should success");
                Test.Assert(CommandAgent.GetAzureStorageBlobCopyState(destBlob, PowerShellAgent.Context, true), "Get copy status for snapshot6 should success");
                blobCount = destContainer.ListBlobs(destBlobName, true, blobListingDetails: BlobListingDetails.Snapshots).Count();
                Test.Assert(blobCount == ++i, string.Format("After IncrementalCopy, blob count: {0} = {1}.", blobCount, i));
            }
            finally
            {
                blobUtil.RemoveContainer(container);
                blobUtil.RemoveContainer(destContainer);
            }
        }
Пример #6
0
        public void StartIncrementalCopy_Negtive()
        {
            CloudBlobContainer container     = blobUtil.CreateContainer();
            CloudBlobContainer destContainer = blobUtil.CreateContainer();
            string             srcBlobName   = Utility.GenNameString("src");
            CloudBlob          srcBlob       = blobUtil.CreateRandomBlob(container, srcBlobName, Microsoft.WindowsAzure.Storage.Blob.BlobType.PageBlob);
            CloudBlob          snapshot1     = srcBlob.Snapshot();
            CloudBlob          snapshot2     = srcBlob.Snapshot();
            CloudBlob          snapshot3     = srcBlob.Snapshot();

            string    destBlockBlobName = Utility.GenNameString("destblock");
            CloudBlob destBlockBlob     = blobUtil.CreateRandomBlob(destContainer, destBlockBlobName, Microsoft.WindowsAzure.Storage.Blob.BlobType.BlockBlob);

            string    destPageBlobName = Utility.GenNameString("destpage");
            CloudBlob destPageBlob     = blobUtil.CreateRandomBlob(destContainer, destPageBlobName, Microsoft.WindowsAzure.Storage.Blob.BlobType.PageBlob);

            Validator validator = ExpectedContainErrorMessage;

            try
            {
                //source not snapshot
                Test.Assert(!CommandAgent.StartAzureStorageBlobIncrementalCopy(container.GetPageBlobReference(srcBlobName), destContainer.Name, null), "Start Incremental copy should failed with source not snapshot.");
                validator("The source for incremental copy request must be a snapshot.");

                //Dest is Block
                Test.Assert(!CommandAgent.StartAzureStorageBlobIncrementalCopy(container, srcBlobName, snapshot2.SnapshotTime, destContainer.Name, destBlockBlobName), "Start Incremental copy should failed with dest is block blob.");
                validator("The specified operation is not allowed on an incremental copy blob.");

                //Dest is Page not created with Incremental Copy
                Test.Assert(!CommandAgent.StartAzureStorageBlobIncrementalCopy(container, srcBlobName, snapshot2.SnapshotTime, destContainer.Name, destPageBlobName), "Start Incremental copy should failed with dest is existing Page blob.");
                validator("The specified operation is not allowed on an incremental copy blob.");

                //copy early snapshot than latest copied
                Test.Assert(CommandAgent.StartAzureStorageBlobIncrementalCopy(container, srcBlobName, snapshot2.SnapshotTime, destContainer.Name, null), "copy snapshot2 should success");
                Test.Assert(CommandAgent.GetAzureStorageBlobCopyState(destContainer.Name, srcBlobName, true), "Get copy status for snapshot2 should success");
                Test.Assert(!CommandAgent.StartAzureStorageBlobIncrementalCopy(container, srcBlobName, snapshot1.SnapshotTime, destContainer.Name, null), "Start Incremental copy should failed with copy early snapshot than latest copied.");
                validator("The specified snapshot is earlier than the last snapshot copied into the incremental copy blob.");
            }
            finally
            {
                blobUtil.RemoveContainer(container);
                blobUtil.RemoveContainer(destContainer);
            }
        }
Пример #7
0
        public void GetCopyStateFromUriTest()
        {
            blobUtil.SetupTestContainerAndBlob();
            string copiedName = Utility.GenNameString("copied");

            //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
            {
                Test.Assert(CommandAgent.StartAzureStorageBlobCopy(blobUtil.Blob.Uri.ToString(), blobUtil.ContainerName, copiedName, PowerShellAgent.Context), Utility.GenComparisonData("Start copy blob using source uri", true));
                Test.Assert(CommandAgent.GetAzureStorageBlobCopyState(blobUtil.ContainerName, copiedName, true), "Get copy state in dest container should succeed.");
                AssertFinishedCopyState(blobUtil.Blob.Uri);
            }
            finally
            {
                blobUtil.CleanupTestContainerAndBlob();
            }
        }
Пример #8
0
        public void GetCopyStateWithInvalidNameTest()
        {
            string invalidContainerName = "Invalid";
            int    maxBlobNameLength    = 1024;
            string invalidBlobName      = new string('a', maxBlobNameLength + 1);
            string invalidContainerErrorMessage;
            string invalidBlobErrorMessage;

            if (lang == Language.PowerShell)
            {
                invalidContainerErrorMessage = String.Format("Container name '{0}' is invalid.", invalidContainerName);
                invalidBlobErrorMessage      = String.Format("Blob name '{0}' is invalid.", invalidBlobName);
            }
            else
            {
                invalidContainerErrorMessage = "Container name format is incorrect";
                invalidBlobErrorMessage      = "BadRequest";
            }
            Test.Assert(!CommandAgent.GetAzureStorageBlobCopyState(invalidContainerName, Utility.GenNameString("blob"), false), "get copy state should failed with invalid container name");
            ExpectedContainErrorMessage(invalidContainerErrorMessage);
            Test.Assert(!CommandAgent.GetAzureStorageBlobCopyState(Utility.GenNameString("container"), invalidBlobName, false), "get copy state should failed with invalid blob name");
            ExpectedContainErrorMessage(invalidBlobErrorMessage);
        }
Пример #9
0
        public void StartIncrementalCopy_DefaultDestBlobName()
        {
            CloudBlobContainer container     = blobUtil.CreateContainer();
            CloudBlobContainer destContainer = blobUtil.CreateContainer();
            string             srcBlobName   = Utility.GenNameString("src");
            CloudBlob          srcBlob       = blobUtil.CreateRandomBlob(container, srcBlobName, Microsoft.WindowsAzure.Storage.Blob.BlobType.PageBlob);
            CloudBlob          snapshot1     = srcBlob.Snapshot();
            CloudBlob          snapshot2     = srcBlob.Snapshot();
            CloudBlob          snapshot3     = srcBlob.Snapshot();

            string        destBlobName = srcBlobName;
            CloudPageBlob destBlob     = destContainer.GetPageBlobReference(destBlobName);

            try
            {
                int i = 1;
                Test.Assert(CommandAgent.StartAzureStorageBlobIncrementalCopy(container.GetPageBlobReference(snapshot1.Name, snapshot1.SnapshotTime), destContainer.Name, null), "copy snapshot1 should success");
                Test.Assert(CommandAgent.GetAzureStorageBlobCopyState(destBlob, PowerShellAgent.Context, true), "Get copy status for snapshot1 should success");
                int blobCount = destContainer.ListBlobs(destBlobName, true, blobListingDetails: BlobListingDetails.Snapshots).Count();
                Test.Assert(blobCount == ++i, string.Format("After IncrementalCopy, blob count: {0} = {1}.", blobCount, i));

                Test.Assert(CommandAgent.StartAzureStorageBlobIncrementalCopy(container, srcBlobName, snapshot2.SnapshotTime, destContainer.Name, null), "copy snapshot2 should success");
                Test.Assert(CommandAgent.GetAzureStorageBlobCopyState(destBlob, PowerShellAgent.Context, true), "Get copy status for snapshot2 should success");
                blobCount = destContainer.ListBlobs(destBlobName, true, blobListingDetails: BlobListingDetails.Snapshots).Count();
                Test.Assert(blobCount == ++i, string.Format("After IncrementalCopy, blob count: {0} = {1}.", blobCount, i));

                Test.Assert(CommandAgent.StartAzureStorageBlobIncrementalCopy(container.Name, srcBlobName, snapshot3.SnapshotTime, destContainer.Name, null), "copy snapshot3 should success");
                Test.Assert(CommandAgent.GetAzureStorageBlobCopyState(destBlob, PowerShellAgent.Context, true), "Get copy status for snapshot3 should success");
                blobCount = destContainer.ListBlobs(destBlobName, true, blobListingDetails: BlobListingDetails.Snapshots).Count();
                Test.Assert(blobCount == ++i, string.Format("After IncrementalCopy, blob count: {0} = {1}.", blobCount, i));
            }
            finally
            {
                blobUtil.RemoveContainer(container);
                blobUtil.RemoveContainer(destContainer);
            }
        }
Пример #10
0
        public void GetCopyStateWhenCopyingTest()
        {
            CloudBlobContainer Container     = blobUtil.CreateContainer();
            string             ContainerName = Container.Name;
            string             BlobName      = Utility.GenNameString("blob");
            CloudBlob          Blob          = blobUtil.CreateBlockBlob(Container, BlobName);

            string uri = Test.Data.Get("BigBlobUri");

            Test.Assert(!String.IsNullOrEmpty(uri), string.Format("Big file uri should be not empty, actually it's {0}", uri));

            if (String.IsNullOrEmpty(uri))
            {
                return;
            }

            Blob.StartCopy(new Uri(uri));

            int maxMonitorCount = 3;
            int checkCount      = 0;
            int sleepInterval   = 1000; //ms

            CopyStatus status = CopyStatus.Pending;

            try
            {
                int expectedCopyStateCount = 1;

                do
                {
                    Test.Info(String.Format("{0}th check current copy state", checkCount));
                    Test.Assert(CommandAgent.GetAzureStorageBlobCopyState(ContainerName, BlobName, false), "Get copy state in dest container should succeed.");

                    Test.Assert(CommandAgent.Output.Count == expectedCopyStateCount, String.Format("Should contain {0} copy state, and actually it's {1}", expectedCopyStateCount, CommandAgent.Output.Count));

                    if (lang == Language.PowerShell)
                    {
                        status = (CopyStatus)CommandAgent.Output[0]["Status"];
                        Test.Assert(status == CopyStatus.Pending, String.Format("Copy status should be Pending, actually it's {0}", status));
                    }
                    else
                    {
                        if (((JObject)CommandAgent.Output[0]["copy"])["status"].ToString().Equals("pending"))
                        {
                            status = CopyStatus.Pending;
                        }
                        else
                        {
                            status = CopyStatus.Invalid;
                        }
                    }

                    checkCount++;
                    Thread.Sleep(sleepInterval);
                }while (status == CopyStatus.Pending && checkCount < maxMonitorCount);

                Test.Info("Finish the monitor loop and try to abort copy");

                try
                {
                    Blob.AbortCopy(Blob.CopyState.CopyId);
                }
                catch (StorageException e)
                {
                    //TODO use extension method
                    if (e.RequestInformation != null && e.RequestInformation.HttpStatusCode == 409)
                    {
                        Test.Info("Skip 409 abort conflict exception. Error:{0}", e.Message);
                        Test.Info("Detail Error Message: {0}", e.RequestInformation.HttpStatusMessage);
                    }
                    else
                    {
                        Test.AssertFail(String.Format("Can't abort copy. Error: {0}", e.Message));
                    }
                }

                Test.Assert(CommandAgent.GetAzureStorageBlobCopyState(ContainerName, BlobName, false), "Get copy state in dest container should succeed.");
                Test.Assert(CommandAgent.Output.Count == expectedCopyStateCount, String.Format("Should contain {0} copy state, and actually it's {1}", expectedCopyStateCount, CommandAgent.Output.Count));
                if (lang == Language.PowerShell)
                {
                    status = (CopyStatus)CommandAgent.Output[0]["Status"];
                }
                else
                {
                    if (((JObject)CommandAgent.Output[0]["copy"])["status"].ToString().Equals("aborted"))
                    {
                        status = CopyStatus.Aborted;
                    }
                    else
                    {
                        status = CopyStatus.Pending;
                    }
                }
                Test.Assert(status == CopyStatus.Aborted, String.Format("Copy status should be Aborted, actually it's {0}", status));
            }
            finally
            {
                blobUtil.RemoveContainer(Container.Name);
            }
        }