Exemplo n.º 1
0
        public void DownloadPageBlobWithManyRanges()
        {
            CloudBlobContainer container        = blobUtil.CreateContainer();
            string             blobName         = Utility.GenNameString("blob");
            string             downloadFileName = Path.Combine(downloadDirRoot, Utility.GenNameString("download"));
            string             tmpFileName      = Path.Combine(downloadDirRoot, Utility.GenNameString("download"));

            try
            {
                // create a random blob size from 148M to 200M
                int blobSize = 1024 * 1024 * Utility.GetRandomTestCount(148, 200);
                blobUtil.CreatePageBlobWithManySmallRanges(container.Name, blobName, blobSize);

                // download the page blob by CLI agent
                Test.Assert(CommandAgent.GetAzureStorageBlobContent(blobName, downloadFileName, container.Name, true), "download page blob should succeed");
                string downloadedMD5 = FileUtil.GetFileContentMD5(downloadFileName);

                Test.Info("using xscl to download the page blob in order to check the MD5 value");
                CommonBlobHelper.DownloadFile(container.Name, blobName, tmpFileName);
                string previousMD5 = Helper.GetFileContentMD5(tmpFileName);

                ExpectEqual(previousMD5, downloadedMD5, "content md5");
            }
            finally
            {
                blobUtil.RemoveContainer(container.Name);
                File.Delete(tmpFileName);
                FileUtil.RemoveFile(downloadFileName);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// download specified blob
        /// </summary>
        /// <param name="container"></param>
        /// <param name="blob"></param>
        private void DownloadBlobFromContainer(CloudBlobContainer container, StorageBlob.BlobType type)
        {
            string    blobName = Utility.GenNameString("blob");
            CloudBlob blob     = blobUtil.CreateBlob(container, blobName, type);

            string filePath = Path.Combine(downloadDirRoot, blob.Name);

            Test.Assert(CommandAgent.GetAzureStorageBlobContent(blob.Name, filePath, container.Name, true), "download blob should be successful");
            string localMd5 = FileUtil.GetFileContentMD5(filePath);

            Test.Assert(localMd5 == blob.Properties.ContentMD5, string.Format("local content md5 should be {0}, and actually it's {1}", blob.Properties.ContentMD5, localMd5));
            CommandAgent.OutputValidation(new List <CloudBlob> {
                blob
            });
        }
Exemplo n.º 3
0
        public void GetBlobContentFromSnapshot()
        {
            SetupTestContainerAndBlob();

            try
            {
                List <CloudBlob> blobs = new List <CloudBlob>();
                int minSnapshot        = 1;
                int maxSnapshot        = 5;
                int snapshotCount      = random.Next(minSnapshot, maxSnapshot);

                for (int i = 0; i < snapshotCount; i++)
                {
                    CloudBlob blob = Blob.Snapshot();
                    blobs.Add(blob);
                }

                blobs.Add(Blob);

                List <IListBlobItem> blobLists = Container.ListBlobs(string.Empty, true, BlobListingDetails.All).ToList();
                Test.Assert(blobLists.Count == blobs.Count, string.Format("container {0} should contain {1} blobs, and actually it contain {2} blobs", ContainerName, blobs.Count, blobLists.Count));

                FileUtil.CleanDirectory(downloadDirRoot);

                ((PowerShellAgent)CommandAgent).AddPipelineScript(string.Format("Get-AzureStorageContainer {0}", ContainerName));
                ((PowerShellAgent)CommandAgent).AddPipelineScript("Get-AzureStorageBlob");
                Test.Assert(CommandAgent.GetAzureStorageBlobContent(string.Empty, downloadDirRoot, string.Empty, true), "download blob should be successful");
                Test.Assert(CommandAgent.Output.Count == blobs.Count, "Get-AzureStroageBlobContent should download {0} blobs, and actully it's {1}", blobs.Count, CommandAgent.Output.Count);

                for (int i = 0, count = blobs.Count(); i < count; i++)
                {
                    CloudBlob blob = blobLists[i] as CloudBlob;
                    string    path = Path.Combine(downloadDirRoot, blobUtil.ConvertBlobNameToFileName(blob.Name, string.Empty, blob.SnapshotTime));

                    Test.Assert(File.Exists(path), string.Format("local file '{0}' should exists after downloading.", path));

                    string localMd5      = FileUtil.GetFileContentMD5(path);
                    string convertedName = blobUtil.ConvertBlobNameToFileName(blob.Name, string.Empty);
                    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(downloadDirRoot);
                CleanupTestContainerAndBlob();
            }
        }
Exemplo n.º 4
0
        public void GetBlobContentByName()
        {
            SetupTestContainerAndBlob();

            try
            {
                string destFileName = Utility.GenNameString("download");
                string destFilePath = Path.Combine(downloadDirRoot, destFileName);
                Test.Assert(CommandAgent.GetAzureStorageBlobContent(BlobName, destFilePath, ContainerName, true), "download blob should be successful");
                string localMd5 = FileUtil.GetFileContentMD5(destFilePath);
                Test.Assert(localMd5 == Blob.Properties.ContentMD5, string.Format("blob content md5 should be {0}, and actually it's {1}", localMd5, Blob.Properties.ContentMD5));
            }
            finally
            {
                CleanupTestContainerAndBlob();
            }
        }
Exemplo n.º 5
0
        public void DownloadBlobWithZeroSize(BlobType blobType)
        {
            CloudBlobContainer container        = blobUtil.CreateContainer();
            string             blobName         = Utility.GenNameString("blob");
            string             downloadFileName = Path.Combine(downloadDirRoot, Utility.GenNameString("download"));

            try
            {
                CloudBlob blob = blobUtil.CreateBlob(container, blobName, blobType);
                Test.Assert(CommandAgent.GetAzureStorageBlobContent(blobName, downloadFileName, container.Name, true), "download blob with zero size should succeed");
                string downloadedMD5 = FileUtil.GetFileContentMD5(downloadFileName);

                ExpectEqual(downloadedMD5, blob.Properties.ContentMD5, "content md5");
            }
            finally
            {
                blobUtil.RemoveContainer(container.Name);
                FileUtil.RemoveFile(downloadFileName);
            }
        }
Exemplo n.º 6
0
        public void GetBlobContentWithNotExistsBlob()
        {
            SetupTestContainerAndBlob();

            try
            {
                string        notExistingBlobName = Utility.GenNameString("notexisting");
                DirectoryInfo dir = new DirectoryInfo(downloadDirRoot);
                int           filesCountBeforeDowloading = dir.GetFiles().Count();
                string        downloadFileName           = Path.Combine(downloadDirRoot, Utility.GenNameString("download"));
                Test.Assert(!CommandAgent.GetAzureStorageBlobContent(notExistingBlobName, downloadFileName, ContainerName, true), "download not existing blob should fail");
                CommandAgent.ValidateErrorMessage(MethodBase.GetCurrentMethod().Name, notExistingBlobName, ContainerName);
                int filesCountAfterDowloading = dir.GetFiles().Count();
                Test.Assert(filesCountBeforeDowloading == filesCountAfterDowloading, "the files count should be equal after a failed downloading");
            }
            finally
            {
                CleanupTestContainerAndBlob();
            }
        }
Exemplo n.º 7
0
        internal void DownloadBlobTestGB(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
                CloudBlob blob = CloudBlobUtil.GetBlob(container, blobName, blobType);

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

                //--------------Download operation--------------
                Test.Assert(CommandAgent.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 actually it's {1}", localMd5, uploadMd5));
            }
            finally
            {
                // cleanup
                container.DeleteIfExists();
                File.Delete(uploadFilePath);
                File.Delete(downloadFilePath);
            }
        }
Exemplo n.º 8
0
        public void DownloadBlobWithSpecialChars(BlobType blobType)
        {
            CloudBlobContainer container = blobUtil.CreateContainer();
            string             blobName  = SpecialChars;
            CloudBlob          blob      = blobUtil.CreateBlob(container, blobName, blobType);

            string downloadFileName = Path.Combine(downloadDirRoot, Utility.GenNameString("download"));

            try
            {
                Test.Assert(CommandAgent.GetAzureStorageBlobContent(blobName, downloadFileName, container.Name, true), "download blob name with special chars should succeed");
                blob.FetchAttributes();
                string downloadedMD5 = FileUtil.GetFileContentMD5(downloadFileName);
                ExpectEqual(downloadedMD5, blob.Properties.ContentMD5, "content md5");
            }
            finally
            {
                blobUtil.RemoveContainer(container.Name);
                FileUtil.RemoveFile(downloadFileName);
            }
        }
Exemplo n.º 9
0
        public void DownloadBlobCheckMD5()
        {
            CloudBlobContainer container        = blobUtil.CreateContainer();
            string             blobName         = Utility.GenNameString("blob");
            string             downloadFileName = Path.Combine(downloadDirRoot, Utility.GenNameString("download"));

            try
            {
                CloudBlob blob        = blobUtil.CreateRandomBlob(container, blobName);
                string    previousMD5 = blob.Properties.ContentMD5;

                // download blob and check MD5.
                Test.Assert(CommandAgent.GetAzureStorageBlobContent(blobName, downloadFileName, container.Name, true, CheckMd5: true), "download blob with CheckMd5 should succeed.");

                string downloadedMD5 = FileUtil.GetFileContentMD5(downloadFileName);
                ExpectEqual(previousMD5, downloadedMD5, "content md5");

                blob.Properties.ContentMD5 = "";
                blob.SetProperties();

                // Blob's ContentMD5 property is empty, download file and check MD5.
                Test.Assert(!CommandAgent.GetAzureStorageBlobContent(blobName, downloadFileName, container.Name, true, CheckMd5: true), "It should fail to download blob whose Content-MD5 property is incorrect with CheckMd5");
                ExpectedContainErrorMessage("The MD5 hash calculated from the downloaded data does not match the MD5 hash stored in the property of source");

                downloadedMD5 = FileUtil.GetFileContentMD5(downloadFileName);
                ExpectEqual(previousMD5, downloadedMD5, "content md5");

                // Blob's ContentMD5 property is empty, download file without check MD5
                Test.Assert(CommandAgent.GetAzureStorageBlobContent(blobName, downloadFileName, container.Name, true, CheckMd5: false), "It should suceed to download blob whose Content-MD5 property is incorrect without CheckMd5");

                downloadedMD5 = FileUtil.GetFileContentMD5(downloadFileName);
                ExpectEqual(previousMD5, downloadedMD5, "content md5");
            }
            finally
            {
                blobUtil.RemoveContainer(container.Name);
                FileUtil.RemoveFile(downloadFileName);
            }
        }
Exemplo n.º 10
0
        public void GetBlobContentWithNotExistsContainer()
        {
            string        containerName = Utility.GenNameString("notexistingcontainer");
            string        blobName      = Utility.GenNameString("blob");
            DirectoryInfo dir           = new DirectoryInfo(downloadDirRoot);
            int           filesCountBeforeDowloading = dir.GetFiles().Count();
            string        downloadFileName           = Path.Combine(downloadDirRoot, Utility.GenNameString("download"));

            Test.Assert(!CommandAgent.GetAzureStorageBlobContent(blobName, downloadFileName, containerName, true), "download blob from not existing container should fail");

            try
            {
                CommandAgent.ValidateErrorMessage(MethodBase.GetCurrentMethod().Name, blobName, containerName);

                int filesCountAfterDowloading = dir.GetFiles().Count();
                Test.Assert(filesCountBeforeDowloading == filesCountAfterDowloading, "the files count should be equal after download failure");
            }
            finally
            {
                FileUtil.CleanDirectory(downloadDirRoot);
            }
        }
Exemplo n.º 11
0
        public void BlobOrContainerWithReadPermission(StorageObjectType objectType, BlobType blobType)
        {
            blobUtil.SetupTestContainerAndBlob(SpecialCharsPrefix, blobType);

            try
            {
                CommandAgent.SetContextWithSASToken(StorageAccount.Credentials.AccountName, blobUtil, objectType, StorageEndpoint, string.Empty, "r");

                // Get blob with the generated SAS token
                Test.Assert(CommandAgent.GetAzureStorageBlob(blobUtil.Blob.Name, blobUtil.ContainerName),
                            string.Format("Get existing blob {0} in container {1} should succeed", blobUtil.Blob.Name, blobUtil.ContainerName));

                // Download blob with the generated SAS token
                string downloadFilePath = Path.Combine(downloadDirPath, blobUtil.Blob.Name);
                Test.Assert(CommandAgent.GetAzureStorageBlobContent(blobUtil.Blob.Name, downloadFilePath, blobUtil.ContainerName),
                            string.Format("Download blob {0} in container {1} to File {2} should succeed", blobUtil.Blob.Name, blobUtil.ContainerName, downloadFilePath));

                // Copy blob with the generated SAS token(as source)
                string copiedName  = Utility.GenNameString("copied");
                object destContext = null;
                if (lang == Language.PowerShell)
                {
                    destContext = PowerShellAgent.GetStorageContext(StorageAccount.ToString(true));
                }
                else
                {
                    destContext = StorageAccount;
                }

                Test.Assert(CommandAgent.StartAzureStorageBlobCopy(blobUtil.ContainerName, blobUtil.Blob.Name, blobUtil.ContainerName, copiedName, destContext: destContext),
                            string.Format("Copy blob {0} in container {1} to blob {2} in container {3} should succeed",
                                          blobUtil.Blob.Name, blobUtil.ContainerName, blobUtil.ContainerName, copiedName));
            }
            finally
            {
                blobUtil.CleanupTestContainerAndBlob();
            }
        }