public void CopyFromFile2SASFile()
        {
            CopyFromFile2SASFile((sourceShare) =>
            {
                string connectionString = (new CloudStorageAccount(sourceShare.ServiceClient.Credentials, null, null, null, sourceShare.ServiceClient.StorageUri.PrimaryUri)).ToString(true);
                if (lang == Language.PowerShell)
                {
                    PowerShellAgent.SetStorageContext(connectionString);
                }
                else
                {
                    NodeJSAgent.SetStorageContext(connectionString);
                }
            });

            CopyFromFile2SASFile((sourceShare) =>
            {
                string sasToken = sourceShare.GetSharedAccessSignature(new SharedAccessFilePolicy()
                {
                    Permissions            = SharedAccessFilePermissions.Read,
                    SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddHours(1)
                });

                CommandAgent.SetStorageContextWithSASToken(StorageAccount.Credentials.AccountName, sasToken);
            });
        }
        public void CopyFromBlob2SASFile()
        {
            CopyFromBlob2SASFile((sourceContainer) =>
            {
                if (lang == Language.PowerShell)
                {
                    PowerShellAgent.SetStorageContext(StorageAccount.ToString(true));
                }
                else
                {
                    NodeJSAgent.SetStorageContext(StorageAccount.ToString(true));
                };
            });

            CopyFromBlob2SASFile((sourceContainer) =>
            {
                string sasToken = sourceContainer.GetSharedAccessSignature(new SharedAccessBlobPolicy()
                {
                    Permissions            = SharedAccessBlobPermissions.Read,
                    SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddHours(1)
                });

                CommandAgent.SetStorageContextWithSASToken(StorageAccount.Credentials.AccountName, sasToken);
            });
        }
Ejemplo n.º 3
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();
            }
        }
Ejemplo n.º 4
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();
        }
Ejemplo n.º 5
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();
            }
        }
Ejemplo n.º 6
0
        public static void ClassInitialize(TestContext testContext, bool useHttps)
        {
            //first set the storage account
            //second init common bvt
            //third set storage context in powershell
            isSecondary         = true;
            SetUpStorageAccount = TestBase.GetCloudStorageAccountFromConfig("Secondary", useHttps);
            StorageAccountName  = SetUpStorageAccount.Credentials.AccountName;
            string StorageEndpoint   = Test.Data.Get("SecondaryStorageEndPoint");
            string StorageAccountKey = Test.Data.Get("SecondaryStorageAccountKey");

            CLICommonBVT.CLICommonBVTInitialize(testContext);
            Agent.Context = SetUpStorageAccount;

            if (lang == Language.PowerShell)
            {
                string azureEnvironmentName = PowerShellAgent.AddRandomAzureEnvironment(StorageEndpoint, "bvt");
                PowerShellAgent.SetStorageContextWithAzureEnvironment(StorageAccountName, StorageAccountKey, useHttps, azureEnvironmentName);
            }
            else
            {
                NodeJSAgent.AgentConfig.UseEnvVar   = false;
                NodeJSAgent.AgentConfig.AccountName = StorageAccountName;
                NodeJSAgent.AgentConfig.AccountKey  = StorageAccountKey;
            }
        }
Ejemplo n.º 7
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);
            }
        }
Ejemplo n.º 8
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();
            }
        }
        public void CopyFromBlob2File()
        {
            CopyFromBlob2File((sourceContainer) =>
            {
                string sasToken = sourceContainer.GetSharedAccessSignature(new SharedAccessBlobPolicy()
                {
                    Permissions            = SharedAccessBlobPermissions.Read,
                    SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddHours(1)
                });

                CommandAgent.SetStorageContextWithSASToken(StorageAccount.Credentials.AccountName, sasToken);
            });

            CopyFromBlob2File((sourceContainer) =>
            {
                var permissions          = sourceContainer.GetPermissions();
                permissions.PublicAccess = BlobContainerPublicAccessType.Blob;

                if (lang == Language.PowerShell)
                {
                    PowerShellAgent.SetAnonymousStorageContext(StorageAccount.Credentials.AccountName, false);
                }
                else
                {
                    Agent.Context = null;
                }
            });
        }
Ejemplo n.º 10
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);
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// set up azure subscription
        /// </summary>
        private static void SetupSubscription()
        {
            string subscriptionFile = Test.Data.Get("AzureSubscriptionPath");
            string subscriptionName = Test.Data.Get("AzureSubscriptionName");
            //TODO add tests about invalid storage account name
            string storageAccountName = Test.Data.Get("StorageAccountName");

            PowerShellAgent.ImportAzureSubscriptionAndSetStorageAccount(subscriptionFile, subscriptionName, storageAccountName);
        }
Ejemplo n.º 12
0
        public void UploadCopyBlobWithPremiumPageBlobTier()
        {
            string xIOStorageConnectionString = Test.Data.Get("XIOStorageConnectionString");

            PowerShellAgent.SetStorageContext(xIOStorageConnectionString);

            string             filePath      = FileUtil.GenerateOneTempTestFile();
            CloudBlobClient    xIOBlobClient = CloudStorageAccount.Parse(xIOStorageConnectionString).CreateCloudBlobClient();
            CloudBlobContainer container     = xIOBlobClient.GetContainerReference(Utility.GenNameString("container"));

            container.CreateIfNotExists();

            string blobName  = Utility.GenNameString("blob");
            string blobName2 = Utility.GenNameString("blob");
            string blobName3 = Utility.GenNameString("blob");

            try
            {
                //Create local file
                string localMD5 = FileUtil.GetFileContentMD5(filePath);

                //upload
                Test.Assert(CommandAgent.SetAzureStorageBlobContent(filePath, container.Name, StorageBlob.BlobType.PageBlob, blobName, true, premiumPageBlobTier: PremiumPageBlobTier.P20), "upload a blob name with premiumPageBlobTier should succeed");
                CloudPageBlob blob = container.GetPageBlobReference(blobName);
                blob.FetchAttributes();

                ////The check MD5 code are comment, and add code to set contentMD5 since a bug in server that set blob tier will clear contentMD5. Will revert it when the bug fixed.
                //ExpectEqual(localMD5, blob.Properties.ContentMD5, "content md5");
                blob.Properties.ContentMD5 = localMD5;
                blob.SetProperties();

                Test.Assert(PremiumPageBlobTier.P20 == blob.Properties.PremiumPageBlobTier, "PremiumPageBlobTier shoud match: {0} == {1}", PremiumPageBlobTier.P20, blob.Properties.PremiumPageBlobTier);

                //Copy 1
                Test.Assert(CommandAgent.StartAzureStorageBlobCopy(container.Name, blobName, container.Name, blobName2, premiumPageBlobTier: PremiumPageBlobTier.P30), "upload a blob name with premiumPageBlobTier should succeed");
                blob = container.GetPageBlobReference(blobName2);
                blob.FetchAttributes();

                ExpectEqual(localMD5, blob.Properties.ContentMD5, "content md5");
                Test.Assert(PremiumPageBlobTier.P30 == blob.Properties.PremiumPageBlobTier, "PremiumPageBlobTier shoud match: {0} == {1}", PremiumPageBlobTier.P30, blob.Properties.PremiumPageBlobTier);

                //Copy 2
                Test.Assert(CommandAgent.StartAzureStorageBlobCopy(blob, container.Name, blobName3, premiumPageBlobTier: PremiumPageBlobTier.P4), "upload a blob name with premiumPageBlobTier should succeed");
                blob = container.GetPageBlobReference(blobName3);
                blob.FetchAttributes();

                ExpectEqual(localMD5, blob.Properties.ContentMD5, "content md5");
                Test.Assert(PremiumPageBlobTier.P4 == blob.Properties.PremiumPageBlobTier, "PremiumPageBlobTier shoud match: {0} == {1}", PremiumPageBlobTier.P4, blob.Properties.PremiumPageBlobTier);
            }
            finally
            {
                string StorageConnectionString = Test.Data.Get("StorageConnectionString");
                PowerShellAgent.SetStorageContext(StorageConnectionString);
                container.DeleteIfExists();
                FileUtil.RemoveFile(filePath);
            }
        }
Ejemplo n.º 13
0
 public void GetAzureStorageUsageInvalidCredential()
 {
     if (isResourceMode)
     {
         PowerShellAgent.RemoveAzureSubscriptionIfExists();
         CommandAgent.Logout();
         Test.Assert(!CommandAgent.GetAzureStorageUsage(), "Get azure storage usage should fail.");
         ExpectedContainErrorMessage("No subscription found in the context.");
     }
 }
Ejemplo n.º 14
0
        public static void AnonymousHTTPBVTClassInitialize(TestContext testContext)
        {
            TestBase.TestClassInitialize(testContext);
            string StorageAccountName = Test.Data.Get("StorageAccountName");

            useHttps = false;
            PowerShellAgent.SetAnonymousStorageContext(StorageAccountName, useHttps);
            downloadDirRoot = Test.Data.Get("DownloadDir");
            SetupDownloadDir();
        }
Ejemplo n.º 15
0
 public static void AzureEmulatorBVTClassInitialize(TestContext testContext)
 {
     //first set the storage account
     //second init common bvt
     //third set storage context in powershell
     SetUpStorageAccount = CloudStorageAccount.DevelopmentStorageAccount;
     CLICommonBVT.CLICommonBVTInitialize(testContext);
     PowerShellAgent.SetLocalStorageContext();
     StartStorageEmulator();
 }
Ejemplo n.º 16
0
 public static void ConnectionStringHTTPBVTClassInitialize(TestContext testContext)
 {
     //first set the storage account
     //second init common bvt
     //third set storage context in powershell
     useHttps            = false;
     SetUpStorageAccount = TestBase.GetCloudStorageAccountFromConfig(string.Empty, useHttps);
     CLICommonBVT.CLICommonBVTInitialize(testContext);
     PowerShellAgent.SetStorageContext(SetUpStorageAccount.ToString(true));
 }
Ejemplo n.º 17
0
 public void CheckAccountNameAvailabilityInvalidCredential()
 {
     if (isResourceMode)
     {
         PowerShellAgent.RemoveAzureSubscriptionIfExists();
         CommandAgent.Logout();
         string accountName = AccountUtils.GenerateAvailableAccountName();
         Test.Assert(!CommandAgent.CheckNameAvailability(accountName), "Check name availability should fail.");
         ExpectedContainErrorMessage("No subscription found in the context.");
     }
 }
Ejemplo n.º 18
0
 public static void AnonymousBVTClassInitialize(TestContext testContext)
 {
     TestBase.TestClassInitialize(testContext);
     CLICommonBVT.SaveAndCleanSubScriptionAndEnvConnectionString();
     StorageAccountName = Test.Data.Get("StorageAccountName");
     StorageEndPoint    = Test.Data.Get("StorageEndPoint").Trim();
     useHttps           = true;
     PowerShellAgent.SetAnonymousStorageContext(StorageAccountName, useHttps, StorageEndPoint);
     downloadDirRoot = Test.Data.Get("DownloadDir");
     SetupDownloadDir();
 }
Ejemplo n.º 19
0
        public void GetMooncakeStorageContext()
        {
            CLICommonBVT.SaveAndCleanSubScriptionAndEnvConnectionString();

            PowerShellAgent.ImportAzureSubscriptionAndSetStorageAccount(
                Test.Data.Get("MooncakeSubscriptionPath"),
                Test.Data.Get("MooncakeSubscriptionName"),
                null);

            ValidateStorageContext(Test.Data.Get("MooncakeStorageAccountName"), Test.Data.Get("MooncakeStorageAccountKey"), "core.chinacloudapi.cn");
        }
Ejemplo n.º 20
0
 /// <summary>
 /// set up azure subscription
 /// </summary>
 private static void SetupOAuth()
 {
     if (isResourceMode)
     {
         PowerShellAgent ps = new PowerShellAgent();
         ps.Logout();
         ps.Login();
         string storageAccountName = Test.Data.Get("StorageAccountName");
         PowerShellAgent.SetOAuthStorageContext(storageAccountName, useHttps);
     }
 }
Ejemplo n.º 21
0
        private void ValidateStorageContext(string accountName, string accountKey, string endpointSuffix)
        {
            object context = PowerShellAgent.GetStorageContext(accountName, accountKey);

            CloudStorageAccount storageAccount = null;

            Type myType = context.GetType();
            IList <PropertyInfo> props = new List <PropertyInfo>(myType.GetProperties());

            foreach (PropertyInfo prop in props)
            {
                if (string.Equals(prop.Name, "BlobEndPoint"))
                {
                    string blobEndPoint = prop.GetValue(context, null) as string;

                    Test.Assert(blobEndPoint.Contains(string.Format("{0}.blob.{1}", accountName, endpointSuffix)), "BlobEndPoint should be correct.");
                }
                else if (string.Equals(prop.Name, "TableEndPoint"))
                {
                    string tableEndpoint = prop.GetValue(context, null) as string;

                    Test.Assert(tableEndpoint.Contains(string.Format("{0}.table.{1}", accountName, endpointSuffix)), "TableEndPoint should be correct.");
                }
                else if (string.Equals(prop.Name, "QueueEndPoint"))
                {
                    string queueEndPoint = prop.GetValue(context, null) as string;

                    Test.Assert(queueEndPoint.Contains(string.Format("{0}.queue.{1}", accountName, endpointSuffix)), "QueueEndPoint should be correct.");
                }
                else if (string.Equals(prop.Name, "EndPointSuffix"))
                {
                    string contextEndPointSuffix = prop.GetValue(context, null) as string;

                    Test.Assert(contextEndPointSuffix.Contains(endpointSuffix), "EndPointSuffix should be correct.");
                }
                else if (string.Equals(prop.Name, "StorageAccountName"))
                {
                    string storageAccountName = prop.GetValue(context, null) as string;

                    Test.Assert(string.Equals(storageAccountName, accountName), "StorageAccountName should be correct.");
                }
                else if (string.Equals(prop.Name, "StorageAccount"))
                {
                    storageAccount = prop.GetValue(context, null) as CloudStorageAccount;
                    Test.Assert(string.Equals(storageAccount.Credentials.AccountName, accountName), "StorageAccount name should be correct.");
                }
            }

            PowerShellAgent.SetStorageContext(accountName, accountKey);

            UploadBlobWithAccount(storageAccount);
        }
Ejemplo n.º 22
0
        public void GetStorageContextWithNameKeyEndPoint()
        {
            PowerShellAgent psAgent     = (PowerShellAgent)CommandAgent;
            string          accountName = Utility.GenNameString("account");
            string          accountKey  = Utility.GenBase64String("key");
            string          endPoint    = Utility.GenNameString("core.abc.def");

            Test.Assert(psAgent.NewAzureStorageContext(accountName, accountKey, endPoint), "New storage context with specified name/key/endpoint should succeed");
            // Verification for returned values
            Collection <Dictionary <string, object> > comp = GetContextCompareData(accountName, endPoint);

            CommandAgent.OutputValidation(comp);
        }
Ejemplo n.º 23
0
        public static void ConnectionStringHTTPBVTClassInitialize(TestContext testContext)
        {
            //first set the storage account
            //second init common bvt
            //third set storage context in powershell
            string ConnectionString = Test.Data.Get("HTTPConnectionString");

            SetUpStorageAccount = CloudStorageAccount.Parse(ConnectionString);

            CLICommonBVT.CLICommonBVTInitialize(testContext);
            PowerShellAgent.SetStorageContext(ConnectionString);
            useHttps = false;
        }
Ejemplo n.º 24
0
        public static void SecondaryEndPointBVTClassInitialize(TestContext testContext)
        {
            //first set the storage account
            //second init common bvt
            //third set storage context in powershell
            useHttps            = true;
            isSecondary         = true;
            SetUpStorageAccount = TestBase.GetCloudStorageAccountFromConfig("Secondary", useHttps);
            StorageAccountName  = SetUpStorageAccount.Credentials.AccountName;
            string StorageEndPoint = Test.Data.Get("SecondaryStorageEndPoint");

            CLICommonBVT.CLICommonBVTInitialize(testContext);
            PowerShellAgent.SetStorageContext(SetUpStorageAccount.ToString(true));
        }
Ejemplo n.º 25
0
        public static void NameKeyContextBVTClassInitialize(TestContext testContext)
        {
            //first set the storage account
            //second init common bvt
            //third set storage context in powershell
            StorageAccountName = Test.Data.Get("StorageAccountName");
            StorageAccountKey  = Test.Data.Get("StorageAccountKey");
            StorageCredentials credential = new StorageCredentials(StorageAccountName, StorageAccountKey);

            useHttps            = true;
            SetUpStorageAccount = new CloudStorageAccount(credential, useHttps);

            CLICommonBVT.CLICommonBVTInitialize(testContext);
            PowerShellAgent.SetStorageContext(StorageAccountName, StorageAccountKey, useHttps);
        }
        public void GetCopyStateWithSAS()
        {
            string         destShareName = Utility.GenNameString("destshare");
            CloudFileShare destShare     = fileUtil.EnsureFileShareExists(destShareName);

            try
            {
                string fileName = Utility.GenNameString("DestFile");
                StorageFile.CloudFile destFile = fileUtil.GetFileReference(destShare.GetRootDirectoryReference(), fileName);

                object destContext;
                if (lang == Language.PowerShell)
                {
                    destContext = PowerShellAgent.GetStorageContext(StorageAccount.ToString(true));
                }
                else
                {
                    destContext = NodeJSAgent.GetStorageContext(StorageAccount.ToString(true));
                }

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

                Test.Assert(CommandAgent.StartFileCopy(bigBlobUri, destShareName, fileName, destContext), "Copy to file should succeed.");

                string sasToken = destShare.GetSharedAccessSignature(new SharedAccessFilePolicy()
                {
                    Permissions            = SharedAccessFilePermissions.Read,
                    SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddHours(1)
                });

                CommandAgent.SetStorageContextWithSASToken(StorageAccount.Credentials.AccountName, sasToken);

                Test.Assert(CommandAgent.GetFileCopyState(destShareName, fileName, destContext), "Get copy state with sas token should succeed.");

                string copyId = null;
                if (lang == Language.NodeJS)
                {
                    copyId = ((JObject)CommandAgent.Output[0]["copy"])["id"].ToString();
                }

                NodeJSAgent.AgentConfig.ConnectionString = StorageAccount.ToString(true);
                Test.Assert(CommandAgent.StopFileCopy(destFile, copyId), "Stop file copy should succeed.");
            }
            finally
            {
                fileUtil.DeleteFileShareIfExists(destShareName);
            }
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Save azure subscription and env connection string. So the current settings can't impact our tests.
        /// </summary>
        //TODO move to TestBase
        public static void SaveAndCleanSubScriptionAndEnvConnectionString()
        {
            Test.Info("Clean Azure Subscription and save env connection string");
            //can't restore the azure subscription files
            PowerShellAgent.RemoveAzureSubscriptionIfExists();

            //set env connection string
            //TODO A little bit trivial, move to CLITestBase class
            if (string.IsNullOrEmpty(EnvKey))
            {
                EnvKey = Test.Data.Get("EnvContextKey");
            }

            SavedEnvString = System.Environment.GetEnvironmentVariable(EnvKey);
            System.Environment.SetEnvironmentVariable(EnvKey, string.Empty);
        }
Ejemplo n.º 28
0
        public static void Initialize(TestContext testContext, bool useHttps)
        {
            StorageAccount = null;
            TestBase.TestClassInitialize(testContext);
            CLICommonBVT.SaveAndCleanSubScriptionAndEnvConnectionString();
            StorageAccountName = Test.Data.Get("StorageAccountName");
            StorageEndPoint    = Test.Data.Get("StorageEndPoint").Trim();

            if (lang == Language.PowerShell)
            {
                PowerShellAgent.SetAnonymousStorageContext(StorageAccountName, useHttps, StorageEndPoint);
            }

            downloadDirRoot = Test.Data.Get("DownloadDir");
            SetupDownloadDir();
        }
Ejemplo n.º 29
0
        public static void AzureEnvironmentBVTClassInitialize(TestContext testContext)
        {
            //first set the storage account
            //second init common bvt
            //third set storage context in powershell
            useHttps            = true;
            isSecondary         = true;
            SetUpStorageAccount = TestBase.GetCloudStorageAccountFromConfig("Secondary", useHttps);
            StorageAccountName  = SetUpStorageAccount.Credentials.AccountName;
            string StorageEndpoint   = Test.Data.Get("SecondaryStorageEndPoint");
            string StorageAccountKey = Test.Data.Get("SecondaryStorageAccountKey");

            CLICommonBVT.CLICommonBVTInitialize(testContext);
            azureEnvironmentName = PowerShellAgent.AddRandomAzureEnvironment(StorageEndpoint, "bvt");
            PowerShellAgent.SetStorageContextWithAzureEnvironment(StorageAccountName, StorageAccountKey, useHttps, azureEnvironmentName);
        }
        public static void NameKeyContextHTTPBVTClassInitialize(TestContext testContext)
        {
            //first set the storage account
            //second init common bvt
            //third set storage context in powershell
            StorageAccountName = Test.Data.Get("StorageAccountName");
            string             StorageAccountKey = Test.Data.Get("StorageAccountKey");
            string             StorageEndPoint   = Test.Data.Get("StorageEndPoint");
            StorageCredentials credential        = new StorageCredentials(StorageAccountName, StorageAccountKey);

            useHttps            = false;
            isSecondary         = false;
            SetUpStorageAccount = Utility.GetStorageAccountWithEndPoint(credential, useHttps, StorageEndPoint);

            CLICommonBVT.CLICommonBVTInitialize(testContext);
            PowerShellAgent.SetStorageContext(StorageAccountName, StorageAccountKey, useHttps, StorageEndPoint);
        }
Ejemplo n.º 31
0
        /// <summary>
        /// Create a container and then get it using powershell cmdlet
        /// </summary>
        /// <returns>A CloudBlobContainer object which is returned by PowerShell</returns>
        protected CloudBlobContainer CreateAndPsGetARandomContainer()
        {
            string containerName = Utility.GenNameString("bvt");
            CloudBlobContainer container = SetUpStorageAccount.CreateCloudBlobClient().GetContainerReference(containerName);
            container.CreateIfNotExists();

            try
            {
                PowerShellAgent agent = new PowerShellAgent();
                Test.Assert(agent.GetAzureStorageContainer(containerName), Utility.GenComparisonData("GetAzureStorageContainer", true));
                int count = 1;
                Test.Assert(agent.Output.Count == count, string.Format("get container should return only 1 container, actully it's {0}", agent.Output.Count));
                return (CloudBlobContainer)agent.Output[0]["CloudBlobContainer"];
            }
            finally
            {
                // clean up
                container.DeleteIfExists();
            }
        }
Ejemplo n.º 32
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();
            }
        }
Ejemplo n.º 33
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();
            }
        }