Esempio n. 1
0
        public void AzureReservedIPNegativeTest()
        {
            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);

            try
            {
                string wrongAffName        = "AffinityNotExist";
                string wrongDeploymentName = "DeploymentNotExist";
                string wrongServiceName    = "ServiceNotExist";
                string wrongReservedIPName = "ReservedIPNotExist";

                vmPowershellCmdlets.NewAzureAffinityGroup(affName1, locationName, null, null);

                // Try to create a reserved IP with a wrong affinity group name
                Utilities.VerifyFailure(
                    () => vmPowershellCmdlets.NewAzureReservedIP(rsvIpName1, wrongAffName, rsvIPLabel),
                    BadRequestException);

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

                // Try to remove an affinity group that holds a reserved IP.
                Utilities.VerifyFailure(
                    () => vmPowershellCmdlets.RemoveAzureAffinityGroup(affName1),
                    BadRequestException);

                // Try to create a reserved IP with an existing reserved ip name
                Utilities.VerifyFailure(
                    () => vmPowershellCmdlets.NewAzureReservedIP(rsvIpName1, affName1, rsvIPLabel),
                    ConflictErrorException);

                // Try to create a reserved IP with a deployment name that does not exist
                Utilities.VerifyFailure(
                    () =>
                    vmPowershellCmdlets.NewAzureReservedIP(rsvIpName2, affName1, wrongServiceName,
                                                           wrongDeploymentName,
                                                           rsvIPLabel),
                    BadRequestException);

                // Try to get a reserved IP that does not exist
                Utilities.VerifyFailure(
                    () => vmPowershellCmdlets.GetAzureReservedIP(wrongReservedIPName), ResourceNotFoundException);

                // Try to remove a reserved IP that does not exist
                Utilities.VerifyFailure(
                    () => vmPowershellCmdlets.RemoveAzureReservedIP(wrongReservedIPName), ResourceNotFoundException);

                vmPowershellCmdlets.RemoveAzureReservedIP(rsvIpName1);
                vmPowershellCmdlets.RemoveAzureAffinityGroup(affName1);

                pass = true;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Esempio n. 2
0
        public void StaticCAExhautionTest()
        {
            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);
            string vnet1   = VirtualNets[0];
            string vmName1 = Utilities.GetUniqueShortName(vmNamePrefix);

            try
            {
                //Test a static CA
                //Test-AzureStaticVNetIP-VNetName $vnet -IPAddress “10.0.0.5”
                const string ipaddress          = "10.64.0.5";
                var          availibiltyContext = vmPowershellCmdlets.TestAzureStaticVNetIP(vnet1, ipaddress);
                //Assert that it is available.
                Assert.IsTrue(availibiltyContext.IsAvailable);

                var vm = CreatIaasVMObject(vmName1, ipaddress, StaticCASubnet1);

                vmPowershellCmdlets.NewAzureVM(serviceName, new[] { vm }, vnet1, new DnsServer[1] {
                    DnsServers[0]
                },
                                               serviceName, "service for DeployVMWithStaticCATest", string.Empty, string.Empty, null, AffinityGroup);
                Console.WriteLine("New Azure service with name:{0} created successfully.", serviceName);


                availibiltyContext = vmPowershellCmdlets.TestAzureStaticVNetIP(vnet1, ipaddress);
                int availableVIPsCount = availibiltyContext.AvailableAddresses.Count();
                Console.WriteLine(string.Format("AvailableAddresses:{0}{1}", Environment.NewLine, availibiltyContext.AvailableAddresses.Aggregate((current, next) => current + Environment.NewLine + next)));
                Console.WriteLine("VIPs avilable now:{0}", availableVIPsCount);
                int i = 0;
                foreach (string ip in availibiltyContext.AvailableAddresses)
                {
                    Console.WriteLine("Creating VM-{0} with IP: {1}", ++i, ip);
                    vm = CreatIaasVMObject(Utilities.GetUniqueShortName(vmNamePrefix), ip, StaticCASubnet1);
                    vmPowershellCmdlets.NewAzureVM(serviceName, new[] { vm }, null);
                    Console.WriteLine("Created VM-{0} with IP: {1}", i, ip);
                }

                //try to create an vm and verify that it fails
                Console.WriteLine("Creating VM-{0}", ++i);
                vm = vmPowershellCmdlets.NewAzureVMConfig(new AzureVMConfigInfo(Utilities.GetUniqueShortName(vmNamePrefix), InstanceSize.Small.ToString(), imageName));
                var azureProvisioningConfig = new AzureProvisioningConfigInfo(OS.Windows, username, password);
                azureProvisioningConfig.Vm = vm;
                vm = vmPowershellCmdlets.AddAzureProvisioningConfig(azureProvisioningConfig);
                vm = vmPowershellCmdlets.SetAzureSubnet(vm, new [] { StaticCASubnet1 });
                Utilities.VerifyFailure(() => vmPowershellCmdlets.NewAzureVM(serviceName, new[] { vm }), BadRequestException);
                Console.WriteLine("Creating VM-{0} failed as expected.", i);
                pass = true;
            }
            catch (Exception)
            {
                pass = false;
                throw;
            }
        }
Esempio n. 3
0
 public void GetAzureVMImageNegativeTest()
 {
     try
     {
         skipCleanup = true;
         //  Try to get a wrong vm image.
         Utilities.VerifyFailure(() => vmPowershellCmdlets.GetAzureVMImage(Utilities.GetUniqueShortName(vmNamePrefix)), ResourceNotFoundException);
         pass = true;
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.ToString());
         throw;
     }
 }
Esempio n. 4
0
        public void PublicIpPerVMTest()
        {
            try
            {
                string vmName        = Utilities.GetUniqueShortName(vmNamePrefix);
                string vmName2       = Utilities.GetUniqueShortName(vmNamePrefix);
                string vmName3       = Utilities.GetUniqueShortName(vmNamePrefix);
                string endpointName  = Utilities.GetUniqueShortName("endpoint");
                string endpointName2 = Utilities.GetUniqueShortName("endpoint");
                string endpointName3 = Utilities.GetUniqueShortName("endpoint");
                string disklabel1    = Utilities.GetUniqueShortName("disk");
                string disklabel2    = Utilities.GetUniqueShortName("disk");
                string disklabel3    = Utilities.GetUniqueShortName("disk");
                string publicIpName  = Utilities.GetUniqueShortName("publicIp");
                string publicIpName2 = Utilities.GetUniqueShortName("publicIp");
                string publicIpName3 = Utilities.GetUniqueShortName("publicIp");

                vmPowershellCmdlets.NewAzureService(serviceName, locationName);
                var vm1 = CreateVMWithEndpointDataDiskAndPublicIP(vmName, endpointName, disklabel1, publicIpName, serviceName, LOCAL_PORT_NUMBER1, PUBLIC_PORT_NUMBER1);
                vmPowershellCmdlets.NewAzureVM(serviceName, new[] { vm1 });

                VerifyPublicIP(publicIpName, vm1);

                var vm2 = CreateVMWithEndpointDataDiskAndPublicIP(vmName2, endpointName2, disklabel2, publicIpName2, serviceName, LOCAL_PORT_NUMBER2, PUBLIC_PORT_NUMBER2);
                vmPowershellCmdlets.NewAzureVM(serviceName, new[] { vm2 });
                VerifyPublicIP(publicIpName2, vm2);

                var vm3 = CreateVMWithEndpointDataDiskAndPublicIP(vmName3, endpointName3, disklabel3, publicIpName3, serviceName, LOCAL_PORT_NUMBER3, PUBLIC_PORT_NUMBER3);
                Utilities.VerifyFailure(() => vmPowershellCmdlets.NewAzureVM(serviceName, new[] { vm3 }), BadRequestException);
                pass = true;
            }
            catch (Exception ex)
            {
                pass = false;
                Console.WriteLine(ex.InnerException.ToString());
                throw ex;
            }
        }
Esempio n. 5
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---------------------------------");
     }
 }
Esempio n. 6
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);
            }
        }
Esempio n. 7
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);
            }
        }
Esempio n. 8
0
 private void VerifyReservedIpRemoved(string reservedIpName)
 {
     Utilities.VerifyFailure(() => vmPowershellCmdlets.GetAzureReservedIP(reservedIpName), ResourceNotFoundException);
 }
Esempio n. 9
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;
            }
        }
Esempio n. 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;
            }
        }