PageRenderTime 64ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/ScenarioTest.cs

https://github.com/IrisClasson/azure-sdk-tools
C# | 1508 lines | 1107 code | 277 blank | 124 comment | 55 complexity | 97562440cf961ae994e5546beabe2f4f MD5 | raw file
Possible License(s): Apache-2.0

Large files files are truncated, but you can click here to view the full file

  1. // ----------------------------------------------------------------------------------
  2. //
  3. // Copyright Microsoft Corporation
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. // ----------------------------------------------------------------------------------
  14. namespace Microsoft.WindowsAzure.Commands.ServiceManagement.Test.FunctionalTests
  15. {
  16. using ConfigDataInfo;
  17. using Extensions;
  18. using Model;
  19. using Properties;
  20. using Service.Gateway;
  21. using System;
  22. using System.Collections.Generic;
  23. using System.Collections.ObjectModel;
  24. using System.IO;
  25. using System.Management.Automation;
  26. using System.Net;
  27. using System.Net.Cache;
  28. using System.Reflection;
  29. using System.Text;
  30. using System.Threading;
  31. using System.Xml;
  32. using System.Xml.Linq;
  33. using VisualStudio.TestTools.UnitTesting;
  34. using WindowsAzure.ServiceManagement;
  35. using System.Security.Cryptography.X509Certificates;
  36. using System.Linq;
  37. using Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.PersistentVMs;
  38. [TestClass]
  39. public class ScenarioTest : ServiceManagementTest
  40. {
  41. private const string ReadyState = "ReadyRole";
  42. private string serviceName;
  43. string perfFile;
  44. [TestInitialize]
  45. public void Initialize()
  46. {
  47. serviceName = Utilities.GetUniqueShortName(serviceNamePrefix);
  48. pass = false;
  49. testStartTime = DateTime.Now;
  50. }
  51. /// <summary>
  52. /// </summary>
  53. [TestMethod(), TestCategory("Scenario"), TestCategory("BVT"), TestProperty("Feature", "IaaS"), Priority(1), Owner("priya"), Description("Test the cmdlets (New-AzureQuickVM,Get-AzureVMImage,Get-AzureVM,Get-AzureLocation,Import-AzurePublishSettingsFile,Get-AzureSubscription,Set-AzureSubscription)")]
  54. public void NewWindowsAzureQuickVM()
  55. {
  56. StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);
  57. string newAzureQuickVMName1 = Utilities.GetUniqueShortName(vmNamePrefix);
  58. string newAzureQuickVMName2 = Utilities.GetUniqueShortName(vmNamePrefix);
  59. try
  60. {
  61. if (string.IsNullOrEmpty(imageName))
  62. imageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Windows" }, false);
  63. vmPowershellCmdlets.NewAzureQuickVM(OS.Windows, newAzureQuickVMName1, serviceName, imageName, username, password, locationName);
  64. // Verify
  65. Assert.AreEqual(newAzureQuickVMName1, vmPowershellCmdlets.GetAzureVM(newAzureQuickVMName1, serviceName).Name, true);
  66. vmPowershellCmdlets.NewAzureQuickVM(OS.Windows, newAzureQuickVMName2, serviceName, imageName, username, password);
  67. // Verify
  68. Assert.AreEqual(newAzureQuickVMName2, vmPowershellCmdlets.GetAzureVM(newAzureQuickVMName2, serviceName).Name, true);
  69. try
  70. {
  71. vmPowershellCmdlets.RemoveAzureVM(newAzureQuickVMName1 + "wrongVMName", serviceName);
  72. Assert.Fail("Should Fail!!");
  73. }
  74. catch (Exception e)
  75. {
  76. Console.WriteLine("Fail as expected: {0}", e.ToString());
  77. }
  78. // Cleanup
  79. vmPowershellCmdlets.RemoveAzureVM(newAzureQuickVMName1, serviceName);
  80. Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureQuickVMName1, serviceName));
  81. Assert.AreEqual(newAzureQuickVMName2, vmPowershellCmdlets.GetAzureVM(newAzureQuickVMName2, serviceName).Name, true);
  82. vmPowershellCmdlets.RemoveAzureVM(newAzureQuickVMName2, serviceName);
  83. Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureQuickVMName2, serviceName));
  84. //Remove the service after removing the VM above
  85. vmPowershellCmdlets.RemoveAzureService(serviceName);
  86. //DisableWinRMHttps Test Case
  87. try
  88. {
  89. vmPowershellCmdlets.NewAzureQuickVM(OS.Windows, newAzureQuickVMName2, serviceName, imageName, username, password, locationName, null, "");
  90. pass = true;
  91. }
  92. catch (Exception e)
  93. {
  94. pass = false;
  95. if (e is AssertFailedException)
  96. {
  97. throw;
  98. }
  99. }
  100. finally
  101. {
  102. if (pass == true) pass = true;
  103. vmPowershellCmdlets.RemoveAzureVM(newAzureQuickVMName2, serviceName);
  104. Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureQuickVMName2, serviceName));
  105. }
  106. //End DisableWinRMHttps Test Case
  107. // Negative Test Case--It should Fail
  108. try
  109. {
  110. vmPowershellCmdlets.NewAzureQuickVM(OS.Windows, newAzureQuickVMName1, serviceName, imageName, username, password, locationName);
  111. Assert.Fail("Should have failed, but succeeded!!");
  112. pass = true;
  113. }
  114. catch (Exception e)
  115. {
  116. if (e is AssertFailedException)
  117. {
  118. throw;
  119. }
  120. Console.WriteLine("This exception is expected.");
  121. pass = true;
  122. }
  123. // End of Negative Test Case -- It should Fail]
  124. }
  125. catch (Exception e)
  126. {
  127. Console.WriteLine(e);
  128. throw;
  129. }
  130. }
  131. /// <summary>
  132. /// Get-AzureWinRMUri
  133. /// </summary>
  134. [TestMethod(), TestCategory("Scenario"), TestCategory("BVT"), TestProperty("Feature", "IaaS"), Priority(1), Owner("v-rakonj"), Description("Test the cmdlets (Get-AzureWinRMUri)")]
  135. public void GetAzureWinRMUri()
  136. {
  137. StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);
  138. try
  139. {
  140. string newAzureQuickVMName = Utilities.GetUniqueShortName(vmNamePrefix);
  141. if (string.IsNullOrEmpty(imageName))
  142. imageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Windows" }, false);
  143. vmPowershellCmdlets.NewAzureQuickVM(OS.Windows, newAzureQuickVMName, serviceName, imageName, username, password, locationName);
  144. // Verify the VM
  145. var vmRoleCtxt = vmPowershellCmdlets.GetAzureVM(newAzureQuickVMName, serviceName);
  146. Assert.AreEqual(newAzureQuickVMName, vmRoleCtxt.Name, true, "VM names are not matched!");
  147. // Get the WinRM Uri
  148. var resultUri = vmPowershellCmdlets.GetAzureWinRMUri(serviceName, vmRoleCtxt.Name);
  149. // starting the test.
  150. InputEndpointContext winRMEndpoint = null;
  151. foreach (InputEndpointContext inputEndpointCtxt in vmPowershellCmdlets.GetAzureEndPoint(vmRoleCtxt))
  152. {
  153. if (inputEndpointCtxt.Name.Equals("WinRmHTTPs"))
  154. {
  155. winRMEndpoint = inputEndpointCtxt;
  156. }
  157. }
  158. Assert.IsNotNull(winRMEndpoint, "There is no WinRM endpoint!");
  159. Assert.IsNotNull(resultUri, "No WinRM Uri!");
  160. Console.WriteLine("InputEndpointContext Name: {0}", winRMEndpoint.Name);
  161. Console.WriteLine("InputEndpointContext port: {0}", winRMEndpoint.Port);
  162. Console.WriteLine("InputEndpointContext protocol: {0}", winRMEndpoint.Protocol);
  163. Console.WriteLine("WinRM Uri: {0}", resultUri.AbsoluteUri);
  164. Console.WriteLine("WinRM Port: {0}", resultUri.Port);
  165. Console.WriteLine("WinRM Scheme: {0}", resultUri.Scheme);
  166. Assert.AreEqual(winRMEndpoint.Port, resultUri.Port, "Port numbers are not matched!");
  167. pass = true;
  168. }
  169. catch (Exception e)
  170. {
  171. Console.WriteLine(e);
  172. throw;
  173. }
  174. }
  175. /// <summary>
  176. /// Basic Provisioning a Virtual Machine
  177. /// </summary>
  178. [TestMethod(), TestCategory("Scenario"), TestCategory("BVT"), TestProperty("Feature", "IaaS"), Priority(1), Owner("priya"), Description("Test the cmdlets (Get-AzureLocation,Test-AzureName ,Get-AzureVMImage,New-AzureQuickVM,Get-AzureVM ,Restart-AzureVM,Stop-AzureVM , Start-AzureVM)")]
  179. public void ProvisionLinuxVM()
  180. {
  181. StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);
  182. string newAzureLinuxVMName = Utilities.GetUniqueShortName("PSLinuxVM");
  183. string linuxImageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Linux" }, false);
  184. try
  185. {
  186. vmPowershellCmdlets.NewAzureQuickVM(OS.Linux, newAzureLinuxVMName, serviceName, linuxImageName, "user",
  187. password, locationName);
  188. // Verify
  189. PersistentVMRoleContext vmRoleCtxt = vmPowershellCmdlets.GetAzureVM(newAzureLinuxVMName, serviceName);
  190. Assert.AreEqual(newAzureLinuxVMName, vmRoleCtxt.Name, true);
  191. try
  192. {
  193. vmPowershellCmdlets.RemoveAzureVM(newAzureLinuxVMName + "wrongVMName", serviceName);
  194. Assert.Fail("Should Fail!!");
  195. }
  196. catch (Exception e)
  197. {
  198. if (e is AssertFailedException)
  199. {
  200. throw;
  201. }
  202. Console.WriteLine("Fail as expected: {0}", e);
  203. }
  204. // Cleanup
  205. vmPowershellCmdlets.RemoveAzureVM(newAzureLinuxVMName, serviceName);
  206. Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureLinuxVMName, serviceName));
  207. pass = true;
  208. }
  209. catch (Exception e)
  210. {
  211. Console.WriteLine(e.ToString());
  212. throw;
  213. }
  214. }
  215. /// <summary>
  216. /// Verify Advanced Provisioning for the Dev/Test Scenario
  217. /// Make an Service
  218. /// Make a VM
  219. /// Add 4 additonal endpoints
  220. /// Makes a storage account
  221. /// </summary>
  222. [TestMethod(), TestCategory("Scenario"), TestProperty("Feature", "IaaS"), Priority(1), Owner("msampson"), Description("Test the cmdlets (Get-AzureDeployment, New-AzureVMConfig, Add-AzureProvisioningConfig, Add-AzureEndpoint, New-AzureVM, New-AzureStorageAccount)")]
  223. public void DevTestProvisioning()
  224. {
  225. StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);
  226. string newAzureVM1Name = Utilities.GetUniqueShortName(vmNamePrefix);
  227. //Find a Windows VM Image
  228. imageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Windows" }, false);
  229. //Specify a small Windows image, with username and pw
  230. AzureVMConfigInfo azureVMConfigInfo1 = new AzureVMConfigInfo(newAzureVM1Name, InstanceSize.ExtraSmall.ToString(), imageName);
  231. AzureProvisioningConfigInfo azureProvisioningConfig = new AzureProvisioningConfigInfo(OS.Windows, username, password);
  232. AzureEndPointConfigInfo azureEndPointConfigInfo = new AzureEndPointConfigInfo(AzureEndPointConfigInfo.ParameterSet.NoLB, ProtocolInfo.tcp, 80, 80, "Http");
  233. PersistentVMConfigInfo persistentVMConfigInfo1 = new PersistentVMConfigInfo(azureVMConfigInfo1, azureProvisioningConfig, null, azureEndPointConfigInfo);
  234. PersistentVM persistentVM1 = vmPowershellCmdlets.GetPersistentVM(persistentVMConfigInfo1);
  235. //Add all the endpoints that are added by the Dev Test feature in Azure Tools
  236. azureEndPointConfigInfo = new AzureEndPointConfigInfo(AzureEndPointConfigInfo.ParameterSet.NoLB, ProtocolInfo.tcp, 443, 443, "Https");
  237. azureEndPointConfigInfo.Vm = persistentVM1;
  238. persistentVM1 = vmPowershellCmdlets.AddAzureEndPoint(azureEndPointConfigInfo);
  239. azureEndPointConfigInfo = new AzureEndPointConfigInfo(AzureEndPointConfigInfo.ParameterSet.NoLB, ProtocolInfo.tcp, 1433, 1433, "MSSQL");
  240. azureEndPointConfigInfo.Vm = persistentVM1;
  241. persistentVM1 = vmPowershellCmdlets.AddAzureEndPoint(azureEndPointConfigInfo);
  242. azureEndPointConfigInfo = new AzureEndPointConfigInfo(AzureEndPointConfigInfo.ParameterSet.NoLB, ProtocolInfo.tcp, 8172, 8172, "WebDeploy");
  243. azureEndPointConfigInfo.Vm = persistentVM1;
  244. persistentVM1 = vmPowershellCmdlets.AddAzureEndPoint(azureEndPointConfigInfo);
  245. // Make a storage account named "devtestNNNNN"
  246. string storageAcctName = "devtest" + new Random().Next(10000, 99999);
  247. vmPowershellCmdlets.NewAzureStorageAccount(storageAcctName, locationName);
  248. // When making a new azure VM, you can't specify a location if you want to use the existing service
  249. PersistentVM[] VMs = { persistentVM1 };
  250. vmPowershellCmdlets.NewAzureVM(serviceName, VMs, locationName);
  251. var svcDeployment = vmPowershellCmdlets.GetAzureDeployment(serviceName);
  252. Assert.AreEqual(svcDeployment.ServiceName, serviceName);
  253. var vmDeployment = vmPowershellCmdlets.GetAzureVM(newAzureVM1Name, serviceName);
  254. Assert.AreEqual(vmDeployment.InstanceName, newAzureVM1Name);
  255. // Cleanup
  256. vmPowershellCmdlets.RemoveAzureVM(newAzureVM1Name, serviceName);
  257. Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureVM1Name, serviceName));
  258. Utilities.RetryActionUntilSuccess(() => vmPowershellCmdlets.RemoveAzureStorageAccount(storageAcctName), "in use", 10, 30);
  259. pass = true;
  260. }
  261. /// <summary>
  262. /// Verify Advanced Provisioning
  263. /// </summary>
  264. [TestMethod(), TestCategory("Scenario"), TestProperty("Feature", "IaaS"), Priority(1), Owner("priya"), Description("Test the cmdlets (New-AzureService,New-AzureVMConfig,Add-AzureProvisioningConfig ,Add-AzureDataDisk ,Add-AzureEndpoint,New-AzureVM)")]
  265. public void AdvancedProvisioning()
  266. {
  267. StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);
  268. string newAzureVM1Name = Utilities.GetUniqueShortName(vmNamePrefix);
  269. string newAzureVM2Name = Utilities.GetUniqueShortName(vmNamePrefix);
  270. if (string.IsNullOrEmpty(imageName))
  271. {
  272. imageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Windows" }, false);
  273. }
  274. vmPowershellCmdlets.NewAzureService(serviceName, serviceName, locationName);
  275. var azureVMConfigInfo1 = new AzureVMConfigInfo(newAzureVM1Name, InstanceSize.ExtraSmall.ToString(), imageName);
  276. var azureVMConfigInfo2 = new AzureVMConfigInfo(newAzureVM2Name, InstanceSize.ExtraSmall.ToString(), imageName);
  277. var azureProvisioningConfig = new AzureProvisioningConfigInfo(OS.Windows, username, password);
  278. var azureDataDiskConfigInfo = new AddAzureDataDiskConfig(DiskCreateOption.CreateNew, 50, "datadisk1", 0);
  279. var azureEndPointConfigInfo = new AzureEndPointConfigInfo(AzureEndPointConfigInfo.ParameterSet.CustomProbe, ProtocolInfo.tcp, 80, 80, "web", "lbweb", 80, ProtocolInfo.http, @"/", null, null);
  280. var persistentVMConfigInfo1 = new PersistentVMConfigInfo(azureVMConfigInfo1, azureProvisioningConfig, azureDataDiskConfigInfo, azureEndPointConfigInfo);
  281. var persistentVMConfigInfo2 = new PersistentVMConfigInfo(azureVMConfigInfo2, azureProvisioningConfig, azureDataDiskConfigInfo, azureEndPointConfigInfo);
  282. PersistentVM persistentVM1 = vmPowershellCmdlets.GetPersistentVM(persistentVMConfigInfo1);
  283. PersistentVM persistentVM2 = vmPowershellCmdlets.GetPersistentVM(persistentVMConfigInfo2);
  284. PersistentVM[] VMs = { persistentVM1, persistentVM2 };
  285. vmPowershellCmdlets.NewAzureVM(serviceName, VMs);
  286. // Cleanup
  287. vmPowershellCmdlets.RemoveAzureVM(newAzureVM1Name, serviceName);
  288. vmPowershellCmdlets.RemoveAzureVM(newAzureVM2Name, serviceName);
  289. Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureVM1Name, serviceName));
  290. Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureVM2Name, serviceName));
  291. pass = true;
  292. }
  293. /// <summary>
  294. /// Modifying Existing Virtual Machines
  295. /// </summary>
  296. [TestMethod(), TestCategory("Scenario"), TestProperty("Feature", "IaaS"), Priority(1), Owner("priya"), Description("Test the cmdlets (New-AzureVMConfig,Add-AzureProvisioningConfig ,Add-AzureDataDisk ,Add-AzureEndpoint,New-AzureVM)")]
  297. public void ModifyingVM()
  298. {
  299. StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);
  300. string newAzureQuickVMName = Utilities.GetUniqueShortName(vmNamePrefix);
  301. if (string.IsNullOrEmpty(imageName))
  302. imageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Windows" }, false);
  303. vmPowershellCmdlets.NewAzureQuickVM(OS.Windows, newAzureQuickVMName, serviceName, imageName, username, password, locationName);
  304. AddAzureDataDiskConfig azureDataDiskConfigInfo1 = new AddAzureDataDiskConfig(DiskCreateOption.CreateNew, 50, "datadisk1", 0);
  305. AddAzureDataDiskConfig azureDataDiskConfigInfo2 = new AddAzureDataDiskConfig(DiskCreateOption.CreateNew, 50, "datadisk2", 1);
  306. AzureEndPointConfigInfo azureEndPointConfigInfo = new AzureEndPointConfigInfo(AzureEndPointConfigInfo.ParameterSet.NoLB, ProtocolInfo.tcp, 1433, 2000, "sql");
  307. AddAzureDataDiskConfig[] dataDiskConfig = { azureDataDiskConfigInfo1, azureDataDiskConfigInfo2 };
  308. vmPowershellCmdlets.AddVMDataDisksAndEndPoint(newAzureQuickVMName, serviceName, dataDiskConfig, azureEndPointConfigInfo);
  309. SetAzureDataDiskConfig setAzureDataDiskConfig1 = new SetAzureDataDiskConfig(HostCaching.ReadWrite, 0);
  310. SetAzureDataDiskConfig setAzureDataDiskConfig2 = new SetAzureDataDiskConfig(HostCaching.ReadWrite, 0);
  311. SetAzureDataDiskConfig[] diskConfig = { setAzureDataDiskConfig1, setAzureDataDiskConfig2 };
  312. vmPowershellCmdlets.SetVMDataDisks(newAzureQuickVMName, serviceName, diskConfig);
  313. vmPowershellCmdlets.GetAzureDataDisk(newAzureQuickVMName, serviceName);
  314. // Cleanup
  315. vmPowershellCmdlets.RemoveAzureVM(newAzureQuickVMName, serviceName);
  316. Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureQuickVMName, serviceName));
  317. pass = true;
  318. }
  319. /// <summary>
  320. /// Changes that Require a Reboot
  321. /// </summary>
  322. [TestMethod(), TestCategory("Scenario"), TestProperty("Feature", "IaaS"), Priority(1), Owner("priya"), Description("Test the cmdlets (Get-AzureVM,Set-AzureDataDisk ,Update-AzureVM,Set-AzureVMSize)")]
  323. public void UpdateAndReboot()
  324. {
  325. StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);
  326. string newAzureQuickVMName = Utilities.GetUniqueShortName("PSTestVM");
  327. if (string.IsNullOrEmpty(imageName))
  328. imageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Windows" }, false);
  329. vmPowershellCmdlets.NewAzureQuickVM(OS.Windows, newAzureQuickVMName, serviceName, imageName, username, password, locationName);
  330. var azureDataDiskConfigInfo1 = new AddAzureDataDiskConfig(DiskCreateOption.CreateNew, 50, "datadisk1", 0);
  331. var azureDataDiskConfigInfo2 = new AddAzureDataDiskConfig(DiskCreateOption.CreateNew, 50, "datadisk2", 1);
  332. AddAzureDataDiskConfig[] dataDiskConfig = { azureDataDiskConfigInfo1, azureDataDiskConfigInfo2 };
  333. vmPowershellCmdlets.AddVMDataDisks(newAzureQuickVMName, serviceName, dataDiskConfig);
  334. var setAzureDataDiskConfig1 = new SetAzureDataDiskConfig(HostCaching.ReadOnly, 0);
  335. var setAzureDataDiskConfig2 = new SetAzureDataDiskConfig(HostCaching.ReadOnly, 0);
  336. SetAzureDataDiskConfig[] diskConfig = { setAzureDataDiskConfig1, setAzureDataDiskConfig2 };
  337. vmPowershellCmdlets.SetVMDataDisks(newAzureQuickVMName, serviceName, diskConfig);
  338. var vmSizeConfig = new SetAzureVMSizeConfig(InstanceSize.Medium.ToString());
  339. vmPowershellCmdlets.SetVMSize(newAzureQuickVMName, serviceName, vmSizeConfig);
  340. // Cleanup
  341. vmPowershellCmdlets.RemoveAzureVM(newAzureQuickVMName, serviceName);
  342. Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureQuickVMName, serviceName));
  343. pass = true;
  344. }
  345. /// <summary>
  346. /// </summary>
  347. [TestMethod(), TestCategory("Scenario"), TestProperty("Feature", "IaaS"), Priority(1), Owner("hylee"), Description("Test the cmdlets (Get-AzureDisk,Remove-AzureVM,Remove-AzureDisk,Get-AzureVMImage)")]
  348. public void ManagingDiskImages()
  349. {
  350. StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);
  351. // Create a unique VM name and Service Name
  352. string newAzureQuickVMName = Utilities.GetUniqueShortName(vmNamePrefix);
  353. if (string.IsNullOrEmpty(imageName))
  354. {
  355. imageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Windows" }, false);
  356. }
  357. vmPowershellCmdlets.NewAzureQuickVM(OS.Windows, newAzureQuickVMName, serviceName, imageName, username, password, locationName); // New-AzureQuickVM
  358. Console.WriteLine("VM is created successfully: -Name {0} -ServiceName {1}", newAzureQuickVMName, serviceName);
  359. // starting the test.
  360. Collection<DiskContext> vmDisks = vmPowershellCmdlets.GetAzureDiskAttachedToRoleName(new[] { newAzureQuickVMName }); // Get-AzureDisk | Where {$_.AttachedTo.RoleName -eq $vmname }
  361. foreach (var disk in vmDisks)
  362. Console.WriteLine("The disk, {0}, is created", disk.DiskName);
  363. vmPowershellCmdlets.RemoveAzureVM(newAzureQuickVMName, serviceName); // Remove-AzureVM
  364. Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureQuickVMName, serviceName));
  365. Console.WriteLine("The VM, {0}, is successfully removed.", newAzureQuickVMName);
  366. foreach (var disk in vmDisks)
  367. {
  368. for (int i = 0; i < 3; i++)
  369. {
  370. try
  371. {
  372. vmPowershellCmdlets.RemoveAzureDisk(disk.DiskName, false); // Remove-AzureDisk
  373. break;
  374. }
  375. catch (Exception e)
  376. {
  377. if (e.ToString().ToLowerInvariant().Contains("currently in use") && i != 2)
  378. {
  379. Console.WriteLine("The vhd, {0}, is still in the state of being used by the deleted VM", disk.DiskName);
  380. Thread.Sleep(120000);
  381. continue;
  382. }
  383. else
  384. {
  385. Assert.Fail("error during Remove-AzureDisk: {0}", e.ToString());
  386. }
  387. }
  388. }
  389. try
  390. {
  391. vmPowershellCmdlets.GetAzureDisk(disk.DiskName); // Get-AzureDisk -DiskName (try to get the removed disk.)
  392. Console.WriteLine("Disk is not removed: {0}", disk.DiskName);
  393. pass = false;
  394. }
  395. catch (Exception e)
  396. {
  397. if (e.ToString().ToLowerInvariant().Contains("does not exist"))
  398. {
  399. Console.WriteLine("The disk, {0}, is successfully removed.", disk.DiskName);
  400. continue;
  401. }
  402. else
  403. {
  404. Assert.Fail("Exception: {0}", e.ToString());
  405. }
  406. }
  407. }
  408. pass = true;
  409. }
  410. /// <summary>
  411. /// </summary>
  412. [TestMethod(), TestCategory("Scenario"), TestProperty("Feature", "IaaS"), Priority(1), Owner("hylee"), Description("Test the cmdlets (New-AzureVMConfig,Add-AzureProvisioningConfig,New-AzureVM,Save-AzureVMImage)")]
  413. public void CaptureImagingExportingImportingVMConfig()
  414. {
  415. StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);
  416. // Create a unique VM name
  417. string newAzureVMName = Utilities.GetUniqueShortName("PSTestVM");
  418. Console.WriteLine("VM Name: {0}", newAzureVMName);
  419. // Create a unique Service Name
  420. vmPowershellCmdlets.NewAzureService(serviceName, serviceName, locationName);
  421. Console.WriteLine("Service Name: {0}", serviceName);
  422. if (string.IsNullOrEmpty(imageName))
  423. imageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Windows" }, false);
  424. // starting the test.
  425. var azureVMConfigInfo = new AzureVMConfigInfo(newAzureVMName, InstanceSize.Small.ToString(), imageName); // parameters for New-AzureVMConfig (-Name -InstanceSize -ImageName)
  426. var azureProvisioningConfig = new AzureProvisioningConfigInfo(OS.Windows, username, password); // parameters for Add-AzureProvisioningConfig (-Windows -Password)
  427. var persistentVMConfigInfo = new PersistentVMConfigInfo(azureVMConfigInfo, azureProvisioningConfig, null, null);
  428. PersistentVM persistentVM = vmPowershellCmdlets.GetPersistentVM(persistentVMConfigInfo); // New-AzureVMConfig & Add-AzureProvisioningConfig
  429. PersistentVM[] VMs = { persistentVM };
  430. vmPowershellCmdlets.NewAzureVM(serviceName, VMs); // New-AzureVM
  431. Console.WriteLine("The VM is successfully created: {0}", persistentVM.RoleName);
  432. PersistentVMRoleContext vmRoleCtxt = vmPowershellCmdlets.GetAzureVM(persistentVM.RoleName, serviceName);
  433. Assert.AreEqual(vmRoleCtxt.Name, persistentVM.RoleName, true);
  434. vmPowershellCmdlets.StopAzureVM(newAzureVMName, serviceName, true); // Stop-AzureVM
  435. for (int i = 0; i < 3; i++)
  436. {
  437. vmRoleCtxt = vmPowershellCmdlets.GetAzureVM(persistentVM.RoleName, serviceName);
  438. if (vmRoleCtxt.InstanceStatus == "StoppedVM")
  439. {
  440. break;
  441. }
  442. Console.WriteLine("The status of the VM {0} : {1}", persistentVM.RoleName, vmRoleCtxt.InstanceStatus);
  443. Thread.Sleep(120000);
  444. }
  445. Assert.AreEqual(vmRoleCtxt.InstanceStatus, "StoppedVM", true);
  446. // Save-AzureVMImage
  447. vmPowershellCmdlets.SaveAzureVMImage(serviceName, newAzureVMName, newAzureVMName);
  448. // Verify VM image.
  449. var image = vmPowershellCmdlets.GetAzureVMImage(newAzureVMName)[0];
  450. Assert.AreEqual("Windows", image.OS, "OS is not matching!");
  451. Assert.AreEqual(newAzureVMName, image.ImageName, "Names are not matching!");
  452. // Verify that the VM is removed
  453. Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(persistentVM.RoleName, serviceName));
  454. // Cleanup the registered image
  455. vmPowershellCmdlets.RemoveAzureVMImage(newAzureVMName, true);
  456. pass = true;
  457. }
  458. /// <summary>
  459. /// </summary>
  460. [TestMethod(), TestCategory("Scenario"), TestProperty("Feature", "IaaS"), Priority(1), Owner("hylee"), Description("Test the cmdlets (Export-AzureVM,Remove-AzureVM,Import-AzureVM,New-AzureVM)")]
  461. public void ExportingImportingVMConfigAsTemplateforRepeatableUsage()
  462. {
  463. StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);
  464. // Create a new Azure quick VM
  465. string newAzureQuickVMName = Utilities.GetUniqueShortName("PSTestVM");
  466. if (string.IsNullOrEmpty(imageName))
  467. imageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Windows" }, false);
  468. vmPowershellCmdlets.NewAzureQuickVM(OS.Windows, newAzureQuickVMName, serviceName, imageName, username, password, locationName); // New-AzureQuickVM
  469. Console.WriteLine("VM is created successfully: -Name {0} -ServiceName {1}", newAzureQuickVMName, serviceName);
  470. // starting the test.
  471. string path = ".\\mytestvmconfig1.xml";
  472. PersistentVMRoleContext vmRole = vmPowershellCmdlets.ExportAzureVM(newAzureQuickVMName, serviceName, path); // Export-AzureVM
  473. Console.WriteLine("Exporting VM is successfully done: path - {0} Name - {1}", path, vmRole.Name);
  474. vmPowershellCmdlets.RemoveAzureVM(newAzureQuickVMName, serviceName); // Remove-AzureVM
  475. Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureQuickVMName, serviceName));
  476. Console.WriteLine("The VM is successfully removed: {0}", newAzureQuickVMName);
  477. List<PersistentVM> VMs = new List<PersistentVM>();
  478. foreach (var pervm in vmPowershellCmdlets.ImportAzureVM(path)) // Import-AzureVM
  479. {
  480. VMs.Add(pervm);
  481. Console.WriteLine("The VM, {0}, is imported.", pervm.RoleName);
  482. }
  483. for (int i = 0; i < 3; i++)
  484. {
  485. try
  486. {
  487. vmPowershellCmdlets.NewAzureVM(serviceName, VMs.ToArray()); // New-AzureVM
  488. Console.WriteLine("All VMs are successfully created.");
  489. foreach (var vm in VMs)
  490. {
  491. Console.WriteLine("created VM: {0}", vm.RoleName);
  492. }
  493. break;
  494. }
  495. catch (Exception e)
  496. {
  497. if (e.ToString().ToLowerInvariant().Contains("currently in use") && i != 2)
  498. {
  499. Console.WriteLine("The removed VM is still using the vhd");
  500. Thread.Sleep(120000);
  501. continue;
  502. }
  503. else
  504. {
  505. Assert.Fail("error during New-AzureVM: {0}", e.ToString());
  506. }
  507. }
  508. }
  509. // Verify
  510. PersistentVMRoleContext vmRoleCtxt = vmPowershellCmdlets.GetAzureVM(newAzureQuickVMName, serviceName);
  511. Assert.AreEqual(newAzureQuickVMName, vmRoleCtxt.Name, true);
  512. // Cleanup
  513. vmPowershellCmdlets.RemoveAzureVM(newAzureQuickVMName, serviceName);
  514. Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureQuickVMName, serviceName));
  515. pass = true;
  516. }
  517. /// <summary>
  518. /// </summary>
  519. [TestMethod(), TestCategory("Scenario"), TestProperty("Feature", "IaaS"), Priority(1), Owner("hylee"), Description("Test the cmdlets (Get-AzureVM,Get-AzureEndpoint,Get-AzureRemoteDesktopFile)")]
  520. public void ManagingRDPSSHConnectivity()
  521. {
  522. StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);
  523. // Create a new Azure quick VM
  524. string newAzureQuickVMName = Utilities.GetUniqueShortName("PSTestVM");
  525. if (string.IsNullOrEmpty(imageName))
  526. imageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Windows" }, false);
  527. vmPowershellCmdlets.NewAzureQuickVM(OS.Windows, newAzureQuickVMName, serviceName, imageName, username, password, locationName); // New-AzureQuickVM
  528. Console.WriteLine("VM is created successfully: -Name {0} -ServiceName {1}", newAzureQuickVMName, serviceName);
  529. // starting the test.
  530. PersistentVMRoleContext vmRoleCtxt = vmPowershellCmdlets.GetAzureVM(newAzureQuickVMName, serviceName); // Get-AzureVM
  531. InputEndpointContext inputEndpointCtxt = vmPowershellCmdlets.GetAzureEndPoint(vmRoleCtxt)[0]; // Get-AzureEndpoint
  532. Console.WriteLine("InputEndpointContext Name: {0}", inputEndpointCtxt.Name);
  533. Console.WriteLine("InputEndpointContext port: {0}", inputEndpointCtxt.Port);
  534. Console.WriteLine("InputEndpointContext protocol: {0}", inputEndpointCtxt.Protocol);
  535. Assert.AreEqual(inputEndpointCtxt.Name, "RemoteDesktop", true);
  536. string path = ".\\myvmconnection.rdp";
  537. vmPowershellCmdlets.GetAzureRemoteDesktopFile(newAzureQuickVMName, serviceName, path, false); // Get-AzureRemoteDesktopFile
  538. Console.WriteLine("RDP file is successfully created at: {0}", path);
  539. // ToDo: Automate RDP.
  540. //vmPowershellCmdlets.GetAzureRemoteDesktopFile(newAzureQuickVMName, newAzureQuickVMSvcName, path, true); // Get-AzureRemoteDesktopFile -Launch
  541. Console.WriteLine("Test passed");
  542. // Cleanup
  543. vmPowershellCmdlets.RemoveAzureVM(newAzureQuickVMName, serviceName);
  544. Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureQuickVMName, serviceName));
  545. pass = true;
  546. }
  547. /// <summary>
  548. /// Basic Provisioning a Virtual Machine
  549. /// </summary>
  550. [TestMethod(), TestCategory("Scenario"), TestProperty("Feature", "PAAS"), Priority(1), Owner("hylee"), Description("Test the cmdlet ((New,Get,Set,Remove,Move)-AzureDeployment)")]
  551. [DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", "|DataDirectory|\\Resources\\packageScenario.csv", "packageScenario#csv", DataAccessMethod.Sequential)]
  552. public void DeploymentUpgrade()
  553. {
  554. StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);
  555. perfFile = @"..\deploymentUpgradeResult.csv";
  556. // Choose the package and config files from local machine
  557. string path = Convert.ToString(TestContext.DataRow["path"]);
  558. string packageName = Convert.ToString(TestContext.DataRow["packageName"]);
  559. string configName = Convert.ToString(TestContext.DataRow["configName"]);
  560. string upgradePackageName = Convert.ToString(TestContext.DataRow["upgradePackage"]);
  561. string upgradeConfigName = Convert.ToString(TestContext.DataRow["upgradeConfig"]);
  562. string upgradeConfigName2 = Convert.ToString(TestContext.DataRow["upgradeConfig2"]);
  563. var packagePath1 = new FileInfo(@path + packageName); // package with two roles
  564. var packagePath2 = new FileInfo(@path + upgradePackageName); // package with one role
  565. var configPath1 = new FileInfo(@path + configName); // config with 2 roles, 4 instances each
  566. var configPath2 = new FileInfo(@path + upgradeConfigName); // config with 1 role, 2 instances
  567. var configPath3 = new FileInfo(@path + upgradeConfigName2); // config with 1 role, 4 instances
  568. Assert.IsTrue(File.Exists(packagePath1.FullName), "VHD file not exist={0}", packagePath1);
  569. Assert.IsTrue(File.Exists(configPath1.FullName), "VHD file not exist={0}", configPath1);
  570. string deploymentName = "deployment1";
  571. string deploymentLabel = "label1";
  572. DeploymentInfoContext result;
  573. try
  574. {
  575. vmPowershellCmdlets.NewAzureService(serviceName, serviceName, locationName);
  576. Console.WriteLine("service, {0}, is created.", serviceName);
  577. // New deployment to Production
  578. DateTime start = DateTime.Now;
  579. vmPowershellCmdlets.NewAzureDeployment(serviceName, packagePath1.FullName, configPath1.FullName, DeploymentSlotType.Production, deploymentLabel, deploymentName, false, false);
  580. TimeSpan duration = DateTime.Now - start;
  581. Uri site = Utilities.GetDeploymentAndWaitForReady(serviceName, DeploymentSlotType.Production, 10, 1000);
  582. System.IO.File.AppendAllLines(perfFile, new string[] { String.Format("Deployment, {0}, {1}", duration, DateTime.Now - start) });
  583. Console.WriteLine("site: {0}", site.ToString());
  584. Console.WriteLine("Time for all instances to become in ready state: {0}", DateTime.Now - start);
  585. // Auto-Upgrade the deployment
  586. start = DateTime.Now;
  587. vmPowershellCmdlets.SetAzureDeploymentUpgrade(serviceName, DeploymentSlotType.Production, UpgradeType.Auto, packagePath1.FullName, configPath1.FullName);
  588. duration = DateTime.Now - start;
  589. Console.WriteLine("Auto upgrade took {0}.", duration);
  590. result = vmPowershellCmdlets.GetAzureDeployment(serviceName, DeploymentSlotType.Production);
  591. Utilities.PrintAndCompareDeployment(result, serviceName, deploymentName, serviceName, DeploymentSlotType.Production, null, 8);
  592. Console.WriteLine("successfully updated the deployment");
  593. site = Utilities.GetDeploymentAndWaitForReady(serviceName, DeploymentSlotType.Production, 10, 600);
  594. System.IO.File.AppendAllLines(perfFile, new string[] { String.Format("Auto Upgrade, {0}, {1}", duration, DateTime.Now - start) });
  595. // Manual-Upgrade the deployment
  596. start = DateTime.Now;
  597. vmPowershellCmdlets.SetAzureDeploymentUpgrade(serviceName, DeploymentSlotType.Production, UpgradeType.Manual, packagePath1.FullName, configPath1.FullName);
  598. vmPowershellCmdlets.SetAzureWalkUpgradeDomain(serviceName, DeploymentSlotType.Production, 0);
  599. vmPowershellCmdlets.SetAzureWalkUpgradeDomain(serviceName, DeploymentSlotType.Production, 1);
  600. vmPowershellCmdlets.SetAzureWalkUpgradeDomain(serviceName, DeploymentSlotType.Production, 2);
  601. vmPowershellCmdlets.SetAzureWalkUpgradeDomain(serviceName, DeploymentSlotType.Production, 3);
  602. vmPowershellCmdlets.SetAzureWalkUpgradeDomain(serviceName, DeploymentSlotType.Production, 4);
  603. duration = DateTime.Now - start;
  604. Console.WriteLine("Manual upgrade took {0}.", duration);
  605. result = vmPowershellCmdlets.GetAzureDeployment(serviceName, DeploymentSlotType.Production);
  606. Utilities.PrintAndCompareDeployment(result, serviceName, deploymentName, serviceName, DeploymentSlotType.Production, null, 8);
  607. Console.WriteLine("successfully updated the deployment");
  608. site = Utilities.GetDeploymentAndWaitForReady(serviceName, DeploymentSlotType.Production, 10, 600);
  609. System.IO.File.AppendAllLines(perfFile, new string[] { String.Format("Manual Upgrade, {0}, {1}", duration, DateTime.Now - start) });
  610. // Simulatenous-Upgrade the deployment
  611. start = DateTime.Now;
  612. vmPowershellCmdlets.SetAzureDeploymentUpgrade(serviceName, DeploymentSlotType.Production, UpgradeType.Simultaneous, packagePath1.FullName, configPath1.FullName);
  613. duration = DateTime.Now - start;
  614. Console.WriteLine("Simulatenous upgrade took {0}.", duration);
  615. result = vmPowershellCmdlets.GetAzureDeployment(serviceName, DeploymentSlotType.Production);
  616. Utilities.PrintAndCompareDeployment(result, serviceName, deploymentName, serviceName, DeploymentSlotType.Production, null, 8);
  617. Console.WriteLine("successfully updated the deployment");
  618. site = Utilities.GetDeploymentAndWaitForReady(serviceName, DeploymentSlotType.Production, 10, 600);
  619. System.IO.File.AppendAllLines(perfFile, new string[] { String.Format("Simulatenous Upgrade, {0}, {1}", duration, DateTime.Now - start) });
  620. vmPowershellCmdlets.RemoveAzureDeployment(serviceName, DeploymentSlotType.Production, true);
  621. pass = Utilities.CheckRemove(vmPowershellCmdlets.GetAzureDeployment, serviceName);
  622. }
  623. catch (Exception e)
  624. {
  625. pass = false;
  626. Assert.Fail("Exception occurred: {0}", e.ToString());
  627. }
  628. }
  629. /// <summary>
  630. /// AzureVNetGatewayTest()
  631. /// </summary>
  632. /// Note: Create a VNet, a LocalNet from the portal without creating a gateway.
  633. [TestMethod(), TestCategory("Scenario"), TestProperty("Feature", "IAAS"), Priority(1), Owner("hylee"),
  634. Description("Test the cmdlet ((Set,Remove)-AzureVNetConfig, Get-AzureVNetSite, (New,Get,Set,Remove)-AzureVNetGateway, Get-AzureVNetConnection)")]
  635. public void VNetTest()
  636. {
  637. StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);
  638. string newAzureQuickVMName = Utilities.GetUniqueShortName(vmNamePrefix);
  639. if (string.IsNullOrEmpty(imageName))
  640. imageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Windows" }, false);
  641. // Read the vnetconfig file and get the names of local networks, virtual networks and affinity groups.
  642. XDocument vnetconfigxml = XDocument.Load(vnetConfigFilePath);
  643. List<string> localNets = new List<string>();
  644. List<string> virtualNets = new List<string>();
  645. HashSet<string> affinityGroups = new HashSet<string>();
  646. Dictionary<string,string> dns = new Dictionary<string,string>();
  647. List<LocalNetworkSite> localNetworkSites = new List<LocalNetworkSite>();
  648. AddressPrefixList prefixlist = null;
  649. foreach (XElement el in vnetconfigxml.Descendants())
  650. {
  651. switch (el.Name.LocalName)
  652. {
  653. case "LocalNetworkSite":
  654. {
  655. localNets.Add(el.FirstAttribute.Value);
  656. List<XElement> elements = el.Elements().ToList<XElement>();
  657. prefixlist = new AddressPrefixList();
  658. prefixlist.Add(elements[0].Elements().First().Value);
  659. localNetworkSites.Add(new LocalNetworkSite()
  660. {
  661. VpnGatewayAddress = elements[1].Value,
  662. AddressSpace = new AddressSpace() { AddressPrefixes = prefixlist }
  663. }
  664. );
  665. }
  666. break;
  667. case "VirtualNetworkSite":
  668. virtualNets.Add(el.Attribute("name").Value);
  669. affinityGroups.Add(el.Attribute("AffinityGroup").Value);
  670. break;
  671. case "DnsServer":
  672. {
  673. dns.Add(el.Attribute("name").Value, el.Attribute("IPAddress").Value);
  674. break;
  675. }
  676. default:
  677. break;
  678. }
  679. }
  680. foreach (string aff in affinityGroups)
  681. {
  682. if (Utilities.CheckRemove(vmPowershellCmdlets.GetAzureAffinityGroup, aff))
  683. {
  684. vmPowershellCmdlets.NewAzureAffinityGroup(aff, locationName, null, null);
  685. }
  686. }
  687. string vnet1 = virtualNets[0];
  688. string lnet1 = localNets[0];
  689. try
  690. {
  691. vmPowershellCmdlets.NewAzureQuickVM(OS.Windows, newAzureQuickVMName, serviceName, imageName, username, password, locationName); // New-AzureQuickVM
  692. Console.WriteLine("VM is created successfully: -Name {0} -ServiceName {1}", newAzureQuickVMName, serviceName);
  693. vmPowershellCmdlets.SetAzureVNetConfig(vnetConfigFilePath);
  694. foreach (VirtualNetworkSiteContext site in vmPowershellCmdlets.GetAzureVNetSite(null))
  695. {
  696. Console.WriteLine("Name: {0}, AffinityGroup: {1}", site.Name, site.AffinityGroup);
  697. }
  698. foreach (string vnet in virtualNets)
  699. {
  700. VirtualNetworkSiteContext vnetsite = vmPowershellCmdlets.GetAzureVNetSite(vnet)[0];
  701. Assert.AreEqual(vnet, vnetsite.Name);
  702. //Verify DNS and IPAddress
  703. Assert.AreEqual(1, vnetsite.DnsServers.Count());
  704. Assert.IsTrue(dns.ContainsKey(vnetsite.DnsServers.First().Name));
  705. Assert.AreEqual(dns[vnetsite.DnsServers.First().Name], vnetsite.DnsServers.First().Address);
  706. //Verify the Gateway sites
  707. Assert.AreEqual(1,vnetsite.GatewaySites.Count);
  708. Assert.AreEqual(localNetworkSites[0].VpnGatewayAddress, vnetsite.GatewaySites[0].VpnGatewayAddress);
  709. Assert.IsTrue(localNetworkSites[0].AddressSpace.AddressPrefixes.All(c => vnetsite.GatewaySites[0].AddressSpace.AddressPrefixes.Contains(c)));
  710. Assert.AreEqual(ProvisioningState.NotProvisioned, vmPowershellCmdlets.GetAzureVNetGateway(vnet)[0].State);
  711. }
  712. vmPowershellCmdlets.NewAzureVNetGateway(vnet1);
  713. Assert.IsTrue(GetVNetState(vnet1, ProvisioningState.Provisioned, 12, 60));
  714. // Set-AzureVNetGateway -Connect Test
  715. vmPowershellCmdlets.SetAzureVNetGateway("connect", vnet1, lnet1);
  716. foreach (GatewayConnectionContext connection in vmPowershellCmdlets.GetAzureVNetConnection(vnet1))
  717. {
  718. Console.WriteLine("Connectivity: {0}, LocalNetwork: {1}", connection.ConnectivityState, connection.LocalNetworkSiteName);
  719. Assert.IsFalse(connection.ConnectivityState.ToLowerInvariant().Contains("notconnected"));
  720. }
  721. // Get-AzureVNetGatewayKey
  722. SharedKeyContext result = vmPowershellCmdlets.GetAzureVNetGatewayKey(vnet1,
  723. vmPowershellCmdlets.GetAzureVNetConnection(vnet1)[0].LocalNetworkSiteName);
  724. Console.WriteLine("Gateway Key: {0}", result.Value);
  725. // Set-AzureVNetGateway -Disconnect
  726. vmPowershellCmdlets.SetAzureVNetGateway("disconnect", vnet1, lnet1);
  727. foreach (GatewayConnectionContext connection in vmPowershellCmdlets.GetAzureVNetConnection(vnet1))
  728. {
  729. Console.WriteLine("Connectivity: {0}, LocalNetwork: {1}", connection.ConnectivityState, connection.LocalNetworkSiteName);
  730. }
  731. // Remove-AzureVnetGateway
  732. vmPowershellCmdlets.RemoveAzureVNetGateway(vnet1);
  733. foreach (string vnet in virtualNets)
  734. {
  735. VirtualNetworkGatewayContext gateway = vmPowershellCmdlets.GetAzureVNetGateway(vnet)[0];
  736. Console.WriteLine("State: {0}, VIP: {1}", gateway.State.ToString(), gateway.VIPAddress);
  737. if (vnet.Equals(vnet1))
  738. {
  739. if (gateway.State != ProvisioningState.Deprovisioning &&
  740. gateway.State != ProvisioningState.NotProvisioned)
  741. {
  742. Assert.Fail("The state of the gateway is neither Deprovisioning nor NotProvisioned!");
  743. }
  744. }
  745. else
  746. {
  747. Assert.AreEqual(ProvisioningState.NotProvisioned, gateway.State);
  748. }
  749. }
  750. //Utilities.RetryFunctionUntilSuccess<ManagementOperationContext>(vmPowershellCmdlets.RemoveAzureVNetConfig, "in use", 10, 30);
  751. Utilities.RetryActionUntilSuccess(() => vmPowershellCmdlets.RemoveAzureVNetConfig(), "in use", 10, 30);
  752. pass = true;
  753. }
  754. catch (Exception e)
  755. {
  756. pass = false;
  757. if (cleanupIfFailed)
  758. {
  759. try
  760. {
  761. vmPowershellCmdlets.RemoveAzureVNetGateway(vnet1);
  762. }
  763. catch { }
  764. Utilities.RetryActionUntilSuccess(() => vmPowershellCmdlets.Remov

Large files files are truncated, but you can click here to view the full file