PageRenderTime 63ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/src/ServiceManagement/Common/Commands.ScenarioTest/WAPackIaaS/VirtualMachine/NewWAPackVMTests.cs

https://gitlab.com/jslee1/azure-powershell
C# | 353 lines | 276 code | 64 blank | 13 comment | 1 complexity | e472920afee362286f09c681191154b9 MD5 | raw 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. using System.Collections.Generic;
  15. using System.Linq;
  16. using System.Management.Automation;
  17. using Microsoft.VisualStudio.TestTools.UnitTesting;
  18. namespace Microsoft.WindowsAzure.Commands.ScenarioTest.WAPackIaaS.FunctionalTest
  19. {
  20. [TestClass]
  21. public class NewWAPackVMTests : CmdletTestBase
  22. {
  23. public const string cmdletName = "New-WAPackVM";
  24. public List<PSObject> CreatedVirtualMachines;
  25. [TestInitialize]
  26. public void Initialize()
  27. {
  28. CreatedVirtualMachines = new List<PSObject>();
  29. }
  30. [TestMethod]
  31. [TestCategory("WAPackIaaS-All")]
  32. [TestCategory("WAPackIaaS-Functional")]
  33. public void CreateVMFromTemplateWithVNet()
  34. {
  35. string vmNameToCreate = "TestWindowsVM_VMFromTemplateWithVNet";
  36. var ps = this.PowerShell;
  37. var inputParams = new Dictionary<string, object>()
  38. {
  39. {"Name", WAPackConfigurationFactory.Win7_64TemplateName}
  40. };
  41. var template = this.InvokeCmdlet("Get-WAPackVMTemplate", inputParams);
  42. Assert.AreEqual(template.Count, 1);
  43. ps.Commands.Clear();
  44. inputParams = new Dictionary<string, object>()
  45. {
  46. {"Name", WAPackConfigurationFactory.AvenzVnetName}
  47. };
  48. var vNet = this.InvokeCmdlet("Get-WAPackVnet", inputParams);
  49. Assert.AreEqual(vNet.Count, 1);
  50. inputParams = new Dictionary<string, object>()
  51. {
  52. {"Name", vmNameToCreate},
  53. {"Template", template.First()},
  54. {"VNet", vNet.First()},
  55. {"VMCredential", WAPackConfigurationFactory.WindowsVMCredential},
  56. {"Windows", null},
  57. };
  58. var actualCreatedVM = this.InvokeCmdlet(cmdletName, inputParams);
  59. Assert.AreEqual(1, actualCreatedVM.Count);
  60. var createdVMName = actualCreatedVM.First().Properties["Name"].Value;
  61. Assert.AreEqual(vmNameToCreate, createdVMName);
  62. this.CreatedVirtualMachines.AddRange(actualCreatedVM);
  63. }
  64. [TestMethod]
  65. [TestCategory("WAPackIaaS-All")]
  66. [TestCategory("WAPackIaaS-Functional")]
  67. public void CreateVMFromTemplateWithoutVNet()
  68. {
  69. string vmNameToCreate = "TestWindowsVM_VMFromTemplateWithoutVNet";
  70. var inputParams = new Dictionary<string, object>()
  71. {
  72. {"Name", WAPackConfigurationFactory.Win7_64TemplateName}
  73. };
  74. var template = this.InvokeCmdlet("Get-WAPackVMTemplate", inputParams);
  75. Assert.AreEqual(template.Count, 1);
  76. inputParams = new Dictionary<string, object>()
  77. {
  78. {"Name", vmNameToCreate},
  79. {"Template", template.First()},
  80. {"VMCredential", WAPackConfigurationFactory.WindowsVMCredential},
  81. {"Windows", null},
  82. };
  83. var actualCreatedVM = this.InvokeCmdlet(cmdletName, inputParams);
  84. Assert.AreEqual(1, actualCreatedVM.Count);
  85. var createdVMName = actualCreatedVM.First().Properties["Name"].Value;
  86. Assert.AreEqual(vmNameToCreate, createdVMName);
  87. this.CreatedVirtualMachines.AddRange(actualCreatedVM);
  88. }
  89. [TestMethod]
  90. [TestCategory("WAPackIaaS-All")]
  91. [TestCategory("WAPackIaaS-Functional")]
  92. public void CreateVMFromVHDWithVNet()
  93. {
  94. string vmNameToCreate = "TestWindowsVM_VMFromVHDWithVNet";
  95. var inputParams = new Dictionary<string, object>()
  96. {
  97. {"Name", WAPackConfigurationFactory.AvenzVnetName}
  98. };
  99. var vNet = this.InvokeCmdlet("Get-WAPackVnet", inputParams);
  100. Assert.AreEqual(vNet.Count, 1);
  101. inputParams = new Dictionary<string, object>()
  102. {
  103. {"Name", WAPackConfigurationFactory.Ws2k8R2OSDiskName}
  104. };
  105. var osDisk = this.InvokeCmdlet("Get-WAPackVMOSDisk", inputParams);
  106. Assert.AreEqual(osDisk.Count, 1);
  107. inputParams = new Dictionary<string, object>()
  108. {
  109. {"Name", WAPackConfigurationFactory.VMSizeProfileName}
  110. };
  111. var vmSizeProfile = this.InvokeCmdlet("Get-WAPackVMSizeProfile", inputParams);
  112. Assert.AreEqual(vmSizeProfile.Count, 1);
  113. inputParams = new Dictionary<string, object>()
  114. {
  115. {"Name", vmNameToCreate},
  116. {"OSDisk", osDisk.First()},
  117. {"VNet", vNet.First()},
  118. {"VMSizeProfile", vmSizeProfile.First()}
  119. };
  120. var actualCreatedVM = this.InvokeCmdlet(cmdletName, inputParams);
  121. Assert.AreEqual(1, actualCreatedVM.Count);
  122. var createdVMName = actualCreatedVM.First().Properties["Name"].Value;
  123. Assert.AreEqual(vmNameToCreate, createdVMName);
  124. this.CreatedVirtualMachines.AddRange(actualCreatedVM);
  125. }
  126. [TestMethod]
  127. [TestCategory("WAPackIaaS-All")]
  128. [TestCategory("WAPackIaaS-Functional")]
  129. public void CreateVMFromVHDWithoutVNet()
  130. {
  131. string vmNameToCreate = "TestWindowsVM_VMFromVHDWithoutVNet";
  132. var inputParams = new Dictionary<string, object>()
  133. {
  134. {"Name", WAPackConfigurationFactory.Ws2k8R2OSDiskName}
  135. };
  136. var osDisk = this.InvokeCmdlet("Get-WAPackVMOSDisk", inputParams);
  137. Assert.AreEqual(osDisk.Count, 1);
  138. inputParams = new Dictionary<string, object>()
  139. {
  140. {"Name", WAPackConfigurationFactory.VMSizeProfileName}
  141. };
  142. var vmSizeProfile = this.InvokeCmdlet("Get-WAPackVMSizeProfile", inputParams);
  143. Assert.AreEqual(vmSizeProfile.Count, 1);
  144. inputParams = new Dictionary<string, object>()
  145. {
  146. {"Name", vmNameToCreate},
  147. {"OSDisk", osDisk.First()},
  148. {"VMSizeProfile", vmSizeProfile.First()},
  149. };
  150. var actualCreatedVM = this.InvokeCmdlet(cmdletName, inputParams);
  151. Assert.AreEqual(1, actualCreatedVM.Count);
  152. var createdVMName = actualCreatedVM.First().Properties["Name"].Value;
  153. Assert.AreEqual(vmNameToCreate, createdVMName);
  154. this.CreatedVirtualMachines.AddRange(actualCreatedVM);
  155. }
  156. [TestMethod]
  157. [TestCategory("WAPackIaaS-All")]
  158. [TestCategory("WAPackIaaS-Functional")]
  159. public void CreateUbuntuVMFromTemplate()
  160. {
  161. string vmNameToCreate = "TestUbuntuVM_FromTemplate";
  162. var inputParams = new Dictionary<string, object>()
  163. {
  164. {"Name", WAPackConfigurationFactory.LinuxUbuntu_64TemplateName}
  165. };
  166. var template = this.InvokeCmdlet("Get-WAPackVMTemplate", inputParams);
  167. Assert.AreEqual(template.Count, 1);
  168. inputParams = new Dictionary<string, object>()
  169. {
  170. {"Name", vmNameToCreate},
  171. {"Template", template.First()},
  172. {"VMCredential", WAPackConfigurationFactory.LinuxVMCredential},
  173. {"Linux", null},
  174. };
  175. var actualCreatedVM = this.InvokeCmdlet(cmdletName, inputParams);
  176. Assert.AreEqual(1, actualCreatedVM.Count);
  177. var createdVMName = actualCreatedVM.First().Properties["Name"].Value;
  178. Assert.AreEqual(vmNameToCreate, createdVMName);
  179. this.CreatedVirtualMachines.AddRange(actualCreatedVM);
  180. }
  181. [TestMethod]
  182. [TestCategory("WAPackIaaS-All")]
  183. [TestCategory("WAPackIaaS-Functional")]
  184. public void CreateUbuntuVMFromVHDWithVNet()
  185. {
  186. string vmNameToCreate = "TestUbuntuVM_FromVHD";
  187. var inputParams = new Dictionary<string, object>()
  188. {
  189. {"Name", WAPackConfigurationFactory.LinuxOSDiskName}
  190. };
  191. var osDisk = this.InvokeCmdlet("Get-WAPackVMOSDisk", inputParams);
  192. Assert.AreEqual(osDisk.Count, 1);
  193. inputParams = new Dictionary<string, object>()
  194. {
  195. {"Name", WAPackConfigurationFactory.VMSizeProfileName}
  196. };
  197. var vmSizeProfile = this.InvokeCmdlet("Get-WAPackVMSizeProfile", inputParams);
  198. Assert.AreEqual(vmSizeProfile.Count, 1);
  199. inputParams = new Dictionary<string, object>()
  200. {
  201. {"Name", WAPackConfigurationFactory.AvenzVnetName}
  202. };
  203. var vNet = this.InvokeCmdlet("Get-WAPackVnet", inputParams);
  204. Assert.AreEqual(vNet.Count, 1);
  205. inputParams = new Dictionary<string, object>()
  206. {
  207. {"Name", vmNameToCreate},
  208. {"OSDisk", osDisk.First()},
  209. {"VMSizeProfile", vmSizeProfile.First()},
  210. {"VNet", vNet.First()},
  211. };
  212. var actualCreatedVM = this.InvokeCmdlet(cmdletName, inputParams);
  213. Assert.AreEqual(1, actualCreatedVM.Count);
  214. var createdVMName = actualCreatedVM.First().Properties["Name"].Value;
  215. Assert.AreEqual(vmNameToCreate, createdVMName);
  216. this.CreatedVirtualMachines.AddRange(actualCreatedVM);
  217. }
  218. [TestMethod]
  219. [TestCategory("WAPackIaaS-All")]
  220. [TestCategory("WAPackIaaS-Functional")]
  221. public void CreateUbuntuVMFromVHDWithoutVnet()
  222. {
  223. string vmNameToCreate = "TestUbuntuVM_FromVHDWithoutVnet";
  224. var inputParams = new Dictionary<string, object>()
  225. {
  226. {"Name", WAPackConfigurationFactory.LinuxOSDiskName}
  227. };
  228. var osDisk = this.InvokeCmdlet("Get-WAPackVMOSDisk", inputParams);
  229. Assert.AreEqual(osDisk.Count, 1);
  230. inputParams = new Dictionary<string, object>()
  231. {
  232. {"Name", WAPackConfigurationFactory.VMSizeProfileName}
  233. };
  234. var vmSizeProfile = this.InvokeCmdlet("Get-WAPackVMSizeProfile", inputParams);
  235. Assert.AreEqual(vmSizeProfile.Count, 1);
  236. inputParams = new Dictionary<string, object>()
  237. {
  238. {"Name", vmNameToCreate},
  239. {"OSDisk", osDisk.First()},
  240. {"VMSizeProfile", vmSizeProfile.First()}
  241. };
  242. var actualCreatedVM = this.InvokeCmdlet(cmdletName, inputParams);
  243. Assert.AreEqual(1, actualCreatedVM.Count);
  244. var createdVMName = actualCreatedVM.First().Properties["Name"].Value;
  245. Assert.AreEqual(vmNameToCreate, createdVMName);
  246. this.CreatedVirtualMachines.AddRange(actualCreatedVM);
  247. }
  248. [TestMethod]
  249. [TestCategory("WAPackIaaS-All")]
  250. [TestCategory("WAPackIaaS-Functional")]
  251. public void CreateVMQuickCreate()
  252. {
  253. string vmNameToCreate = "TestWindowsVM_QuickCreate";
  254. var inputParams = new Dictionary<string, object>()
  255. {
  256. {"Name", WAPackConfigurationFactory.Win7_64TemplateName}
  257. };
  258. var template = this.InvokeCmdlet("Get-WAPackVMTemplate", inputParams);
  259. Assert.AreEqual(template.Count, 1);
  260. inputParams = new Dictionary<string, object>()
  261. {
  262. {"Name", vmNameToCreate},
  263. {"Template", template.First()},
  264. {"VMCredential", WAPackConfigurationFactory.WindowsVMCredential}
  265. };
  266. var actualCreatedVM = this.InvokeCmdlet("New-WAPackQuickVM", inputParams);
  267. Assert.AreEqual(1, actualCreatedVM.Count);
  268. var createdVMName = actualCreatedVM.First().Properties["Name"].Value;
  269. Assert.AreEqual(vmNameToCreate, createdVMName);
  270. this.CreatedVirtualMachines.AddRange(actualCreatedVM);
  271. }
  272. [TestCleanup]
  273. public void Cleanup()
  274. {
  275. if (!this.CreatedVirtualMachines.Any())
  276. return;
  277. var ps = this.PowerShell;
  278. foreach (var vm in this.CreatedVirtualMachines)
  279. {
  280. var inputParams = new Dictionary<string, object>()
  281. {
  282. {"VM", vm},
  283. {"Force", null}
  284. };
  285. this.InvokeCmdlet("Remove-WAPackVM", inputParams);
  286. }
  287. }
  288. }
  289. }