PageRenderTime 66ms CodeModel.GetById 27ms RepoModel.GetById 1ms 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
  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.RemoveAzureVNetConfig(), "in use", 10, 30);
  765. //Utilities.RetryFunctionUntilSuccess<ManagementOperationContext>(vmPowershellCmdlets.RemoveAzureVNetConfig, "in use", 10, 30);
  766. }
  767. Assert.Fail("Exception occurred: {0}", e.ToString());
  768. }
  769. finally
  770. {
  771. foreach (string aff in affinityGroups)
  772. {
  773. try
  774. {
  775. vmPowershellCmdlets.RemoveAzureAffinityGroup(aff);
  776. }
  777. catch
  778. {
  779. // Some service uses the affinity group, so it cannot be deleted. Just leave it.
  780. }
  781. }
  782. }
  783. }
  784. [TestMethod(), TestCategory("Scenario"), TestProperty("Feature", "PAAS"), Priority(1), Owner("hylee"), Description("Test the cmdlet (New-AzureServiceRemoteDesktopConfig)")]
  785. [DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", "|DataDirectory|\\Resources\\nodiagpackage.csv", "nodiagpackage#csv", DataAccessMethod.Sequential)]
  786. public void AzureServiceDiagnosticsExtensionConfigScenarioTest()
  787. {
  788. StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);
  789. // Choose the package and config files from local machine
  790. string packageName = Convert.ToString(TestContext.DataRow["packageName"]);
  791. string configName = Convert.ToString(TestContext.DataRow["configName"]);
  792. var packagePath1 = new FileInfo(Directory.GetCurrentDirectory() + "\\" + packageName);
  793. var configPath1 = new FileInfo(Directory.GetCurrentDirectory() + "\\" + configName);
  794. Assert.IsTrue(File.Exists(packagePath1.FullName), "VHD file not exist={0}", packagePath1);
  795. Assert.IsTrue(File.Exists(configPath1.FullName), "VHD file not exist={0}", configPath1);
  796. string deploymentName = "deployment1";
  797. string deploymentLabel = "label1";
  798. DeploymentInfoContext result;
  799. string storage = defaultAzureSubscription.CurrentStorageAccountName;
  800. XmlDocument daConfig = new XmlDocument();
  801. daConfig.Load(@".\da.xml");
  802. try
  803. {
  804. serviceName = Utilities.GetUniqueShortName(serviceNamePrefix);
  805. vmPowershellCmdlets.NewAzureService(serviceName, serviceName, locationName);
  806. Console.WriteLine("service, {0}, is created.", serviceName);
  807. ExtensionConfigurationInput config = vmPowershellCmdlets.NewAzureServiceDiagnosticsExtensionConfig(storage, daConfig);
  808. vmPowershellCmdlets.NewAzureDeployment(serviceName, packagePath1.FullName, configPath1.FullName, DeploymentSlotType.Production, deploymentLabel, deploymentName, false, false, config);
  809. result = vmPowershellCmdlets.GetAzureDeployment(serviceName, DeploymentSlotType.Production);
  810. pass = Utilities.PrintAndCompareDeployment(result, serviceName, deploymentName, deploymentLabel, DeploymentSlotType.Production, null, 2);
  811. Console.WriteLine("successfully deployed the package");
  812. DiagnosticExtensionContext resultContext = vmPowershellCmdlets.GetAzureServiceDiagnosticsExtension(serviceName)[0];
  813. VerifyDiagExtContext(resultContext, "AllRoles", "Default-Diagnostics-Production-Ext-0", storage, daConfig);
  814. vmPowershellCmdlets.RemoveAzureServiceDiagnosticsExtension(serviceName);
  815. Assert.AreEqual(vmPowershellCmdlets.GetAzureServiceDiagnosticsExtension(serviceName).Count, 0);
  816. vmPowershellCmdlets.RemoveAzureDeployment(serviceName, DeploymentSlotType.Production, true);
  817. pass &= Utilities.CheckRemove(vmPowershellCmdlets.GetAzureDeployment, serviceName, DeploymentSlotType.Production);
  818. }
  819. catch (Exception e)
  820. {
  821. pass = false;
  822. Assert.Fail("Exception occurred: {0}", e.ToString());
  823. }
  824. }
  825. [TestMethod(), TestCategory("Scenario"), TestProperty("Feature", "PAAS"), Priority(1), Owner("hylee"), Description("Test the cmdlet ((Get,Set,Remove)-AzureServiceRemoteDesktopExtension)")]
  826. [DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", "|DataDirectory|\\Resources\\nodiagpackage.csv", "nodiagpackage#csv", DataAccessMethod.Sequential)]
  827. public void AzureServiceDiagnosticsExtensionTest()
  828. {
  829. StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);
  830. // Choose the package and config files from local machine
  831. string packageName = Convert.ToString(TestContext.DataRow["packageName"]);
  832. string configName = Convert.ToString(TestContext.DataRow["configName"]);
  833. var packagePath1 = new FileInfo(Directory.GetCurrentDirectory() + "\\" + packageName);
  834. var configPath1 = new FileInfo(Directory.GetCurrentDirectory() + "\\" + configName);
  835. Assert.IsTrue(File.Exists(packagePath1.FullName), "VHD file not exist={0}", packagePath1);
  836. Assert.IsTrue(File.Exists(configPath1.FullName), "VHD file not exist={0}", configPath1);
  837. string deploymentName = "deployment1";
  838. string deploymentLabel = "label1";
  839. DeploymentInfoContext result;
  840. string storage = defaultAzureSubscription.CurrentStorageAccountName;
  841. XmlDocument daConfig = new XmlDocument();
  842. daConfig.Load(@".\da.xml");
  843. try
  844. {
  845. serviceName = Utilities.GetUniqueShortName(serviceNamePrefix);
  846. vmPowershellCmdlets.NewAzureService(serviceName, serviceName, locationName);
  847. Console.WriteLine("service, {0}, is created.", serviceName);
  848. vmPowershellCmdlets.NewAzureDeployment(serviceName, packagePath1.FullName, configPath1.FullName, DeploymentSlotType.Production, deploymentLabel, deploymentName, false, false);
  849. result = vmPowershellCmdlets.GetAzureDeployment(serviceName, DeploymentSlotType.Production);
  850. pass = Utilities.PrintAndCompareDeployment(result, serviceName, deploymentName, deploymentLabel, DeploymentSlotType.Production, null, 2);
  851. Console.WriteLine("successfully deployed the package");
  852. vmPowershellCmdlets.SetAzureServiceDiagnosticsExtension(serviceName, storage, daConfig);
  853. DiagnosticExtensionContext resultContext = vmPowershellCmdlets.GetAzureServiceDiagnosticsExtension(serviceName)[0];
  854. Assert.IsTrue(VerifyDiagExtContext(resultContext, "AllRoles", "Default-Diagnostics-Production-Ext-0", storage, daConfig));
  855. vmPowershellCmdlets.RemoveAzureServiceDiagnosticsExtension(serviceName, true);
  856. Assert.AreEqual(vmPowershellCmdlets.GetAzureServiceDiagnosticsExtension(serviceName).Count, 0);
  857. vmPowershellCmdlets.RemoveAzureDeployment(serviceName, DeploymentSlotType.Production, true);
  858. pass &= Utilities.CheckRemove(vmPowershellCmdlets.GetAzureDeployment, serviceName, DeploymentSlotType.Production);
  859. }
  860. catch (Exception e)
  861. {
  862. pass = false;
  863. Assert.Fail("Exception occurred: {0}", e.ToString());
  864. }
  865. }
  866. // Disabled. Tracking Issue # 1479
  867. [TestMethod(), TestCategory("Scenario"), TestProperty("Feature", "PAAS"), Priority(1), Owner("hylee"), Description("Test the cmdlet (New-AzureServiceRemoteDesktopConfig)")]
  868. [DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", "|DataDirectory|\\Resources\\package.csv", "package#csv", DataAccessMethod.Sequential)]
  869. public void AzureServiceRemoteDesktopExtensionConfigScenarioTest()
  870. {
  871. StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);
  872. // Choose the package and config files from local machine
  873. string packageName = Convert.ToString(TestContext.DataRow["upgradePackage"]);
  874. string configName = Convert.ToString(TestContext.DataRow["upgradeConfig"]);
  875. var packagePath1 = new FileInfo(Directory.GetCurrentDirectory() + "\\" + packageName);
  876. var configPath1 = new FileInfo(Directory.GetCurrentDirectory() + "\\" + configName);
  877. Assert.IsTrue(File.Exists(packagePath1.FullName), "VHD file not exist={0}", packagePath1);
  878. Assert.IsTrue(File.Exists(configPath1.FullName), "VHD file not exist={0}", configPath1);
  879. string deploymentName = "deployment1";
  880. string deploymentLabel = "label1";
  881. DeploymentInfoContext result;
  882. PSCredential cred = new PSCredential(username, Utilities.convertToSecureString(password));
  883. string rdpPath = @".\WebRole1.rdp";
  884. string dns;
  885. try
  886. {
  887. serviceName = Utilities.GetUniqueShortName(serviceNamePrefix);
  888. vmPowershellCmdlets.NewAzureService(serviceName, serviceName, locationName);
  889. Console.WriteLine("service, {0}, is created.", serviceName);
  890. ExtensionConfigurationInput config = vmPowershellCmdlets.NewAzureServiceRemoteDesktopExtensionConfig(cred);
  891. vmPowershellCmdlets.NewAzureDeployment(serviceName, packagePath1.FullName, configPath1.FullName, DeploymentSlotType.Production, deploymentLabel, deploymentName, false, false, config);
  892. result = vmPowershellCmdlets.GetAzureDeployment(serviceName, DeploymentSlotType.Production);
  893. pass = Utilities.PrintAndCompareDeployment(result, serviceName, deploymentName, deploymentLabel, DeploymentSlotType.Production, null, 2);
  894. Console.WriteLine("successfully deployed the package");
  895. RemoteDesktopExtensionContext resultContext = vmPowershellCmdlets.GetAzureServiceRemoteDesktopExtension(serviceName)[0];
  896. VerifyRDPExtContext(resultContext, "AllRoles", "Default-RDP-Production-Ext-0", username, DateTime.Now.AddMonths(6));
  897. Utilities.GetDeploymentAndWaitForReady(serviceName, DeploymentSlotType.Production, 10, 600);
  898. vmPowershellCmdlets.GetAzureRemoteDesktopFile("WebRole1_IN_0", serviceName, rdpPath, false);
  899. using (StreamReader stream = new StreamReader(rdpPath))
  900. {
  901. string firstLine = stream.ReadLine();
  902. dns = Utilities.FindSubstring(firstLine, ':', 2);
  903. }
  904. Assert.IsTrue((Utilities.RDPtestPaaS(dns, "WebRole1", 0, username, password, true)), "Cannot RDP to the instance!!");
  905. vmPowershellCmdlets.RemoveAzureServiceRemoteDesktopExtension(serviceName);
  906. try
  907. {
  908. vmPowershellCmdlets.GetAzureRemoteDesktopFile("WebRole1_IN_0", serviceName, rdpPath, false);
  909. Assert.Fail("Succeeded, but extected to fail!");
  910. }
  911. catch (Exception e)
  912. {
  913. if (e is AssertFailedException)
  914. {
  915. throw;
  916. }
  917. else
  918. {
  919. Console.WriteLine("Failed to get RDP file as expected");
  920. }
  921. }
  922. vmPowershellCmdlets.RemoveAzureDeployment(serviceName, DeploymentSlotType.Production, true);
  923. pass &= Utilities.CheckRemove(vmPowershellCmdlets.GetAzureDeployment, serviceName, DeploymentSlotType.Production);
  924. }
  925. catch (Exception e)
  926. {
  927. pass = false;
  928. Assert.Fail("Exception occurred: {0}", e.ToString());
  929. }
  930. }
  931. // Disabled. Tracking Issue # 1479
  932. [TestMethod(), TestCategory("Scenario"), TestProperty("Feature", "PAAS"), Priority(1), Owner("hylee"), Description("Test the cmdlet ((Get,Set,Remove)-AzureServiceRemoteDesktopExtension)")]
  933. [DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", "|DataDirectory|\\Resources\\package.csv", "package#csv", DataAccessMethod.Sequential)]
  934. public void AzureServiceRemoteDesktopExtensionTest()
  935. {
  936. StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);
  937. // Choose the package and config files from local machine
  938. string packageName = Convert.ToString(TestContext.DataRow["upgradePackage"]);
  939. string configName = Convert.ToString(TestContext.DataRow["upgradeConfig"]);
  940. var packagePath1 = new FileInfo(Directory.GetCurrentDirectory() + "\\" + packageName);
  941. var configPath1 = new FileInfo(Directory.GetCurrentDirectory() + "\\" + configName);
  942. Assert.IsTrue(File.Exists(packagePath1.FullName), "VHD file not exist={0}", packagePath1);
  943. Assert.IsTrue(File.Exists(configPath1.FullName), "VHD file not exist={0}", configPath1);
  944. string deploymentName = "deployment1";
  945. string deploymentLabel = "label1";
  946. DeploymentInfoContext result;
  947. PSCredential cred = new PSCredential(username, Utilities.convertToSecureString(password));
  948. string rdpPath = @".\WebRole1.rdp";
  949. string dns;
  950. try
  951. {
  952. serviceName = Utilities.GetUniqueShortName(serviceNamePrefix);
  953. vmPowershellCmdlets.NewAzureService(serviceName, serviceName, locationName);
  954. Console.WriteLine("service, {0}, is created.", serviceName);
  955. vmPowershellCmdlets.NewAzureDeployment(serviceName, packagePath1.FullName, configPath1.FullName, DeploymentSlotType.Production, deploymentLabel, deploymentName, false, false);
  956. result = vmPowershellCmdlets.GetAzureDeployment(serviceName, DeploymentSlotType.Production);
  957. pass = Utilities.PrintAndCompareDeployment(result, serviceName, deploymentName, deploymentLabel, DeploymentSlotType.Production, null, 2);
  958. Console.WriteLine("successfully deployed the package");
  959. vmPowershellCmdlets.SetAzureServiceRemoteDesktopExtension(serviceName, cred);
  960. RemoteDesktopExtensionContext resultContext = vmPowershellCmdlets.GetAzureServiceRemoteDesktopExtension(serviceName)[0];
  961. VerifyRDPExtContext(resultContext, "AllRoles", "Default-RDP-Production-Ext-0", username, DateTime.Now.AddMonths(6));
  962. vmPowershellCmdlets.GetAzureRemoteDesktopFile("WebRole1_IN_0", serviceName, rdpPath, false);
  963. using (StreamReader stream = new StreamReader(rdpPath))
  964. {
  965. string firstLine = stream.ReadLine();
  966. dns = Utilities.FindSubstring(firstLine, ':', 2);
  967. }
  968. Assert.IsTrue((Utilities.RDPtestPaaS(dns, "WebRole1", 0, username, password, true)), "Cannot RDP to the instance!!");
  969. vmPowershellCmdlets.RemoveAzureServiceRemoteDesktopExtension(serviceName, true);
  970. try
  971. {
  972. vmPowershellCmdlets.GetAzureRemoteDesktopFile("WebRole1_IN_0", serviceName, rdpPath, false);
  973. Assert.Fail("Succeeded, but extected to fail!");
  974. }
  975. catch (Exception e)
  976. {
  977. if (e is AssertFailedException)
  978. {
  979. throw;
  980. }
  981. else
  982. {
  983. Console.WriteLine("Failed to get RDP file as expected");
  984. }
  985. }
  986. vmPowershellCmdlets.RemoveAzureDeployment(serviceName, DeploymentSlotType.Production, true);
  987. pass &= Utilities.CheckRemove(vmPowershellCmdlets.GetAzureDeployment, serviceName, DeploymentSlotType.Production);
  988. }
  989. catch (Exception e)
  990. {
  991. pass = false;
  992. Assert.Fail("Exception occurred: {0}", e.ToString());
  993. }
  994. }
  995. [TestMethod(), TestCategory("Scenario"), TestProperty("Feature", "PAAS"), Priority(1), Owner("hylee"), Description("Test the cmdlet (Reset-AzureRoleInstanceTest with Reboot and Reimage paramaeters)")]
  996. [DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", "|DataDirectory|\\Resources\\package.csv", "package#csv", DataAccessMethod.Sequential)]
  997. public void ReSetAzureRoleInstanceTest()
  998. {
  999. StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);
  1000. // Choose the package and config files from local machine
  1001. string packageName = Convert.ToString(TestContext.DataRow[2]);
  1002. string configName = Convert.ToString(TestContext.DataRow[3]);
  1003. var packagePath1 = new FileInfo(Directory.GetCurrentDirectory() + "\\" + packageName);
  1004. var configPath1 = new FileInfo(Directory.GetCurrentDirectory() + "\\" + configName);
  1005. Assert.IsTrue(File.Exists(packagePath1.FullName), "file not exist={0}", packagePath1);
  1006. Assert.IsTrue(File.Exists(configPath1.FullName), "file not exist={0}", configPath1);
  1007. string deploymentName = Utilities.GetUniqueShortName("ResetRoleInst", 20);
  1008. string deploymentLabel = Utilities.GetUniqueShortName("ResetRoleInstDepLabel", 20);
  1009. DeploymentInfoContext result;
  1010. try
  1011. {
  1012. vmPowershellCmdlets.NewAzureService(serviceName, serviceName, locationName);
  1013. Console.WriteLine("service, {0}, is created.", serviceName);
  1014. vmPowershellCmdlets.NewAzureDeployment(serviceName, packagePath1.FullName, configPath1.FullName, DeploymentSlotType.Staging, deploymentLabel, deploymentName, false, false);
  1015. result = vmPowershellCmdlets.GetAzureDeployment(serviceName, DeploymentSlotType.Staging);
  1016. pass = Utilities.PrintAndCompareDeployment(result, serviceName, deploymentName, deploymentLabel, DeploymentSlotType.Staging, null, 2);
  1017. Console.WriteLine("successfully deployed the package");
  1018. //Reboot the role instance
  1019. vmPowershellCmdlets.ResetAzureRoleInstance(serviceName, "WebRole1_IN_0", DeploymentSlotType.Staging, reboot: true);
  1020. var deploymentContextInfo = vmPowershellCmdlets.GetAzureDeployment(serviceName, DeploymentSlotType.Staging);
  1021. //verify that other instances are in ready state
  1022. string roleStatus = string.Empty;
  1023. foreach (var instance in deploymentContextInfo.RoleInstanceList)
  1024. {
  1025. if (instance.InstanceName.Equals("WebRole1_IN_1"))
  1026. {
  1027. roleStatus = instance.InstanceStatus;
  1028. break;
  1029. }
  1030. }
  1031. pass = roleStatus == ReadyState;
  1032. //Reimage the role instance
  1033. vmPowershellCmdlets.ResetAzureRoleInstance(serviceName, "WebRole1_IN_1", DeploymentSlotType.Staging, reimage: true);
  1034. //verify that other instances are in ready state
  1035. deploymentContextInfo = vmPowershellCmdlets.GetAzureDeployment(serviceName, DeploymentSlotType.Staging);
  1036. roleStatus = string.Empty;
  1037. foreach (var instance in deploymentContextInfo.RoleInstanceList)
  1038. {
  1039. if (instance.InstanceName.Equals("WebRole1_IN_0"))
  1040. {
  1041. roleStatus = instance.InstanceStatus;
  1042. break;
  1043. }
  1044. }
  1045. pass = roleStatus == ReadyState;
  1046. }
  1047. catch (Exception e)
  1048. {
  1049. pass = false;
  1050. Assert.Fail("Exception occurred: {0}", e.ToString());
  1051. }
  1052. finally
  1053. {
  1054. //Ceanup service
  1055. vmPowershellCmdlets.RemoveAzureDeployment(serviceName, DeploymentSlotType.Staging, true);
  1056. pass &= Utilities.CheckRemove(vmPowershellCmdlets.GetAzureDeployment, serviceName, DeploymentSlotType.Staging);
  1057. }
  1058. }
  1059. /// <summary>
  1060. /// Deploy an IaaS VM with Domain Join
  1061. /// </summary>
  1062. [TestMethod(), TestCategory("Scenario"), TestProperty("Feature", "IaaS"), Priority(1), Owner("hylee"), Description("Test the cmdlets (New-AzureVMConfig,Add-AzureProvisioningConfig,New-AzureVM)")]
  1063. public void NewAzureVMDomainJoinTest()
  1064. {
  1065. StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);
  1066. var newAzureVMName = Utilities.GetUniqueShortName(vmNamePrefix);
  1067. const string joinDomainStr = "www.microsoft.com";
  1068. const string domainStr = "microsoft.com";
  1069. const string domainUser = "pstestdomainuser";
  1070. const string domainPassword = "p@ssw0rd";
  1071. try
  1072. {
  1073. if (string.IsNullOrEmpty(imageName))
  1074. {
  1075. imageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Windows" }, false);
  1076. }
  1077. vmPowershellCmdlets.NewAzureService(serviceName, serviceName, locationName);
  1078. var azureVMConfigInfo = new AzureVMConfigInfo(newAzureVMName, InstanceSize.Small.ToString(), imageName);
  1079. var azureProvisioningConfig = new AzureProvisioningConfigInfo("WindowsDomain", username, password,
  1080. joinDomainStr, domainStr, domainUser,
  1081. domainPassword);
  1082. var persistentVMConfigInfo = new PersistentVMConfigInfo(azureVMConfigInfo, azureProvisioningConfig, null,
  1083. null);
  1084. PersistentVM persistentVM = vmPowershellCmdlets.GetPersistentVM(persistentVMConfigInfo);
  1085. PersistentVM[] VMs = { persistentVM };
  1086. vmPowershellCmdlets.NewAzureVM(serviceName, VMs);
  1087. // Todo: Check the domain of the VM
  1088. pass = true;
  1089. }
  1090. catch (Exception e)
  1091. {
  1092. Console.WriteLine(e.ToString());
  1093. throw;
  1094. }
  1095. }
  1096. [TestMethod(), TestCategory("Scenario"), TestProperty("Feature", "IaaS"), Priority(1), Owner("hylee"), Description("Test the cmdlets (New-AzureVMConfig,Add-AzureProvisioningConfig,New-AzureVM)")]
  1097. public void SetProvisionGuestAgentTest()
  1098. {
  1099. try
  1100. {
  1101. string vmName = Utilities.GetUniqueShortName(vmNamePrefix);
  1102. Console.WriteLine("VM Name:{0}", vmName);
  1103. PersistentVM vm = Utilities.CreateIaaSVMObject(vmName, InstanceSize.Small, imageName, true, username, password, true);
  1104. vmPowershellCmdlets.NewAzureVM(serviceName, new[] { vm }, locationName, false);
  1105. var vmRoleContext = vmPowershellCmdlets.GetAzureVM(vmName, serviceName);
  1106. Utilities.PrintContext(vmRoleContext);
  1107. Assert.IsNotNull(vmRoleContext.VM.ProvisionGuestAgent,"ProvisionGuestAgent value cannot be null");
  1108. Assert.IsFalse(vmRoleContext.VM.ProvisionGuestAgent.Value);
  1109. Console.WriteLine("Guest Agent Status: {0}", vmRoleContext.VM.ProvisionGuestAgent.Value);
  1110. vmRoleContext.VM.ProvisionGuestAgent = true;
  1111. vmPowershellCmdlets.UpdateAzureVM(vmName, serviceName, vmRoleContext.VM);
  1112. vmRoleContext = vmPowershellCmdlets.GetAzureVM(vmName, serviceName);
  1113. Utilities.PrintContext(vmRoleContext);
  1114. Assert.IsNotNull(vmRoleContext.VM.ProvisionGuestAgent, "ProvisionGuestAgent value cannot be null");
  1115. Assert.IsTrue(vmRoleContext.VM.ProvisionGuestAgent.Value);
  1116. Console.WriteLine("Guest Agent Status: {0}", vmRoleContext.VM.ProvisionGuestAgent.Value);
  1117. pass = true;
  1118. }
  1119. catch (Exception e)
  1120. {
  1121. Console.WriteLine(e.ToString());
  1122. throw;
  1123. }
  1124. }
  1125. [TestCleanup]
  1126. public virtual void CleanUp()
  1127. {
  1128. Console.WriteLine("Test {0}", pass ? "passed" : "failed");
  1129. // Remove the service
  1130. if ((cleanupIfPassed && pass) || (cleanupIfFailed && !pass))
  1131. {
  1132. CleanupService(serviceName);
  1133. }
  1134. }
  1135. private string GetSiteContent(Uri uri, int maxRetryTimes, bool holdConnection)
  1136. {
  1137. Console.WriteLine("GetSiteContent. uri={0} maxRetryTimes={1}", uri.AbsoluteUri, maxRetryTimes);
  1138. HttpWebRequest request;
  1139. HttpWebResponse response = null;
  1140. var noCachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
  1141. HttpWebRequest.DefaultCachePolicy = noCachePolicy;
  1142. int i;
  1143. for (i = 1; i <= maxRetryTimes; i++)
  1144. {
  1145. try
  1146. {
  1147. request = (HttpWebRequest)WebRequest.Create(uri);
  1148. request.Timeout = 10 * 60 * 1000; //set to 10 minutes, default 100 sec. default IE7/8 is 60 minutes
  1149. response = (HttpWebResponse)request.GetResponse();
  1150. break;
  1151. }
  1152. catch (WebException e)
  1153. {
  1154. Console.WriteLine("Exception Message: " + e.Message);
  1155. if (e.Status == WebExceptionStatus.ProtocolError)
  1156. {
  1157. Console.WriteLine("Status Code: {0}", ((HttpWebResponse)e.Response).StatusCode);
  1158. Console.WriteLine("Status Description: {0}", ((HttpWebResponse)e.Response).StatusDescription);
  1159. }
  1160. }
  1161. Thread.Sleep(30 * 1000);
  1162. }
  1163. if (i > maxRetryTimes)
  1164. {
  1165. throw new Exception("Web Site has error and reached maxRetryTimes");
  1166. }
  1167. Stream responseStream = response.GetResponseStream();
  1168. StringBuilder sb = new StringBuilder();
  1169. byte[] buf = new byte[100];
  1170. int length;
  1171. while ((length = responseStream.Read(buf, 0, 100)) != 0)
  1172. {
  1173. if (holdConnection)
  1174. {
  1175. Thread.Sleep(TimeSpan.FromSeconds(10));
  1176. }
  1177. sb.Append(Encoding.UTF8.GetString(buf, 0, length));
  1178. }
  1179. string responseString = sb.ToString();
  1180. Console.WriteLine("Site content: (IsFromCache={0})", response.IsFromCache);
  1181. Console.WriteLine(responseString);
  1182. return responseString;
  1183. }
  1184. private bool GetVNetState(string vnet, ProvisioningState expectedState, int maxTime, int intervalTime)
  1185. {
  1186. ProvisioningState vnetState;
  1187. int i = 0;
  1188. do
  1189. {
  1190. vnetState = vmPowershellCmdlets.GetAzureVNetGateway(vnet)[0].State;
  1191. Thread.Sleep(intervalTime * 1000);
  1192. i++;
  1193. }
  1194. while (!vnetState.Equals(expectedState) || i < maxTime);
  1195. return vnetState.Equals(expectedState);
  1196. }
  1197. private bool VerifyDiagExtContext(DiagnosticExtensionContext resultContext, string role, string extID, string storage, XmlDocument config)
  1198. {
  1199. try
  1200. {
  1201. Assert.AreEqual(role, resultContext.Role.RoleType.ToString());
  1202. Assert.AreEqual("Diagnostics", resultContext.Extension);
  1203. Assert.AreEqual(extID, resultContext.Id);
  1204. Assert.AreEqual(storage, resultContext.StorageAccountName);
  1205. string inner = Utilities.GetInnerXml(resultContext.WadCfg, "WadCfg");
  1206. Assert.IsTrue(Utilities.CompareWadCfg(inner, config));
  1207. return true;
  1208. }
  1209. catch
  1210. {
  1211. return false;
  1212. }
  1213. }
  1214. private bool VerifyRDPExtContext(RemoteDesktopExtensionContext resultContext, string role, string extID, string userName, DateTime exp)
  1215. {
  1216. try
  1217. {
  1218. Assert.AreEqual(role, resultContext.Role.RoleType.ToString());
  1219. Assert.AreEqual("RDP", resultContext.Extension);
  1220. Assert.AreEqual(extID, resultContext.Id);
  1221. Assert.AreEqual(userName, resultContext.UserName);
  1222. Assert.IsTrue(Utilities.CompareDateTime(exp, resultContext.Expiration));
  1223. return true;
  1224. }
  1225. catch
  1226. {
  1227. return false;
  1228. }
  1229. }
  1230. }
  1231. }