public void NewAzureVMWithWindowsAndCustomData()
        {
            try
            {
                _serviceName = Utilities.GetUniqueShortName(serviceNamePrefix);
                string newAzureVMName = Utilities.GetUniqueShortName("PSWinVM");

                var customDataFile    = @".\CustomData.bin";
                var customDataContent = File.ReadAllText(customDataFile);

                // Add-AzureProvisioningConfig with X509Certificate
                var          azureVMConfigInfo       = new AzureVMConfigInfo(newAzureVMName, 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);
                Console.WriteLine("New Azure service with name:{0} created successfully.", _serviceName);

                StopAzureVMTest.WaitForReadyState(_serviceName, newAzureVMName, 60, 30);

                // Get-AzureVM
                var vmContext = vmPowershellCmdlets.GetAzureVM(newAzureVMName, _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, newAzureVMName);
                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;
            }
        }
Exemple #2
0
        public static void Intialize(TestContext context)
        {
            imageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Windows" }, false);
            var vnetConfig = vmPowershellCmdlets.GetAzureVNetConfig(null);

            if (vnetConfig.Count > 0)
            {
                vmPowershellCmdlets.RunPSScript("Get-AzureService | Remove-AzureService -Force");
                Utilities.RetryActionUntilSuccess(() => vmPowershellCmdlets.RemoveAzureVNetConfig(), "in use", 5, 30);
            }
            ReadVnetConfig();
            SetVNetForStaticCAtest();
        }
Exemple #3
0
        public void UpdateVMWithNewStaticCATest()
        {
            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);
            string vnet1   = VirtualNets[0];
            string vmName1 = Utilities.GetUniqueShortName(vmNamePrefix);

            try
            {
                const string ipaddress = "10.0.0.7";
                //Test a static CA
                Console.WriteLine("Checking if ipaddress {0} is available", ipaddress);
                CheckAvailabilityofIpAddress(vnet1, ipaddress);
                Console.WriteLine("ipaddress {0} is available", ipaddress);

                //Create an IaaS VM
                vmPowershellCmdlets.NewAzureQuickVM(OS.Windows, vmName1, serviceName, imageName, new string[1] {
                    StaticCASubnet0
                }, InstanceSize.Small, username, password, VNetName, AffinityGroup);

                //Update the IaaS VM with a static CA
                var    vmRoleContext      = vmPowershellCmdlets.GetAzureVM(vmName1, serviceName);
                string nonStaticIpAddress = vmRoleContext.IpAddress;
                Console.WriteLine("Non static IpAddress of the vm {0} is {1}", vmName1, nonStaticIpAddress);
                var vm = vmPowershellCmdlets.SetAzureStaticVNetIP(ipaddress, vmRoleContext.VM);
                vmPowershellCmdlets.UpdateAzureVM(vmName1, serviceName, vm);

                //Verify that the DIP of the VM is matched with an input.
                VerifyVmWithStaticCAIsReserved(vmName1, serviceName, ipaddress);

                //Verify that the first DIP is released.
                Console.WriteLine("Checking for the availability of non static IpAdress after giving a static CA to the VM");

                Thread.Sleep(TimeSpan.FromMinutes(2));

                var availabilityContext = vmPowershellCmdlets.TestAzureStaticVNetIP(vnet1, nonStaticIpAddress);

                Utilities.RetryActionUntilSuccess(
                    () => Assert.IsTrue(availabilityContext.IsAvailable, "Non static IpAddress {0} is not realesed.", nonStaticIpAddress),
                    "Non static IpAddress", 3, 60);
                //Assert.IsTrue(availabilityContext.IsAvailable, "Non static IpAddress {0} is not realesed.",nonStaticIpAddress);
                Utilities.PrintContext(availabilityContext);
                pass = true;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                throw;
            }
        }
        public static void ClassInitialize(TestContext context)
        {
            var vnetConfig = vmPowershellCmdlets.GetAzureVNetConfig(null);

            if (vnetConfig.Count > 0)
            {
                vmPowershellCmdlets.RunPSScript("Get-AzureService | Remove-AzureService -Force");
                Utilities.RetryActionUntilSuccess(() => vmPowershellCmdlets.RemoveAzureVNetConfig(), "in use", 5, 30);
            }
            vmPowershellCmdlets.SetAzureVNetConfig(Directory.GetCurrentDirectory() + "\\VnetconfigWithLocation.netcfg");
            var sites = vmPowershellCmdlets.GetAzureVNetSite(null);

            subNet   = sites[0].Subnets.First().Name;
            vnetName = sites[0].Name;
        }
        private void VerifyRDPExtension(string vmName, string serviceName)
        {
            Console.WriteLine("Fetching Azure VM RDP file");
            vmPowershellCmdlets.GetAzureRemoteDesktopFile(vmName, serviceName, rdpPath, false);
            using (StreamReader stream = new StreamReader(rdpPath))
            {
                string firstLine  = stream.ReadLine();
                var    dnsAndport = Utilities.FindSubstring(firstLine, ':', 2).Split(new char[] { ':' });
                dns  = dnsAndport[0];
                port = int.Parse(dnsAndport[1]);
            }
            Console.WriteLine("Azure VM RDP file downloaded.");

            Console.WriteLine("Waiting for a minute vefore trying to connect to VM");
            Thread.Sleep(TimeSpan.FromMinutes(4));
            Utilities.RetryActionUntilSuccess(() => ValidateLogin(dns, port, vmAccessUserName, vmAccessPassword), "Cannot RDP to the instance!!", 5, 10000);
        }
 private static void CleanUpVnetConfigForStaticCA()
 {
     Utilities.RetryActionUntilSuccess(() => vmPowershellCmdlets.RemoveAzureVNetConfig(), "in use", 10, 30);
 }
 private static void SetVNetForStaticCAtest()
 {
     Utilities.RetryActionUntilSuccess(
         () => vmPowershellCmdlets.SetAzureVNetConfig(Directory.GetCurrentDirectory() + "\\StaticCAvnetconfig.netcfg"),
         "in use", 10, 30);
 }