Example #1
0
        public void SaveAzureVhdThreadNumberTest()
        {
            testName = MethodBase.GetCurrentMethod().Name;
            StartTest(testName, testStartTime);

            // Choose the vhd path in your local machine
            string   vhdName      = Convert.ToString(TestContext.DataRow["vhdLocalPath"]) + Utilities.GetUniqueShortName();
            FileInfo vhdLocalPath = new FileInfo(vhdName);

            DateTime start = DateTime.Now;

            // Download with 2 threads and verify it.
            SaveVhdAndAssertContent(blobHandle, vhdLocalPath, 2, false, true);
            TimeSpan duration = DateTime.Now - start;

            // Choose the vhd path in your local machine
            string   vhdName2      = Convert.ToString(TestContext.DataRow["vhdLocalPath"]) + Utilities.GetUniqueShortName();
            FileInfo vhdLocalPath2 = new FileInfo(vhdName2);

            // Download with 16 threads and verify it.
            start = DateTime.Now;
            SaveVhdAndAssertContent(blobHandle, vhdLocalPath2, 16, false, true);
            //Assert.IsTrue(DateTime.Now - start < duration, "16 threads took longer!");
            if (DateTime.Now - start > duration)
            {
                Console.WriteLine("16 threads took longer than 2 threads!");
            }


            DateTime testEndTime = DateTime.Now;

            Console.WriteLine("{0} test passed at {1}.", testName, testEndTime);
            Console.WriteLine("Duration of the test pass: {0} seconds", (testEndTime - testStartTime).TotalSeconds);

            System.IO.File.AppendAllLines(perfFile, new string[] { String.Format("{0},{1}", testName, (testEndTime - testStartTime).TotalSeconds) });
        }
Example #2
0
        public void AzureEndpointTest()
        {
            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);

            string           ep1Name               = "tcp1";
            int              ep1LocalPort          = 60010;
            int              ep1PublicPort         = 60011;
            string           ep1LBSetName          = "lbset1";
            int              ep1ProbePort          = 60012;
            string           ep1ProbePath          = string.Empty;
            int?             ep1ProbeInterval      = 7;
            int?             ep1ProbeTimeout       = null;
            NetworkAclObject ep1AclObj             = null;
            bool             ep1DirectServerReturn = false;

            string           ep2Name               = "tcp2";
            int              ep2LocalPort          = 60020;
            int              ep2PublicPort         = 60021;
            int              ep2LocalPortChanged   = 60030;
            int              ep2PublicPortChanged  = 60031;
            string           ep2LBSetName          = "lbset2";
            int              ep2ProbePort          = 60022;
            string           ep2ProbePath          = @"/";
            int?             ep2ProbeInterval      = null;
            int?             ep2ProbeTimeout       = 32;
            NetworkAclObject ep2AclObj             = null;
            bool             ep2DirectServerReturn = false;


            AzureEndPointConfigInfo ep1Info = new AzureEndPointConfigInfo(
                AzureEndPointConfigInfo.ParameterSet.CustomProbe,
                ProtocolInfo.tcp,
                ep1LocalPort,
                ep1PublicPort,
                ep1Name,
                ep1LBSetName,
                ep1ProbePort,
                ProtocolInfo.tcp,
                ep1ProbePath,
                ep1ProbeInterval,
                ep1ProbeTimeout,
                ep1AclObj,
                ep1DirectServerReturn);

            AzureEndPointConfigInfo ep2Info = new AzureEndPointConfigInfo(
                AzureEndPointConfigInfo.ParameterSet.CustomProbe,
                ProtocolInfo.tcp,
                ep2LocalPort,
                ep2PublicPort,
                ep2Name,
                ep2LBSetName,
                ep2ProbePort,
                ProtocolInfo.http,
                ep2ProbePath,
                ep2ProbeInterval,
                ep2ProbeTimeout,
                ep2AclObj,
                ep2DirectServerReturn);

            string defaultVm = Utilities.GetUniqueShortName(vmNamePrefix);

            Assert.IsNull(vmPowershellCmdlets.GetAzureVM(defaultVm, serviceName));

            vmPowershellCmdlets.NewAzureQuickVM(OS.Windows, defaultVm, serviceName, imageName, username, password, locationName);
            Console.WriteLine("Service Name: {0} is created.", serviceName);

            try
            {
                foreach (AzureEndPointConfigInfo.ParameterSet p in Enum.GetValues(typeof(AzureEndPointConfigInfo.ParameterSet)))
                {
                    string pSetName = Enum.GetName(typeof(AzureEndPointConfigInfo.ParameterSet), p);
                    Console.WriteLine("--Begin Endpoint Test with '{0}' parameter set.", pSetName);

                    ep1Info.ParamSet           = p;
                    ep2Info.ParamSet           = p;
                    ep1Info.Acl                = vmPowershellCmdlets.NewAzureAclConfig();
                    ep2Info.Acl                = vmPowershellCmdlets.NewAzureAclConfig();
                    ep2Info.EndpointLocalPort  = ep2LocalPort;
                    ep2Info.EndpointPublicPort = ep2PublicPort;

                    // Add two new endpoints
                    Console.WriteLine("-----Add 2 new endpoints.");
                    vmPowershellCmdlets.AddEndPoint(defaultVm, serviceName, new[] { ep1Info, ep2Info }); // Add-AzureEndpoint with Get-AzureVM and Update-AzureVm
                    CheckEndpoint(defaultVm, serviceName, new[] { ep1Info, ep2Info });

                    // Change the endpoint
                    if (p == AzureEndPointConfigInfo.ParameterSet.NoLB)
                    {
                        Console.WriteLine("-----Change the second endpoint.");
                        ep2Info.EndpointLocalPort  = ep2LocalPortChanged;
                        ep2Info.EndpointPublicPort = ep2PublicPortChanged;
                        vmPowershellCmdlets.SetEndPoint(defaultVm, serviceName, ep2Info); // Set-AzureEndpoint with Get-AzureVM and Update-AzureVm
                        CheckEndpoint(defaultVm, serviceName, new[] { ep2Info });
                    }
                    else
                    {
                        Console.WriteLine("-----Change the second endpoint.");
                        ep2Info.ServiceName        = serviceName;
                        ep2Info.EndpointLocalPort  = ep2LocalPortChanged;
                        ep2Info.EndpointPublicPort = ep2PublicPortChanged;
                        vmPowershellCmdlets.SetLBEndPoint(defaultVm, serviceName, ep2Info, p);

                        CheckEndpoint(defaultVm, serviceName, new[] { ep2Info });
                    }

                    // Remove Endpoint
                    Console.WriteLine("-----Remove endpoints.");
                    vmPowershellCmdlets.RemoveEndPoint(defaultVm, serviceName, new[] { ep1Name, ep2Name }); // Remove-AzureEndpoint
                    CheckEndpointRemoved(defaultVm, serviceName, new[] { ep1Info, ep2Info });

                    Console.WriteLine("Endpoint Test passed with '{0}' parameter set.", pSetName);
                }

                pass = true;
            }
            catch (Exception e)
            {
                pass = false;
                Assert.Fail("Exception occurred: {0}", e.ToString());
            }
        }
Example #3
0
        public void SaveAzureVhdResumeTest()
        {
            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);

            // Choose the vhd path in your local machine
            string   vhdName      = Convert.ToString(TestContext.DataRow["vhdLocalPath"]) + Utilities.GetUniqueShortName();
            FileInfo vhdLocalPath = new FileInfo(vhdName);

            Assert.IsFalse(File.Exists(vhdLocalPath.FullName), "VHD file already exist={0}", vhdLocalPath);

            // Start uploading and stop after 5 seconds...
            Console.WriteLine("downloading {0} to {1}", vhdBlobLocation, vhdLocalPath);
            string result = vmPowershellCmdlets.SaveAzureVhdStop(blobHandle.Blob.Uri, vhdLocalPath, null, null, false, 5000);

            if (result.ToLowerInvariant() == "stopped")
            {
                Console.WriteLine("successfully stopped");


                SaveVhdAndAssertContent(blobHandle, vhdLocalPath, false, true);
            }
            else
            {
                Console.WriteLine("didn't stop!");
            }

            DateTime testEndTime = DateTime.Now;

            Console.WriteLine("{0} test passed at {1}.", testName, testEndTime);
            Console.WriteLine("Duration of the test pass: {0} seconds", (testEndTime - testStartTime).TotalSeconds);

            System.IO.File.AppendAllLines(perfFile, new string[] { String.Format("{0},{1}", testName, (testEndTime - testStartTime).TotalSeconds) });
        }
Example #4
0
        public void AzureVMImageListRemoveTest()
        {
            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);
            string newImageName = Utilities.GetUniqueShortName("vmimage");
            string oldLabel     = "old label";
            string newLabel     = Utilities.GetUniqueShortName("vmimage");
            string vmName       = Utilities.GetUniqueShortName(vmNamePrefix);
            string serviceName1 = Utilities.GetUniqueShortName("Pstestsvc");

            try
            {
                string mediaLocation = UploadVhdFile();
                Console.WriteLine("------------------------------Add an OS image---------------------------------");
                //      a.	Add an OS image
                var result = vmPowershellCmdlets.AddAzureVMImage(newImageName, mediaLocation, OS.Windows, newImageName);
                Console.WriteLine("------------------------------Add an OS image: Completed---------------------------------");
                //b.	Deploy a new IaaS VM
                Console.WriteLine("------------------------------Deploy a new IaaS VM---------------------------------");
                var vm = CreateIaaSVMObjectWithDisk(vmName, InstanceSize.Small, newImageName, true, username, password);
                vmPowershellCmdlets.NewAzureVM(serviceName, new[] { vm }, locationName);
                Console.WriteLine("------------------------------Deploy a new IaaS VM: Completed---------------------------------");
                //c.	Stop the VM
                Console.WriteLine("------------------------------Stop the VM---------------------------------");
                vmPowershellCmdlets.StopAzureVM(vm, serviceName, true);
                Console.WriteLine("------------------------------Stop the VM: Completed---------------------------------");
                //d.	Try to save the OS image with an existing os image name. (should fail)
                Console.WriteLine("------------------------------Try to save the OS image with an existing os image name---------------------------------");
                Utilities.VerifyFailure(() => vmPowershellCmdlets.SaveAzureVMImage(serviceName, vmName, oldLabel, CONSTANT_SPECIALIZED, oldLabel), BadRequestException);
                Console.WriteLine("------------------------------Try to save the OS image with an existing os image name: Completed---------------------------------");
                //e.	Save the OS image with a new image name.
                Console.WriteLine("------------------------------Save the OS image with a new image name.---------------------------------");
                vmPowershellCmdlets.SaveAzureVMImage(serviceName, vmName, newLabel);
                Console.WriteLine("------------------------------Save the OS image with a new image name: Completed---------------------------------");
                //f.	Deploy a new IaaS VM
                Console.WriteLine("------------------------------Deploy a new IaaS VM---------------------------------");
                string vmName1 = Utilities.GetUniqueShortName(vmNamePrefix);
                vm = CreateIaaSVMObjectWithDisk(vmName1, InstanceSize.Small, newLabel, true, username, password);
                vmPowershellCmdlets.NewAzureVM(serviceName1, new[] { vm }, locationName);
                var vmRoleContext = vmPowershellCmdlets.GetAzureVM(vmName1, serviceName1);
                Console.WriteLine("------------------------------Deploy a new IaaS VM: Completed---------------------------------");

                //g.	Stop the VM
                Console.WriteLine("------------------------------Stop the VM---------------------------------");
                vmPowershellCmdlets.StopAzureVM(vm, serviceName1, true);
                Console.WriteLine("------------------------------Stop the VM: Completed---------------------------------");
                //h.	Save the VM image with the existing os image name (should fail)
                Console.WriteLine("------------------------------Save the VM image with the existing os image name---------------------------------");
                vmImageName = vmName1 + "Image";
                Utilities.VerifyFailure(() => vmPowershellCmdlets.SaveAzureVMImage(serviceName1, vmName1, newLabel, CONSTANT_SPECIALIZED, vmImageName), "OSImage");
                Console.WriteLine("------------------------------Save the VM image with the existing os image name: Completed---------------------------------");
                //i.	List VM Images
                //i.	Get-AzureVMImage
                //VerifyVMImage(vmImageName, OS.Windows, vmImageName, CONSTANT_SPECIALIZED, cahcing, lunSlot1, diskSize1, 1);
                Console.WriteLine("------------------------------Get-AzureVMImage---------------------------------");
                VerifyOsImage(newLabel, new OSImageContext()
                {
                    ImageName = newLabel,
                    Category  = CONSTANT_CATEGORY,
                    Location  = locationName,
                    Label     = newLabel,
                    OS        = OS.Windows.ToString()
                });
                Console.WriteLine("------------------------------Get-AzureVMImage: Completed---------------------------------");
                //j.	Try to remove a wrong vm
                Console.WriteLine("------------------------------Try to remove a wrong vm---------------------------------");
                Utilities.VerifyFailure(() => vmPowershellCmdlets.RemoveAzureVMImage(Utilities.GetUniqueShortName()), ResourceNotFoundException);
                Console.WriteLine("------------------------------Try to remove a wrong vm: Completed---------------------------------");
                pass = true;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                throw;
            }
            finally
            {
                //k.	Remove the VM Images
                DeleteVMImageIfExists(newLabel);
                vmPowershellCmdlets.RemoveAzureService(serviceName1);
            }
        }
Example #5
0
        public void CaptureSpecializedVMAndDeploy()
        {
            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);
            string serviceName1 = Utilities.GetUniqueShortName(serviceNamePrefix);

            try
            {
                //      a.	Deploy a new IaaS VM
                string vmName = Utilities.GetUniqueShortName(vmNamePrefix);
                Console.WriteLine("--------------------------------Deploying a new IaaS VM :{0}--------------------------------", vmName);
                var vm = CreateIaaSVMObjectWithDisk(vmName, InstanceSize.Small, imageName, true, username, password);
                vmPowershellCmdlets.NewAzureVM(serviceName, new[] { vm }, locationName);
                Console.WriteLine("--------------------------------Deploying a new IaaS VM :{0} completed.---------------------", vmName);
                //b.	Stop the VM
                Console.WriteLine("--------------------------------Stopping vm :{0}--------------------------------", vmName);
                vmPowershellCmdlets.StopAzureVM(vmName, serviceName, force: true);
                Console.WriteLine("--------------------------------Stopped vm :{0}--------------------------------", vmName);
                //c.	Save the VM image
                Console.WriteLine("--------------------------------Save the VM image--------------------------------");
                vmImageName = vmName + "Image";
                vmPowershellCmdlets.SaveAzureVMImage(serviceName, vmName, vmImageName, CONSTANT_SPECIALIZED, vmImageName);
                Console.WriteLine("--------------------------------Saved VM image with name {0}----------------------");
                //d.	Verify the VM image by Get-AzureVMImage
                Console.WriteLine("--------------------------------Verify the VM image--------------------------------");
                VerifyVMImage(vmImageName, OS.Windows, vmImageName, CONSTANT_SPECIALIZED, cahcing, lunSlot1, diskSize1, 1);
                Console.WriteLine("--------------------------------Verified that the VM image is saved successfully--------------------------------");
                //e.	Deploy a new IaaS VM with the save VM image
                Console.WriteLine("--------------------------------Deploy a new IaaS VM with the saved VM image {0}--------------------------------", vmImageName);
                string vmName1 = Utilities.GetUniqueShortName(vmNamePrefix);
                vm = Utilities.CreateIaaSVMObject(vmName1, InstanceSize.Small, vmImageName);
                vmPowershellCmdlets.NewAzureVM(serviceName1, new[] { vm }, locationName);
                Console.WriteLine("--------------------------------Deployed a IaaS VM {0} with the saved VM image {1}--------------------------------", vmName1, vmImageName);
                //f.	Verify the VM by Get-AzureVM
                Console.WriteLine("--------------------------------Verify the VM by Get-AzureVM--------------------------------", vmName1, vmImageName);
                var vmRoleContext = vmPowershellCmdlets.GetAzureVM(vmName1, serviceName1);
                Utilities.PrintContext(vmRoleContext);
                VerifyVM(vmRoleContext.VM, OS.Windows, HostCaching.ReadWrite, diskSize1, 1);
                Console.WriteLine("--------------------------------Verified the VM {0} successfully--------------------------------", vmName1);
                //g.	Add another IaaS VM with the save VM image to the existing service
                string vmName2 = Utilities.GetUniqueShortName(vmNamePrefix);
                Console.WriteLine("--------------------------------Deploy a new IaaS VM with the saved VM image {0}--------------------------------", vmImageName);
                vmPowershellCmdlets.NewAzureQuickVM(OS.Windows, vmName2, serviceName1, vmImageName);
                Console.WriteLine("--------------------------------Deployed a IaaS VM {0} with the saved VM image {1}--------------------------------", vmName2, vmImageName);
                //h.	Verify the VM by Get-AzureVM
                Console.WriteLine("--------------------------------Verify the VM by Get-AzureVM--------------------------------", vmName2, vmImageName);
                vmRoleContext = vmPowershellCmdlets.GetAzureVM(vmName2, serviceName1);
                VerifyVM(vmRoleContext.VM, OS.Windows, HostCaching.ReadWrite, diskSize1, 1);
                Utilities.PrintContext(vmRoleContext);
                Console.WriteLine("--------------------------------Verified the VM {0} successfully--------------------------------", vmName2);

                pass = true;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                throw;
            }
            finally
            {
                CleanupService(serviceName1);
                //	Delete the VM image
                Console.WriteLine("------------------------------Delete the VM image---------------------------------");
                DeleteVMImageIfExists(vmImageName);
                Console.WriteLine("------------------------------Deleted the VM image---------------------------------");
            }
        }
Example #6
0
 public void Initialize()
 {
     serviceName   = Utilities.GetUniqueShortName(serviceNamePrefix);
     pass          = false;
     testStartTime = DateTime.Now;
 }
Example #7
0
        public void AzureVMImageSizeTest()
        {
            string mediaLocation = UploadVhdFile();
            string newImageName  = Utilities.GetUniqueShortName("vmimage");

            try
            {
                var       instanceSizes        = vmPowershellCmdlets.GetAzureRoleSize().Where(r => r.Cores <= 2 && !r.InstanceSize.StartsWith("Standard_"));
                const int numOfMinimumInstSize = 3;
                Assert.IsTrue(instanceSizes.Count() >= numOfMinimumInstSize);
                var instanceSizesArr = instanceSizes.Take(numOfMinimumInstSize).ToArray();
                int arrayLength      = instanceSizesArr.Count();

                for (int i = 0; i < arrayLength; i++)
                {
                    Utilities.PrintContext(instanceSizesArr[i]);
                    // Add-AzureVMImage test for VM size
                    OSImageContext result         = vmPowershellCmdlets.AddAzureVMImage(newImageName, mediaLocation, OS.Windows, null, instanceSizesArr[i].InstanceSize);
                    OSImageContext resultReturned = vmPowershellCmdlets.GetAzureVMImage(newImageName)[0];
                    Assert.IsTrue(!string.IsNullOrEmpty(resultReturned.IOType));
                    Assert.IsTrue(CompareContext <OSImageContext>(result, resultReturned));

                    // Update-AzureVMImage test for VM size
                    System.Threading.Thread.Sleep(TimeSpan.FromSeconds(10));
                    result         = vmPowershellCmdlets.UpdateAzureVMImage(newImageName, resultReturned.ImageName, instanceSizesArr[Math.Max((i + 1) % arrayLength, 1)].InstanceSize);
                    resultReturned = vmPowershellCmdlets.GetAzureVMImage(newImageName)[0];
                    Assert.IsTrue(!string.IsNullOrEmpty(resultReturned.IOType));
                    Assert.IsTrue(CompareContext <OSImageContext>(result, resultReturned));

                    vmPowershellCmdlets.RemoveAzureVMImage(newImageName);
                    System.Threading.Thread.Sleep(TimeSpan.FromSeconds(10));
                    pass = true;
                }
            }
            catch (Exception e)
            {
                pass = false;
                System.Threading.Thread.Sleep(TimeSpan.FromSeconds(10));
                vmPowershellCmdlets.RemoveAzureVMImage(newImageName, true);
                Console.WriteLine("Exception occurred: {0}", e.ToString());
                throw;
            }
            finally
            {
                try
                {
                    vmPowershellCmdlets.GetAzureVMImage(newImageName);
                    vmPowershellCmdlets.RemoveAzureVMImage(newImageName);
                }
                catch (Exception e)
                {
                    if (e.ToString().Contains("ResourceNotFound"))
                    {
                        Console.WriteLine("The vm image, {0}, is already deleted.", newImageName);
                    }
                    else
                    {
                        throw;
                    }
                }
            }
        }
Example #8
0
        public void AzureReservedIPTest()
        {
            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);

            try
            {
                // IP1 and IP2 on AG1
                vmPowershellCmdlets.NewAzureAffinityGroup(affName1, locationName, null, null);
                vmPowershellCmdlets.NewAzureReservedIP(rsvIpName1, affName1, rsvIPLabel);
                vmPowershellCmdlets.NewAzureReservedIP(rsvIpName2, affName1, rsvIPLabel);

                var reservedIPReturned = vmPowershellCmdlets.GetAzureReservedIP(rsvIpName1)[0];
                Verify.AzureReservedIPNotInUse(reservedIPReturned, rsvIpName1, rsvIPLabel, affName1);

                // Create an affinity group in another location
                var anotherLocation = GetLocation("PersistentVMRole", locationName);
                vmPowershellCmdlets.NewAzureAffinityGroup(affName2, anotherLocation.Name, null, null);

                string rsvIpName3 = rsvIpNamePrefix + Utilities.GetUniqueShortName();
                string rsvIpName4 = rsvIpNamePrefix + Utilities.GetUniqueShortName();
                var    rsvIPNames = new[] { rsvIpName1, rsvIpName2, rsvIpName3, rsvIpName4 };
                vmPowershellCmdlets.NewAzureReservedIP(rsvIpName3, affName2, rsvIPLabel); // IP3 on AG2
                vmPowershellCmdlets.NewAzureReservedIP(rsvIpName4, affName2, rsvIPLabel); // IP4 on AG2

                var rsvIPs = vmPowershellCmdlets.GetAzureReservedIP();
                foreach (var ip in rsvIPs)
                {
                    if (rsvIPNames.Contains(ip.ReservedIPName))
                    {
                        reservedIPReturned = vmPowershellCmdlets.GetAzureReservedIP(ip.ReservedIPName)[0];
                        Verify.AzureReservedIPNotInUse(reservedIPReturned, ip.ReservedIPName, ip.Label, ip.Location,
                                                       ip.Id);
                    }
                }

                // Remove IP1
                vmPowershellCmdlets.RemoveAzureReservedIP(rsvIpName1);
                Utilities.CheckRemove(vmPowershellCmdlets.GetAzureReservedIP, rsvIpName1);

                rsvIPs = vmPowershellCmdlets.GetAzureReservedIP();
                foreach (var ip in rsvIPs)
                {
                    if (rsvIPNames.Contains(ip.ReservedIPName))
                    {
                        reservedIPReturned = vmPowershellCmdlets.GetAzureReservedIP(ip.ReservedIPName)[0];
                        Verify.AzureReservedIPNotInUse(reservedIPReturned, ip.ReservedIPName, ip.Label, ip.Location,
                                                       ip.Id);
                    }
                }

                // Remove IP3
                vmPowershellCmdlets.RemoveAzureReservedIP(rsvIpName3);
                Utilities.CheckRemove(vmPowershellCmdlets.GetAzureReservedIP, rsvIpName3);

                rsvIPs = vmPowershellCmdlets.GetAzureReservedIP();
                foreach (var ip in rsvIPs)
                {
                    if (rsvIPNames.Contains(ip.ReservedIPName))
                    {
                        reservedIPReturned = vmPowershellCmdlets.GetAzureReservedIP(ip.ReservedIPName)[0];
                        Verify.AzureReservedIPNotInUse(reservedIPReturned, ip.ReservedIPName, ip.Label, ip.Location,
                                                       ip.Id);
                    }
                }

                vmPowershellCmdlets.RemoveAzureReservedIP(rsvIpName4);
                Utilities.CheckRemove(vmPowershellCmdlets.GetAzureReservedIP, rsvIpName4);
                vmPowershellCmdlets.RemoveAzureReservedIP(rsvIpName2);
                Utilities.CheckRemove(vmPowershellCmdlets.GetAzureReservedIP, rsvIpName2);

                pass = true;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                throw;
            }
        }
Example #9
0
        private string StoreConfigFileWithReservedIp(string configFileName, string reservedIpName)
        {
            var originalConfigPath = new FileInfo(Directory.GetCurrentDirectory() + "\\" + configFileName);
            var tempConfigPath     = new FileInfo(Directory.GetCurrentDirectory() + "\\" + Utilities.GetUniqueShortName(configFileName));

            string _config1_format = File.ReadAllText(originalConfigPath.FullName);

            File.WriteAllText(tempConfigPath.FullName, string.Format(_config1_format, reservedIpName));
            return(tempConfigPath.FullName);
        }
Example #10
0
        public void CreateDeploymentWithReservedIPNegativeTest()
        {
            try
            {
                string newAzureVM1Name = Utilities.GetUniqueShortName(vmNamePrefix);
                string newAzureVM2Name = Utilities.GetUniqueShortName(vmNamePrefix);
                if (string.IsNullOrEmpty(imageName))
                {
                    imageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Windows" }, false);
                }

                var azureVMConfigInfo1      = new AzureVMConfigInfo(newAzureVM1Name, InstanceSize.ExtraSmall.ToString(), imageName);
                var azureVMConfigInfo2      = new AzureVMConfigInfo(newAzureVM2Name, InstanceSize.Small.ToString(), imageName);
                var azureProvisioningConfig = new AzureProvisioningConfigInfo(OS.Windows, username, password);
                var azureDataDiskConfigInfo = new AddAzureDataDiskConfig(DiskCreateOption.CreateNew, 50, "datadisk1", 0);
                var azureEndPointConfigInfo = new AzureEndPointConfigInfo(AzureEndPointConfigInfo.ParameterSet.CustomProbe, ProtocolInfo.tcp, 80, 80, "web", "lbweb", 80, ProtocolInfo.http, @"/", null, null);

                var persistentVMConfigInfo1 = new PersistentVMConfigInfo(azureVMConfigInfo1, azureProvisioningConfig, azureDataDiskConfigInfo, azureEndPointConfigInfo);
                var persistentVMConfigInfo2 = new PersistentVMConfigInfo(azureVMConfigInfo2, azureProvisioningConfig, azureDataDiskConfigInfo, null);

                PersistentVM persistentVM1 = vmPowershellCmdlets.GetPersistentVM(persistentVMConfigInfo1);
                PersistentVM persistentVM2 = vmPowershellCmdlets.GetPersistentVM(persistentVMConfigInfo2);

                PersistentVM[] VMs = { persistentVM1, persistentVM2 };


                // AG1 on location 1
                vmPowershellCmdlets.NewAzureAffinityGroup(affName1, locationName, null, null);

                // AG2 on location 2
                var anotherLocation = GetLocation("PersistentVMRole", locationName);
                vmPowershellCmdlets.NewAzureAffinityGroup(affName2, anotherLocation.Name, null, null);

                // Reserve an ip on AG1
                vmPowershellCmdlets.NewAzureReservedIP(rsvIpName1, affName2);
                var rsvIPreturned = vmPowershellCmdlets.GetAzureReservedIP(rsvIpName1)[0];
                Verify.AzureReservedIPNotInUse(rsvIPreturned, rsvIpName1, null, affName2);

                // Try to create a new deployment with AG2 and the reserved IP
                Utilities.VerifyFailure(
                    () => vmPowershellCmdlets.NewAzureVMWithReservedIP(svcNameAG, VMs, rsvIpName1, affName1),
                    BadRequestException);

                // Create a new deployment with location 2, and then reserved the IP of it
                vmPowershellCmdlets.NewAzureVM(svcNameLoc, VMs, locationName);

                Utilities.VerifyFailure(
                    () => vmPowershellCmdlets.NewAzureReservedIP(rsvIpName2, affName2, svcNameLoc, svcNameLoc),
                    BadRequestException);

                // Remove the reserved IP and verify
                vmPowershellCmdlets.RemoveAzureReservedIP(rsvIpName1);
                Utilities.VerifyFailure(
                    () => vmPowershellCmdlets.GetAzureReservedIP(rsvIpName1), ResourceNotFoundException);

                pass = true;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Example #11
0
        public void RemoveAzureReservedIPWithDeploymentTest()
        {
            try
            {
                vmPowershellCmdlets.NewAzureAffinityGroup(affName1, locationName, null, null);

                string newAzureVM1Name = Utilities.GetUniqueShortName(vmNamePrefix);

                if (string.IsNullOrEmpty(imageName))
                {
                    imageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Windows" }, false);
                }

                var azureVMConfigInfo1      = new AzureVMConfigInfo(newAzureVM1Name, InstanceSize.ExtraSmall.ToString(), imageName);
                var azureProvisioningConfig = new AzureProvisioningConfigInfo(OS.Windows, username, password);
                var azureDataDiskConfigInfo = new AddAzureDataDiskConfig(DiskCreateOption.CreateNew, 50, "datadisk1", 0);
                var azureEndPointConfigInfo = new AzureEndPointConfigInfo(AzureEndPointConfigInfo.ParameterSet.CustomProbe, ProtocolInfo.tcp, 80, 80, "web", "lbweb", 80, ProtocolInfo.http, @"/", null, null);

                var persistentVMConfigInfo1 = new PersistentVMConfigInfo(azureVMConfigInfo1, azureProvisioningConfig, azureDataDiskConfigInfo, azureEndPointConfigInfo);

                PersistentVM persistentVM1 = vmPowershellCmdlets.GetPersistentVM(persistentVMConfigInfo1);


                //PersistentVM[] VMs = { persistentVM1, persistentVM2 };
                PersistentVM[] VMs = { persistentVM1 };

                // Create a new deployment
                vmPowershellCmdlets.NewAzureVMWithAG(svcNameAG, VMs, affName1);

                // Reserve the ip of the deployment
                vmPowershellCmdlets.NewAzureReservedIP(rsvIpName1, affName1, svcNameAG, svcNameAG, rsvIPLabel);

                // Get the deployment and verify
                var deploymentReturned = vmPowershellCmdlets.GetAzureDeployment(svcNameAG);

                // Verify the reserved ip
                var reservedIPReturned = vmPowershellCmdlets.GetAzureReservedIP(rsvIpName1)[0];
                Verify.AzureReservedIPInUse(reservedIPReturned, rsvIpName1, rsvIPLabel, affName1,
                                            deploymentReturned.VirtualIPs[0].Address, deploymentReturned.DeploymentName,
                                            deploymentReturned.ServiceName);

                // Stop-deallocate the first VM and verify reserved ip
                Utilities.VerifyFailure(() => vmPowershellCmdlets.RemoveAzureReservedIP(rsvIpName1), BadRequestException);

                vmPowershellCmdlets.StopAzureVM(newAzureVM1Name, svcNameAG, false, true);

                // Verify the reserved ip
                reservedIPReturned = vmPowershellCmdlets.GetAzureReservedIP(rsvIpName1)[0];
                Verify.AzureReservedIPInUse(reservedIPReturned, rsvIpName1, rsvIPLabel, affName1,
                                            deploymentReturned.VirtualIPs[0].Address, deploymentReturned.DeploymentName,
                                            deploymentReturned.ServiceName);

                // Stop-deallocate the second VM and verify reserved ip
                Utilities.VerifyFailure(() => vmPowershellCmdlets.RemoveAzureReservedIP(rsvIpName1), BadRequestException);

                // Remove all VMs and service and verify reserved ip
                vmPowershellCmdlets.RemoveAzureVM(newAzureVM1Name, svcNameAG, true);

                // Verify the reserved ip
                reservedIPReturned = vmPowershellCmdlets.GetAzureReservedIP(rsvIpName1)[0];
                Verify.AzureReservedIPNotInUse(reservedIPReturned, rsvIpName1, rsvIPLabel, affName1);

                // Remove the reserved IP and verify
                vmPowershellCmdlets.RemoveAzureReservedIP(rsvIpName1);
                Utilities.VerifyFailure(
                    () => vmPowershellCmdlets.GetAzureReservedIP(rsvIpName1), ResourceNotFoundException);

                pass = true;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Example #12
0
        public void AzureVMImageTest()
        {
            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);
            vhdName = "os1.vhd";
            string newImageName  = Utilities.GetUniqueShortName("vmimage");
            string mediaLocation = string.Format("{0}{1}/{2}", blobUrlRoot, vhdContainerName, vhdName);

            string oldLabel     = "old label";
            string newLabel     = "new label";
            string vmSize       = "Small";
            var    iconUri      = "http://www.bing.com";
            var    smallIconUri = "http://www.bing.com";
            bool   showInGui    = true;

            try
            {
                // BVT Tests for OS Images
                OSImageContext result = vmPowershellCmdlets.AddAzureVMImage(newImageName, mediaLocation, OS.Windows, oldLabel, vmSize, iconUri, smallIconUri, showInGui);

                OSImageContext resultReturned = vmPowershellCmdlets.GetAzureVMImage(newImageName)[0];
                Assert.IsTrue(!string.IsNullOrEmpty(resultReturned.IOType));
                Assert.IsTrue(CompareContext <OSImageContext>(result, resultReturned));

                result         = vmPowershellCmdlets.UpdateAzureVMImage(newImageName, newLabel);
                resultReturned = vmPowershellCmdlets.GetAzureVMImage(newImageName)[0];
                Assert.IsTrue(!string.IsNullOrEmpty(resultReturned.IOType));
                Assert.IsTrue(CompareContext <OSImageContext>(result, resultReturned));

                result         = vmPowershellCmdlets.UpdateAzureVMImage(newImageName, newLabel, true);
                resultReturned = vmPowershellCmdlets.GetAzureVMImage(newImageName)[0];
                Assert.IsTrue(resultReturned.ShowInGui.HasValue && !resultReturned.ShowInGui.Value);
                Assert.IsTrue(CompareContext <OSImageContext>(result, resultReturned));

                vmPowershellCmdlets.RemoveAzureVMImage(newImageName, false);
                Assert.IsTrue(Utilities.CheckRemove(vmPowershellCmdlets.GetAzureVMImage, newImageName));

                // BVT Tests for VM Images
                // Unique Container Prefix
                var containerPrefix = Utilities.GetUniqueShortName("vmimg");

                // Disk Blobs
                var srcVhdName        = "os1.vhd";
                var srcVhdContainer   = vhdContainerName;
                var dstOSVhdContainer = containerPrefix.ToLower() + "os" + vhdContainerName;
                CredentialHelper.CopyTestData(srcVhdContainer, srcVhdName, dstOSVhdContainer);
                string osVhdLink = string.Format("{0}{1}/{2}", blobUrlRoot, dstOSVhdContainer, srcVhdName);

                var dstDataVhdContainer = containerPrefix.ToLower() + "data" + vhdContainerName;
                CredentialHelper.CopyTestData(srcVhdContainer, srcVhdName, dstDataVhdContainer);
                string dataVhdLink = string.Format("{0}{1}/{2}", blobUrlRoot, dstDataVhdContainer, srcVhdName);

                // VM Image OS/Data Disk Configuration
                var addVMImageName = containerPrefix + "Image";
                var diskConfig     = new VirtualMachineImageDiskConfigSet
                {
                    OSDiskConfiguration = new OSDiskConfiguration
                    {
                        HostCaching = HostCaching.ReadWrite.ToString(),
                        OS          = OSType.Windows.ToString(),
                        OSState     = "Generalized",
                        MediaLink   = new Uri(osVhdLink)
                    },
                    DataDiskConfigurations = new DataDiskConfigurationList
                    {
                        new DataDiskConfiguration
                        {
                            HostCaching = HostCaching.ReadOnly.ToString(),
                            Lun         = 0,
                            MediaLink   = new Uri(dataVhdLink)
                        }
                    }
                };

                // Add-AzureVMImage
                string   label             = addVMImageName;
                string   description       = "test";
                string   eula              = "http://www.bing.com/";
                string   imageFamily       = "Windows";
                DateTime?publishedDate     = new DateTime(2015, 1, 1);
                string   privacyUri        = "http://www.bing.com/";
                string   recommendedVMSize = vmSize;
                string   iconName          = "iconName";
                string   smallIconName     = "smallIconName";

                vmPowershellCmdlets.AddAzureVMImage(
                    addVMImageName,
                    label,
                    diskConfig,
                    description,
                    eula,
                    imageFamily,
                    publishedDate,
                    privacyUri,
                    recommendedVMSize,
                    iconName,
                    smallIconName,
                    showInGui);

                // Get-AzureVMImage
                var vmImage = vmPowershellCmdlets.GetAzureVMImageReturningVMImages(addVMImageName).First();

                Assert.IsTrue(vmImage.ImageName == addVMImageName);
                Assert.IsTrue(vmImage.Label == label);
                Assert.IsTrue(vmImage.Description == description);
                Assert.IsTrue(vmImage.Eula == eula);
                Assert.IsTrue(vmImage.ImageFamily == imageFamily);
                Assert.IsTrue(vmImage.PublishedDate.Value.Year == publishedDate.Value.Year);
                Assert.IsTrue(vmImage.PublishedDate.Value.Month == publishedDate.Value.Month);
                Assert.IsTrue(vmImage.PublishedDate.Value.Day == publishedDate.Value.Day);
                Assert.IsTrue(vmImage.PrivacyUri.AbsoluteUri.ToString() == privacyUri);
                Assert.IsTrue(vmImage.RecommendedVMSize == recommendedVMSize);
                Assert.IsTrue(vmImage.IconName == iconName);
                Assert.IsTrue(vmImage.IconUri == iconName);
                Assert.IsTrue(vmImage.SmallIconName == smallIconName);
                Assert.IsTrue(vmImage.SmallIconUri == smallIconName);
                Assert.IsTrue(vmImage.ShowInGui == showInGui);
                Assert.IsTrue(vmImage.OSDiskConfiguration.HostCaching == diskConfig.OSDiskConfiguration.HostCaching);
                Assert.IsTrue(vmImage.OSDiskConfiguration.OS == diskConfig.OSDiskConfiguration.OS);
                Assert.IsTrue(vmImage.OSDiskConfiguration.OSState == diskConfig.OSDiskConfiguration.OSState);
                Assert.IsTrue(vmImage.OSDiskConfiguration.MediaLink == diskConfig.OSDiskConfiguration.MediaLink);
                Assert.IsTrue(vmImage.DataDiskConfigurations.First().HostCaching == diskConfig.DataDiskConfigurations.First().HostCaching);
                Assert.IsTrue(vmImage.DataDiskConfigurations.First().Lun == diskConfig.DataDiskConfigurations.First().Lun);
                Assert.IsTrue(vmImage.DataDiskConfigurations.First().MediaLink == diskConfig.DataDiskConfigurations.First().MediaLink);

                // Remove-AzureVMImage
                vmPowershellCmdlets.RemoveAzureVMImage(addVMImageName);

                pass = true;
            }
            catch (Exception e)
            {
                pass = false;
                Assert.Fail("Exception occurred: {0}", e.ToString());
            }
            finally
            {
                if (!Utilities.CheckRemove(vmPowershellCmdlets.GetAzureVMImage, newImageName))
                {
                    vmPowershellCmdlets.RemoveAzureVMImage(newImageName, false);
                }
            }
        }
        public void AzureDiskTest()
        {
            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);

            vhdName = Utilities.GetUniqueShortName("os0vhd");
            CopyCommonVhd(vhdContainerName, "os0.vhd", vhdName);

            string mediaLocation = String.Format("{0}{1}/{2}", blobUrlRoot, vhdContainerName, vhdName);

            try
            {
                vmPowershellCmdlets.AddAzureDisk(vhdName, mediaLocation, vhdName, null);

                bool found = false;
                foreach (DiskContext disk in vmPowershellCmdlets.GetAzureDisk(vhdName))
                {
                    Console.WriteLine("Disk: Name - {0}, Label - {1}, Size - {2},", disk.DiskName, disk.Label, disk.DiskSizeInGB);
                    if (disk.DiskName == vhdName && disk.Label == vhdName)
                    {
                        found = true;
                        Console.WriteLine("{0} is found", disk.DiskName);
                    }
                }
                Assert.IsTrue(found, "Error: Disk is not added");

                // Update only label
                string newLabel = "NewLabel";
                vmPowershellCmdlets.UpdateAzureDisk(vhdName, newLabel);

                DiskContext virtualDisk = vmPowershellCmdlets.GetAzureDisk(vhdName)[0];

                Console.WriteLine("Disk: Name - {0}, Label - {1}, Size - {2},", virtualDisk.DiskName, virtualDisk.Label, virtualDisk.DiskSizeInGB);
                Assert.AreEqual(newLabel, virtualDisk.Label);
                Console.WriteLine("Disk Label is successfully updated");

                // Update only size
                int newSize = 50;
                vmPowershellCmdlets.UpdateAzureDisk(vhdName, null, newSize);

                virtualDisk = vmPowershellCmdlets.GetAzureDisk(vhdName)[0];

                Console.WriteLine("Disk: Name - {0}, Label - {1}, Size - {2},", virtualDisk.DiskName, virtualDisk.Label, virtualDisk.DiskSizeInGB);
                Assert.AreEqual(newLabel, virtualDisk.Label);
                Assert.AreEqual(newSize, virtualDisk.DiskSizeInGB);
                Console.WriteLine("Disk size is successfully updated");

                // Update both label and size
                newLabel = "NewLabel2";
                newSize  = 100;
                vmPowershellCmdlets.UpdateAzureDisk(vhdName, newLabel, newSize);

                virtualDisk = vmPowershellCmdlets.GetAzureDisk(vhdName)[0];

                Console.WriteLine("Disk: Name - {0}, Label - {1}, Size - {2},", virtualDisk.DiskName, virtualDisk.Label, virtualDisk.DiskSizeInGB);
                Assert.AreEqual(newLabel, virtualDisk.Label);
                Assert.AreEqual(newSize, virtualDisk.DiskSizeInGB);
                Console.WriteLine("Both disk label and size are successfully updated");

                vmPowershellCmdlets.RemoveAzureDisk(vhdName, true);
                Assert.IsTrue(Utilities.CheckRemove(vmPowershellCmdlets.GetAzureDisk, vhdName), "The disk was not removed");
                pass = true;
            }
            catch (Exception e)
            {
                pass = false;

                if (e.ToString().Contains("ResourceNotFound"))
                {
                    Console.WriteLine("Please upload {0} file to \\vhdtest\\ blob directory before running this test", vhdName);
                }

                try
                {
                    vmPowershellCmdlets.RemoveAzureDisk(vhdName, true);
                }
                catch (Exception cleanupError)
                {
                    Console.WriteLine("Error during cleaning up the disk.. Continue..:{0}", cleanupError);
                }

                Assert.Fail("Exception occurs: {0}", e.ToString());
            }
        }
Example #14
0
        public void TestVirtualIPLifecycle()
        {
            try
            {
                string dnsName      = Utilities.GetUniqueShortName("Dns");
                string vmName       = Utilities.GetUniqueShortName(vmNamePrefix);
                string vipName      = Utilities.GetUniqueShortName("Vip");
                string endpointName = Utilities.GetUniqueShortName("Endpoint");
                // Create a new VM with the reserved ip.
                DnsServer dns = null;
                Utilities.ExecuteAndLog(() => { dns = vmPowershellCmdlets.NewAzureDns(dnsName, DNS_IP); },
                                        "Create a new Azure DNS");
                PersistentVM vm = null;
                Utilities.ExecuteAndLog(() =>
                {
                    vm = Utilities.CreateVMObjectWithDataDiskSubnetAndAvailibilitySet(vmName, OS.Windows,
                                                                                      username, password, subnet);
                    vmPowershellCmdlets.NewAzureVM(serviceName, new[] { vm }, vnet, new[] { dns }, location: locationName);
                }, "Create a new windows azure vm without reserved ip.");

                Utilities.ExecuteAndLog(() => vmPowershellCmdlets.AddAzureVirtualIP(vipName, serviceName), "Adding Azure VirtualIP");

                var deployment   = vmPowershellCmdlets.GetAzureDeployment(serviceName, DeploymentSlotType.Production);
                var retrievedVip = deployment.VirtualIPs.FirstOrDefault(vip => string.Equals(vip.Name, vipName));
                Assert.IsNotNull(retrievedVip);
                Assert.IsTrue(string.IsNullOrEmpty(retrievedVip.Address));

                AzureEndPointConfigInfo endpointInfo = new AzureEndPointConfigInfo
                {
                    EndpointName       = endpointName,
                    EndpointProtocol   = ProtocolInfo.tcp,
                    EndpointLocalPort  = 1000,
                    EndpointPublicPort = 444,
                    VirtualIPName      = vipName,
                    Vm = vm
                };

                var updatedVM = vmPowershellCmdlets.AddAzureEndPoint(endpointInfo);
                vmPowershellCmdlets.UpdateAzureVM(vmName, serviceName, updatedVM);
                deployment   = vmPowershellCmdlets.GetAzureDeployment(serviceName, DeploymentSlotType.Production);
                retrievedVip = deployment.VirtualIPs.FirstOrDefault(vip => string.Equals(vip.Name, vipName));
                Assert.IsNotNull(retrievedVip);
                Assert.IsTrue(!string.IsNullOrEmpty(retrievedVip.Address));

                AzureEndPointConfigInfo removeEndpointInfo = new AzureEndPointConfigInfo
                {
                    EndpointName       = endpointName,
                    EndpointProtocol   = ProtocolInfo.tcp,
                    EndpointLocalPort  = 1000,
                    EndpointPublicPort = 444,
                    VirtualIPName      = vipName,
                    Vm = updatedVM
                };

                updatedVM = vmPowershellCmdlets.RemoveAzureEndPoint(endpointName, updatedVM);
                vmPowershellCmdlets.UpdateAzureVM(vmName, serviceName, updatedVM);

                deployment   = vmPowershellCmdlets.GetAzureDeployment(serviceName, DeploymentSlotType.Production);
                retrievedVip = deployment.VirtualIPs.FirstOrDefault(vip => string.Equals(vip.Name, vipName));
                Assert.IsNotNull(retrievedVip);
                Assert.IsTrue(string.IsNullOrEmpty(retrievedVip.Address));

                Utilities.ExecuteAndLog(() => vmPowershellCmdlets.RemoveAzureVirtualIP(vipName, serviceName), "Adding Azure VirtualIP");

                deployment   = vmPowershellCmdlets.GetAzureDeployment(serviceName, DeploymentSlotType.Production);
                retrievedVip = deployment.VirtualIPs.FirstOrDefault(vip => string.Equals(vip.Name, vipName));
                Assert.IsNull(retrievedVip);
                cleanupIfPassed = false;

                vmPowershellCmdlets.RemoveAzureDeployment(serviceName, "Production", true);
                pass = true;
            }
            catch (Exception ex)
            {
                pass = false;
                Console.WriteLine(ex.ToString());
                throw;
            }
        }
        public void PatchNormalSasUriBase()
        {
            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);

            // Choose the base vhd file from local machine
            var baseVhdName      = Convert.ToString(TestContext.DataRow["baseImage"]);
            var baseVhdLocalPath = new FileInfo(Directory.GetCurrentDirectory() + "\\" + baseVhdName);

            Assert.IsTrue(File.Exists(baseVhdLocalPath.FullName), "VHD file not exist={0}", baseVhdLocalPath);

            // Get the pre-calculated MD5 hash of the fixed vhd that was converted from the original vhd.
            string md5hash     = Convert.ToString(TestContext.DataRow["MD5hash"]);
            string md5hashBase = Convert.ToString(TestContext.DataRow["MD5hashBase"]);


            // Choose the child vhd file from the local machine
            var childVhdName      = Convert.ToString(TestContext.DataRow["vhdName"]);
            var childVhdLocalPath = new FileInfo(Directory.GetCurrentDirectory() + "\\" + childVhdName);

            Assert.IsTrue(File.Exists(childVhdLocalPath.FullName), "VHD file not exist={0}", childVhdLocalPath);

            int i = 0;

            while (i < 16)
            {
                if (!isReadWritePermission(i))
                {
                    i++; // Skip negative tests due to BUG: https://github.com/Azure/azure-sdk-tools/issues/2956
                }
                else
                {
                    string destinationSasUriParent = CreateSasUriWithPermission(baseVhdName, i); // the destination of the parent vhd is a Sas Uri

                    // Set the destination of child vhd
                    string vhdBlobName = string.Format("{0}/{1}.vhd", vhdContainerName, Utilities.GetUniqueShortName(Path.GetFileNameWithoutExtension(childVhdName)));
                    string vhdDestUri  = blobUrlRoot + vhdBlobName;

                    try
                    {
                        // Upload the parent vhd using Sas Uri
                        Console.WriteLine("uploads {0} to {1}", baseVhdName, destinationSasUriParent);
                        vmPowershellCmdlets.RemoveAzureSubscriptions();
                        var vhdUploadContext = vmPowershellCmdlets.AddAzureVhd(baseVhdLocalPath, destinationSasUriParent, true);
                        Console.WriteLine("uploading completed: {0}", baseVhdName);

                        // Verify the upload.
                        ReImportSubscription();
                        AssertUploadContextAndContentMD5UsingSaveVhd(destinationSasUriParent, baseVhdLocalPath, vhdUploadContext, md5hashBase, false);

                        Console.WriteLine("uploads {0} to {1} with patching from {2}", childVhdName, vhdDestUri, destinationSasUriParent);
                        var patchVhdUploadContext = vmPowershellCmdlets.AddAzureVhd(childVhdLocalPath, vhdDestUri, destinationSasUriParent);
                        Console.WriteLine("uploading the child vhd completed: {0}", childVhdName);

                        // Verify the upload.
                        AssertUploadContextAndContentMD5UsingSaveVhd(vhdDestUri, childVhdLocalPath, patchVhdUploadContext, md5hash);
                        Console.WriteLine("Test success with permission: {0}", i);
                        i++;
                    }
                    catch (Exception e)
                    {
                        continueIfNotReadWrite(e, ref i);
                        continue;
                    }
                }
            }

            pass = true;
            DateTime testEndTime = DateTime.Now;

            Console.WriteLine("{0} test passed at {1}.", testName, testEndTime);
            Console.WriteLine("Duration of the test pass: {0} seconds", (testEndTime - testStartTime).TotalSeconds);

            System.IO.File.AppendAllLines(perfFile, new string[] { String.Format("{0},{1}", testName, (testEndTime - testStartTime).TotalSeconds) });
        }
Example #16
0
        public void AzurePlatformVMImageScenarioTest()
        {
            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);

            string vmName  = Utilities.GetUniqueShortName("pirtestvm");
            string svcName = Utilities.GetUniqueShortName("pirtestservice");

            try
            {
                SwitchToNormalUser();

                try
                {
                    vmPowershellCmdlets.GetAzureStorageAccount(storageNormalUser);
                }
                catch (Exception e)
                {
                    if (e.ToString().Contains("ResourceNotFound"))
                    {
                        vmPowershellCmdlets.NewAzureStorageAccount(storageNormalUser, location1);
                    }
                    else
                    {
                        Console.WriteLine(e.ToString());
                        throw;
                    }
                }
                vmPowershellCmdlets.SetAzureSubscription(normaluser, normaluserSubId, storageNormalUser);

                // Replicate the user image to "West US" and wait until the replication process is completed.
                SwitchToPublisher();
                ComputeImageConfig compCfg = new ComputeImageConfig
                {
                    Offer   = "test",
                    Sku     = "test",
                    Version = "test"
                };
                MarketplaceImageConfig marketCfg = null;
                vmPowershellCmdlets.SetAzurePlatformVMImageReplicate(image, new string[] { location1 }, compCfg, marketCfg);

                // Make the replicated image public and wait until the PIR image shows up.
                vmPowershellCmdlets.SetAzurePlatformVMImagePublic(image);
                OSImageContext pirImage = WaitForPIRAppear(image, publisher);

                // Switch to the normal User and check the PIR image.
                SwitchToNormalUser();
                WaitForPIRAppear(image, publisher);

                // Create a VM using the PIR image
                vmPowershellCmdlets.NewAzureQuickVM(OS.Windows, vmName, svcName, pirImage.ImageName, username, password, location1);
                Console.WriteLine("VM, {0}, is successfully created using the uploaded PIR image", vmPowershellCmdlets.GetAzureVM(vmName, svcName).Name);

                // Remove the service and VM
                vmPowershellCmdlets.RemoveAzureService(svcName);

                // Switch to the publisher and remove the PIR image
                SwitchToPublisher();
                vmPowershellCmdlets.RemoveAzurePlatformVMImage(image);

                pass = true;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                throw;
            }
        }
Example #17
0
        public void TryToReserveExistingCATest()
        {
            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);
            string vnet1        = VirtualNets[0];
            string serviceName2 = Utilities.GetUniqueShortName(serviceNamePrefix);
            string serviceName3 = Utilities.GetUniqueShortName(serviceNamePrefix);
            string vmName1      = Utilities.GetUniqueShortName(vmNamePrefix);
            string vmName2      = Utilities.GetUniqueShortName(vmNamePrefix);
            string vmName3      = Utilities.GetUniqueShortName(vmNamePrefix);

            try
            {
                string nonStaticIpAddress = string.Empty;

                //Create an IaaS VM
                vmPowershellCmdlets.NewAzureQuickVM(OS.Windows, vmName1, serviceName, imageName, InstanceSize.Small.ToString(), username, password, VNetName, new string[1] {
                    StaticCASubnet0
                }, AffinityGroup);
                //Get the DIP of the VM (Get-AzureVM)
                var vmRoleContext = vmPowershellCmdlets.GetAzureVM(vmName1, serviceName);
                nonStaticIpAddress = vmRoleContext.IpAddress;

                //Assert that the DIP is not available (Test-AzureStaticVNetIP)
                CheckAvailabilityOfIpAddressAndAssertFalse(vnet1, nonStaticIpAddress);

                //Try to deploy an IaaS VM with the same static CA (CreateDeployment) and Verify that the deployment failed
                //Add an IaaS VM with a static CA
                Console.WriteLine("Deploying an IaaS VM with the same static CA {0} (CreateDeployment)", nonStaticIpAddress);
                var vm = CreatIaasVMObject(vmName2, nonStaticIpAddress, StaticCASubnet0);
                //Verify that the deployment failed.
                Utilities.VerifyFailure(
                    () => vmPowershellCmdlets.NewAzureVM(serviceName2, new[] { vm }, vnet1, new DnsServer[1] {
                    DnsServers[0]
                },
                                                         serviceName, "service for AddVMWithStaticCATest", string.Empty, string.Empty, null, AffinityGroup),
                    IPUnavaialbleExceptionMessage);
                Console.WriteLine("Deployment with Static CA {0} failed as expectd", nonStaticIpAddress);

                //Try to deploy an IaaS VM with the same static CA (AddRole) and verify that the deployment fails
                //Add an IaaS VM with a static CA
                Console.WriteLine("Deploying an IaaS VM with the same static CA {0} (AddRole)", nonStaticIpAddress);
                vm = CreatIaasVMObject(vmName3, nonStaticIpAddress, StaticCASubnet0);
                //Verify that the deployment failed.
                Utilities.VerifyFailure(() => vmPowershellCmdlets.NewAzureVM(serviceName, new[] { vm }), IPUnavaialbleExceptionMessage);
                Console.WriteLine("Deployment with Static CA {0} failed as expectd", nonStaticIpAddress);

                //Reserve the DIP of the VM1
                vmRoleContext = vmPowershellCmdlets.GetAzureVM(vmName1, serviceName);
                vm            = vmPowershellCmdlets.SetAzureStaticVNetIP(nonStaticIpAddress, vmRoleContext.VM);
                vmPowershellCmdlets.UpdateAzureVM(vmName1, serviceName, vm);

                //Verify that the DIP is reserved
                VerifyVmWithStaticCAIsReserved(vmName1, serviceName, nonStaticIpAddress);

                //Try to deploy an IaaS VM with the same static CA (CreateDeployment)
                Console.WriteLine("Deploying an IaaS VM with the same static CA {0} (CreateDeployment)", nonStaticIpAddress);
                vm = CreatIaasVMObject(vmName2, nonStaticIpAddress, StaticCASubnet0);
                Utilities.VerifyFailure(() => vmPowershellCmdlets.NewAzureVM(serviceName3, new[] { vm }, vnet1, new DnsServer[1] {
                    DnsServers[0]
                },
                                                                             serviceName, "service for AddVMWithStaticCATest", string.Empty, string.Empty, null, AffinityGroup), IPUnavaialbleExceptionMessage);
                Console.WriteLine("Deployment with Static CA {0} failed as expectd", nonStaticIpAddress);

                //Add an IaaS VM with a static CA
                Console.WriteLine("Deploying an IaaS VM with the same static CA {0} (AddRole)", nonStaticIpAddress);
                vm = CreatIaasVMObject(vmName3, nonStaticIpAddress, StaticCASubnet0);
                Utilities.VerifyFailure(() => vmPowershellCmdlets.NewAzureVM(serviceName, new[] { vm }), IPUnavaialbleExceptionMessage);
                Console.WriteLine("Deployment with Static CA {0} failed as expectd", nonStaticIpAddress);
                pass = true;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                throw;
            }
            finally
            {
                CleanupService(serviceName);
                CleanupService(serviceName2);
                CleanupService(serviceName3);
            }
        }
Example #18
0
        public void CreatePaaSDeploymentAssociateAndDisassociateReservedIp()
        {
            try
            {
                string reservedIpName  = Utilities.GetUniqueShortName("ResrvdIP");
                string reservedIpLabel = Utilities.GetUniqueShortName("ResrvdIPLbl", 5);
                string deploymentName  = Utilities.GetUniqueShortName("Depl");
                string deploymentLabel = Utilities.GetUniqueShortName("DepLbl", 5);

                var input = new ReservedIPContext()
                {
                    DeploymentName = string.Empty,
                    Label          = reservedIpLabel,
                    InUse          = false,
                    Location       = locationName,
                    ReservedIPName = reservedIpName,
                    State          = "Created"
                };

                // Reserve a new IP
                Utilities.ExecuteAndLog(() => vmPowershellCmdlets.NewAzureReservedIP(reservedIpName, locationName, reservedIpLabel), "Reserve a new IP");
                //Get the reserved ip and verify the reserved Ip properties.
                VerifyReservedIpNotInUse(input);
                // Create a new VM with the reserved ip.

                Utilities.ExecuteAndLog(() =>
                                        vmPowershellCmdlets.NewAzureService(serviceName, locationName),
                                        "Create a Hosted Service");

                Utilities.ExecuteAndLog(() =>
                                        vmPowershellCmdlets.NewAzureDeployment(serviceName,
                                                                               "HelloWorld_SDK20.cspkg", "ServiceConfiguration.cscfg", "Staging",
                                                                               deploymentLabel, deploymentName, doNotStart: false, warning: false),
                                        "Create a PaaS deployment");


                Utilities.ExecuteAndLog(() =>
                {
                    vmPowershellCmdlets.SetAzureReservedIPAssociation(reservedIpName,
                                                                      serviceName, DeploymentSlotType.Staging);
                }, "Create a new Azure Reserved IP Association");


                VerifyReservedIpInUse(serviceName, input, deploymentName);

                Utilities.ExecuteAndLog(() =>
                {
                    vmPowershellCmdlets.RemoveAzureReservedIPAssociation(reservedIpName,
                                                                         serviceName, true, DeploymentSlotType.Staging);
                }, "Remove a new Azure Reserved IP Association");

                VerifyReservedIpNotInUse(input);

                Utilities.ExecuteAndLog(() =>
                {
                    vmPowershellCmdlets.RemoveAzureDeployment(serviceName, "Staging", true);
                }, "Remove a new Azure Reserved IP Association");
            }
            catch (Exception ex)
            {
                pass = false;
                Console.WriteLine(ex.ToString());
                throw;
            }
        }
Example #19
0
        public void AzureIaaSBVT()
        {
            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);
            DateTime prevTime = DateTime.Now;

            string diskLabel1 = "disk1";
            int    diskSize1  = 30;
            int    lunSlot1   = 0;

            string diskLabel2 = "disk2";
            int    diskSize2  = 50;
            int    lunSlot2   = 2;


            string           ep1Name               = "tcp1";
            int              ep1LocalPort          = 60010;
            int              ep1PublicPort         = 60011;
            string           ep1LBSetName          = "lbset1";
            int              ep1ProbePort          = 60012;
            string           ep1ProbePath          = string.Empty;
            int?             ep1ProbeInterval      = 7;
            int?             ep1ProbeTimeout       = null;
            NetworkAclObject ep1AclObj             = vmPowershellCmdlets.NewAzureAclConfig();
            bool             ep1DirectServerReturn = false;

            string           ep2Name               = "tcp2";
            int              ep2LocalPort          = 60020;
            int              ep2PublicPort         = 60021;
            int              ep2LocalPortChanged   = 60030;
            int              ep2PublicPortChanged  = 60031;
            string           ep2LBSetName          = "lbset2";
            int              ep2ProbePort          = 60022;
            string           ep2ProbePath          = @"/";
            int?             ep2ProbeInterval      = null;
            int?             ep2ProbeTimeout       = 32;
            NetworkAclObject ep2AclObj             = vmPowershellCmdlets.NewAzureAclConfig();
            bool             ep2DirectServerReturn = false;

            string cerFileName         = "testcert.cer";
            string thumbprintAlgorithm = "sha1";

            try
            {
                // Create a certificate
                X509Certificate2 certCreated = Utilities.CreateCertificate(password);
                byte[]           certData2   = certCreated.Export(X509ContentType.Cert);
                File.WriteAllBytes(cerFileName, certData2);

                // Install the .cer file to local machine.
                StoreLocation    certStoreLocation = StoreLocation.CurrentUser;
                StoreName        certStoreName     = StoreName.My;
                X509Certificate2 installedCert     = Utilities.InstallCert(cerFileName, certStoreLocation, certStoreName);

                PSObject certToUpload = vmPowershellCmdlets.RunPSScript(
                    String.Format("Get-Item cert:\\{0}\\{1}\\{2}", certStoreLocation.ToString(), certStoreName.ToString(), installedCert.Thumbprint))[0];
                string certData = Convert.ToBase64String(((X509Certificate2)certToUpload.BaseObject).RawData);

                string newAzureVMName = Utilities.GetUniqueShortName(vmNamePrefix);
                if (string.IsNullOrEmpty(imageName))
                {
                    imageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Windows" }, false);
                }

                RecordTimeTaken(ref prevTime);

                //
                // New-AzureService and verify with Get-AzureService
                //
                vmPowershellCmdlets.NewAzureService(serviceName, serviceName, locationName);
                Assert.IsTrue(Verify.AzureService(serviceName, serviceName, locationName));
                RecordTimeTaken(ref prevTime);

                //
                // Add-AzureCertificate and verify with Get-AzureCertificate
                //
                vmPowershellCmdlets.AddAzureCertificate(serviceName, certToUpload);
                Assert.IsTrue(Verify.AzureCertificate(serviceName, certCreated.Thumbprint, thumbprintAlgorithm, certData));
                RecordTimeTaken(ref prevTime);

                //
                // Remove-AzureCertificate
                //
                vmPowershellCmdlets.RemoveAzureCertificate(serviceName, certCreated.Thumbprint, thumbprintAlgorithm);
                Assert.IsTrue(Utilities.CheckRemove(vmPowershellCmdlets.GetAzureCertificate, serviceName, certCreated.Thumbprint, thumbprintAlgorithm));
                RecordTimeTaken(ref prevTime);

                //
                // New-AzureVMConfig
                //
                var          azureVMConfigInfo = new AzureVMConfigInfo(newAzureVMName, InstanceSize.Small.ToString(), imageName);
                PersistentVM vm = vmPowershellCmdlets.NewAzureVMConfig(azureVMConfigInfo);

                RecordTimeTaken(ref prevTime);

                //
                // Add-AzureCertificate
                //
                vmPowershellCmdlets.AddAzureCertificate(serviceName, certToUpload);

                //
                // New-AzureCertificateSetting
                //
                CertificateSettingList certList = new CertificateSettingList();
                certList.Add(vmPowershellCmdlets.NewAzureCertificateSetting(certStoreName.ToString(), installedCert.Thumbprint));
                RecordTimeTaken(ref prevTime);

                //
                // Add-AzureProvisioningConfig
                //
                AzureProvisioningConfigInfo azureProvisioningConfig = new AzureProvisioningConfigInfo(OS.Windows, certList, username, password);
                azureProvisioningConfig.Vm = vm;
                vm = vmPowershellCmdlets.AddAzureProvisioningConfig(azureProvisioningConfig);
                RecordTimeTaken(ref prevTime);

                //
                // Add-AzureDataDisk (two disks)
                //
                AddAzureDataDiskConfig azureDataDiskConfigInfo1 = new AddAzureDataDiskConfig(DiskCreateOption.CreateNew, diskSize1, diskLabel1, lunSlot1);
                azureDataDiskConfigInfo1.Vm = vm;
                vm = vmPowershellCmdlets.AddAzureDataDisk(azureDataDiskConfigInfo1);

                AddAzureDataDiskConfig azureDataDiskConfigInfo2 = new AddAzureDataDiskConfig(DiskCreateOption.CreateNew, diskSize2, diskLabel2, lunSlot2);
                azureDataDiskConfigInfo2.Vm = vm;
                vm = vmPowershellCmdlets.AddAzureDataDisk(azureDataDiskConfigInfo2);

                RecordTimeTaken(ref prevTime);

                //
                // Add-AzureEndpoint (two endpoints)
                //
                AzureEndPointConfigInfo azureEndPointConfigInfo1 = new AzureEndPointConfigInfo(
                    AzureEndPointConfigInfo.ParameterSet.CustomProbe,
                    ProtocolInfo.tcp,
                    ep1LocalPort,
                    ep1PublicPort,
                    ep1Name,
                    ep1LBSetName,
                    ep1ProbePort,
                    ProtocolInfo.tcp,
                    ep1ProbePath,
                    ep1ProbeInterval,
                    ep1ProbeTimeout,
                    ep1AclObj,
                    ep1DirectServerReturn,
                    null,
                    null,
                    LoadBalancerDistribution.SourceIP);

                azureEndPointConfigInfo1.Vm = vm;
                vm = vmPowershellCmdlets.AddAzureEndPoint(azureEndPointConfigInfo1);

                AzureEndPointConfigInfo azureEndPointConfigInfo2 = new AzureEndPointConfigInfo(
                    AzureEndPointConfigInfo.ParameterSet.CustomProbe,
                    ProtocolInfo.tcp,
                    ep2LocalPort,
                    ep2PublicPort,
                    ep2Name,
                    ep2LBSetName,
                    ep2ProbePort,
                    ProtocolInfo.http,
                    ep2ProbePath,
                    ep2ProbeInterval,
                    ep2ProbeTimeout,
                    ep2AclObj,
                    ep2DirectServerReturn);

                azureEndPointConfigInfo2.Vm = vm;
                vm = vmPowershellCmdlets.AddAzureEndPoint(azureEndPointConfigInfo2);

                RecordTimeTaken(ref prevTime);

                //
                // Set-AzureAvailabilitySet
                //

                string testAVSetName = "testAVSet1";
                vm = vmPowershellCmdlets.SetAzureAvailabilitySet(testAVSetName, vm);
                RecordTimeTaken(ref prevTime);

                //
                // New-AzureDns
                //

                string dnsName   = "OpenDns1";
                string ipAddress = "208.67.222.222";

                DnsServer dns = vmPowershellCmdlets.NewAzureDns(dnsName, ipAddress);

                RecordTimeTaken(ref prevTime);

                //
                // New-AzureVM
                //
                vmPowershellCmdlets.NewAzureVM(serviceName, new[] { vm }, null, new[] { dns }, null, null, null, null);
                RecordTimeTaken(ref prevTime);

                //
                // Get-AzureVM without any parameter (List VMs)
                //
                var vmlist = vmPowershellCmdlets.GetAzureVM();
                Console.WriteLine("The number of VMs: {0}", vmlist.Count);
                Assert.AreNotSame(0, vmlist.Count, "No VM exists!!!");
                PersistentVMRoleListContext returnedVMlist =
                    vmlist.First(item => item.ServiceName.Equals(serviceName) && item.Name.Equals(newAzureVMName));
                Assert.IsNotNull(returnedVMlist, "Created VM does not exist!!!");
                Utilities.PrintContext((PersistentVMRoleContext)returnedVMlist);

                //
                // Get-AzureVM
                //
                PersistentVMRoleContext returnedVM = vmPowershellCmdlets.GetAzureVM(newAzureVMName, serviceName);
                vm = returnedVM.VM;
                RecordTimeTaken(ref prevTime);

                //
                // Verify AzureDataDisk
                //
                Assert.IsTrue(Verify.AzureDataDisk(vm, diskLabel1, diskSize1, lunSlot1, HostCaching.None), "Data disk is not properly added");
                Assert.IsTrue(Verify.AzureDataDisk(vm, diskLabel2, diskSize2, lunSlot2, HostCaching.None), "Data disk is not properly added");
                Console.WriteLine("Data disk added correctly.");

                RecordTimeTaken(ref prevTime);

                //
                // Verify AzureEndpoint
                //
                Assert.IsTrue(Verify.AzureEndpoint(vm, new[] { azureEndPointConfigInfo1, azureEndPointConfigInfo2 }));

                //
                // Verify RDP & PowerShell Endpoints
                //
                var endpoints = vmPowershellCmdlets.GetAzureEndPoint(vm);
                Assert.IsTrue(endpoints.Count(e => e.Name == "PowerShell" && e.LocalPort == 5986 && e.Protocol == "tcp") == 1);
                Assert.IsTrue(endpoints.Count(e => e.Name == "RemoteDesktop" && e.LocalPort == 3389 && e.Protocol == "tcp") == 1);

                //
                // Verify AzureDns
                //
                Assert.IsTrue(Verify.AzureDns(vmPowershellCmdlets.GetAzureDeployment(serviceName).DnsSettings, dns));

                //
                // Verify AzureAvailibilitySet
                //
                Assert.IsTrue(Verify.AzureAvailabilitySet(vm, testAVSetName));

                //
                // Verify AzureOsDisk
                //
                Assert.IsTrue(Verify.AzureOsDisk(vm, "Windows", HostCaching.ReadWrite));

                //
                // Set-AzureDataDisk
                //
                SetAzureDataDiskConfig setAzureDataDiskConfigInfo = new SetAzureDataDiskConfig(HostCaching.ReadOnly, lunSlot1);
                setAzureDataDiskConfigInfo.Vm = vm;
                vm = vmPowershellCmdlets.SetAzureDataDisk(setAzureDataDiskConfigInfo);
                RecordTimeTaken(ref prevTime);

                //
                // Remove-AzureDataDisk
                //
                RemoveAzureDataDiskConfig removeAzureDataDiskConfig = new RemoveAzureDataDiskConfig(lunSlot2, vm);
                vm = vmPowershellCmdlets.RemoveAzureDataDisk(removeAzureDataDiskConfig);
                RecordTimeTaken(ref prevTime);

                //
                // Set-AzureEndpoint
                //
                azureEndPointConfigInfo2 = new AzureEndPointConfigInfo(
                    AzureEndPointConfigInfo.ParameterSet.CustomProbe,
                    ProtocolInfo.tcp,
                    ep2LocalPortChanged,
                    ep2PublicPortChanged,
                    ep2Name,
                    ep2LBSetName,
                    ep2ProbePort,
                    ProtocolInfo.http,
                    ep2ProbePath,
                    ep2ProbeInterval,
                    ep2ProbeTimeout,
                    ep2AclObj,
                    ep2DirectServerReturn);

                azureEndPointConfigInfo2.Vm = vm;
                vm = vmPowershellCmdlets.SetAzureEndPoint(azureEndPointConfigInfo2);
                RecordTimeTaken(ref prevTime);

                //
                // Remove-AzureEndpoint
                //
                vm = vmPowershellCmdlets.RemoveAzureEndPoint(azureEndPointConfigInfo1.EndpointName, vm);
                RecordTimeTaken(ref prevTime);

                //
                // Set-AzureVMSize
                //
                var vmSizeConfig = new SetAzureVMSizeConfig(InstanceSize.Medium.ToString());
                vmSizeConfig.Vm = vm;
                vm = vmPowershellCmdlets.SetAzureVMSize(vmSizeConfig);
                RecordTimeTaken(ref prevTime);

                //
                // Set-AzureOSDisk
                //
                vm = vmPowershellCmdlets.SetAzureOSDisk(HostCaching.ReadOnly, vm);


                //
                // Update-AzureVM
                //
                vmPowershellCmdlets.UpdateAzureVM(newAzureVMName, serviceName, vm);
                RecordTimeTaken(ref prevTime);

                //
                // Get-AzureVM and Verify the VM
                //
                vm = vmPowershellCmdlets.GetAzureVM(newAzureVMName, serviceName).VM;

                // Verify setting data disk
                Assert.IsTrue(Verify.AzureDataDisk(vm, diskLabel1, diskSize1, lunSlot1, HostCaching.ReadOnly), "Data disk is not properly added");

                // Verify removing a data disk
                Assert.AreEqual(1, vmPowershellCmdlets.GetAzureDataDisk(vm).Count, "DataDisk is not removed.");

                // Verify setting an endpoint
                Assert.IsTrue(Verify.AzureEndpoint(vm, new[] { azureEndPointConfigInfo2 }));

                // Verify removing an endpoint
                Assert.IsFalse(Verify.AzureEndpoint(vm, new[] { azureEndPointConfigInfo1 }));

                // Verify os disk
                Assert.IsTrue(Verify.AzureOsDisk(vm, "Windows", HostCaching.ReadOnly));

                //
                // Remove-AzureVM
                //
                vmPowershellCmdlets.RemoveAzureVM(newAzureVMName, serviceName);

                RecordTimeTaken(ref prevTime);

                Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureVMName, serviceName));
                pass = true;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                throw;
            }
        }
Example #20
0
 public void Intialize()
 {
     serviceName     = Utilities.GetUniqueShortName(serviceNamePrefix);
     cleanupIfPassed = true;
 }
Example #21
0
        public void CaptureGeneralizedLinuxVMAndDeploy()
        {
            string serviceName1   = Utilities.GetUniqueShortName(serviceNamePrefix);
            string linuxImageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Linux" }, false);

            try
            {
                //                a.	Deploy a new IaaS VM
                string vmName = Utilities.GetUniqueShortName(vmNamePrefix);
                Console.WriteLine("--------------------------------Deploying a new IaaS VM :{0} completed.---------------------", vmName);
                PersistentVM vm = CreateIaaSVMObjectWithDisk(vmName, InstanceSize.Small, linuxImageName, false, username, password);
                vmPowershellCmdlets.NewAzureVM(serviceName, new[] { vm }, locationName);
                Console.WriteLine("--------------------------------Deploying a new IaaS VM :{0} completed.---------------------", vmName);
                //b.	Stop the VM
                Console.WriteLine("--------------------------------Stopping vm :{0}--------------------------------", vmName);
                vmPowershellCmdlets.StopAzureVM(vmName, serviceName, force: true);
                Console.WriteLine("--------------------------------Stopped vm :{0}--------------------------------", vmName);
                //c.	Save the VM image
                Console.WriteLine("--------------------------------Save the VM image--------------------------------");
                vmImageName = vmName + "Image";
                vmPowershellCmdlets.SaveAzureVMImage(serviceName, vmName, vmImageName, CONSTANT_GENERALIZED, vmImageName);
                Console.WriteLine("--------------------------------Saved VM image with name {0}----------------------");
                //d.	Verify the VM image by Get-AzureVMImage
                Console.WriteLine("--------------------------------Verify the VM image--------------------------------");
                VerifyVMImage(vmImageName, OS.Linux, vmImageName, CONSTANT_GENERALIZED, cahcing, lunSlot1, diskSize1, 1);
                Console.WriteLine("--------------------------------Verified that the VM image is saved successfully--------------------------------");
                //e.	Deploy a new IaaS VM with the save VM image
                Console.WriteLine("--------------------------------Deploy a new IaaS VM with the saved VM image {0}--------------------------------", vmImageName);
                string vmName1 = Utilities.GetUniqueShortName(vmNamePrefix);
                vm = Utilities.CreateIaaSVMObject(vmName1, InstanceSize.Small, vmImageName, false, username, password);
                vmPowershellCmdlets.NewAzureVM(serviceName1, new[] { vm }, locationName);
                Console.WriteLine("--------------------------------Deployed a IaaS VM {0} with the saved VM image {1}--------------------------------", vmName1, vmImageName);
                //f.	Verify the VM by Get-AzureVM
                Console.WriteLine("--------------------------------Verify the VM by Get-AzureVM--------------------------------", vmName1, vmImageName);
                var vmRoleContext = vmPowershellCmdlets.GetAzureVM(vmName1, serviceName1);
                Utilities.PrintContext(vmRoleContext);
                Console.WriteLine("--------------------------------Verified the VM {0} successfully--------------------------------", vmName1);
                //g.	Add another IaaS VM with the save VM image to the existing service
                string vmName2 = Utilities.GetUniqueShortName(vmNamePrefix);
                Console.WriteLine("--------------------------------Deploy a new IaaS VM with the saved VM image {0}--------------------------------", vmImageName);
                vmPowershellCmdlets.NewAzureQuickVM(OS.Linux, vmName2, serviceName1, vmImageName, username, password);
                Console.WriteLine("--------------------------------Deployed a IaaS VM {0} with the saved VM image {1}--------------------------------", vmName2, vmImageName);
                //h.	Verify the VM by Get-AzureVM
                Console.WriteLine("--------------------------------Verify the VM by Get-AzureVM--------------------------------", vmName2, vmImageName);
                vmRoleContext = vmPowershellCmdlets.GetAzureVM(vmName2, serviceName1);
                Utilities.PrintContext(vmRoleContext);
                Console.WriteLine("--------------------------------Verified the VM {0} successfully--------------------------------", vmName2);

                pass = true;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                throw;
            }
            finally
            {
                CleanupService(serviceName1);
                //Delete the VM image
                Console.WriteLine("------------------------------Delete the VM image---------------------------------");
                vmPowershellCmdlets.RemoveAzureVMImage(vmImageName, true);
                Console.WriteLine("------------------------------Deleted the VM image---------------------------------");
            }
        }
Example #22
0
        public void CreateReservedIPThenPaaSVM()
        {
            try
            {
                string reservedIpName1  = Utilities.GetUniqueShortName("ResrvdIP1");;
                string reservedIpName2  = Utilities.GetUniqueShortName("ResrvdIP2");;
                string reservedIpLabel1 = Utilities.GetUniqueShortName("ResrvdIPLbl", 5);
                string reservedIpLabel2 = Utilities.GetUniqueShortName("ResrvdIPLbl", 5);
                string dnsName          = Utilities.GetUniqueShortName("Dns");
                string deploymentName   = Utilities.GetUniqueShortName("Depl");
                var    input1           = new ReservedIPContext()
                {
                    DeploymentName = string.Empty,
                    Label          = reservedIpLabel1,
                    InUse          = false,
                    Location       = locationName,
                    ReservedIPName = reservedIpName1,
                    State          = "Created"
                };

                var input2 = new ReservedIPContext()
                {
                    DeploymentName = string.Empty,
                    Label          = reservedIpLabel2,
                    InUse          = false,
                    Location       = locationName,
                    ReservedIPName = reservedIpName2,
                    State          = "Created"
                };

                // Reserve a new IP
                Utilities.ExecuteAndLog(() => vmPowershellCmdlets.NewAzureReservedIP(reservedIpName1, locationName, reservedIpLabel1), "Reserve a new IP");
                //Get the reserved ip and verify the reserved Ip properties.
                VerifyReservedIpNotInUse(input1);

                // Reserve a new IP
                Utilities.ExecuteAndLog(() => vmPowershellCmdlets.NewAzureReservedIP(reservedIpName2, locationName, reservedIpLabel2), "Reserve a new IP");
                //Get the reserved ip and verify the reserved Ip properties.
                VerifyReservedIpNotInUse(input2);

                vmPowershellCmdlets.NewAzureService(serviceName, locationName);


                var _packageName       = Convert.ToString(TestContext.DataRow["packageName"]);
                var _configName1       = Convert.ToString(TestContext.DataRow["configName1"]);
                var _configName2       = Convert.ToString(TestContext.DataRow["configName2"]);
                var _configName1update = Convert.ToString(TestContext.DataRow["updateConfig1"]);
                var _configName2update = Convert.ToString(TestContext.DataRow["updateConfig2"]);

                var _packagePath       = new FileInfo(Directory.GetCurrentDirectory() + "\\" + _packageName);
                var _configPath1       = new FileInfo(Directory.GetCurrentDirectory() + "\\" + _configName1);
                var _configPath2       = new FileInfo(Directory.GetCurrentDirectory() + "\\" + _configName2);
                var _configPath1update = new FileInfo(Directory.GetCurrentDirectory() + "\\" + _configName1update);
                var _configPath2update = new FileInfo(Directory.GetCurrentDirectory() + "\\" + _configName2update);


                vmPowershellCmdlets.NewAzureDeployment(serviceName, _packagePath.FullName, _configPath1.FullName,
                                                       DeploymentSlotType.Production, "label", deploymentName, false, false);

                vmPowershellCmdlets.NewAzureDeployment(serviceName, _packagePath.FullName, _configPath2.FullName,
                                                       DeploymentSlotType.Staging, "label", deploymentName, false, false);



                vmPowershellCmdlets.MoveAzureDeployment(serviceName);

                vmPowershellCmdlets.GetAzureDeployment(serviceName, DeploymentSlotType.Production);
                vmPowershellCmdlets.GetAzureDeployment(serviceName, DeploymentSlotType.Staging);

                vmPowershellCmdlets.SetAzureDeploymentConfig(serviceName, DeploymentSlotType.Production, _configPath1update.FullName);
                vmPowershellCmdlets.SetAzureDeploymentConfig(serviceName, DeploymentSlotType.Staging, _configPath2update.FullName);



                pass = true;
            }
            catch (Exception ex)
            {
                pass = false;
                Console.WriteLine(ex.ToString());
                throw;
            }
        }
Example #23
0
 public void SaveAzureVMImageNegativeTest()
 {
     try
     {
         string vmName = Utilities.GetUniqueShortName(vmNamePrefix);
         //      Deploy a new IaaS VM
         Console.WriteLine("------------------------------Deploy a new IaaS VM---------------------------------");
         var vm = CreateIaaSVMObjectWithDisk(vmName, InstanceSize.Small, imageName, true, username, password);
         vmPowershellCmdlets.NewAzureVM(serviceName, new[] { vm }, locationName);
         Console.WriteLine("------------------------------Deploy a new IaaS VM: completed---------------------------------");
         //b.	Stop the VM
         Console.WriteLine("------------------------------Stop the VM---------------------------------");
         vmPowershellCmdlets.StopAzureVM(vm, serviceName, force: true);
         Console.WriteLine("------------------------------Stop the VM: completed---------------------------------");
         //c.	Save the VM image
         Console.WriteLine("------------------------------Save the VM image---------------------------------");
         vmImageName = vmName + "Image";
         vmPowershellCmdlets.SaveAzureVMImage(serviceName, vmName, vmImageName, CONSTANT_SPECIALIZED, vmImageName);
         Console.WriteLine("------------------------------Save the VM image: completed---------------------------------");
         //d.	Deploy another new IaaS VM
         Console.WriteLine("------------------------------Deploy another new IaaS VM---------------------------------");
         string vmName1 = Utilities.GetUniqueShortName(vmNamePrefix);
         vm = CreateIaaSVMObjectWithDisk(vmName1, InstanceSize.Small, imageName, true, username, password);
         vmPowershellCmdlets.NewAzureVM(serviceName, new[] { vm });
         Console.WriteLine("------------------------------Deploy another new IaaS VM: completed---------------------------------");
         //e.	Stop the VM
         Console.WriteLine("------------------------------Deleted the VM image---------------------------------");
         vmPowershellCmdlets.StopAzureVM(vm, serviceName, force: true);
         string testImageName = Utilities.GetUniqueShortName(vmNamePrefix);
         Console.WriteLine("------------------------------Deleted the VM image---------------------------------");
         //f.	Try to save the VM image with the existing name (must fail)
         Console.WriteLine("------------------------------Deleted the VM image---------------------------------");
         Utilities.VerifyFailure(() => vmPowershellCmdlets.SaveAzureVMImage(serviceName, vmName1, vmImageName, CONSTANT_SPECIALIZED, vmImageName), ConflictErrorException);
         Console.WriteLine("------------------------------Deleted the VM image---------------------------------");
         //g.	Try to save the VM image with the wrong vm name (must fail)
         Console.WriteLine("------------------------------Deleted the VM image---------------------------------");
         Utilities.VerifyFailure(() => vmPowershellCmdlets.SaveAzureVMImage(serviceName, Utilities.GetUniqueShortName(vmNamePrefix), testImageName, CONSTANT_SPECIALIZED, testImageName), ResourceNotFoundException);
         Console.WriteLine("------------------------------Deleted the VM image---------------------------------");
         //h.	Try to save the VM image with the wrong service name (must fail)
         Console.WriteLine("------------------------------Deleted the VM image---------------------------------");
         string testVMIMage = Utilities.GetUniqueShortName("VMImage");
         vmPowershellCmdlets.SaveAzureVMImage(Utilities.GetUniqueShortName(vmNamePrefix), vmName1, testVMIMage, CONSTANT_SPECIALIZED, testVMIMage);
         Utilities.VerifyFailure(() => vmPowershellCmdlets.GetAzureVMImage(testVMIMage), ResourceNotFoundException);
         Console.WriteLine("------------------------------Deleted the VM image---------------------------------");
         //i.	Try to save the VM image with the label longer than maximum length of string (must fail)
         Console.WriteLine("------------------------------Deleted the VM image---------------------------------");
         string LongImageName = Utilities.GetUniqueShortName(length: 30) + Utilities.GetUniqueShortName(length: 30) + Guid.NewGuid().ToString() + Guid.NewGuid().ToString();
         Console.WriteLine("Attempting to save a VMImage with name {0} of {1} characters and expecting it to fail.", LongImageName, LongImageName.Length);
         Utilities.VerifyFailure(() => vmPowershellCmdlets.SaveAzureVMImage(serviceName, vmName1, testImageName, CONSTANT_SPECIALIZED, LongImageName), BadRequestException);
         Console.WriteLine("------------------------------Deleted the VM image---------------------------------");
         pass = true;
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.ToString());
         throw;
     }
     finally
     {
         Console.WriteLine("------------------------------Delete the VM image---------------------------------");
         DeleteVMImageIfExists(vmImageName);
         Console.WriteLine("------------------------------Deleted the VM image---------------------------------");
     }
 }
Example #24
0
        public void SaveAzureVhdAllTest()
        {
            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);

            // Choose the vhd path in your local machine
            string   vhdName      = Convert.ToString(TestContext.DataRow["vhdLocalPath"]) + Utilities.GetUniqueShortName();
            FileInfo vhdLocalPath = new FileInfo(vhdName);

            // Download and verify it.
            SaveVhdAndAssertContent(blobHandle, vhdLocalPath, 16, storageAccountKey.Secondary, true, false, true);

            // Download with overwrite and verify it.
            SaveVhdAndAssertContent(blobHandle, vhdLocalPath, 32, storageAccountKey.Primary, true, false, true);

            DateTime testEndTime = DateTime.Now;

            Console.WriteLine("{0} test passed at {1}.", testName, testEndTime);

            //System.IO.File.AppendAllLines(perfFile, new string[] { String.Format("{0},{1}", testName, (testEndTime - testStartTime).TotalSeconds) });
        }
Example #25
0
        public void HiMemVMSizeTest()
        {
            string serviceName = Utilities.GetUniqueShortName(serviceNamePrefix);
            string vmName      = Utilities.GetUniqueShortName(vmNamePrefix);

            try
            {
                // New-AzureQuickVM test for VM size 'A5'
                vmPowershellCmdlets.NewAzureQuickVM(OS.Windows, vmName, serviceName, imageName, username, password, locationName, InstanceSize.A5.ToString());
                PersistentVMRoleContext result       = vmPowershellCmdlets.GetAzureVM(vmName, serviceName);
                RoleSizeContext         returnedSize = vmPowershellCmdlets.GetAzureRoleSize(result.InstanceSize)[0];
                Assert.AreEqual(InstanceSize.A5.ToString(), returnedSize.InstanceSize);
                Console.WriteLine("VM size, {0}, is verified for New-AzureQuickVM", InstanceSize.A5);
                vmPowershellCmdlets.RemoveAzureService(serviceName);

                // New-AzureQuickVM test for VM size 'A6'
                vmPowershellCmdlets.NewAzureQuickVM(OS.Windows, vmName, serviceName, imageName, username, password, locationName, InstanceSize.A6.ToString());
                result       = vmPowershellCmdlets.GetAzureVM(vmName, serviceName);
                returnedSize = vmPowershellCmdlets.GetAzureRoleSize(result.InstanceSize)[0];
                Assert.AreEqual(InstanceSize.A6.ToString(), returnedSize.InstanceSize);
                Console.WriteLine("VM size, {0}, is verified for New-AzureQuickVM", InstanceSize.A6);
                vmPowershellCmdlets.RemoveAzureService(serviceName);

                // New-AzureVMConfig test for VM size 'A7'
                var          azureVMConfigInfo       = new AzureVMConfigInfo(vmName, InstanceSize.A7.ToString(), imageName);
                var          azureProvisioningConfig = new AzureProvisioningConfigInfo(OS.Windows, username, password);
                var          persistentVMConfigInfo  = new PersistentVMConfigInfo(azureVMConfigInfo, azureProvisioningConfig, null, null);
                PersistentVM vm = vmPowershellCmdlets.GetPersistentVM(persistentVMConfigInfo);
                vmPowershellCmdlets.NewAzureVM(serviceName, new[] { vm }, locationName);
                result       = vmPowershellCmdlets.GetAzureVM(vmName, serviceName);
                returnedSize = vmPowershellCmdlets.GetAzureRoleSize(result.InstanceSize)[0];
                Assert.AreEqual(InstanceSize.A7.ToString(), returnedSize.InstanceSize);
                Console.WriteLine("VM size, {0}, is verified for New-AzureVMConfig", InstanceSize.A7);

                // Set-AzureVMSize test for Hi-MEM VM size (A7 to A6)
                vmPowershellCmdlets.SetVMSize(vmName, serviceName, new SetAzureVMSizeConfig(InstanceSize.A6.ToString()));
                result       = vmPowershellCmdlets.GetAzureVM(vmName, serviceName);
                returnedSize = vmPowershellCmdlets.GetAzureRoleSize(result.InstanceSize)[0];
                Assert.AreEqual(InstanceSize.A6.ToString(), returnedSize.InstanceSize);
                Console.WriteLine("SetVMSize is verified from A7 to A6");

                // Set-AzureVMSize test for Hi-MEM VM size (A6 to A5)
                vmPowershellCmdlets.SetVMSize(vmName, serviceName, new SetAzureVMSizeConfig(InstanceSize.A5.ToString()));
                result       = vmPowershellCmdlets.GetAzureVM(vmName, serviceName);
                returnedSize = vmPowershellCmdlets.GetAzureRoleSize(result.InstanceSize)[0];
                Assert.AreEqual(InstanceSize.A5.ToString(), returnedSize.InstanceSize);
                Console.WriteLine("SetVMSize is verified from A6 to A5");

                pass = true;
            }
            catch (Exception e)
            {
                pass = false;
                Console.WriteLine("Exception occurred: {0}", e.ToString());
                throw;
            }
            finally
            {
                if (!Utilities.CheckRemove(vmPowershellCmdlets.GetAzureService, serviceName))
                {
                    if ((cleanupIfFailed && !pass) || (cleanupIfPassed && pass))
                    {
                        vmPowershellCmdlets.RemoveAzureService(serviceName);
                    }
                }
            }
        }
Example #26
0
        public void NewAzureVMWithResizeDiskTest()
        {
            imageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Windows" }, false, 50);
            string    newVMImageName = Utilities.GetUniqueShortName("vmimage");
            const int newDiskSize    = 100;

            try
            {
                vmPowershellCmdlets.NewAzureQuickVM(OS.Windows, _vmName, _serviceName, imageName, username, password, locationName);
                Console.WriteLine("Service Name: {0} is created.  VM: {1} is created.", _serviceName, _vmName);

                string diskLabel1 = "disk1";
                int    diskSize1  = 30;
                int    lunSlot1   = 0;

                string diskLabel2 = "disk2";
                int    diskSize2  = 50;
                int    lunSlot2   = 2;

                AddAzureDataDiskConfig dataDiskInfo1 = new AddAzureDataDiskConfig(DiskCreateOption.CreateNew, diskSize1, diskLabel1, lunSlot1);
                AddAzureDataDiskConfig dataDiskInfo2 = new AddAzureDataDiskConfig(DiskCreateOption.CreateNew, diskSize2, diskLabel2, lunSlot2);

                vmPowershellCmdlets.AddDataDisk(_vmName, _serviceName, new[] { dataDiskInfo1, dataDiskInfo2 });

                vmPowershellCmdlets.SaveAzureVMImage(_serviceName, _vmName, newVMImageName, "Specialized");

                var newImage = vmPowershellCmdlets.GetAzureVMImageReturningVMImages(newVMImageName).FirstOrDefault();

                foreach (var disk in newImage.DataDiskConfigurations)
                {
                    Utilities.PrintContextAndItsBase(disk);
                }

                string disk1 = newImage.DataDiskConfigurations[0].Name;
                string disk2 = newImage.DataDiskConfigurations[1].Name;

                vmPowershellCmdlets.RemoveAzureService(_serviceName);

                // Add-AzureProvisioningConfig with NoSSHEndpoint
                var vm = vmPowershellCmdlets.NewAzureVMConfig(new AzureVMConfigInfo(_vmName, InstanceSize.Small.ToString(), newVMImageName));
                vm = vmPowershellCmdlets.SetAzureDataDisk(new SetAzureDataDiskResizeConfig(disk1, newDiskSize, vm));
                vm = vmPowershellCmdlets.SetAzureDataDisk(new SetAzureDataDiskResizeConfig(disk2, newDiskSize, vm));
                vm = vmPowershellCmdlets.SetAzureOSDisk(null, vm, newDiskSize);

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

                // Validate disk sizes
                var returnedVM = vmPowershellCmdlets.GetAzureVM(_vmName, _serviceName);
                foreach (var disk in returnedVM.VM.DataVirtualHardDisks)
                {
                    Utilities.PrintContextAndItsBase(disk);
                }
                Assert.AreEqual(newDiskSize, returnedVM.VM.DataVirtualHardDisks[0].LogicalDiskSizeInGB);
                Assert.AreEqual(newDiskSize, returnedVM.VM.DataVirtualHardDisks[1].LogicalDiskSizeInGB);

                pass = true;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                if (ex.InnerException != null)
                {
                    Console.WriteLine(ex.InnerException);
                }
                throw;
            }
            finally
            {
                vmPowershellCmdlets.RemoveAzureService(_serviceName);
                vmPowershellCmdlets.RemoveAzureVMImage(newVMImageName, true);
            }
        }