test_vmware.py 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265
  1. # -*- coding: utf-8 -*-
  2. """
  3. :codeauthor: `Nitin Madhok <nmadhok@clemson.edu>`
  4. tests.unit.cloud.clouds.vmware_test
  5. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6. """
  7. # Import Python libs
  8. from __future__ import absolute_import, print_function, unicode_literals
  9. from copy import deepcopy
  10. # Import Salt Libs
  11. from salt import config
  12. from salt.cloud.clouds import vmware
  13. from salt.exceptions import SaltCloudSystemExit
  14. # Import Salt Testing Libs
  15. from tests.support.mixins import LoaderModuleMockMixin
  16. from tests.support.mock import MagicMock, Mock, patch
  17. from tests.support.unit import TestCase, skipIf
  18. # Attempt to import pyVim and pyVmomi libs
  19. HAS_LIBS = True
  20. # pylint: disable=import-error,no-name-in-module,unused-import
  21. try:
  22. from pyVim.connect import SmartConnect, Disconnect
  23. from pyVmomi import vim, vmodl
  24. except ImportError:
  25. HAS_LIBS = False
  26. # pylint: enable=import-error,no-name-in-module,unused-import
  27. # Global Variables
  28. PROVIDER_CONFIG = {
  29. "vcenter01": {
  30. "vmware": {
  31. "driver": "vmware",
  32. "url": "vcenter01.domain.com",
  33. "user": "DOMAIN\\user",
  34. "password": "verybadpass",
  35. }
  36. }
  37. }
  38. VM_NAME = "test-vm"
  39. PROFILE = {
  40. "base-gold": {
  41. "provider": "vcenter01:vmware",
  42. "datastore": "Datastore1",
  43. "resourcepool": "Resources",
  44. "folder": "vm",
  45. }
  46. }
  47. class ExtendedTestCase(TestCase, LoaderModuleMockMixin):
  48. """
  49. Extended TestCase class containing additional helper methods.
  50. """
  51. def setup_loader_modules(self):
  52. return {
  53. vmware: {
  54. "__virtual__": MagicMock(return_value="vmware"),
  55. "__active_provider_name__": "",
  56. }
  57. }
  58. def assertRaisesWithMessage(self, exc_type, exc_msg, func, *args, **kwargs):
  59. try:
  60. func(*args, **kwargs)
  61. self.assertFail()
  62. except Exception as exc: # pylint: disable=broad-except
  63. self.assertEqual(type(exc), exc_type)
  64. self.assertEqual(exc.message, exc_msg)
  65. @skipIf(not HAS_LIBS, "Install pyVmomi to be able to run this test.")
  66. class VMwareTestCase(ExtendedTestCase):
  67. """
  68. Unit TestCase for salt.cloud.clouds.vmware module.
  69. """
  70. def test_test_vcenter_connection_call(self):
  71. """
  72. Tests that a SaltCloudSystemExit is raised when trying to call test_vcenter_connection
  73. with anything other than --function or -f.
  74. """
  75. self.assertRaises(
  76. SaltCloudSystemExit, vmware.test_vcenter_connection, call="action"
  77. )
  78. def test_get_vcenter_version_call(self):
  79. """
  80. Tests that a SaltCloudSystemExit is raised when trying to call get_vcenter_version
  81. with anything other than --function or -f.
  82. """
  83. self.assertRaises(
  84. SaltCloudSystemExit, vmware.get_vcenter_version, call="action"
  85. )
  86. def test_avail_images_call(self):
  87. """
  88. Tests that a SaltCloudSystemExit is raised when trying to call avail_images
  89. with --action or -a.
  90. """
  91. self.assertRaises(SaltCloudSystemExit, vmware.avail_images, call="action")
  92. def test_avail_locations_call(self):
  93. """
  94. Tests that a SaltCloudSystemExit is raised when trying to call avail_locations
  95. with --action or -a.
  96. """
  97. self.assertRaises(SaltCloudSystemExit, vmware.avail_locations, call="action")
  98. def test_avail_sizes_call(self):
  99. """
  100. Tests that a SaltCloudSystemExit is raised when trying to call avail_sizes
  101. with --action or -a.
  102. """
  103. self.assertRaises(SaltCloudSystemExit, vmware.avail_sizes, call="action")
  104. def test_list_datacenters_call(self):
  105. """
  106. Tests that a SaltCloudSystemExit is raised when trying to call list_datacenters
  107. with anything other than --function or -f.
  108. """
  109. self.assertRaises(SaltCloudSystemExit, vmware.list_datacenters, call="action")
  110. def test_list_clusters_call(self):
  111. """
  112. Tests that a SaltCloudSystemExit is raised when trying to call list_clusters
  113. with anything other than --function or -f.
  114. """
  115. self.assertRaises(SaltCloudSystemExit, vmware.list_clusters, call="action")
  116. def test_list_datastore_clusters_call(self):
  117. """
  118. Tests that a SaltCloudSystemExit is raised when trying to call list_datastore_clusters
  119. with anything other than --function or -f.
  120. """
  121. self.assertRaises(
  122. SaltCloudSystemExit, vmware.list_datastore_clusters, call="action"
  123. )
  124. def test_list_datastores_call(self):
  125. """
  126. Tests that a SaltCloudSystemExit is raised when trying to call list_datastores
  127. with anything other than --function or -f.
  128. """
  129. self.assertRaises(SaltCloudSystemExit, vmware.list_datastores, call="action")
  130. def test_list_hosts_call(self):
  131. """
  132. Tests that a SaltCloudSystemExit is raised when trying to call list_hosts
  133. with anything other than --function or -f.
  134. """
  135. self.assertRaises(SaltCloudSystemExit, vmware.list_hosts, call="action")
  136. def test_list_resourcepools_call(self):
  137. """
  138. Tests that a SaltCloudSystemExit is raised when trying to call list_resourcepools
  139. with anything other than --function or -f.
  140. """
  141. self.assertRaises(SaltCloudSystemExit, vmware.list_resourcepools, call="action")
  142. def test_list_networks_call(self):
  143. """
  144. Tests that a SaltCloudSystemExit is raised when trying to call list_networks
  145. with anything other than --function or -f.
  146. """
  147. self.assertRaises(SaltCloudSystemExit, vmware.list_networks, call="action")
  148. def test_list_nodes_call(self):
  149. """
  150. Tests that a SaltCloudSystemExit is raised when trying to call list_nodes
  151. with --action or -a.
  152. """
  153. self.assertRaises(SaltCloudSystemExit, vmware.list_nodes, call="action")
  154. def test_list_nodes_min_call(self):
  155. """
  156. Tests that a SaltCloudSystemExit is raised when trying to call list_nodes_min
  157. with --action or -a.
  158. """
  159. self.assertRaises(SaltCloudSystemExit, vmware.list_nodes_min, call="action")
  160. def test_list_nodes_full_call(self):
  161. """
  162. Tests that a SaltCloudSystemExit is raised when trying to call list_nodes_full
  163. with --action or -a.
  164. """
  165. self.assertRaises(SaltCloudSystemExit, vmware.list_nodes_full, call="action")
  166. def test_list_nodes_select_call(self):
  167. """
  168. Tests that a SaltCloudSystemExit is raised when trying to call list_nodes_full
  169. with --action or -a.
  170. """
  171. self.assertRaises(SaltCloudSystemExit, vmware.list_nodes_select, call="action")
  172. def test_list_folders_call(self):
  173. """
  174. Tests that a SaltCloudSystemExit is raised when trying to call list_folders
  175. with anything other than --function or -f.
  176. """
  177. self.assertRaises(SaltCloudSystemExit, vmware.list_folders, call="action")
  178. def test_list_snapshots_call(self):
  179. """
  180. Tests that a SaltCloudSystemExit is raised when trying to call list_snapshots
  181. with anything other than --function or -f.
  182. """
  183. self.assertRaises(SaltCloudSystemExit, vmware.list_snapshots, call="action")
  184. def test_list_hosts_by_cluster_call(self):
  185. """
  186. Tests that a SaltCloudSystemExit is raised when trying to call list_hosts_by_cluster
  187. with anything other than --function or -f.
  188. """
  189. self.assertRaises(
  190. SaltCloudSystemExit, vmware.list_hosts_by_cluster, call="action"
  191. )
  192. def test_list_clusters_by_datacenter_call(self):
  193. """
  194. Tests that a SaltCloudSystemExit is raised when trying to call list_clusters_by_datacenter
  195. with anything other than --function or -f.
  196. """
  197. self.assertRaises(
  198. SaltCloudSystemExit, vmware.list_clusters_by_datacenter, call="action"
  199. )
  200. def test_list_hosts_by_datacenter_call(self):
  201. """
  202. Tests that a SaltCloudSystemExit is raised when trying to call list_hosts_by_datacenter
  203. with anything other than --function or -f.
  204. """
  205. self.assertRaises(
  206. SaltCloudSystemExit, vmware.list_hosts_by_datacenter, call="action"
  207. )
  208. def test_list_hbas_call(self):
  209. """
  210. Tests that a SaltCloudSystemExit is raised when trying to call list_hbas
  211. with anything other than --function or -f.
  212. """
  213. self.assertRaises(SaltCloudSystemExit, vmware.list_hbas, call="action")
  214. def test_list_dvs_call(self):
  215. """
  216. Tests that a SaltCloudSystemExit is raised when trying to call list_dvs
  217. with anything other than --function or -f.
  218. """
  219. self.assertRaises(SaltCloudSystemExit, vmware.list_dvs, call="action")
  220. def test_list_vapps_call(self):
  221. """
  222. Tests that a SaltCloudSystemExit is raised when trying to call list_vapps
  223. with anything other than --function or -f.
  224. """
  225. self.assertRaises(SaltCloudSystemExit, vmware.list_vapps, call="action")
  226. def test_list_templates_call(self):
  227. """
  228. Tests that a SaltCloudSystemExit is raised when trying to call list_templates
  229. with anything other than --function or -f.
  230. """
  231. self.assertRaises(SaltCloudSystemExit, vmware.list_templates, call="action")
  232. def test_create_datacenter_call(self):
  233. """
  234. Tests that a SaltCloudSystemExit is raised when trying to call create_datacenter
  235. with anything other than --function or -f.
  236. """
  237. self.assertRaises(SaltCloudSystemExit, vmware.create_datacenter, call="action")
  238. def test_create_cluster_call(self):
  239. """
  240. Tests that a SaltCloudSystemExit is raised when trying to call create_cluster
  241. with anything other than --function or -f.
  242. """
  243. self.assertRaises(SaltCloudSystemExit, vmware.create_cluster, call="action")
  244. def test_rescan_hba_call(self):
  245. """
  246. Tests that a SaltCloudSystemExit is raised when trying to call rescan_hba
  247. with anything other than --function or -f.
  248. """
  249. self.assertRaises(SaltCloudSystemExit, vmware.rescan_hba, call="action")
  250. def test_upgrade_tools_all_call(self):
  251. """
  252. Tests that a SaltCloudSystemExit is raised when trying to call upgrade_tools_all
  253. with anything other than --function or -f.
  254. """
  255. self.assertRaises(SaltCloudSystemExit, vmware.upgrade_tools_all, call="action")
  256. def test_enter_maintenance_mode_call(self):
  257. """
  258. Tests that a SaltCloudSystemExit is raised when trying to call enter_maintenance_mode
  259. with anything other than --function or -f.
  260. """
  261. self.assertRaises(
  262. SaltCloudSystemExit, vmware.enter_maintenance_mode, call="action"
  263. )
  264. def test_exit_maintenance_mode_call(self):
  265. """
  266. Tests that a SaltCloudSystemExit is raised when trying to call exit_maintenance_mode
  267. with anything other than --function or -f.
  268. """
  269. self.assertRaises(
  270. SaltCloudSystemExit, vmware.exit_maintenance_mode, call="action"
  271. )
  272. def test_create_folder_call(self):
  273. """
  274. Tests that a SaltCloudSystemExit is raised when trying to call create_folder
  275. with anything other than --function or -f.
  276. """
  277. self.assertRaises(SaltCloudSystemExit, vmware.create_folder, call="action")
  278. def test_add_host_call(self):
  279. """
  280. Tests that a SaltCloudSystemExit is raised when trying to call add_host
  281. with anything other than --function or -f.
  282. """
  283. self.assertRaises(SaltCloudSystemExit, vmware.add_host, call="action")
  284. def test_remove_host_call(self):
  285. """
  286. Tests that a SaltCloudSystemExit is raised when trying to call remove_host
  287. with anything other than --function or -f.
  288. """
  289. self.assertRaises(SaltCloudSystemExit, vmware.remove_host, call="action")
  290. def test_connect_host_call(self):
  291. """
  292. Tests that a SaltCloudSystemExit is raised when trying to call connect_host
  293. with anything other than --function or -f.
  294. """
  295. self.assertRaises(SaltCloudSystemExit, vmware.connect_host, call="action")
  296. def test_disconnect_host_call(self):
  297. """
  298. Tests that a SaltCloudSystemExit is raised when trying to call disconnect_host
  299. with anything other than --function or -f.
  300. """
  301. self.assertRaises(SaltCloudSystemExit, vmware.disconnect_host, call="action")
  302. def test_reboot_host_call(self):
  303. """
  304. Tests that a SaltCloudSystemExit is raised when trying to call reboot_host
  305. with anything other than --function or -f.
  306. """
  307. self.assertRaises(SaltCloudSystemExit, vmware.reboot_host, call="action")
  308. def test_create_datastore_cluster_call(self):
  309. """
  310. Tests that a SaltCloudSystemExit is raised when trying to call create_datastore_cluster
  311. with anything other than --function or -f.
  312. """
  313. self.assertRaises(
  314. SaltCloudSystemExit, vmware.create_datastore_cluster, call="action"
  315. )
  316. def test_show_instance_call(self):
  317. """
  318. Tests that a SaltCloudSystemExit is raised when trying to call show_instance
  319. with anything other than --action or -a.
  320. """
  321. self.assertRaises(
  322. SaltCloudSystemExit, vmware.show_instance, name=VM_NAME, call="function"
  323. )
  324. def test_start_call(self):
  325. """
  326. Tests that a SaltCloudSystemExit is raised when trying to call start
  327. with anything other than --action or -a.
  328. """
  329. self.assertRaises(
  330. SaltCloudSystemExit, vmware.start, name=VM_NAME, call="function"
  331. )
  332. def test_stop_call(self):
  333. """
  334. Tests that a SaltCloudSystemExit is raised when trying to call stop
  335. with anything other than --action or -a.
  336. """
  337. self.assertRaises(
  338. SaltCloudSystemExit, vmware.stop, name=VM_NAME, call="function"
  339. )
  340. def test_suspend_call(self):
  341. """
  342. Tests that a SaltCloudSystemExit is raised when trying to call suspend
  343. with anything other than --action or -a.
  344. """
  345. self.assertRaises(
  346. SaltCloudSystemExit, vmware.suspend, name=VM_NAME, call="function"
  347. )
  348. def test_reset_call(self):
  349. """
  350. Tests that a SaltCloudSystemExit is raised when trying to call reset
  351. with anything other than --action or -a.
  352. """
  353. self.assertRaises(
  354. SaltCloudSystemExit, vmware.reset, name=VM_NAME, call="function"
  355. )
  356. def test_terminate_call(self):
  357. """
  358. Tests that a SaltCloudSystemExit is raised when trying to call terminate
  359. with anything other than --action or -a.
  360. """
  361. self.assertRaises(
  362. SaltCloudSystemExit, vmware.terminate, name=VM_NAME, call="function"
  363. )
  364. def test_destroy_call(self):
  365. """
  366. Tests that a SaltCloudSystemExit is raised when trying to call destroy
  367. with --function or -f.
  368. """
  369. self.assertRaises(
  370. SaltCloudSystemExit, vmware.destroy, name=VM_NAME, call="function"
  371. )
  372. def test_shutdown_host_call(self):
  373. """
  374. Tests that a SaltCloudSystemExit is raised when trying to call convert_to_template
  375. with anything other than --action or -a.
  376. """
  377. with patch.object(vmware, "_get_si", Mock()), patch(
  378. "salt.utils.vmware.get_mor_by_property", Mock()
  379. ):
  380. self.assertRaises(
  381. SaltCloudSystemExit,
  382. vmware.shutdown_host,
  383. kwargs={"host": VM_NAME},
  384. call="action",
  385. )
  386. def test_upgrade_tools_call(self):
  387. """
  388. Tests that a SaltCloudSystemExit is raised when trying to call upgrade_tools
  389. with anything other than --action or -a.
  390. """
  391. self.assertRaises(
  392. SaltCloudSystemExit, vmware.upgrade_tools, name=VM_NAME, call="function"
  393. )
  394. def test_create_snapshot_call(self):
  395. """
  396. Tests that a SaltCloudSystemExit is raised when trying to call create_snapshot
  397. with anything other than --action or -a.
  398. """
  399. self.assertRaises(
  400. SaltCloudSystemExit, vmware.create_snapshot, name=VM_NAME, call="function"
  401. )
  402. def test_revert_to_snapshot_call(self):
  403. """
  404. Tests that a SaltCloudSystemExit is raised when trying to call revert_to_snapshot
  405. with anything other than --action or -a.
  406. """
  407. self.assertRaises(
  408. SaltCloudSystemExit,
  409. vmware.revert_to_snapshot,
  410. name=VM_NAME,
  411. call="function",
  412. )
  413. def test_remove_snapshot_call(self):
  414. """
  415. Tests that a SaltCloudSystemExit is raised when trying to call remove_snapshot
  416. with anything other than --action or -a.
  417. """
  418. self.assertRaises(
  419. SaltCloudSystemExit,
  420. vmware.remove_snapshot,
  421. name=VM_NAME,
  422. kwargs={"snapshot_name": "mySnapshot"},
  423. call="function",
  424. )
  425. def test_remove_snapshot_call_no_snapshot_name_in_kwargs(self):
  426. """
  427. Tests that a SaltCloudSystemExit is raised when name is not present in kwargs.
  428. """
  429. self.assertRaises(
  430. SaltCloudSystemExit, vmware.remove_snapshot, name=VM_NAME, call="action"
  431. )
  432. def test_remove_all_snapshots_call(self):
  433. """
  434. Tests that a SaltCloudSystemExit is raised when trying to call remove_all_snapshots
  435. with anything other than --action or -a.
  436. """
  437. self.assertRaises(
  438. SaltCloudSystemExit,
  439. vmware.remove_all_snapshots,
  440. name=VM_NAME,
  441. call="function",
  442. )
  443. def test_convert_to_template_call(self):
  444. """
  445. Tests that a SaltCloudSystemExit is raised when trying to call convert_to_template
  446. with anything other than --action or -a.
  447. """
  448. self.assertRaises(
  449. SaltCloudSystemExit,
  450. vmware.convert_to_template,
  451. name=VM_NAME,
  452. call="function",
  453. )
  454. def test_avail_sizes(self):
  455. """
  456. Tests that avail_sizes returns an empty dictionary.
  457. """
  458. self.assertEqual(vmware.avail_sizes(call="foo"), {})
  459. def test_create_datacenter_no_kwargs(self):
  460. """
  461. Tests that a SaltCloudSystemExit is raised when no kwargs are provided to
  462. create_datacenter.
  463. """
  464. self.assertRaises(
  465. SaltCloudSystemExit, vmware.create_datacenter, kwargs=None, call="function"
  466. )
  467. def test_create_datacenter_no_name_in_kwargs(self):
  468. """
  469. Tests that a SaltCloudSystemExit is raised when name is not present in
  470. kwargs that are provided to create_datacenter.
  471. """
  472. self.assertRaises(
  473. SaltCloudSystemExit,
  474. vmware.create_datacenter,
  475. kwargs={"foo": "bar"},
  476. call="function",
  477. )
  478. def test_create_datacenter_name_too_short(self):
  479. """
  480. Tests that a SaltCloudSystemExit is raised when name is present in kwargs
  481. that are provided to create_datacenter but is an empty string.
  482. """
  483. self.assertRaises(
  484. SaltCloudSystemExit,
  485. vmware.create_datacenter,
  486. kwargs={"name": ""},
  487. call="function",
  488. )
  489. def test_create_datacenter_name_too_long(self):
  490. """
  491. Tests that a SaltCloudSystemExit is raised when name is present in kwargs
  492. that are provided to create_datacenter but is a string with length <= 80.
  493. """
  494. self.assertRaises(
  495. SaltCloudSystemExit,
  496. vmware.create_datacenter,
  497. kwargs={
  498. "name": "cCD2GgJGPG1DUnPeFBoPeqtdmUxIWxDoVFbA14vIG0BPoUECkgbRMnnY6gaUPBvIDCcsZ5HU48ubgQu5c"
  499. },
  500. call="function",
  501. )
  502. def test_create_cluster_no_kwargs(self):
  503. """
  504. Tests that a SaltCloudSystemExit is raised when no kwargs are provided to
  505. create_cluster.
  506. """
  507. self.assertRaises(
  508. SaltCloudSystemExit, vmware.create_cluster, kwargs=None, call="function"
  509. )
  510. def test_create_cluster_no_name_no_datacenter_in_kwargs(self):
  511. """
  512. Tests that a SaltCloudSystemExit is raised when neither the name nor the
  513. datacenter is present in kwargs that are provided to create_cluster.
  514. """
  515. self.assertRaises(
  516. SaltCloudSystemExit,
  517. vmware.create_cluster,
  518. kwargs={"foo": "bar"},
  519. call="function",
  520. )
  521. def test_create_cluster_no_datacenter_in_kwargs(self):
  522. """
  523. Tests that a SaltCloudSystemExit is raised when the name is present but the
  524. datacenter is not present in kwargs that are provided to create_cluster.
  525. """
  526. self.assertRaises(
  527. SaltCloudSystemExit,
  528. vmware.create_cluster,
  529. kwargs={"name": "my-cluster"},
  530. call="function",
  531. )
  532. def test_create_cluster_no_name_in_kwargs(self):
  533. """
  534. Tests that a SaltCloudSystemExit is raised when the datacenter is present
  535. but the name is not present in kwargs that are provided to create_cluster.
  536. """
  537. self.assertRaises(
  538. SaltCloudSystemExit,
  539. vmware.create_cluster,
  540. kwargs={"datacenter": "my-datacenter"},
  541. call="function",
  542. )
  543. def test_rescan_hba_no_kwargs(self):
  544. """
  545. Tests that a SaltCloudSystemExit is raised when no kwargs are provided to
  546. rescan_hba.
  547. """
  548. self.assertRaises(
  549. SaltCloudSystemExit, vmware.rescan_hba, kwargs=None, call="function"
  550. )
  551. def test_rescan_hba_no_host_in_kwargs(self):
  552. """
  553. Tests that a SaltCloudSystemExit is raised when host is not present in
  554. kwargs that are provided to rescan_hba.
  555. """
  556. self.assertRaises(
  557. SaltCloudSystemExit,
  558. vmware.rescan_hba,
  559. kwargs={"foo": "bar"},
  560. call="function",
  561. )
  562. def test_create_snapshot_no_kwargs(self):
  563. """
  564. Tests that a SaltCloudSystemExit is raised when no kwargs are provided to
  565. create_snapshot.
  566. """
  567. self.assertRaises(
  568. SaltCloudSystemExit,
  569. vmware.create_snapshot,
  570. name=VM_NAME,
  571. kwargs=None,
  572. call="action",
  573. )
  574. def test_create_snapshot_no_snapshot_name_in_kwargs(self):
  575. """
  576. Tests that a SaltCloudSystemExit is raised when snapshot_name is not present
  577. in kwargs that are provided to create_snapshot.
  578. """
  579. self.assertRaises(
  580. SaltCloudSystemExit,
  581. vmware.create_snapshot,
  582. name=VM_NAME,
  583. kwargs={"foo": "bar"},
  584. call="action",
  585. )
  586. def test_add_host_no_esxi_host_user_in_config(self):
  587. """
  588. Tests that a SaltCloudSystemExit is raised when esxi_host_user is not
  589. specified in the cloud provider configuration when calling add_host.
  590. """
  591. with patch.dict(vmware.__opts__, {"providers": PROVIDER_CONFIG}, clean=True):
  592. self.assertRaisesWithMessage(
  593. SaltCloudSystemExit,
  594. "You must specify the ESXi host username in your providers config.",
  595. vmware.add_host,
  596. kwargs=None,
  597. call="function",
  598. )
  599. def test_add_host_no_esxi_host_password_in_config(self):
  600. """
  601. Tests that a SaltCloudSystemExit is raised when esxi_host_password is not
  602. specified in the cloud provider configuration when calling add_host.
  603. """
  604. provider_config_additions = {
  605. "esxi_host_user": "root",
  606. }
  607. provider_config = deepcopy(PROVIDER_CONFIG)
  608. provider_config["vcenter01"]["vmware"].update(provider_config_additions)
  609. with patch.dict(vmware.__opts__, {"providers": provider_config}, clean=True):
  610. self.assertRaisesWithMessage(
  611. SaltCloudSystemExit,
  612. "You must specify the ESXi host password in your providers config.",
  613. vmware.add_host,
  614. kwargs=None,
  615. call="function",
  616. )
  617. def test_no_clonefrom_just_image(self):
  618. """
  619. Tests that the profile is configured correctly when deploying using an image
  620. """
  621. profile_additions = {"image": "some-image.iso"}
  622. provider_config = deepcopy(PROVIDER_CONFIG)
  623. profile = deepcopy(PROFILE)
  624. profile["base-gold"].update(profile_additions)
  625. provider_config_additions = {"profiles": profile}
  626. provider_config["vcenter01"]["vmware"].update(provider_config_additions)
  627. vm_ = {"profile": profile}
  628. with patch.dict(vmware.__opts__, {"providers": provider_config}, clean=True):
  629. self.assertEqual(
  630. config.is_profile_configured(
  631. vmware.__opts__, "vcenter01:vmware", "base-gold", vm_=vm_
  632. ),
  633. True,
  634. )
  635. def test_just_clonefrom(self):
  636. """
  637. Tests that the profile is configured correctly when deploying by cloning from a template
  638. """
  639. profile_additions = {
  640. "clonefrom": "test-template",
  641. "image": "should ignore image",
  642. }
  643. provider_config = deepcopy(PROVIDER_CONFIG)
  644. profile = deepcopy(PROFILE)
  645. profile["base-gold"].update(profile_additions)
  646. provider_config_additions = {"profiles": profile}
  647. provider_config["vcenter01"]["vmware"].update(provider_config_additions)
  648. vm_ = {"profile": profile}
  649. with patch.dict(vmware.__opts__, {"providers": provider_config}, clean=True):
  650. self.assertEqual(
  651. config.is_profile_configured(
  652. vmware.__opts__, "vcenter01:vmware", "base-gold", vm_=vm_
  653. ),
  654. True,
  655. )
  656. def test_add_new_ide_controller_helper(self):
  657. """
  658. Tests that creating a new controller, ensuring that it will generate a controller key
  659. if one is not provided
  660. """
  661. with patch(
  662. "salt.cloud.clouds.vmware.randint", return_value=101
  663. ) as randint_mock:
  664. controller_label = "Some label"
  665. bus_number = 1
  666. spec = vmware._add_new_ide_controller_helper(
  667. controller_label, None, bus_number
  668. )
  669. self.assertEqual(spec.device.key, randint_mock.return_value)
  670. spec = vmware._add_new_ide_controller_helper(
  671. controller_label, 200, bus_number
  672. )
  673. self.assertEqual(spec.device.key, 200)
  674. self.assertEqual(spec.device.busNumber, bus_number)
  675. self.assertEqual(spec.device.deviceInfo.label, controller_label)
  676. self.assertEqual(spec.device.deviceInfo.summary, controller_label)
  677. def test_manage_devices_just_cd(self):
  678. """
  679. Tests that when adding IDE/CD drives, controller keys will be in the apparent
  680. safe-range on ESX 5.5 but randomly generated on other versions (i.e. 6)
  681. """
  682. device_map = {
  683. "ide": {"IDE 0": {}, "IDE 1": {}},
  684. "cd": {"CD/DVD Drive 1": {"controller": "IDE 0"}},
  685. }
  686. with patch(
  687. "salt.cloud.clouds.vmware.get_vcenter_version",
  688. return_value="VMware ESXi 5.5.0",
  689. ):
  690. specs = vmware._manage_devices(device_map, vm=None)["device_specs"]
  691. self.assertEqual(
  692. specs[0].device.key, vmware.SAFE_ESX_5_5_CONTROLLER_KEY_INDEX
  693. )
  694. self.assertEqual(
  695. specs[1].device.key, vmware.SAFE_ESX_5_5_CONTROLLER_KEY_INDEX + 1
  696. )
  697. self.assertEqual(
  698. specs[2].device.controllerKey, vmware.SAFE_ESX_5_5_CONTROLLER_KEY_INDEX
  699. )
  700. with patch(
  701. "salt.cloud.clouds.vmware.get_vcenter_version", return_value="VMware ESXi 6"
  702. ):
  703. with patch(
  704. "salt.cloud.clouds.vmware.randint", return_value=100
  705. ) as first_key:
  706. specs = vmware._manage_devices(device_map, vm=None)["device_specs"]
  707. self.assertEqual(specs[0].device.key, first_key.return_value)
  708. self.assertEqual(specs[2].device.controllerKey, first_key.return_value)
  709. def test_add_host_no_host_in_kwargs(self):
  710. """
  711. Tests that a SaltCloudSystemExit is raised when host is not present in
  712. kwargs that are provided to add_host.
  713. """
  714. provider_config_additions = {
  715. "esxi_host_user": "root",
  716. "esxi_host_password": "myhostpassword",
  717. }
  718. provider_config = deepcopy(PROVIDER_CONFIG)
  719. provider_config["vcenter01"]["vmware"].update(provider_config_additions)
  720. with patch.dict(vmware.__opts__, {"providers": provider_config}, clean=True):
  721. self.assertRaisesWithMessage(
  722. SaltCloudSystemExit,
  723. "You must specify either the IP or DNS name of the host system.",
  724. vmware.add_host,
  725. kwargs={"foo": "bar"},
  726. call="function",
  727. )
  728. def test_add_host_both_cluster_and_datacenter_in_kwargs(self):
  729. """
  730. Tests that a SaltCloudSystemExit is raised when both cluster and datacenter
  731. are present in kwargs that are provided to add_host.
  732. """
  733. provider_config_additions = {
  734. "esxi_host_user": "root",
  735. "esxi_host_password": "myhostpassword",
  736. }
  737. provider_config = deepcopy(PROVIDER_CONFIG)
  738. provider_config["vcenter01"]["vmware"].update(provider_config_additions)
  739. with patch.dict(vmware.__opts__, {"providers": provider_config}, clean=True):
  740. self.assertRaisesWithMessage(
  741. SaltCloudSystemExit,
  742. "You must specify either the cluster name or the datacenter name.",
  743. vmware.add_host,
  744. kwargs={
  745. "host": "my-esxi-host",
  746. "datacenter": "my-datacenter",
  747. "cluster": "my-cluster",
  748. },
  749. call="function",
  750. )
  751. def test_add_host_neither_cluster_nor_datacenter_in_kwargs(self):
  752. """
  753. Tests that a SaltCloudSystemExit is raised when neither cluster nor
  754. datacenter is present in kwargs that are provided to add_host.
  755. """
  756. provider_config_additions = {
  757. "esxi_host_user": "root",
  758. "esxi_host_password": "myhostpassword",
  759. }
  760. provider_config = deepcopy(PROVIDER_CONFIG)
  761. provider_config["vcenter01"]["vmware"].update(provider_config_additions)
  762. with patch.dict(vmware.__opts__, {"providers": provider_config}, clean=True):
  763. self.assertRaisesWithMessage(
  764. SaltCloudSystemExit,
  765. "You must specify either the cluster name or the datacenter name.",
  766. vmware.add_host,
  767. kwargs={"host": "my-esxi-host"},
  768. call="function",
  769. )
  770. @skipIf(HAS_LIBS is False, "Install pyVmomi to be able to run this unit test.")
  771. def test_add_host_cluster_not_exists(self):
  772. """
  773. Tests that a SaltCloudSystemExit is raised when the specified cluster present
  774. in kwargs that are provided to add_host does not exist in the VMware
  775. environment.
  776. """
  777. with patch("salt.cloud.clouds.vmware._get_si", MagicMock(return_value=None)):
  778. with patch(
  779. "salt.utils.vmware.get_mor_by_property", MagicMock(return_value=None)
  780. ):
  781. provider_config_additions = {
  782. "esxi_host_user": "root",
  783. "esxi_host_password": "myhostpassword",
  784. }
  785. provider_config = deepcopy(PROVIDER_CONFIG)
  786. provider_config["vcenter01"]["vmware"].update(provider_config_additions)
  787. with patch.dict(
  788. vmware.__opts__, {"providers": provider_config}, clean=True
  789. ):
  790. self.assertRaisesWithMessage(
  791. SaltCloudSystemExit,
  792. "Specified cluster does not exist.",
  793. vmware.add_host,
  794. kwargs={"host": "my-esxi-host", "cluster": "my-cluster"},
  795. call="function",
  796. )
  797. @skipIf(HAS_LIBS is False, "Install pyVmomi to be able to run this unit test.")
  798. def test_add_host_datacenter_not_exists(self):
  799. """
  800. Tests that a SaltCloudSystemExit is raised when the specified datacenter
  801. present in kwargs that are provided to add_host does not exist in the VMware
  802. environment.
  803. """
  804. with patch("salt.cloud.clouds.vmware._get_si", MagicMock(return_value=None)):
  805. with patch(
  806. "salt.utils.vmware.get_mor_by_property", MagicMock(return_value=None)
  807. ):
  808. provider_config_additions = {
  809. "esxi_host_user": "root",
  810. "esxi_host_password": "myhostpassword",
  811. }
  812. provider_config = deepcopy(PROVIDER_CONFIG)
  813. provider_config["vcenter01"]["vmware"].update(provider_config_additions)
  814. with patch.dict(
  815. vmware.__opts__, {"providers": provider_config}, clean=True
  816. ):
  817. self.assertRaisesWithMessage(
  818. SaltCloudSystemExit,
  819. "Specified datacenter does not exist.",
  820. vmware.add_host,
  821. kwargs={"host": "my-esxi-host", "datacenter": "my-datacenter"},
  822. call="function",
  823. )
  824. def test_remove_host_no_kwargs(self):
  825. """
  826. Tests that a SaltCloudSystemExit is raised when no kwargs are provided to
  827. remove_host.
  828. """
  829. self.assertRaises(
  830. SaltCloudSystemExit, vmware.remove_host, kwargs=None, call="function"
  831. )
  832. def test_remove_host_no_host_in_kwargs(self):
  833. """
  834. Tests that a SaltCloudSystemExit is raised when host is not present in
  835. kwargs that are provided to remove_host.
  836. """
  837. self.assertRaises(
  838. SaltCloudSystemExit,
  839. vmware.remove_host,
  840. kwargs={"foo": "bar"},
  841. call="function",
  842. )
  843. @skipIf(HAS_LIBS is False, "Install pyVmomi to be able to run this unit test.")
  844. def test_remove_host_not_exists(self):
  845. """
  846. Tests that a SaltCloudSystemExit is raised when the specified host present
  847. in kwargs that are provided to remove_host does not exist in the VMware
  848. environment.
  849. """
  850. with patch("salt.cloud.clouds.vmware._get_si", MagicMock(return_value=None)):
  851. with patch(
  852. "salt.utils.vmware.get_mor_by_property", MagicMock(return_value=None)
  853. ):
  854. self.assertRaises(
  855. SaltCloudSystemExit,
  856. vmware.remove_host,
  857. kwargs={"host": "my-host"},
  858. call="function",
  859. )
  860. def test_connect_host_no_kwargs(self):
  861. """
  862. Tests that a SaltCloudSystemExit is raised when no kwargs are provided to
  863. connect_host.
  864. """
  865. self.assertRaises(
  866. SaltCloudSystemExit, vmware.connect_host, kwargs=None, call="function"
  867. )
  868. def test_connect_host_no_host_in_kwargs(self):
  869. """
  870. Tests that a SaltCloudSystemExit is raised when host is not present in
  871. kwargs that are provided to connect_host.
  872. """
  873. self.assertRaises(
  874. SaltCloudSystemExit,
  875. vmware.connect_host,
  876. kwargs={"foo": "bar"},
  877. call="function",
  878. )
  879. @skipIf(HAS_LIBS is False, "Install pyVmomi to be able to run this unit test.")
  880. def test_connect_host_not_exists(self):
  881. """
  882. Tests that a SaltCloudSystemExit is raised when the specified host present
  883. in kwargs that are provided to connect_host does not exist in the VMware
  884. environment.
  885. """
  886. with patch("salt.cloud.clouds.vmware._get_si", MagicMock(return_value=None)):
  887. with patch(
  888. "salt.utils.vmware.get_mor_by_property", MagicMock(return_value=None)
  889. ):
  890. self.assertRaises(
  891. SaltCloudSystemExit,
  892. vmware.connect_host,
  893. kwargs={"host": "my-host"},
  894. call="function",
  895. )
  896. def test_disconnect_host_no_kwargs(self):
  897. """
  898. Tests that a SaltCloudSystemExit is raised when no kwargs are provided to
  899. disconnect_host.
  900. """
  901. self.assertRaises(
  902. SaltCloudSystemExit, vmware.disconnect_host, kwargs=None, call="function"
  903. )
  904. def test_disconnect_host_no_host_in_kwargs(self):
  905. """
  906. Tests that a SaltCloudSystemExit is raised when host is not present in
  907. kwargs that are provided to disconnect_host.
  908. """
  909. self.assertRaises(
  910. SaltCloudSystemExit,
  911. vmware.disconnect_host,
  912. kwargs={"foo": "bar"},
  913. call="function",
  914. )
  915. @skipIf(HAS_LIBS is False, "Install pyVmomi to be able to run this unit test.")
  916. def test_disconnect_host_not_exists(self):
  917. """
  918. Tests that a SaltCloudSystemExit is raised when the specified host present
  919. in kwargs that are provided to disconnect_host does not exist in the VMware
  920. environment.
  921. """
  922. with patch("salt.cloud.clouds.vmware._get_si", MagicMock(return_value=None)):
  923. with patch(
  924. "salt.utils.vmware.get_mor_by_property", MagicMock(return_value=None)
  925. ):
  926. self.assertRaises(
  927. SaltCloudSystemExit,
  928. vmware.disconnect_host,
  929. kwargs={"host": "my-host"},
  930. call="function",
  931. )
  932. def test_reboot_host_no_kwargs(self):
  933. """
  934. Tests that a SaltCloudSystemExit is raised when no kwargs are provided to
  935. reboot_host.
  936. """
  937. self.assertRaises(
  938. SaltCloudSystemExit, vmware.reboot_host, kwargs=None, call="function"
  939. )
  940. def test_reboot_host_no_host_in_kwargs(self):
  941. """
  942. Tests that a SaltCloudSystemExit is raised when host is not present in
  943. kwargs that are provided to reboot_host.
  944. """
  945. self.assertRaises(
  946. SaltCloudSystemExit,
  947. vmware.reboot_host,
  948. kwargs={"foo": "bar"},
  949. call="function",
  950. )
  951. @skipIf(HAS_LIBS is False, "Install pyVmomi to be able to run this unit test.")
  952. def test_reboot_host_not_exists(self):
  953. """
  954. Tests that a SaltCloudSystemExit is raised when the specified host present
  955. in kwargs that are provided to connect_host does not exist in the VMware
  956. environment.
  957. """
  958. with patch("salt.cloud.clouds.vmware._get_si", MagicMock(return_value=None)):
  959. with patch(
  960. "salt.utils.vmware.get_mor_by_property", MagicMock(return_value=None)
  961. ):
  962. self.assertRaises(
  963. SaltCloudSystemExit,
  964. vmware.reboot_host,
  965. kwargs={"host": "my-host"},
  966. call="function",
  967. )
  968. def test_create_datastore_cluster_no_kwargs(self):
  969. """
  970. Tests that a SaltCloudSystemExit is raised when no kwargs are provided to
  971. create_datastore_cluster.
  972. """
  973. self.assertRaises(
  974. SaltCloudSystemExit,
  975. vmware.create_datastore_cluster,
  976. kwargs=None,
  977. call="function",
  978. )
  979. def test_create_datastore_cluster_no_name_in_kwargs(self):
  980. """
  981. Tests that a SaltCloudSystemExit is raised when name is not present in
  982. kwargs that are provided to create_datastore_cluster.
  983. """
  984. self.assertRaises(
  985. SaltCloudSystemExit,
  986. vmware.create_datastore_cluster,
  987. kwargs={"foo": "bar"},
  988. call="function",
  989. )
  990. def test_create_datastore_cluster_name_too_short(self):
  991. """
  992. Tests that a SaltCloudSystemExit is raised when name is present in kwargs
  993. that are provided to create_datastore_cluster but is an empty string.
  994. """
  995. self.assertRaises(
  996. SaltCloudSystemExit,
  997. vmware.create_datastore_cluster,
  998. kwargs={"name": ""},
  999. call="function",
  1000. )
  1001. def test_create_datastore_cluster_name_too_long(self):
  1002. """
  1003. Tests that a SaltCloudSystemExit is raised when name is present in kwargs
  1004. that are provided to create_datastore_cluster but is a string with length <= 80.
  1005. """
  1006. self.assertRaises(
  1007. SaltCloudSystemExit,
  1008. vmware.create_datastore_cluster,
  1009. kwargs={
  1010. "name": "cCD2GgJGPG1DUnPeFBoPeqtdmUxIWxDoVFbA14vIG0BPoUECkgbRMnnY6gaUPBvIDCcsZ5HU48ubgQu5c"
  1011. },
  1012. call="function",
  1013. )
  1014. def test__add_new_hard_disk_helper(self):
  1015. with patch("salt.cloud.clouds.vmware._get_si", MagicMock(return_value=None)):
  1016. with patch(
  1017. "salt.utils.vmware.get_mor_using_container_view",
  1018. side_effect=[None, None],
  1019. ):
  1020. self.assertRaises(
  1021. SaltCloudSystemExit,
  1022. vmware._add_new_hard_disk_helper,
  1023. disk_label="test",
  1024. size_gb=100,
  1025. unit_number=0,
  1026. datastore="whatever",
  1027. )
  1028. with patch(
  1029. "salt.utils.vmware.get_mor_using_container_view",
  1030. side_effect=["Datastore", None],
  1031. ):
  1032. self.assertRaises(
  1033. AttributeError,
  1034. vmware._add_new_hard_disk_helper,
  1035. disk_label="test",
  1036. size_gb=100,
  1037. unit_number=0,
  1038. datastore="whatever",
  1039. )
  1040. vmware.salt.utils.vmware.get_mor_using_container_view.assert_called_with(
  1041. None, vim.Datastore, "whatever"
  1042. )
  1043. with patch(
  1044. "salt.utils.vmware.get_mor_using_container_view",
  1045. side_effect=[None, "Cluster"],
  1046. ):
  1047. self.assertRaises(
  1048. AttributeError,
  1049. vmware._add_new_hard_disk_helper,
  1050. disk_label="test",
  1051. size_gb=100,
  1052. unit_number=0,
  1053. datastore="whatever",
  1054. )
  1055. vmware.salt.utils.vmware.get_mor_using_container_view.assert_called_with(
  1056. None, vim.StoragePod, "whatever"
  1057. )
  1058. class CloneFromSnapshotTest(TestCase):
  1059. """
  1060. Test functionality to clone from snapshot
  1061. """
  1062. @skipIf(HAS_LIBS is False, "Install pyVmomi to be able to run this unit test.")
  1063. def test_quick_linked_clone(self):
  1064. """
  1065. Test that disk move type is
  1066. set to createNewChildDiskBacking
  1067. """
  1068. self._test_clone_type(vmware.QUICK_LINKED_CLONE)
  1069. @skipIf(HAS_LIBS is False, "Install pyVmomi to be able to run this unit test.")
  1070. def test_current_state_linked_clone(self):
  1071. """
  1072. Test that disk move type is
  1073. set to moveChildMostDiskBacking
  1074. """
  1075. self._test_clone_type(vmware.CURRENT_STATE_LINKED_CLONE)
  1076. @skipIf(HAS_LIBS is False, "Install pyVmomi to be able to run this unit test.")
  1077. def test_copy_all_disks_full_clone(self):
  1078. """
  1079. Test that disk move type is
  1080. set to moveAllDiskBackingsAndAllowSharing
  1081. """
  1082. self._test_clone_type(vmware.COPY_ALL_DISKS_FULL_CLONE)
  1083. @skipIf(HAS_LIBS is False, "Install pyVmomi to be able to run this unit test.")
  1084. def test_flatten_all_all_disks_full_clone(self):
  1085. """
  1086. Test that disk move type is
  1087. set to moveAllDiskBackingsAndDisallowSharing
  1088. """
  1089. self._test_clone_type(vmware.FLATTEN_DISK_FULL_CLONE)
  1090. @skipIf(HAS_LIBS is False, "Install pyVmomi to be able to run this unit test.")
  1091. def test_raises_error_for_invalid_disk_move_type(self):
  1092. """
  1093. Test that invalid disk move type
  1094. raises error
  1095. """
  1096. with self.assertRaises(SaltCloudSystemExit):
  1097. self._test_clone_type("foobar")
  1098. def _test_clone_type(self, clone_type):
  1099. """
  1100. Assertions for checking that a certain clone type
  1101. works
  1102. """
  1103. obj_ref = MagicMock()
  1104. obj_ref.snapshot = vim.vm.Snapshot(None, None)
  1105. obj_ref.snapshot.currentSnapshot = vim.vm.Snapshot(None, None)
  1106. clone_spec = vmware.handle_snapshot(
  1107. vim.vm.ConfigSpec(),
  1108. obj_ref,
  1109. vim.vm.RelocateSpec(),
  1110. False,
  1111. {"snapshot": {"disk_move_type": clone_type}},
  1112. )
  1113. self.assertEqual(clone_spec.location.diskMoveType, clone_type)
  1114. obj_ref2 = MagicMock()
  1115. obj_ref2.snapshot = vim.vm.Snapshot(None, None)
  1116. obj_ref2.snapshot.currentSnapshot = vim.vm.Snapshot(None, None)
  1117. clone_spec2 = vmware.handle_snapshot(
  1118. vim.vm.ConfigSpec(),
  1119. obj_ref2,
  1120. vim.vm.RelocateSpec(),
  1121. True,
  1122. {"snapshot": {"disk_move_type": clone_type}},
  1123. )
  1124. self.assertEqual(clone_spec2.location.diskMoveType, clone_type)