Esempio n. 1
0
        public void NewAzureVMWithWindowsAndCustomData()
        {
            try
            {
                var customDataFile    = @".\CustomData.bin";
                var customDataContent = File.ReadAllText(customDataFile);

                // Add-AzureProvisioningConfig with X509Certificate
                var          azureVMConfigInfo       = new AzureVMConfigInfo(_vmName, InstanceSize.Small.ToString(), imageName);
                var          azureProvisioningConfig = new AzureProvisioningConfigInfo(username, password, customDataFile);
                var          persistentVMConfigInfo  = new PersistentVMConfigInfo(azureVMConfigInfo, azureProvisioningConfig, null, null);
                PersistentVM vm = vmPowershellCmdlets.GetPersistentVM(persistentVMConfigInfo);

                // New-AzureVM
                vmPowershellCmdlets.NewAzureVM(_serviceName, new[] { vm }, locationName, true);
                Console.WriteLine("New Azure service with name:{0} created successfully.", _serviceName);

                // Get-AzureVM
                var vmContext = vmPowershellCmdlets.GetAzureVM(_vmName, _serviceName);

                // Get-AzureCertificate
                var winRmCert = vmPowershellCmdlets.GetAzureCertificate(_serviceName, vmContext.VM.DefaultWinRmCertificateThumbprint, "sha1").First();

                // Install the WinRM cert to the local machine's root location.
                InstallCertificate(winRmCert, StoreLocation.LocalMachine, StoreName.Root);

                var connUri = vmPowershellCmdlets.GetAzureWinRMUri(_serviceName, _vmName);
                var cred    = new PSCredential(username, Utilities.convertToSecureString(password));

                Utilities.RetryActionUntilSuccess(() =>
                {
                    // Invoke Command
                    var scriptBlock = ScriptBlock.Create(@"Get-Content -Path 'C:\AzureData\CustomData.bin'");
                    var invokeInfo  = new InvokeCommandCmdletInfo(connUri, cred, scriptBlock);
                    var invokeCmd   = new PowershellCmdlet(invokeInfo);
                    var results     = invokeCmd.Run(false);
                    Assert.IsTrue(customDataContent == results.First().BaseObject as string);
                }, "Access is denied", 10, 30);

                pass = true;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw;
            }
        }
        public void Initialize()
        {
            _serviceName     = Utilities.GetUniqueShortName(serviceNamePrefix);
            _deploymentName  = Utilities.GetUniqueShortName(DeploymentNamePrefix);
            _deploymentLabel = Utilities.GetUniqueShortName(DeploymentLabelPrefix);

            pass = false;

            // Choose the package and config files from local machine
            _packageName  = Convert.ToString(TestContext.DataRow["packageName"]);
            _configName   = Convert.ToString(TestContext.DataRow["configName"]);
            _rdpCertName  = Convert.ToString(TestContext.DataRow["rdpCertName"]);
            _packagePath1 = new FileInfo(Directory.GetCurrentDirectory() + "\\" + _packageName);
            _configPath1  = new FileInfo(Directory.GetCurrentDirectory() + "\\" + _configName);
            _rdpCertPath  = new FileInfo(Directory.GetCurrentDirectory() + "\\" + _rdpCertName);
            _cert         = new X509Certificate2(_rdpCertPath.FullName, password);
            _cred         = new PSCredential(DomainUserName, Utilities.convertToSecureString(password));

            CheckIfPackageAndConfigFilesExists();
            testStartTime = DateTime.Now;
        }