예제 #1
0
        public void AzurePlatformVMImageMultipleLocationsTest()
        {
            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);

            try
            {
                // starting the test.
                PrintOSImageDetailsContext(vmPowershellCmdlets.GetAzurePlatformVMImage(image));

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

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

                // Check the locations of the PIR image.
                string pirlocations = vmPowershellCmdlets.GetAzureVMImage(pirImage.ImageName)[0].Location;
                Assert.IsTrue(pirlocations.Contains(location1));
                Assert.IsTrue(pirlocations.Contains(location2));
                Assert.IsFalse(pirlocations.Contains(location3));

                // Switch to the normal User and check the PIR image.
                SwitchToNormalUser();
                Assert.IsTrue(Utilities.CheckRemove(vmPowershellCmdlets.GetAzureVMImage, image));
                WaitForPIRAppear(image, publisher);

                // Switch to the publisher and make the PIR image private
                SwitchToPublisher();
                vmPowershellCmdlets.SetAzurePlatformVMImagePrivate(image);

                // Switch to the normal User and wait until the PIR image disapper
                SwitchToNormalUser();
                WaitForPIRDisappear(pirImage.ImageName);

                // Switch to the publisher and remove the PIR image.
                SwitchToPublisher();
                vmPowershellCmdlets.RemoveAzurePlatformVMImage(image);
                Assert.AreEqual(0, vmPowershellCmdlets.GetAzurePlatformVMImage(image).ReplicationProgress.Count);
                PrintOSImageDetailsContext(vmPowershellCmdlets.GetAzurePlatformVMImage(image));

                pass = true;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                throw;
            }
        }
        public void RegularVMSizeTest()
        {
            string serviceName = Utilities.GetUniqueShortName(serviceNamePrefix);
            string vmName      = Utilities.GetUniqueShortName(vmNamePrefix);

            try
            {
                var instanceSizes = vmPowershellCmdlets.GetAzureRoleSize().ToArray();
                vmPowershellCmdlets.NewAzureQuickVM(OS.Windows, vmName, serviceName, imageName, username, password, locationName, instanceSizes[1].InstanceSize);

                foreach (var instanceSize in instanceSizes)
                {
                    PersistentVMRoleContext result;
                    RoleSizeContext         returnedSize;

                    var size = instanceSize.InstanceSize;
                    if (!size.Equals(InstanceSize.A5.ToString()) &&
                        !size.Equals(InstanceSize.A6.ToString()) &&
                        !size.Equals(InstanceSize.A7.ToString()) &&
                        !size.Equals(InstanceSize.A8.ToString()) &&
                        !size.Equals(InstanceSize.A9.ToString()) &&
                        !size.Contains("Standard_"))
                    {
                        // Set-AzureVMSize test for regular VM size
                        vmPowershellCmdlets.SetVMSize(vmName, serviceName, new SetAzureVMSizeConfig(size));
                        result       = vmPowershellCmdlets.GetAzureVM(vmName, serviceName);
                        returnedSize = vmPowershellCmdlets.GetAzureRoleSize(result.InstanceSize)[0];
                        Assert.AreEqual(size, returnedSize.InstanceSize);
                        Console.WriteLine("VM size, {0}, is verified for Set-AzureVMSize", size);
                    }

                    if (size.Equals(InstanceSize.ExtraLarge.ToString()))
                    {
                        vmPowershellCmdlets.SetVMSize(vmName, serviceName, new SetAzureVMSizeConfig(InstanceSize.Small.ToString()));
                        result       = vmPowershellCmdlets.GetAzureVM(vmName, serviceName);
                        returnedSize = vmPowershellCmdlets.GetAzureRoleSize(result.InstanceSize)[0];
                        Assert.AreEqual(InstanceSize.Small.ToString(), returnedSize.InstanceSize);
                    }
                }

                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);
                    }
                }
            }
        }
        public void HiMemVMSizeTest()
        {
            string serviceName = Utilities.GetUniqueShortName(serviceNamePrefix);
            string vmName      = Utilities.GetUniqueShortName(vmNamePrefix);

            try
            {
                PersistentVMRoleContext result;

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

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

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

                vmPowershellCmdlets.SetVMSize(vmName, serviceName, new SetAzureVMSizeConfig(InstanceSize.A7));
                result = vmPowershellCmdlets.GetAzureVM(vmName, serviceName);
                Assert.AreEqual(InstanceSize.A7.ToString(), result.InstanceSize);
                Console.WriteLine("SetVMSize is verified from A6 to A7");
            }
            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);
                    }
                }
            }
        }
예제 #4
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
            {
                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));

                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 RegularVMSizeTest()
        {
            string serviceName = Utilities.GetUniqueShortName(serviceNamePrefix);
            string vmName      = Utilities.GetUniqueShortName(vmNamePrefix);

            try
            {
                Array instanceSizes = Enum.GetValues(typeof(InstanceSize));
                vmPowershellCmdlets.NewAzureQuickVM(OS.Windows, vmName, serviceName, imageName, username, password, locationName, InstanceSize.A6);
                PersistentVMRoleContext result;

                foreach (InstanceSize size in instanceSizes)
                {
                    if (!size.Equals(InstanceSize.A6) && !size.Equals(InstanceSize.A7))
                    {
                        // Set-AzureVMSize test for regular VM size
                        vmPowershellCmdlets.SetVMSize(vmName, serviceName, new SetAzureVMSizeConfig(size));
                        result = vmPowershellCmdlets.GetAzureVM(vmName, serviceName);
                        Assert.AreEqual(size.ToString(), result.InstanceSize);
                        Console.WriteLine("VM size, {0}, is verified for Set-AzureVMSize", size.ToString());
                    }

                    if (size.Equals(InstanceSize.ExtraLarge))
                    {
                        vmPowershellCmdlets.SetVMSize(vmName, serviceName, new SetAzureVMSizeConfig(InstanceSize.Small));
                        result = vmPowershellCmdlets.GetAzureVM(vmName, serviceName);
                        Assert.AreEqual(InstanceSize.Small.ToString(), result.InstanceSize);
                    }
                }

                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);
                    }
                }
            }
        }
예제 #6
0
        public void AzureDiskTest()
        {
            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);
            vhdName = "os0.vhd";
            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");

                string newLabel = "NewLabel";
                vmPowershellCmdlets.UpdateAzureDisk(vhdName, newLabel);

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

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

                vmPowershellCmdlets.RemoveAzureDisk(vhdName, false);
                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);
                }

                Assert.Fail("Exception occurs: {0}", e.ToString());
            }
        }
예제 #7
0
        private static void ReadVnetConfig()
        {
            // Read the vnetconfig file and get the names of local networks, virtual networks and affinity groups.
            XDocument vnetconfigxml = XDocument.Load(vnetConfigFilePath);

            foreach (XElement el in vnetconfigxml.Descendants())
            {
                switch (el.Name.LocalName)
                {
                case "LocalNetworkSite":
                    LocalNets.Add(el.FirstAttribute.Value);
                    List <XElement> elements   = el.Elements().ToList();
                    var             prefixlist = new AddressPrefixList();
                    prefixlist.Add(elements[0].Elements().First().Value);
                    LocalNetworkSites.Add(new LocalNetworkSite()
                    {
                        Name = el.FirstAttribute.Value,
                        VpnGatewayAddress = elements[1].Value,
                        AddressSpace      = new AddressSpace()
                        {
                            AddressPrefixes = prefixlist
                        }
                    });
                    break;

                case "VirtualNetworkSite":
                    VirtualNets.Add(el.Attribute("name").Value);
                    AffinityGroups.Add(el.Attribute("AffinityGroup").Value);
                    break;

                case "DnsServer":
                    DnsServers.Add(new DnsServer()
                    {
                        Name = el.Attribute("name").Value, Address = el.Attribute("IPAddress").Value
                    });
                    break;
                }
            }

            foreach (string aff in AffinityGroups)
            {
                if (Utilities.CheckRemove(vmPowershellCmdlets.GetAzureAffinityGroup, aff))
                {
                    vmPowershellCmdlets.NewAzureAffinityGroup(aff, locationName, null, null);
                }
            }
        }
예제 #8
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";

            try
            {
                OSImageContext result = vmPowershellCmdlets.AddAzureVMImage(newImageName, mediaLocation, OS.Windows, oldLabel);

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

                result = vmPowershellCmdlets.UpdateAzureVMImage(newImageName, newLabel);

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

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

                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);
                }
            }
        }
예제 #9
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;
            }
        }
        public void AzureServiceExtensionTest()
        {
            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);
            const string rdpPath = @".\WebRole2.rdp";

            try
            {
                Collection <ExtensionImageContext> resultExtensions = vmPowershellCmdlets.GetAzureServiceAvailableExtension();

                foreach (var extension in resultExtensions)
                {
                    if (extension.ExtensionName == "RDP")
                    {
                        _extensionName     = extension.ExtensionName;
                        _providerNamespace = extension.ProviderNameSpace;
                        _version           = extension.Version;
                        break;
                    }
                }

                vmPowershellCmdlets.NewAzureService(_serviceName, _serviceName, locationName);
                Console.WriteLine("service, {0}, is created.", _serviceName);

                vmPowershellCmdlets.NewAzureDeployment(_serviceName, _packagePath.FullName, _configPath.FullName,
                                                       DeploymentSlotType.Production, DeploymentLabel, DeploymentName, false, false);

                DeploymentInfoContext result = vmPowershellCmdlets.GetAzureDeployment(_serviceName, DeploymentSlotType.Production);
                pass = Utilities.PrintAndCompareDeployment(result, _serviceName, DeploymentName, DeploymentLabel, DeploymentSlotType.Production, null, 2);
                Console.WriteLine("successfully deployed the package");

                vmPowershellCmdlets.SetAzureServiceExtension(
                    serviceName: _serviceName,
                    extensionName: _extensionName,
                    providerNamespace: _providerNamespace,
                    publicConfig: PublicConfig,
                    privateConfig: PrivateConfig,
                    version: _version
                    );

                ExtensionContext resultExtensionContext = vmPowershellCmdlets.GetAzureServiceExtension(_serviceName)[0];

                Utilities.PrintContext(resultExtensionContext);

                VerifyExtensionContext(resultExtensionContext, "AllRoles", _extensionName, _providerNamespace, _version);

                RemoteDesktopExtensionContext resultContext = vmPowershellCmdlets.GetAzureServiceRemoteDesktopExtension(_serviceName)[0];

                Utilities.PrintContext(resultContext);

                VerifyRDP(_serviceName, rdpPath);

                vmPowershellCmdlets.RemoveAzureServiceExtension(
                    serviceName: _serviceName,
                    extensionName: _extensionName,
                    providerNamespace: _providerNamespace,
                    uninstall: true);

                try
                {
                    vmPowershellCmdlets.GetAzureRemoteDesktopFile("WebRole1_IN_0", _serviceName, rdpPath, false);
                    Assert.Fail("Succeeded, but extected to fail!");
                }
                catch (Exception e)
                {
                    if (e is AssertFailedException)
                    {
                        throw;
                    }
                    Console.WriteLine("Failed to get RDP file as expected");
                }

                vmPowershellCmdlets.RemoveAzureDeployment(_serviceName, DeploymentSlotType.Production, true);

                pass &= Utilities.CheckRemove(vmPowershellCmdlets.GetAzureDeployment, _serviceName, DeploymentSlotType.Production);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception occurred: {0}", e);
                throw;
            }
        }
예제 #11
0
        public void AzureCertificateTest()
        {
            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);

            // Certificate files to test
            string cerFileName         = Convert.ToString(TestContext.DataRow["cerFileName"]);
            string pfxFileName         = Convert.ToString(TestContext.DataRow["pfxFileName"]);
            string password            = Convert.ToString(TestContext.DataRow["password"]);
            string thumbprintAlgorithm = Convert.ToString(TestContext.DataRow["algorithm"]);

            // Create a certificate
            X509Certificate2 certCreated = Utilities.CreateCertificate(password);

            byte[] certData = certCreated.Export(X509ContentType.Pfx, password);
            File.WriteAllBytes(pfxFileName, certData);
            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);

            // Certificate1: get it from the installed certificate.
            PSObject cert1 = vmPowershellCmdlets.RunPSScript(
                String.Format("Get-Item cert:\\{0}\\{1}\\{2}", certStoreLocation.ToString(), certStoreName.ToString(), installedCert.Thumbprint))[0];
            string cert1data = Convert.ToBase64String(((X509Certificate2)cert1.BaseObject).RawData);

            // Certificate2: get it from .pfx file.
            X509Certificate2Collection cert2 = new X509Certificate2Collection();

            cert2.Import(pfxFileName, password, X509KeyStorageFlags.PersistKeySet);
            string cert2data = Convert.ToBase64String(cert2[0].RawData);

            // Certificate3: get it from .cer file.
            X509Certificate2Collection cert3 = new X509Certificate2Collection();

            cert3.Import(cerFileName);
            string cert3data = Convert.ToBase64String(cert3[0].RawData);

            try
            {
                RemoveAllExistingCerts(defaultService);
                Assert.Fail("Cert issue is fixed!");
            }
            catch (Exception e)
            {
                if (e.ToString().Contains("InternalError"))
                {
                    Console.WriteLine("This exception is expected: {0}", e);
                }
                else
                {
                    throw;
                }
            }

            try
            {
                // Add a cert item
                vmPowershellCmdlets.AddAzureCertificate(defaultService, cert1);
                CertificateContext getCert1 = vmPowershellCmdlets.GetAzureCertificate(defaultService).FirstOrDefault(a => a.Thumbprint.Equals(installedCert.Thumbprint));
                Console.WriteLine("Cert is added: {0}", getCert1.Thumbprint);
                Assert.AreEqual(getCert1.Data, cert1data, "Cert is different!!");

                Thread.Sleep(TimeSpan.FromMinutes(2));
                vmPowershellCmdlets.RemoveAzureCertificate(defaultService, getCert1.Thumbprint, thumbprintAlgorithm);
                pass = Utilities.CheckRemove(vmPowershellCmdlets.GetAzureCertificate, defaultService, getCert1.Thumbprint, thumbprintAlgorithm);

                // Add .pfx file
                vmPowershellCmdlets.AddAzureCertificate(defaultService, pfxFileName, password);
                CertificateContext getCert2 = vmPowershellCmdlets.GetAzureCertificate(defaultService, cert2[0].Thumbprint, thumbprintAlgorithm)[0];
                Console.WriteLine("Cert is added: {0}", cert2[0].Thumbprint);
                Assert.AreEqual(getCert2.Data, cert2data, "Cert is different!!");
                Thread.Sleep(TimeSpan.FromMinutes(2));
                vmPowershellCmdlets.RemoveAzureCertificate(defaultService, cert2[0].Thumbprint, thumbprintAlgorithm);
                pass &= Utilities.CheckRemove(vmPowershellCmdlets.GetAzureCertificate, defaultService, cert2[0].Thumbprint, thumbprintAlgorithm);


                // Add .cer file
                vmPowershellCmdlets.AddAzureCertificate(defaultService, cerFileName);
                CertificateContext getCert3 = vmPowershellCmdlets.GetAzureCertificate(defaultService, cert3[0].Thumbprint, thumbprintAlgorithm)[0];
                Console.WriteLine("Cert is added: {0}", cert3[0].Thumbprint);
                Assert.AreEqual(getCert3.Data, cert3data, "Cert is different!!");
                Thread.Sleep(TimeSpan.FromMinutes(2));
                vmPowershellCmdlets.RemoveAzureCertificate(defaultService, cert3[0].Thumbprint, thumbprintAlgorithm);
                pass &= Utilities.CheckRemove(vmPowershellCmdlets.GetAzureCertificate, defaultService, cert3[0].Thumbprint, thumbprintAlgorithm);

                var certs = vmPowershellCmdlets.GetAzureCertificate(defaultService);
                Console.WriteLine("number of certs: {0}", certs.Count);
                Utilities.PrintContext(certs);
            }
            catch (Exception e)
            {
                pass = false;
                Assert.Fail(e.ToString());
            }
        }
예제 #12
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;
            }
        }
예제 #13
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());
            }
        }
예제 #15
0
        public void AzureServiceExtensionConfigScenarioTest()
        {
            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);

            const string rdpPath = @".\WebRole1.rdp";

            try
            {
                Collection <ExtensionImageContext> resultExtensions = vmPowershellCmdlets.GetAzureServiceAvailableExtension();

                foreach (var extension in resultExtensions)
                {
                    if (extension.ExtensionName == "RDP")
                    {
                        _extensionName     = extension.ExtensionName;
                        _providerNamespace = extension.ProviderNameSpace;
                        break;
                    }
                }

                vmPowershellCmdlets.NewAzureService(_serviceName, _serviceName, locationName);
                Console.WriteLine("service, {0}, is created.", _serviceName);

                ExtensionConfigurationInput config = vmPowershellCmdlets.NewAzureServiceExtensionConfig(
                    extensionName: _extensionName,
                    providerNamespace: _providerNamespace,
                    publicConfig: PublicConfig,
                    privateConfig: PrivateConfig
                    );

                vmPowershellCmdlets.NewAzureDeployment(_serviceName, _packagePath.FullName, _configPath.FullName,
                                                       DeploymentSlotType.Production, DeploymentLabel, DeploymentName, false, false, config);

                DeploymentInfoContext result = vmPowershellCmdlets.GetAzureDeployment(_serviceName, DeploymentSlotType.Production);
                pass = Utilities.PrintAndCompareDeployment(result, _serviceName, DeploymentName, DeploymentLabel, DeploymentSlotType.Production, null, 2);
                Console.WriteLine("successfully deployed the package");

                ExtensionContext resultExtensionContext = vmPowershellCmdlets.GetAzureServiceExtension(_serviceName)[0];

                Utilities.PrintContext(resultExtensionContext);

                VerifyExtensionContext(resultExtensionContext, "AllRoles", _extensionName, _providerNamespace);

                RemoteDesktopExtensionContext resultContext = vmPowershellCmdlets.GetAzureServiceRemoteDesktopExtension(_serviceName)[0];

                Utilities.PrintContext(resultContext);

                Utilities.GetDeploymentAndWaitForReady(_serviceName, DeploymentSlotType.Production, 10, 600);

                vmPowershellCmdlets.GetAzureRemoteDesktopFile("WebRole1_IN_0", _serviceName, rdpPath, false);

                string dns;

                using (var stream = new StreamReader(rdpPath))
                {
                    string firstLine = stream.ReadLine();
                    dns = Utilities.FindSubstring(firstLine, ':', 2);
                }

                Assert.IsTrue((Utilities.RDPtestPaaS(dns, "WebRole1", 0, username, password, true)), "Cannot RDP to the instance!!");

                vmPowershellCmdlets.RemoveAzureServiceExtension(
                    serviceName: _serviceName,
                    extensionName: _extensionName,
                    providerNamespace: _providerNamespace);

                try
                {
                    vmPowershellCmdlets.GetAzureRemoteDesktopFile("WebRole1_IN_0", _serviceName, rdpPath, false);
                    Assert.Fail("Succeeded, but extected to fail!");
                }
                catch (Exception e)
                {
                    if (e is AssertFailedException)
                    {
                        throw;
                    }
                    Console.WriteLine("Failed to get RDP file as expected");
                }

                vmPowershellCmdlets.RemoveAzureDeployment(_serviceName, DeploymentSlotType.Production, true);

                pass &= Utilities.CheckRemove(vmPowershellCmdlets.GetAzureDeployment, _serviceName, DeploymentSlotType.Production);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception occurred: {0}", e);
                throw;
            }
        }