public void ValidateAvailableExtesnion(VirtualMachineExtensionImageContext extension) { Utilities.PrintContext(extension); Assert.IsFalse(string.IsNullOrEmpty(extension.ExtensionName)); Assert.IsFalse(string.IsNullOrEmpty(extension.Publisher)); Assert.IsFalse(string.IsNullOrEmpty(extension.Version)); if (!extension.IsJsonExtension) { switch (extension.ExtensionName) { case "DiagnosticsAgent": { Assert.IsFalse(string.IsNullOrEmpty(extension.PublicConfigurationSchema)); break; } case "VMAccessAgent": { Assert.IsFalse(string.IsNullOrEmpty(extension.PublicConfigurationSchema)); Assert.IsFalse(string.IsNullOrEmpty(extension.PrivateConfigurationSchema)); break; } } } }
public void AzureVMImageSizeTest() { vhdName = "os2.vhd"; string newImageName = Utilities.GetUniqueShortName("vmimage"); string mediaLocation = string.Format("{0}{1}/{2}", blobUrlRoot, vhdContainerName, vhdName); try { var instanceSizes = vmPowershellCmdlets.GetAzureRoleSize().ToArray(); int arrayLength = instanceSizes.Count(); for (int i = 0; i < arrayLength; i++) { Utilities.PrintContext(instanceSizes[i]); // Add-AzureVMImage test for VM size OSImageContext result = vmPowershellCmdlets.AddAzureVMImage(newImageName, mediaLocation, OS.Windows, null, instanceSizes[i].InstanceSize); OSImageContext resultReturned = vmPowershellCmdlets.GetAzureVMImage(newImageName)[0]; Assert.IsTrue(CompareContext <OSImageContext>(result, resultReturned)); // Update-AzureVMImage test for VM size result = vmPowershellCmdlets.UpdateAzureVMImage(newImageName, null, instanceSizes[Math.Max((i + 1) % arrayLength, 1)].InstanceSize); resultReturned = vmPowershellCmdlets.GetAzureVMImage(newImageName)[0]; Assert.IsTrue(CompareContext <OSImageContext>(result, resultReturned)); vmPowershellCmdlets.RemoveAzureVMImage(newImageName); } } catch (Exception e) { pass = false; Console.WriteLine("Exception occurred: {0}", e.ToString()); throw; } }
private void ValidateVMAccessExtension(string vmName, string serviceName, bool enabled) { var vmExtension = GetAzureVMAccessExtesnion(vmName, serviceName); Utilities.PrintContext(vmExtension); if (enabled) { Console.WriteLine("Verifying the enabled extension"); Assert.AreEqual("Enable", vmExtension.State, "State is not Enable"); //Assert.IsFalse(string.IsNullOrEmpty(vmExtension.PublicConfiguration), "PublicConfiguration is empty."); XmlDocument doc = new XmlDocument(); doc.LoadXml(vmExtension.PublicConfiguration); XmlDocument inputPublicConfigDoc = new XmlDocument(); inputPublicConfigDoc.LoadXml(publicConfiguration); Assert.AreEqual(inputPublicConfigDoc.GetElementsByTagName("PublicConfig")[0].InnerXml, doc.GetElementsByTagName("PublicConfig")[0].InnerXml); Console.WriteLine("Verifed the enabled extension successfully."); } else { Console.WriteLine("Verifying the disabled extension"); Assert.AreEqual("Disable", vmExtension.State, "State is not Disable"); Console.WriteLine("Verifed the disabled extension successfully."); } Assert.IsNull(vmExtension.PrivateConfiguration); }
public void NewAzureVMWithLinuxAndCustomData() { try { // Add-AzureProvisioningConfig without NoSSHEndpoint or DisableSSH option var azureVMConfigInfo = new AzureVMConfigInfo(_vmName, InstanceSize.Small.ToString(), _linuxImageName); var azureProvisioningConfig = new AzureProvisioningConfigInfo(username, password, false, false, null, null, false, @".\cloudinittest.sh"); var persistentVMConfigInfo = new PersistentVMConfigInfo(azureVMConfigInfo, azureProvisioningConfig, null, null); PersistentVM vm = vmPowershellCmdlets.GetPersistentVM(persistentVMConfigInfo); // New-AzureVM vmPowershellCmdlets.NewAzureVM(_serviceName, new[] { vm }, locationName); Console.WriteLine("New Azure service with name:{0} created successfully.", _serviceName); Collection <InputEndpointContext> endpoints = vmPowershellCmdlets.GetAzureEndPoint(vmPowershellCmdlets.GetAzureVM(_vmName, _serviceName)); Console.WriteLine("The number of endpoints: {0}", endpoints.Count); foreach (var ep in endpoints) { Utilities.PrintContext(ep); } Assert.AreEqual(1, endpoints.Count); pass = true; } catch (Exception ex) { Console.WriteLine(ex.Message); throw; } }
public void NewAzureVMWithLinuxAndNoSSHEnpoint() { try { _serviceName = Utilities.GetUniqueShortName(serviceNamePrefix); string newAzureLinuxVMName = Utilities.GetUniqueShortName("PSLinuxVM"); // Add-AzureProvisioningConfig with NoSSHEndpoint var azureVMConfigInfo = new AzureVMConfigInfo(newAzureLinuxVMName, InstanceSize.Small.ToString(), _linuxImageName); var azureProvisioningConfig = new AzureProvisioningConfigInfo(username, password, true); var persistentVMConfigInfo = new PersistentVMConfigInfo(azureVMConfigInfo, azureProvisioningConfig, null, null); PersistentVM vm = vmPowershellCmdlets.GetPersistentVM(persistentVMConfigInfo); // New-AzureVM vmPowershellCmdlets.NewAzureVM(_serviceName, new[] { vm }, locationName); Console.WriteLine("New Azure service with name:{0} created successfully.", _serviceName); Collection <InputEndpointContext> endpoints = vmPowershellCmdlets.GetAzureEndPoint(vmPowershellCmdlets.GetAzureVM(newAzureLinuxVMName, _serviceName)); Console.WriteLine("The number of endpoints: {0}", endpoints.Count); foreach (var ep in endpoints) { Utilities.PrintContext(ep); } Assert.AreEqual(0, endpoints.Count); pass = true; } catch (Exception ex) { Console.WriteLine(ex.Message); throw; } }
public void VerifyVMImage(string vmImageName, OS ImageFamily, string imageLabel, string osState, HostCaching hostCaching, int LUN, int LogicalDiskSizeInGB, int noOfDataDisks) { var vmImages = vmPowershellCmdlets.GetAzureVMImageReturningVMImages(vmImageName); Assert.IsTrue(vmImages.Count >= 1); var vmImageInfo = vmImages[0]; Utilities.PrintContext(vmImageInfo); Utilities.PrintContext(vmImageInfo.OSDiskConfiguration); Utilities.PrintContext(vmImageInfo.DataDiskConfigurations[0]); //Verify ImageName Assert.IsTrue(vmImageName.Equals(vmImageInfo.ImageName)); Assert.IsTrue(vmImageInfo.Label.Equals(imageLabel)); //Verify Category Assert.IsTrue("User".Equals(vmImageInfo.Category, StringComparison.CurrentCultureIgnoreCase)); //Verify LogicalDiskSizeInGB, HostCaching Assert.AreEqual(hostCaching.ToString(), vmImageInfo.OSDiskConfiguration.HostCaching, "Property HostCaching is not matching."); Assert.AreEqual(hostCaching.ToString(), vmImageInfo.DataDiskConfigurations[0].HostCaching, "Data disk HostCaching iproperty is not matching."); //Verify LogicalDiskSizeInGB, Assert.AreEqual(LogicalDiskSizeInGB, vmImageInfo.DataDiskConfigurations[0].LogicalDiskSizeInGB); //Verify OSstate Assert.AreEqual(osState, vmImageInfo.OSDiskConfiguration.OSState, "OsState is not matching."); //Verify OS Assert.AreEqual(ImageFamily.ToString(), vmImageInfo.OSDiskConfiguration.OS, "Os Family is not matching."); //Verify LUN Assert.AreEqual(LUN, vmImageInfo.DataDiskConfigurations[0].Lun); //Verify the no of the data disks Assert.AreEqual(noOfDataDisks, vmImageInfo.DataDiskConfigurations.Count); }
static private void VerifyVmWithStaticCAIsReserved(string vmName, string svcName, string inputDip) { //Get the DIP of the VM (Get-AzureVM) VirtualNetworkStaticIPContext ipContext PersistentVMRoleContext vm = vmPowershellCmdlets.GetAzureVM(vmName, svcName); string confirguredVip = vm.IpAddress; if (!string.IsNullOrEmpty(confirguredVip)) { //Verify that the DIP of the VM is matched with an input DIP. Console.WriteLine("Verifying that the DIP of the VM {0} is matched with input DIP {1}.", inputDip, confirguredVip); Assert.AreEqual(inputDip, confirguredVip, string.Format("Static CA IpAddress {0} is not the same as the Input DIP {1}", confirguredVip, inputDip)); Console.WriteLine("Verifyied that the DIP of the VM {0} is matched with input DIP {1}.", inputDip, confirguredVip); //Verify that the DIP is actually reserved. Console.WriteLine("Verifying that the DIP of the VM is actually reserved"); var ipContext = vmPowershellCmdlets.GetAzureStaticVNetIP(vm.VM); Utilities.PrintContext(ipContext); Assert.AreEqual(inputDip, ipContext.IPAddress, string.Format("Reserved IPAddress {0} is not equal to the input DIP {1}", ipContext.IPAddress, inputDip)); Console.WriteLine("Verifyied that the DIP of the VM is actually reserved"); //Verify that the IP is not available (Test-AzureStaticVNetIP –VnetName $vnet –IPAddress “10.0.0.5”) Console.WriteLine("Verifing that the IP {0} is not available", inputDip); VirtualNetworkStaticIPAvailabilityContext availibiltyContext = vmPowershellCmdlets.TestAzureStaticVNetIP(VNetName, inputDip); Console.WriteLine("IsAvailable:{0}", availibiltyContext.IsAvailable); Console.WriteLine("AvailableAddresses:{0}{1}", Environment.NewLine, availibiltyContext.AvailableAddresses.Aggregate((current, next) => current + Environment.NewLine + next)); Assert.IsFalse(availibiltyContext.IsAvailable, string.Format("Test-AzureStaticVNetIP should return true as {0} is reserved", inputDip, vm.Name)); Assert.IsFalse(availibiltyContext.AvailableAddresses.Contains(inputDip), string.Format("{0} is reserved for vm {1} and should not be in available addresses.", inputDip, vmName)); Console.WriteLine("Verified that the IP {0} is not available", inputDip); } else { throw new Exception("Configured IPAddres value is null or empty"); } }
private void GetAzureServiceDomainJoinExtension() { var domianContext = vmPowershellCmdlets.GetAzureServiceDomainJoinExtension(_serviceName, DeploymentSlotType.Production); Utilities.PrintContext(domianContext); Assert.IsFalse(string.IsNullOrEmpty(domianContext.Extension), "Extension is empty or null."); Console.WriteLine("Service domain join extension fetched successfully."); }
private VirtualMachineExtensionContext GetAzureVMExtesnion(string vmName, string serviceName) { Console.WriteLine("Get Azure VM's extension"); var vmExtension = vmPowershellCmdlets.GetAzureVMExtension(GetAzureVM(vmName, serviceName)); Utilities.PrintContext(vmExtension); Console.WriteLine("Azure VM's extension info retrieved successfully."); return(vmExtension); }
private void CheckAvailabilityOfIpAddressAndAssertFalse(string vnetName, string ipaddress) { var availibiltyContext = vmPowershellCmdlets.TestAzureStaticVNetIP(vnetName, ipaddress); Utilities.PrintContext(availibiltyContext); Console.WriteLine("AvailableAddresses:{0}{1}", Environment.NewLine, availibiltyContext.AvailableAddresses.Aggregate((current, next) => current + Environment.NewLine + next)); Assert.IsFalse(availibiltyContext.IsAvailable, "Ipaddress {0} is avialable.", ipaddress); }
public void NewAzureVMWithAffinityGroup() { _serviceName = Utilities.GetUniqueShortName(serviceNamePrefix); string _affiniyGroupName1 = Utilities.GetUniqueShortName("aff"); string _affiniyGroupName2 = Utilities.GetUniqueShortName("aff"); try { // New-AzureService vmPowershellCmdlets.NewAzureAffinityGroup(_affiniyGroupName1, locationName, "location1", "location1"); vmPowershellCmdlets.NewAzureAffinityGroup(_affiniyGroupName2, locationName, "location2", "location2"); vmPowershellCmdlets.NewAzureService(_serviceName, "service1", null, _affiniyGroupName1); // New-AzureVMConfig string newAzureVMName = Utilities.GetUniqueShortName("PSVM"); string imageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Windows" }, false); // Add-AzureProvisioningConfig var azureVMConfigInfo = new AzureVMConfigInfo(newAzureVMName, InstanceSize.Small.ToString(), imageName); var azureProvisioningConfig = new AzureProvisioningConfigInfo(OS.Windows, username, password); var persistentVMConfigInfo = new PersistentVMConfigInfo(azureVMConfigInfo, azureProvisioningConfig, null, null); PersistentVM vm = vmPowershellCmdlets.GetPersistentVM(persistentVMConfigInfo); // New-AzureVM try { vmPowershellCmdlets.NewAzureVMWithAG(_serviceName, new[] { vm }, _affiniyGroupName2); Assert.Fail("Should fail, but succeeded!"); } catch (Exception ex) { if (ex is AssertFailedException) { throw; } else { Console.WriteLine("Failure is expected. Continue the tests..."); } } vmPowershellCmdlets.NewAzureVMWithAG(_serviceName, new[] { vm }, _affiniyGroupName1); Console.WriteLine("New Azure service with name:{0} created successfully.", _serviceName); var vmReturned = vmPowershellCmdlets.GetAzureVM(newAzureVMName, _serviceName); Utilities.PrintContext(vmReturned); Assert.AreEqual(_serviceName, vmReturned.ServiceName); pass = true; } catch (Exception ex) { Console.WriteLine(ex.Message); throw; } }
private static void VerifyPublicIP(string publicIpName, PersistentVM vm1) { Utilities.ExecuteAndLog(() => { var publicIpContext = vmPowershellCmdlets.GetAzurePublicIpName(publicIpName, vm1); Console.WriteLine("Public IP Context Properties:"); Utilities.PrintContext(publicIpContext); Console.WriteLine("\n Verifing recquired properties"); Utilities.LogAssert(() => Assert.AreEqual(publicIpName, publicIpContext.Name), "Public IP Name"); }, "Verify Public ip of the VM"); }
private void CheckAvailabilityofIpAddress(string vnetName, string ipaddress) { Console.WriteLine("Checking if VIP {0} is available and unreserved", ipaddress); VirtualNetworkStaticIPAvailabilityContext availibiltyContext = vmPowershellCmdlets.TestAzureStaticVNetIP(vnetName, ipaddress); Utilities.PrintContext(availibiltyContext); //Assert that it is available. Assert.IsTrue(availibiltyContext.IsAvailable, "ipaddress {0} is expected to be available", ipaddress); Console.WriteLine("Ip address {0} is available", ipaddress); }
public void VerifyOsImage(string ImageName, OSImageContext imageContext) { var vmImage = vmPowershellCmdlets.GetAzureVMImage(ImageName); Utilities.PrintContext(vmImage[0]); Assert.AreEqual(imageContext.ImageName, vmImage[0].ImageName, "ImageName property of the saved os image is not matching."); Assert.AreEqual(imageContext.Category, vmImage[0].Category, "Category property of the saved os image is not matching."); Assert.AreEqual(imageContext.Location, vmImage[0].Location, "Location property of the saved os image is not matching."); Assert.AreEqual(imageContext.Label, vmImage[0].Label, "Label property of the saved os image is not matching."); Assert.AreEqual(imageContext.OS, vmImage[0].OS, "OS property of the saved os image is not matching."); }
public void VerifyVM(PersistentVM vm, OS ImageFamily, HostCaching hostCaching, int LogicalDiskSizeInGB, int noOfDataDisks) { //Verify OS Disk Console.WriteLine("VM OS Virtual Hard Disk properties:"); Utilities.PrintContext(vm.OSVirtualHardDisk); Assert.AreEqual(HostCaching.ReadWrite.ToString(), vm.OSVirtualHardDisk.HostCaching, "Os disk Property HostCaching is not matching."); Assert.AreEqual(ImageFamily.ToString(), vm.OSVirtualHardDisk.OS, "ImageFamily property is not matching."); //Verify Data Disk Console.WriteLine("VM Data Hard Disk properties:"); Utilities.PrintContext(vm.DataVirtualHardDisks[0]); Assert.AreEqual(hostCaching.ToString(), vm.DataVirtualHardDisks[0].HostCaching, "Data disk Property HostCaching is not matching."); Assert.AreEqual(LogicalDiskSizeInGB, vm.DataVirtualHardDisks[0].LogicalDiskSizeInGB, "Data disk size is not matching."); Assert.AreEqual(noOfDataDisks, vm.DataVirtualHardDisks.Count, "Data disks count is not matching."); }
public void UpdateVMWithNewStaticCATest() { StartTest(MethodBase.GetCurrentMethod().Name, testStartTime); string vnet1 = VirtualNets[0]; string vmName1 = Utilities.GetUniqueShortName(vmNamePrefix); try { const string ipaddress = "10.0.0.7"; //Test a static CA Console.WriteLine("Checking if ipaddress {0} is available", ipaddress); CheckAvailabilityofIpAddress(vnet1, ipaddress); Console.WriteLine("ipaddress {0} is available", ipaddress); //Create an IaaS VM vmPowershellCmdlets.NewAzureQuickVM(OS.Windows, vmName1, serviceName, imageName, new string[1] { StaticCASubnet0 }, InstanceSize.Small, username, password, VNetName, AffinityGroup); //Update the IaaS VM with a static CA var vmRoleContext = vmPowershellCmdlets.GetAzureVM(vmName1, serviceName); string nonStaticIpAddress = vmRoleContext.IpAddress; Console.WriteLine("Non static IpAddress of the vm {0} is {1}", vmName1, nonStaticIpAddress); var vm = vmPowershellCmdlets.SetAzureStaticVNetIP(ipaddress, vmRoleContext.VM); vmPowershellCmdlets.UpdateAzureVM(vmName1, serviceName, vm); //Verify that the DIP of the VM is matched with an input. VerifyVmWithStaticCAIsReserved(vmName1, serviceName, ipaddress); //Verify that the first DIP is released. Console.WriteLine("Checking for the availability of non static IpAdress after giving a static CA to the VM"); Thread.Sleep(TimeSpan.FromMinutes(2)); var availabilityContext = vmPowershellCmdlets.TestAzureStaticVNetIP(vnet1, nonStaticIpAddress); Utilities.RetryActionUntilSuccess( () => Assert.IsTrue(availabilityContext.IsAvailable, "Non static IpAddress {0} is not realesed.", nonStaticIpAddress), "Non static IpAddress", 3, 60); //Assert.IsTrue(availabilityContext.IsAvailable, "Non static IpAddress {0} is not realesed.",nonStaticIpAddress); Utilities.PrintContext(availabilityContext); pass = true; } catch (Exception e) { Console.WriteLine(e.ToString()); throw; } }
/// <summary> /// Verifies that the properties of the result of Get-azureInternalLoadBalancer is same as expected. /// </summary> /// <param name="ilbName"></param> private void VerifyInternalLoadBalancer(string verificationMessage, InternalLoadBalancerConfig expectedIlbConfig) { Utilities.ExecuteAndLog(() => { var ilbConfig = vmPowershellCmdlets.GetAzureInternalLoadBalancer(serviceName); Console.WriteLine("ILB Context Properties:"); Utilities.PrintContext(ilbConfig); Console.WriteLine("\n Verifing recquired properties"); Utilities.LogAssert(() => Assert.AreEqual(expectedIlbConfig.InternalLoadBalancerName, ilbConfig.InternalLoadBalancerName), "InternalLoadBalancerName"); Utilities.LogAssert(() => Assert.AreEqual(serviceName, ilbConfig.ServiceName), "ServiceName"); Utilities.LogAssert(() => Assert.AreEqual(serviceName, ilbConfig.DeploymentName), "DeploymentName"); Utilities.LogAssert(() => Assert.AreEqual(expectedIlbConfig.IPAddress, ilbConfig.IPAddress), "IPAddress"); Utilities.LogAssert(() => Assert.AreEqual(expectedIlbConfig.SubnetName, ilbConfig.SubnetName), "SubnetName"); }, verificationMessage); }
private VirtualMachineExtensionContext GetAzureVMAccessExtesnion(string vmName, string serviceName) { Console.WriteLine("Get Azure VM's extension"); var vmExtensions = vmPowershellCmdlets.GetAzureVMExtension(GetAzureVM(vmName, serviceName), VmAccessAgentExtensionName, publisher); var vmExtension = vmExtensions !=null ? vmExtensions[0] : null; if (vmExtension != null) { Utilities.PrintContext(vmExtension); Console.WriteLine("Azure VM's extension info retrieved successfully."); } else { Console.WriteLine("VM Access extesnion is not applied to the VM"); } return vmExtension; }
public void NewAzureVMWithLocation() { string _altLocation = GetAlternateLocation(locationName); try { // New-AzureService vmPowershellCmdlets.NewAzureService(_serviceName, locationName); var azureVMConfigInfo = new AzureVMConfigInfo(_vmName, InstanceSize.Small.ToString(), imageName); var azureProvisioningConfig = new AzureProvisioningConfigInfo(OS.Windows, username, password); var persistentVMConfigInfo = new PersistentVMConfigInfo(azureVMConfigInfo, azureProvisioningConfig, null, null); PersistentVM vm = vmPowershellCmdlets.GetPersistentVM(persistentVMConfigInfo); // New-AzureVM try { vmPowershellCmdlets.NewAzureVM(_serviceName, new[] { vm }, _altLocation); Assert.Fail("Should fail, but succeeded!"); } catch (Exception ex) { if (ex is AssertFailedException) { throw; } else { Console.WriteLine("Failure is expected. Continue the tests..."); } } vmPowershellCmdlets.NewAzureVM(_serviceName, new[] { vm }, locationName); Console.WriteLine("New Azure service with name:{0} created successfully.", _serviceName); var vmReturned = vmPowershellCmdlets.GetAzureVM(_vmName, _serviceName); Utilities.PrintContext(vmReturned); Assert.AreEqual(_serviceName, vmReturned.ServiceName); pass = true; } catch (Exception ex) { Console.WriteLine(ex.Message); throw; } }
public void NewAzureLinuxVMWithoutPasswordAndNoSSHEnpoint() { try { _serviceName = Utilities.GetUniqueShortName(serviceNamePrefix); //Create service vmPowershellCmdlets.NewAzureService(_serviceName, locationName); //Add installed certificate to the service PSObject certToUpload = vmPowershellCmdlets.RunPSScript( String.Format("Get-Item cert:\\{0}\\{1}\\{2}", certStoreLocation.ToString(), certStoreName.ToString(), _installedCert.Thumbprint))[0]; vmPowershellCmdlets.AddAzureCertificate(_serviceName, certToUpload); string newAzureLinuxVMName = Utilities.GetUniqueShortName("PSLinuxVM"); var key = vmPowershellCmdlets.NewAzureSSHKey(NewAzureSshKeyType.PublicKey, _installedCert.Thumbprint, keyPath); var sshKeysList = new Model.LinuxProvisioningConfigurationSet.SSHPublicKeyList(); sshKeysList.Add(key); // Add-AzureProvisioningConfig without password and NoSSHEndpoint var azureVMConfigInfo = new AzureVMConfigInfo(newAzureLinuxVMName, InstanceSize.Small.ToString(), _linuxImageName); var azureProvisioningConfig = new AzureProvisioningConfigInfo(username, noSshEndpoint: true, sSHPublicKeyList: sshKeysList); var persistentVMConfigInfo = new PersistentVMConfigInfo(azureVMConfigInfo, azureProvisioningConfig, null, null); PersistentVM vm = vmPowershellCmdlets.GetPersistentVM(persistentVMConfigInfo); // New-AzureVM vmPowershellCmdlets.NewAzureVM(_serviceName, new[] { vm }); Console.WriteLine("New Azure service with name:{0} created successfully.", _serviceName); Collection <InputEndpointContext> endpoints = vmPowershellCmdlets.GetAzureEndPoint(vmPowershellCmdlets.GetAzureVM(newAzureLinuxVMName, _serviceName)); Console.WriteLine("The number of endpoints: {0}", endpoints.Count); foreach (var ep in endpoints) { Utilities.PrintContext(ep); } Assert.AreEqual(0, endpoints.Count); pass = true; } catch (Exception ex) { Console.WriteLine(ex.Message); throw; } }
internal static bool AzureReservedIP(ReservedIPContext rsvIP, string name, string label, string affname, string ip, string dep, string svcName, string id) { Utilities.PrintContext(rsvIP); Assert.AreEqual(name, rsvIP.ReservedIPName, "Reserved IP names are not equal!"); Assert.AreEqual(label, rsvIP.Label, "Reserved IP labels are not equal!"); Assert.AreEqual(affname, rsvIP.AffinityGroup, "Reserved IP affinity groups are not equal!"); if (!string.IsNullOrEmpty(ip)) { Assert.AreEqual(ip, rsvIP.Address, "Reserved IP addresses are not equal!"); } Assert.AreEqual(dep, rsvIP.DeploymentName, "Reserved IP deployment names are not equal!"); Assert.AreEqual(svcName, rsvIP.ServiceName, "Reserved IP service names are not equal!"); if (!string.IsNullOrEmpty(id)) { Assert.AreEqual(id, rsvIP.Id, "Reserved IP IDs are not equal!"); } return(true); }
public void GetAzureServiceAvailableExtensionTest() { StartTest(MethodBase.GetCurrentMethod().Name, testStartTime); try { Collection <ExtensionImageContext> resultExtensions = vmPowershellCmdlets.GetAzureServiceAvailableExtension(); foreach (var extension in resultExtensions) { Utilities.PrintContext(extension); } _extensionName = resultExtensions[0].ExtensionName; _providerNamespace = resultExtensions[0].ProviderNameSpace; resultExtensions = vmPowershellCmdlets.GetAzureServiceAvailableExtension( extensionName: _extensionName, providerNamespace: _providerNamespace, allVersion: true); foreach (var extension in resultExtensions) { Utilities.PrintContext(extension); } string ver = resultExtensions[0].Version; resultExtensions = vmPowershellCmdlets.GetAzureServiceAvailableExtension( extensionName: _extensionName, providerNamespace: _providerNamespace, version: ver); Utilities.PrintContext(resultExtensions[0]); pass = true; } catch (Exception e) { Console.WriteLine("Exception occurred: {0}", e); throw; } }
private void VerifyEndpoint(string verificationMessage, string vmName, AzureEndPointConfigInfo endpointConfig) { Utilities.ExecuteAndLog(() => { var vmRole = vmPowershellCmdlets.GetAzureVM(vmName, serviceName); var endpointCollection = vmPowershellCmdlets.GetAzureEndPoint(vmRole.VM); var inputEndpointCollection = from c in endpointCollection where c.Name.Equals(endpointConfig.EndpointName) select c; var endpointConfigInfo = inputEndpointCollection.First(); Console.WriteLine("Endpoint Configuraion Properties:"); Utilities.PrintContext(endpointConfigInfo); ipAddress = endpointConfigInfo.Vip; Console.WriteLine("\n Verifing recquired properties"); Utilities.LogAssert(() => Assert.AreEqual(string.IsNullOrEmpty(endpointConfig.LBSetName) ? null : endpointConfig.LBSetName, endpointConfigInfo.LBSetName), "LBSetName"); Utilities.LogAssert(() => Assert.AreEqual(endpointConfig.EndpointLocalPort, endpointConfig.EndpointLocalPort), "EndpointLocalPort"); Utilities.LogAssert(() => Assert.AreEqual(endpointConfig.EndpointName, endpointConfig.EndpointName), "EndpointName"); Utilities.LogAssert(() => Assert.AreEqual(endpointConfig.EndpointProtocol, endpointConfig.EndpointProtocol), "EndpointProtocol"); Utilities.LogAssert(() => Assert.AreEqual(endpointConfig.InternalLoadBalancerName, endpointConfig.InternalLoadBalancerName), "InternalLoadBalancerName"); }, verificationMessage); }
/// <summary> /// Verify the properties of the reserved ip /// </summary> /// <param name="input">ReservedIpContext object containing expected values</param> private void VerifyReservedIp(ReservedIPContext input) { var reservedIps = vmPowershellCmdlets.GetAzureReservedIP(input.ReservedIPName); if (reservedIps.Count > 0) { var reservedIpContext = reservedIps[0]; Utilities.PrintContext(reservedIpContext); Utilities.LogAssert(() => Assert.IsFalse(string.IsNullOrEmpty(reservedIpContext.Address)), "Address"); Utilities.LogAssert(() => Assert.AreEqual(input.Location, reservedIpContext.Location), "Location"); Utilities.LogAssert(() => Assert.AreEqual(input.ReservedIPName, reservedIpContext.ReservedIPName), "ReservedIPName"); Utilities.LogAssert(() => Assert.AreEqual(input.State, reservedIpContext.State), "State"); Utilities.LogAssert(() => Assert.AreEqual(input.DeploymentName, reservedIpContext.DeploymentName), "DeploymentName"); Utilities.LogAssert(() => Assert.AreEqual(input.InUse, reservedIpContext.InUse), "InUse"); Utilities.LogAssert(() => Assert.AreEqual(input.ServiceName, reservedIpContext.ServiceName), "ServiceName"); } else { Assert.Fail("Didnt find reserved ip with name {0}", input.ReservedIPName); } }
private void VerifyDeployment(string verificationMessage, string internalLoadBalancerName = null, string vnet = null) { Utilities.ExecuteAndLog(() => { var deploymentContext = vmPowershellCmdlets.GetAzureDeployment(serviceName); Console.WriteLine("Deployment Context Properties:"); Utilities.PrintContext(deploymentContext); Console.WriteLine("\n Verifing recquired properties"); Utilities.LogAssert(() => Assert.AreEqual(internalLoadBalancerName, deploymentContext.InternalLoadBalancerName), "InternalLoadBalancerName"); Utilities.LogAssert(() => { if (internalLoadBalancerName == null) { Assert.AreEqual(deploymentContext.LoadBalancers.Count, 0); } else { Assert.AreEqual(internalLoadBalancerName, deploymentContext.LoadBalancers[0].Name); } }, "LoadBalancers"); Utilities.LogAssert(() => Assert.AreEqual(vnet, deploymentContext.VNetName), "VNetName"); }, verificationMessage); }
public void ValidateAvailableExtesnion(VirtualMachineExtensionImageContext extension) { Utilities.PrintContext(extension); Assert.IsFalse(string.IsNullOrEmpty(extension.ExtensionName)); Assert.IsFalse(string.IsNullOrEmpty(extension.Publisher)); Assert.IsFalse(string.IsNullOrEmpty(extension.Version)); // Intentionally commented as the cmdlet prod cmdlet doesnt have these properties and dogfood returns errors // now //Assert.IsTrue(extension.ReplicationCompleted); //Assert.IsTrue(Utilities.validateHttpUri(extension.PrivacyUri.ToString())); //Assert.IsTrue(Utilities.validateHttpUri(extension.PrivacyUri.ToString())); //Assert.IsTrue(Utilities.validateHttpUri(extension.Eula.ToString())); switch (extension.ExtensionName) { //case "BGInfo": // { // Assert.IsTrue(extension.ReplicationCompleted); // break; // } case "DiagnosticsAgent": { Assert.IsFalse(string.IsNullOrEmpty(extension.PublicConfigurationSchema)); break; } case "VMAccessAgent": { Assert.IsFalse(string.IsNullOrEmpty(extension.PublicConfigurationSchema)); Assert.IsFalse(string.IsNullOrEmpty(extension.PrivateConfigurationSchema)); //Assert.IsFalse(string.IsNullOrEmpty(extension.SampleConfig)); break; } } }
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 CaptureGeneralizedLinuxVMAndDeploy() { string serviceName1 = Utilities.GetUniqueShortName(serviceNamePrefix); string linuxImageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Linux" }, false); try { // a. Deploy a new IaaS VM string vmName = Utilities.GetUniqueShortName(vmNamePrefix); Console.WriteLine("--------------------------------Deploying a new IaaS VM :{0} completed.---------------------", vmName); PersistentVM vm = CreateIaaSVMObjectWithDisk(vmName, InstanceSize.Small, linuxImageName, false, username, password); vmPowershellCmdlets.NewAzureVM(serviceName, new[] { vm }, locationName); Console.WriteLine("--------------------------------Deploying a new IaaS VM :{0} completed.---------------------", vmName); //b. Stop the VM Console.WriteLine("--------------------------------Stopping vm :{0}--------------------------------", vmName); vmPowershellCmdlets.StopAzureVM(vmName, serviceName, force: true); Console.WriteLine("--------------------------------Stopped vm :{0}--------------------------------", vmName); //c. Save the VM image Console.WriteLine("--------------------------------Save the VM image--------------------------------"); vmImageName = vmName + "Image"; vmPowershellCmdlets.SaveAzureVMImage(serviceName, vmName, vmImageName, CONSTANT_GENERALIZED, vmImageName); Console.WriteLine("--------------------------------Saved VM image with name {0}----------------------"); //d. Verify the VM image by Get-AzureVMImage Console.WriteLine("--------------------------------Verify the VM image--------------------------------"); VerifyVMImage(vmImageName, OS.Linux, vmImageName, CONSTANT_GENERALIZED, cahcing, lunSlot1, diskSize1, 1); Console.WriteLine("--------------------------------Verified that the VM image is saved successfully--------------------------------"); //e. Deploy a new IaaS VM with the save VM image Console.WriteLine("--------------------------------Deploy a new IaaS VM with the saved VM image {0}--------------------------------", vmImageName); string vmName1 = Utilities.GetUniqueShortName(vmNamePrefix); vm = Utilities.CreateIaaSVMObject(vmName1, InstanceSize.Small, vmImageName, false, username, password); vmPowershellCmdlets.NewAzureVM(serviceName1, new[] { vm }, locationName); Console.WriteLine("--------------------------------Deployed a IaaS VM {0} with the saved VM image {1}--------------------------------", vmName1, vmImageName); //f. Verify the VM by Get-AzureVM Console.WriteLine("--------------------------------Verify the VM by Get-AzureVM--------------------------------", vmName1, vmImageName); var vmRoleContext = vmPowershellCmdlets.GetAzureVM(vmName1, serviceName1); Utilities.PrintContext(vmRoleContext); Console.WriteLine("--------------------------------Verified the VM {0} successfully--------------------------------", vmName1); //g. Add another IaaS VM with the save VM image to the existing service string vmName2 = Utilities.GetUniqueShortName(vmNamePrefix); Console.WriteLine("--------------------------------Deploy a new IaaS VM with the saved VM image {0}--------------------------------", vmImageName); vmPowershellCmdlets.NewAzureQuickVM(OS.Linux, vmName2, serviceName1, vmImageName, username, password); Console.WriteLine("--------------------------------Deployed a IaaS VM {0} with the saved VM image {1}--------------------------------", vmName2, vmImageName); //h. Verify the VM by Get-AzureVM Console.WriteLine("--------------------------------Verify the VM by Get-AzureVM--------------------------------", vmName2, vmImageName); vmRoleContext = vmPowershellCmdlets.GetAzureVM(vmName2, serviceName1); Utilities.PrintContext(vmRoleContext); Console.WriteLine("--------------------------------Verified the VM {0} successfully--------------------------------", vmName2); pass = true; } catch (Exception ex) { Console.WriteLine(ex.ToString()); throw; } finally { CleanupService(serviceName1); //Delete the VM image Console.WriteLine("------------------------------Delete the VM image---------------------------------"); vmPowershellCmdlets.RemoveAzureVMImage(vmImageName, true); Console.WriteLine("------------------------------Deleted the VM image---------------------------------"); } }
public void AzureVMImageSizeTest() { string mediaLocation = UploadVhdFile(); string newImageName = Utilities.GetUniqueShortName("vmimage"); try { var instanceSizes = vmPowershellCmdlets.GetAzureRoleSize().Where(r => r.Cores <= 2 && !r.InstanceSize.StartsWith("Standard_")); const int numOfMinimumInstSize = 3; Assert.IsTrue(instanceSizes.Count() >= numOfMinimumInstSize); var instanceSizesArr = instanceSizes.Take(numOfMinimumInstSize).ToArray(); int arrayLength = instanceSizesArr.Count(); for (int i = 0; i < arrayLength; i++) { Utilities.PrintContext(instanceSizesArr[i]); // Add-AzureVMImage test for VM size OSImageContext result = vmPowershellCmdlets.AddAzureVMImage(newImageName, mediaLocation, OS.Windows, null, instanceSizesArr[i].InstanceSize); OSImageContext resultReturned = vmPowershellCmdlets.GetAzureVMImage(newImageName)[0]; Assert.IsTrue(!string.IsNullOrEmpty(resultReturned.IOType)); Assert.IsTrue(CompareContext <OSImageContext>(result, resultReturned)); // Update-AzureVMImage test for VM size System.Threading.Thread.Sleep(TimeSpan.FromSeconds(10)); result = vmPowershellCmdlets.UpdateAzureVMImage(newImageName, resultReturned.ImageName, instanceSizesArr[Math.Max((i + 1) % arrayLength, 1)].InstanceSize); resultReturned = vmPowershellCmdlets.GetAzureVMImage(newImageName)[0]; Assert.IsTrue(!string.IsNullOrEmpty(resultReturned.IOType)); Assert.IsTrue(CompareContext <OSImageContext>(result, resultReturned)); vmPowershellCmdlets.RemoveAzureVMImage(newImageName); System.Threading.Thread.Sleep(TimeSpan.FromSeconds(10)); pass = true; } } catch (Exception e) { pass = false; System.Threading.Thread.Sleep(TimeSpan.FromSeconds(10)); vmPowershellCmdlets.RemoveAzureVMImage(newImageName, true); Console.WriteLine("Exception occurred: {0}", e.ToString()); throw; } finally { try { vmPowershellCmdlets.GetAzureVMImage(newImageName); vmPowershellCmdlets.RemoveAzureVMImage(newImageName); } catch (Exception e) { if (e.ToString().Contains("ResourceNotFound")) { Console.WriteLine("The vm image, {0}, is already deleted.", newImageName); } else { throw; } } } }
public void CaptureSpecializedVMAndDeploy() { StartTest(MethodBase.GetCurrentMethod().Name, testStartTime); string serviceName1 = Utilities.GetUniqueShortName(serviceNamePrefix); try { // a. Deploy a new IaaS VM string vmName = Utilities.GetUniqueShortName(vmNamePrefix); Console.WriteLine("--------------------------------Deploying a new IaaS VM :{0}--------------------------------", vmName); var vm = CreateIaaSVMObjectWithDisk(vmName, InstanceSize.Small, imageName, true, username, password); vmPowershellCmdlets.NewAzureVM(serviceName, new[] { vm }, locationName); Console.WriteLine("--------------------------------Deploying a new IaaS VM :{0} completed.---------------------", vmName); //b. Stop the VM Console.WriteLine("--------------------------------Stopping vm :{0}--------------------------------", vmName); vmPowershellCmdlets.StopAzureVM(vmName, serviceName, force: true); Console.WriteLine("--------------------------------Stopped vm :{0}--------------------------------", vmName); //c. Save the VM image Console.WriteLine("--------------------------------Save the VM image--------------------------------"); vmImageName = vmName + "Image"; vmPowershellCmdlets.SaveAzureVMImage(serviceName, vmName, vmImageName, CONSTANT_SPECIALIZED, vmImageName); Console.WriteLine("--------------------------------Saved VM image with name {0}----------------------"); //d. Verify the VM image by Get-AzureVMImage Console.WriteLine("--------------------------------Verify the VM image--------------------------------"); VerifyVMImage(vmImageName, OS.Windows, vmImageName, CONSTANT_SPECIALIZED, cahcing, lunSlot1, diskSize1, 1); Console.WriteLine("--------------------------------Verified that the VM image is saved successfully--------------------------------"); //e. Deploy a new IaaS VM with the save VM image Console.WriteLine("--------------------------------Deploy a new IaaS VM with the saved VM image {0}--------------------------------", vmImageName); string vmName1 = Utilities.GetUniqueShortName(vmNamePrefix); vm = Utilities.CreateIaaSVMObject(vmName1, InstanceSize.Small, vmImageName); vmPowershellCmdlets.NewAzureVM(serviceName1, new[] { vm }, locationName); Console.WriteLine("--------------------------------Deployed a IaaS VM {0} with the saved VM image {1}--------------------------------", vmName1, vmImageName); //f. Verify the VM by Get-AzureVM Console.WriteLine("--------------------------------Verify the VM by Get-AzureVM--------------------------------", vmName1, vmImageName); var vmRoleContext = vmPowershellCmdlets.GetAzureVM(vmName1, serviceName1); Utilities.PrintContext(vmRoleContext); VerifyVM(vmRoleContext.VM, OS.Windows, HostCaching.ReadWrite, diskSize1, 1); Console.WriteLine("--------------------------------Verified the VM {0} successfully--------------------------------", vmName1); //g. Add another IaaS VM with the save VM image to the existing service string vmName2 = Utilities.GetUniqueShortName(vmNamePrefix); Console.WriteLine("--------------------------------Deploy a new IaaS VM with the saved VM image {0}--------------------------------", vmImageName); vmPowershellCmdlets.NewAzureQuickVM(OS.Windows, vmName2, serviceName1, vmImageName); Console.WriteLine("--------------------------------Deployed a IaaS VM {0} with the saved VM image {1}--------------------------------", vmName2, vmImageName); //h. Verify the VM by Get-AzureVM Console.WriteLine("--------------------------------Verify the VM by Get-AzureVM--------------------------------", vmName2, vmImageName); vmRoleContext = vmPowershellCmdlets.GetAzureVM(vmName2, serviceName1); VerifyVM(vmRoleContext.VM, OS.Windows, HostCaching.ReadWrite, diskSize1, 1); Utilities.PrintContext(vmRoleContext); Console.WriteLine("--------------------------------Verified the VM {0} successfully--------------------------------", vmName2); pass = true; } catch (Exception ex) { Console.WriteLine(ex.ToString()); throw; } finally { CleanupService(serviceName1); // Delete the VM image Console.WriteLine("------------------------------Delete the VM image---------------------------------"); DeleteVMImageIfExists(vmImageName); Console.WriteLine("------------------------------Deleted the VM image---------------------------------"); } }