public AddAzureDataDiskCmdletInfo(AddAzureDataDiskConfig diskConfig)
 {
     this.cmdletName = Utilities.AddAzureDataDiskCmdletName;
                
     this.cmdletParams.Add(new CmdletParam("CreateNew", null));
     this.cmdletParams.Add(new CmdletParam("DiskSizeInGB", diskConfig.DiskSizeGB));
     this.cmdletParams.Add(new CmdletParam("DiskLabel", diskConfig.DiskLabel));
     this.cmdletParams.Add(new CmdletParam("LUN", diskConfig.LunSlot));
     this.cmdletParams.Add(new CmdletParam("VM", diskConfig.Vm));
     if (!string.IsNullOrEmpty(diskConfig.HostCaching))
     this.cmdletParams.Add(new CmdletParam("HostCaching",diskConfig.HostCaching));
 }
Esempio n. 2
0
        public void AdvancedProvisioning()
        {
            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);

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

            vmPowershellCmdlets.NewAzureService(serviceName, serviceName, locationName);

            var azureVMConfigInfo1 = new AzureVMConfigInfo(newAzureVM1Name, InstanceSize.ExtraSmall.ToString(), imageName);
            var azureVMConfigInfo2 = new AzureVMConfigInfo(newAzureVM2Name, 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);
            var persistentVMConfigInfo2 = new PersistentVMConfigInfo(azureVMConfigInfo2, azureProvisioningConfig, azureDataDiskConfigInfo, azureEndPointConfigInfo);

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

            PersistentVM[] VMs = { persistentVM1, persistentVM2 };
            vmPowershellCmdlets.NewAzureVM(serviceName, VMs);

            // Cleanup
            vmPowershellCmdlets.RemoveAzureVM(newAzureVM1Name, serviceName);
            vmPowershellCmdlets.RemoveAzureVM(newAzureVM2Name, serviceName);

            Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureVM1Name, serviceName));
            Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureVM2Name, serviceName));
            pass = true;
        }
 private static PersistentVM CreateVMWithEndpointDataDiskAndPublicIP(string vmName, string endpointName, string disklabel1, string publicIpName, string serviceName, int localPort, int publicport, string publicIpDomainNameLabel = null)
 {
     var vm1 = Utilities.CreateIaaSVMObject(vmName, InstanceSize.Small, imageName, true, username, password);
     var endpointConfiginput = new AzureEndPointConfigInfo(AzureEndPointConfigInfo.ParameterSet.NoLB, TCP_PROTOCAL, localPort, publicport, endpointName, serviceName: serviceName);
     endpointConfiginput.Vm = vm1;
     vm1 = vmPowershellCmdlets.AddAzureEndPoint(endpointConfiginput);
     var dataDiskConfig1 = new AddAzureDataDiskConfig(DiskCreateOption.CreateNew, 128, disklabel1, 0);
     dataDiskConfig1.Vm = vm1;
     vm1 = vmPowershellCmdlets.AddAzureDataDisk(dataDiskConfig1);
     vm1 = (PersistentVM)vmPowershellCmdlets.SetAzurePublicIp(publicIpName, vm1, publicIpDomainNameLabel);
     return vm1;
 }
        public void AddEndPointACLsWithNewDeployment()
        {
            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);

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

            vmPowershellCmdlets.NewAzureService(serviceName, serviceName, locationName);

            NetworkAclObject aclObj = vmPowershellCmdlets.NewAzureAclConfig();
            vmPowershellCmdlets.SetAzureAclConfig(SetACLConfig.AddRule, aclObj, 100, ACLAction.Permit, "172.0.0.0/8", "notes1");
            vmPowershellCmdlets.SetAzureAclConfig(SetACLConfig.AddRule, aclObj, 200, ACLAction.Deny, "10.0.0.0/8", "notes2");

            var azureVMConfigInfo1 = new AzureVMConfigInfo(newAzureVM1Name, InstanceSize.ExtraSmall.ToString(), imageName);
            var azureVMConfigInfo2 = new AzureVMConfigInfo(newAzureVM2Name, 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.DefaultProbe, ProtocolInfo.tcp, 80, 80, "web", "lbweb", aclObj, true);

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

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

            PersistentVM[] VMs = { persistentVM1, persistentVM2 };
            vmPowershellCmdlets.NewAzureVM(serviceName, VMs);

            // Cleanup
            vmPowershellCmdlets.RemoveAzureVM(newAzureVM1Name, serviceName);
            vmPowershellCmdlets.RemoveAzureVM(newAzureVM2Name, serviceName);

            Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureVM1Name, serviceName));
            Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureVM2Name, serviceName));
            pass = true;
        }
 public PersistentVM CreateIaaSVMObjectWithDisk(string vmName, InstanceSize size, string imageName, bool isWindows, string username, string password)
 {
     PersistentVM vm = Utilities.CreateIaaSVMObject(vmName, InstanceSize.Small, imageName, isWindows, username, password);
     AddAzureDataDiskConfig azureDataDiskConfigInfo1 = new AddAzureDataDiskConfig(DiskCreateOption.CreateNew, diskSize1, diskLabel1, lunSlot1,cahcing.ToString());
     azureDataDiskConfigInfo1.Vm = vm;
     return vmPowershellCmdlets.AddAzureDataDisk(azureDataDiskConfigInfo1);
 }
        public void UpdateVMImageDataDiskAndOsDiskTest()
        {
            StartTest(MethodBase.GetCurrentMethod().Name, DateTime.Now);
            try
            {
                //Create a new vmImage with 2 data disks
                string vmName = Utilities.GetUniqueShortName(vmNamePrefix);
                string disk1 = "Disk1";
                string disk2 = "Disk2";
                HostCaching disk1HostCaching = HostCaching.ReadOnly;
                HostCaching disk2HostCaching = HostCaching.None;

                //Creating VM with 2 data disks.;
                Utilities.ExecuteAndLog(() =>
                    {
                        PersistentVM vm = Utilities.CreateIaaSVMObject(vmName, InstanceSize.Small, imageName, true, username, password);
                        //Attach disk 1 with hostcaching 'Readonly'
                        AddAzureDataDiskConfig azureDataDiskConfigInfo1 = new AddAzureDataDiskConfig(DiskCreateOption.CreateNew, diskSize1, disk1, 0, disk1HostCaching.ToString());
                        azureDataDiskConfigInfo1.Vm = vm;
                        vm = vmPowershellCmdlets.AddAzureDataDisk(azureDataDiskConfigInfo1);
                        //Attach disk 2 with hostcaching 'None'
                        AddAzureDataDiskConfig azureDataDiskConfigInfo2 = new AddAzureDataDiskConfig(DiskCreateOption.CreateNew, diskSize1, disk2, 1, disk2HostCaching.ToString());
                        azureDataDiskConfigInfo2.Vm = vm;
                        vm = vmPowershellCmdlets.AddAzureDataDisk(azureDataDiskConfigInfo2);
                        //deploy the VM
                        vmPowershellCmdlets.NewAzureVM(serviceName, new[] { vm }, locationName);
                    },"Creating VM with 2 data disks.");

                //Save image of the VM as a Specialized vm image.
                vmImageName = vmName + "Image";
                Utilities.ExecuteAndLog(() => 
                {
                    Utilities.PrintHeader("Save specialized vm image of the deployed vm.");
                    vmPowershellCmdlets.StopAzureVM(vmPowershellCmdlets.GetAzureVM(vmName, serviceName).VM, serviceName,force:true);
                    vmPowershellCmdlets.SaveAzureVMImage(serviceName, vmName, vmImageName, "Specialized", vmImageName);
                },"Save specialized vm image of the deployed vm.");

                //Verify the saved vm Image
                DataDiskConfigurationList diskConfig = new DataDiskConfigurationList();
                Utilities.ExecuteAndLog(() => 
                {
                    diskConfig.Add(new DataDiskConfiguration() { Lun = 0, LogicalDiskSizeInGB = diskSize1, HostCaching = disk1HostCaching.ToString() });
                    diskConfig.Add(new DataDiskConfiguration() { Lun = 1, LogicalDiskSizeInGB = diskSize1, HostCaching = disk2HostCaching.ToString() });
                    VerifyVMImage(vmImageName, OS.Windows, vmImageName, "Specialized", cahcing, diskConfig);
                },"Fetch the saved vm image info and verify the vm image info.");


                UpdateAzureVMImageDetails(vmImageName);

                string disk1Name,disk2Name;
                UpdateVMImageOsAndDataDiskAnderifyChanges(diskConfig, out disk1Name, out disk2Name);

                //Update VMImage using DiskConfig set prepared manually.
                UpdateVmImageUsingDiskConfigSetAndVerifyChanges(diskConfig, disk1Name, disk2Name);
                pass = true;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                throw ex;
            }

        }
 private bool CheckDataDisk(string vmName, string serviceName, AddAzureDataDiskConfig dataDiskInfo, HostCaching hc)
 {
     bool found = false;
     foreach (DataVirtualHardDisk disk in vmPowershellCmdlets.GetAzureDataDisk(vmName, serviceName))
     {
         Console.WriteLine("DataDisk - Name:{0}, Label:{1}, Size:{2}, LUN:{3}, HostCaching: {4}", disk.DiskName, disk.DiskLabel, disk.LogicalDiskSizeInGB, disk.Lun, disk.HostCaching);
         if (disk.DiskLabel == dataDiskInfo.DiskLabel && disk.LogicalDiskSizeInGB == dataDiskInfo.DiskSizeGB && disk.Lun == dataDiskInfo.LunSlot)
         {
             if (disk.HostCaching == hc.ToString())
             {
                 found = true;
                 Console.WriteLine("DataDisk found: {0}", disk.DiskLabel);
             }
         }
     }
     return found;
 }
        public void AzureDataDiskTest()
        {
            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);
            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;


            try
            {
                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 }); // Add-AzureDataDisk with Get-AzureVM and Update-AzureVm

                Assert.IsTrue(CheckDataDisk(vmName, serviceName, dataDiskInfo1, HostCaching.None), "Data disk is not properly added");
                Console.WriteLine("Data disk added correctly.");

                Assert.IsTrue(CheckDataDisk(vmName, serviceName, dataDiskInfo2, HostCaching.None), "Data disk is not properly added");
                Console.WriteLine("Data disk added correctly.");

                vmPowershellCmdlets.SetDataDisk(vmName, serviceName, HostCaching.ReadOnly, lunSlot1);
                Assert.IsTrue(CheckDataDisk(vmName, serviceName, dataDiskInfo1, HostCaching.ReadOnly), "Data disk is not properly changed");
                Console.WriteLine("Data disk is changed correctly.");

                pass = true;

            }
            catch (Exception e)
            {
                pass = false;
                Assert.Fail("Exception occurred: {0}", e.ToString());
            }
            finally
            {
                // Remove DataDisks created
                foreach (DataVirtualHardDisk disk in vmPowershellCmdlets.GetAzureDataDisk(vmName, serviceName))
                {
                    vmPowershellCmdlets.RemoveDataDisk(vmName, serviceName, new[] { disk.Lun }); // Remove-AzureDataDisk
                    RemoveDisk(disk.DiskName, 10);
                }
                Assert.AreEqual(0, vmPowershellCmdlets.GetAzureDataDisk(vmName, serviceName).Count, "DataDisk is not removed.");
            }
        }
        public void UpdateAndReboot()
        {
            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);

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

            vmPowershellCmdlets.NewAzureQuickVM(OS.Windows, newAzureQuickVMName, serviceName, imageName, username, password, locationName);

            var azureDataDiskConfigInfo1 = new AddAzureDataDiskConfig(DiskCreateOption.CreateNew, 50, "datadisk1", 0);
            var azureDataDiskConfigInfo2 = new AddAzureDataDiskConfig(DiskCreateOption.CreateNew, 50, "datadisk2", 1);
            AddAzureDataDiskConfig[] dataDiskConfig = { azureDataDiskConfigInfo1, azureDataDiskConfigInfo2 };
            vmPowershellCmdlets.AddVMDataDisks(newAzureQuickVMName, serviceName, dataDiskConfig);

            var setAzureDataDiskConfig1 = new SetAzureDataDiskConfig(HostCaching.ReadOnly, 0);
            var setAzureDataDiskConfig2 = new SetAzureDataDiskConfig(HostCaching.ReadOnly, 0);
            SetAzureDataDiskConfig[] diskConfig = { setAzureDataDiskConfig1, setAzureDataDiskConfig2 };
            vmPowershellCmdlets.SetVMDataDisks(newAzureQuickVMName, serviceName, diskConfig);

            var vmSizeConfig = new SetAzureVMSizeConfig(InstanceSize.Medium.ToString());
            vmPowershellCmdlets.SetVMSize(newAzureQuickVMName, serviceName, vmSizeConfig);

            // Cleanup
            vmPowershellCmdlets.RemoveAzureVM(newAzureQuickVMName, serviceName);
            Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureQuickVMName, serviceName));
            pass = true;
        }
Esempio n. 10
0
        public void ModifyingVM()
        {
            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);

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

            vmPowershellCmdlets.NewAzureQuickVM(OS.Windows, newAzureQuickVMName, serviceName, imageName, username, password, locationName);

            AddAzureDataDiskConfig azureDataDiskConfigInfo1 = new AddAzureDataDiskConfig(DiskCreateOption.CreateNew, 50, "datadisk1", 0);
            AddAzureDataDiskConfig azureDataDiskConfigInfo2 = new AddAzureDataDiskConfig(DiskCreateOption.CreateNew, 50, "datadisk2", 1);
            AzureEndPointConfigInfo azureEndPointConfigInfo = new AzureEndPointConfigInfo(AzureEndPointConfigInfo.ParameterSet.NoLB, ProtocolInfo.tcp, 1433, 2000, "sql");
            AddAzureDataDiskConfig[] dataDiskConfig = { azureDataDiskConfigInfo1, azureDataDiskConfigInfo2 };
            vmPowershellCmdlets.AddVMDataDisksAndEndPoint(newAzureQuickVMName, serviceName, dataDiskConfig, azureEndPointConfigInfo);

            SetAzureDataDiskConfig setAzureDataDiskConfig1 = new SetAzureDataDiskConfig(HostCaching.ReadWrite, 0);
            SetAzureDataDiskConfig setAzureDataDiskConfig2 = new SetAzureDataDiskConfig(HostCaching.ReadWrite, 0);
            SetAzureDataDiskConfig[] diskConfig = { setAzureDataDiskConfig1, setAzureDataDiskConfig2 };
            vmPowershellCmdlets.SetVMDataDisks(newAzureQuickVMName, serviceName, diskConfig);

            vmPowershellCmdlets.GetAzureDataDisk(newAzureQuickVMName, serviceName);

            // Cleanup
            vmPowershellCmdlets.RemoveAzureVM(newAzureQuickVMName, serviceName);

            Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureQuickVMName, serviceName));
            pass = true;
        }
        private PersistentVM CreateVMObjectWithDataDiskSubnetAndAvailibilitySet(string vmName, OS os)
        {
            string disk1 = "Disk1";
            int diskSize = 30;
            string availabilitySetName = Utilities.GetUniqueShortName("AvailSet");
            string img = string.Empty;

            bool isWindowsOs = false;
            if (os == OS.Windows)
            {
                img = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Windows" }, false);
                isWindowsOs = true;
            }
            else
            {
                img = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Linux" }, false);
                isWindowsOs = false;
            }

            PersistentVM vm = Utilities.CreateIaaSVMObject(vmName, InstanceSize.Small, img, isWindowsOs,username, password);
            AddAzureDataDiskConfig azureDataDiskConfigInfo1 = new AddAzureDataDiskConfig(DiskCreateOption.CreateNew, diskSize, disk1, 0, HostCaching.ReadWrite.ToString());
            azureDataDiskConfigInfo1.Vm = vm;

            vm = vmPowershellCmdlets.SetAzureSubnet(vm, new string[] {subnet});
            vm = vmPowershellCmdlets.SetAzureAvailabilitySet(availabilitySetName, vm);
            return vm;
        }
Esempio n. 12
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
                //
                AzureVMConfigInfo azureVMConfigInfo = new AzureVMConfigInfo(newAzureVMName, InstanceSize.Small, 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);

                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
                //
                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 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
                //
                SetAzureVMSizeConfig vmSizeConfig = new SetAzureVMSizeConfig(InstanceSize.Medium);
                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;
            }
        }
        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);
            }
        }
Esempio n. 14
0
        public void StopDeallocationReservedIPTest()
        {
            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 };

                // Create a new deployment
                vmPowershellCmdlets.NewAzureVM(svcNameLoc, VMs, locationName);

                // Reserve the ip of the deployment
                vmPowershellCmdlets.NewAzureAffinityGroup(affName1, locationName, null, null);
                vmPowershellCmdlets.NewAzureReservedIP(rsvIpName1, affName1, svcNameLoc, svcNameLoc, rsvIPLabel);

                // Get the deployment and verify
                var deploymentReturned = vmPowershellCmdlets.GetAzureDeployment(svcNameLoc);
                Utilities.PrintContext(deploymentReturned);

                // 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 the first VM and verify the reserved ip
                Console.WriteLine("Stopping the first VM...");
                vmPowershellCmdlets.StopAzureVM(newAzureVM1Name, svcNameLoc);

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

                // Stop the second VM and verify the reserved ip
                Console.WriteLine("Stopping the second VM...");
                vmPowershellCmdlets.StopAzureVM(newAzureVM2Name, svcNameLoc, 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);

                deploymentReturned = vmPowershellCmdlets.GetAzureDeployment(svcNameLoc);
                Utilities.PrintContext(deploymentReturned);
                Assert.AreEqual(0, deploymentReturned.VirtualIPs.Count, "The deployment still holds a VIP!");

                // Restart the VM and verify
                vmPowershellCmdlets.StartAzureVM(newAzureVM1Name, svcNameLoc);

                deploymentReturned = vmPowershellCmdlets.GetAzureDeployment(svcNameLoc);
                Utilities.PrintContext(deploymentReturned);

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

                deploymentReturned = vmPowershellCmdlets.GetAzureDeployment(svcNameLoc);
                Utilities.PrintContext(deploymentReturned);

                // Remove all VMs and service
                vmPowershellCmdlets.RemoveAzureService(svcNameLoc);
                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;
            }
        }
Esempio n. 15
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;
            }
        }