test_opennebula.py 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649
  1. # -*- coding: utf-8 -*-
  2. '''
  3. :codeauthor: Nicole Thomas <nicole@saltstack.com>
  4. '''
  5. # Import Python libs
  6. from __future__ import absolute_import, print_function, unicode_literals
  7. # Import Salt Testing Libs
  8. from tests.support.mixins import LoaderModuleMockMixin
  9. from tests.support.unit import TestCase, skipIf
  10. from tests.support.mock import MagicMock, NO_MOCK, NO_MOCK_REASON, patch
  11. # Import Salt Libs
  12. from salt.cloud.clouds import opennebula
  13. from salt.exceptions import SaltCloudSystemExit, SaltCloudNotFound
  14. # Import Third Party Libs
  15. try:
  16. from lxml import etree # pylint: disable=W0611
  17. HAS_XML_LIBS = True
  18. except ImportError:
  19. HAS_XML_LIBS = False
  20. VM_NAME = 'my-vm'
  21. @skipIf(NO_MOCK, NO_MOCK_REASON)
  22. class OpenNebulaTestCase(TestCase, LoaderModuleMockMixin):
  23. '''
  24. Unit TestCase for salt.cloud.clouds.opennebula module.
  25. '''
  26. def setup_loader_modules(self):
  27. return {
  28. opennebula: {
  29. '__virtual__': MagicMock(return_value='opennebula'),
  30. '__utils__': {
  31. 'cloud.cache_node': MagicMock()
  32. },
  33. '__active_provider_name__': ''
  34. }
  35. }
  36. def test_avail_images_action(self):
  37. '''
  38. Tests that a SaltCloudSystemExit error is raised when trying to call
  39. avail_images with --action or -a.
  40. '''
  41. self.assertRaises(SaltCloudSystemExit, opennebula.avail_images, 'action')
  42. def test_avail_locations_action(self):
  43. '''
  44. Tests that a SaltCloudSystemExit is raised when trying to call avail_locations
  45. with --action or -a.
  46. '''
  47. self.assertRaises(SaltCloudSystemExit, opennebula.avail_locations, 'action')
  48. def test_avail_sizes_action(self):
  49. '''
  50. Tests that a SaltCloudSystemExit is raised when trying to call avail_sizes
  51. with --action or -a.
  52. '''
  53. self.assertRaises(SaltCloudSystemExit, opennebula.avail_sizes, 'action')
  54. def test_avail_sizes(self):
  55. '''
  56. Tests that avail_sizes returns an empty dictionary.
  57. '''
  58. self.assertEqual(opennebula.avail_sizes(call='foo'), {})
  59. def test_list_clusters_action(self):
  60. '''
  61. Tests that a SaltCloudSystemExit is raised when trying to call list_clusters
  62. with --action or -a.
  63. '''
  64. self.assertRaises(SaltCloudSystemExit, opennebula.list_clusters, 'action')
  65. def test_list_datastores_action(self):
  66. '''
  67. Tests that a SaltCloudSystemExit is raised when trying to call list_datastores
  68. with --action or -a.
  69. '''
  70. self.assertRaises(SaltCloudSystemExit, opennebula.list_datastores, 'action')
  71. def test_list_hosts_action(self):
  72. '''
  73. Tests that a SaltCloudSystemExit is raised when trying to call list_datastores
  74. with --action or -a.
  75. '''
  76. self.assertRaises(SaltCloudSystemExit, opennebula.list_hosts, 'action')
  77. def test_list_nodes_action(self):
  78. '''
  79. Tests that a SaltCloudSystemExit is raised when trying to call list_nodes
  80. with --action or -a.
  81. '''
  82. self.assertRaises(SaltCloudSystemExit, opennebula.list_nodes, 'action')
  83. def test_list_nodes_full_action(self):
  84. '''
  85. Tests that a SaltCloudSystemExit is raised when trying to call list_nodes_full
  86. with --action or -a.
  87. '''
  88. self.assertRaises(SaltCloudSystemExit, opennebula.list_nodes_full, 'action')
  89. def test_list_nodes_select_action(self):
  90. '''
  91. Tests that a SaltCloudSystemExit is raised when trying to call list_nodes_full
  92. with --action or -a.
  93. '''
  94. self.assertRaises(SaltCloudSystemExit, opennebula.list_nodes_select, 'action')
  95. def test_list_security_groups_action(self):
  96. '''
  97. Tests that a SaltCloudSystemExit is raised when trying to call
  98. list_security_groups with --action or -a.
  99. '''
  100. self.assertRaises(SaltCloudSystemExit, opennebula.list_security_groups, 'action')
  101. def test_list_templates_action(self):
  102. '''
  103. Tests that a SaltCloudSystemExit is raised when trying to call list_templates
  104. with --action or -a.
  105. '''
  106. self.assertRaises(SaltCloudSystemExit, opennebula.list_templates, 'action')
  107. def test_list_vns_action(self):
  108. '''
  109. Tests that a SaltCloudSystemExit is raised when trying to call list_vns
  110. with --action or -a.
  111. '''
  112. self.assertRaises(SaltCloudSystemExit, opennebula.list_vns, 'action')
  113. def test_reboot_error(self):
  114. '''
  115. Tests that a SaltCloudSystemExit is raised when trying to call reboot
  116. with anything other that --action or -a.
  117. '''
  118. self.assertRaises(SaltCloudSystemExit, opennebula.reboot, 'my-vm', 'foo')
  119. def test_start_error(self):
  120. '''
  121. Tests that a SaltCloudSystemExit is raised when trying to call start
  122. with anything other that --action or -a.
  123. '''
  124. self.assertRaises(SaltCloudSystemExit, opennebula.start, 'my-vm', 'foo')
  125. def test_stop_error(self):
  126. '''
  127. Tests that a SaltCloudSystemExit is raised when trying to call stop
  128. with anything other that --action or -a.
  129. '''
  130. self.assertRaises(SaltCloudSystemExit, opennebula.stop, 'my-vm', 'foo')
  131. def test_get_cluster_id_action(self):
  132. '''
  133. Tests that a SaltCloudSystemExit is raised when trying to call
  134. get_cluster_id with --action or -a.
  135. '''
  136. self.assertRaises(SaltCloudSystemExit,
  137. opennebula.get_cluster_id,
  138. call='action')
  139. def test_get_cluster_id_no_name(self):
  140. '''
  141. Tests that a SaltCloudSystemExit is raised when no name is provided.
  142. '''
  143. self.assertRaises(SaltCloudSystemExit,
  144. opennebula.get_cluster_id,
  145. None,
  146. call='foo')
  147. def test_get_cluster_id_not_found(self):
  148. '''
  149. Tests that a SaltCloudSystemExit is raised when no name is provided.
  150. '''
  151. with patch('salt.cloud.clouds.opennebula.list_clusters',
  152. MagicMock(return_value={'foo': {'id': 'bar'}})):
  153. self.assertRaises(SaltCloudSystemExit,
  154. opennebula.get_cluster_id,
  155. kwargs={'name': 'test'},
  156. call='function')
  157. def test_get_cluster_id_success(self):
  158. '''
  159. Tests that the function returns successfully.
  160. '''
  161. with patch('salt.cloud.clouds.opennebula.list_clusters',
  162. MagicMock(return_value={'test-cluster': {'id': '100'}})):
  163. mock_id = '100'
  164. mock_kwargs = {'name': 'test-cluster'}
  165. self.assertEqual(opennebula.get_cluster_id(mock_kwargs, 'foo'),
  166. mock_id)
  167. def test_get_datastore_id_action(self):
  168. '''
  169. Tests that a SaltCloudSystemExit is raised when trying to call
  170. get_datastore_id with --action or -a.
  171. '''
  172. self.assertRaises(SaltCloudSystemExit,
  173. opennebula.get_datastore_id,
  174. call='action')
  175. def test_get_datastore_id_no_name(self):
  176. '''
  177. Tests that a SaltCloudSystemExit is raised when no name is provided.
  178. '''
  179. self.assertRaises(SaltCloudSystemExit,
  180. opennebula.get_datastore_id,
  181. None,
  182. call='foo')
  183. def test_get_datastore_id_not_found(self):
  184. '''
  185. Tests that a SaltCloudSystemExit is raised when no name is provided.
  186. '''
  187. with patch('salt.cloud.clouds.opennebula.list_datastores',
  188. MagicMock(return_value={'test-datastore': {'id': '100'}})):
  189. self.assertRaises(SaltCloudSystemExit,
  190. opennebula.get_datastore_id,
  191. kwargs={'name': 'test'},
  192. call='function')
  193. def test_get_datastore_id_success(self):
  194. '''
  195. Tests that the function returns successfully.
  196. '''
  197. with patch('salt.cloud.clouds.opennebula.list_datastores',
  198. MagicMock(return_value={'test-datastore': {'id': '100'}})):
  199. mock_id = '100'
  200. mock_kwargs = {'name': 'test-datastore'}
  201. self.assertEqual(opennebula.get_datastore_id(mock_kwargs, 'foo'),
  202. mock_id)
  203. def test_get_host_id_action(self):
  204. '''
  205. Tests that a SaltCloudSystemExit is raised when trying to call
  206. get_host_id with --action or -a.
  207. '''
  208. self.assertRaises(SaltCloudSystemExit,
  209. opennebula.get_host_id,
  210. call='action')
  211. def test_get_host_id_no_name(self):
  212. '''
  213. Tests that a SaltCloudSystemExit is raised when no name is provided.
  214. '''
  215. self.assertRaises(SaltCloudSystemExit,
  216. opennebula.get_host_id,
  217. None,
  218. call='foo')
  219. def test_get_host_id_not_found(self):
  220. '''
  221. Tests that a SaltCloudSystemExit is raised when no name is provided.
  222. '''
  223. with patch('salt.cloud.clouds.opennebula.avail_locations',
  224. MagicMock(return_value={'test-host': {'id': '100'}})):
  225. self.assertRaises(SaltCloudSystemExit,
  226. opennebula.get_host_id,
  227. kwargs={'name': 'test'},
  228. call='function')
  229. def test_get_host_id_success(self):
  230. '''
  231. Tests that the function returns successfully.
  232. '''
  233. with patch('salt.cloud.clouds.opennebula.avail_locations',
  234. MagicMock(return_value={'test-host': {'id': '100'}})):
  235. mock_id = '100'
  236. mock_kwargs = {'name': 'test-host'}
  237. self.assertEqual(opennebula.get_host_id(mock_kwargs, 'foo'),
  238. mock_id)
  239. def test_get_image_not_found(self):
  240. '''
  241. Tests that a SaltCloudNotFound is raised when the image doesn't exist.
  242. '''
  243. with patch('salt.cloud.clouds.opennebula.avail_images', MagicMock(return_value={})):
  244. with patch('salt.config.get_cloud_config_value', MagicMock(return_value='foo')):
  245. self.assertRaises(SaltCloudNotFound, opennebula.get_image, 'my-vm')
  246. def test_get_image_success(self):
  247. '''
  248. Tests that the image is returned successfully.
  249. '''
  250. with patch('salt.cloud.clouds.opennebula.avail_images',
  251. MagicMock(return_value={'my-vm': {'name': 'my-vm', 'id': 0}})):
  252. with patch('salt.config.get_cloud_config_value', MagicMock(return_value='my-vm')):
  253. self.assertEqual(opennebula.get_image('my-vm'), 0)
  254. def test_get_image_id_action(self):
  255. '''
  256. Tests that a SaltCloudSystemExit is raised when trying to call
  257. get_image_id with --action or -a.
  258. '''
  259. self.assertRaises(SaltCloudSystemExit,
  260. opennebula.get_image_id,
  261. call='action')
  262. def test_get_image_id_no_name(self):
  263. '''
  264. Tests that a SaltCloudSystemExit is raised when no name is provided.
  265. '''
  266. self.assertRaises(SaltCloudSystemExit,
  267. opennebula.get_image_id,
  268. None,
  269. call='foo')
  270. def test_get_image_id_not_found(self):
  271. '''
  272. Tests that a SaltCloudSystemExit is raised when no name is provided.
  273. '''
  274. with patch('salt.cloud.clouds.opennebula.avail_images',
  275. MagicMock(return_value={'test-image': {'id': '100'}})):
  276. self.assertRaises(SaltCloudSystemExit,
  277. opennebula.get_image_id,
  278. kwargs={'name': 'test'},
  279. call='function')
  280. def test_get_image_id_success(self):
  281. '''
  282. Tests that the function returns successfully.
  283. '''
  284. with patch('salt.cloud.clouds.opennebula.avail_images',
  285. MagicMock(return_value={'test-image': {'id': '100'}})):
  286. mock_id = '100'
  287. mock_kwargs = {'name': 'test-image'}
  288. self.assertEqual(opennebula.get_image_id(mock_kwargs, 'foo'),
  289. mock_id)
  290. def test_get_location_not_found(self):
  291. '''
  292. Tests that a SaltCloudNotFound is raised when the location doesn't exist.
  293. '''
  294. with patch('salt.cloud.clouds.opennebula.avail_locations', MagicMock(return_value={})):
  295. with patch('salt.config.get_cloud_config_value', MagicMock(return_value='foo')):
  296. self.assertRaises(SaltCloudNotFound, opennebula.get_location, 'my-vm')
  297. def test_get_location_success(self):
  298. '''
  299. Tests that the image is returned successfully.
  300. '''
  301. with patch('salt.cloud.clouds.opennebula.avail_locations',
  302. MagicMock(return_value={'my-host': {'name': 'my-host', 'id': 0}})):
  303. with patch('salt.config.get_cloud_config_value', MagicMock(return_value='my-host')):
  304. self.assertEqual(opennebula.get_location('my-host'), 0)
  305. def test_get_secgroup_id_action(self):
  306. '''
  307. Tests that a SaltCloudSystemExit is raised when trying to call
  308. get_host_id with --action or -a.
  309. '''
  310. self.assertRaises(SaltCloudSystemExit,
  311. opennebula.get_secgroup_id,
  312. call='action')
  313. def test_get_secgroup_id_no_name(self):
  314. '''
  315. Tests that a SaltCloudSystemExit is raised when no name is provided.
  316. '''
  317. self.assertRaises(SaltCloudSystemExit,
  318. opennebula.get_secgroup_id,
  319. None,
  320. call='foo')
  321. def test_get_secgroup_id_not_found(self):
  322. '''
  323. Tests that a SaltCloudSystemExit is raised when no name is provided.
  324. '''
  325. with patch('salt.cloud.clouds.opennebula.list_security_groups',
  326. MagicMock(return_value={'test-security-group': {'id': '100'}})):
  327. self.assertRaises(SaltCloudSystemExit,
  328. opennebula.get_secgroup_id,
  329. kwargs={'name': 'test'},
  330. call='function')
  331. def test_get_secgroup_id_success(self):
  332. '''
  333. Tests that the function returns successfully.
  334. '''
  335. with patch('salt.cloud.clouds.opennebula.list_security_groups',
  336. MagicMock(return_value={'test-secgroup': {'id': '100'}})):
  337. mock_id = '100'
  338. mock_kwargs = {'name': 'test-secgroup'}
  339. self.assertEqual(opennebula.get_secgroup_id(mock_kwargs, 'foo'),
  340. mock_id)
  341. def test_get_template_id_action(self):
  342. '''
  343. Tests that a SaltCloudSystemExit is raised when trying to call
  344. get_template_id with --action or -a.
  345. '''
  346. self.assertRaises(SaltCloudSystemExit,
  347. opennebula.get_template_id,
  348. call='action')
  349. def test_get_template_id_no_name(self):
  350. '''
  351. Tests that a SaltCloudSystemExit is raised when no name is provided.
  352. '''
  353. self.assertRaises(SaltCloudSystemExit,
  354. opennebula.get_template_id,
  355. None,
  356. call='foo')
  357. def test_get_template_id_not_found(self):
  358. '''
  359. Tests that a SaltCloudSystemExit is raised when no name is provided.
  360. '''
  361. with patch('salt.cloud.clouds.opennebula.list_templates',
  362. MagicMock(return_value={'test-template': {'id': '100'}})):
  363. self.assertRaises(SaltCloudSystemExit,
  364. opennebula.get_template_id,
  365. kwargs={'name': 'test'},
  366. call='function')
  367. def test_get_template_id_success(self):
  368. '''
  369. Tests that the function returns successfully.
  370. '''
  371. with patch('salt.cloud.clouds.opennebula.list_templates',
  372. MagicMock(return_value={'test-template': {'id': '100'}})):
  373. mock_id = '100'
  374. mock_kwargs = {'name': 'test-template'}
  375. self.assertEqual(opennebula.get_template_id(mock_kwargs, 'foo'),
  376. mock_id)
  377. def test_get_vm_id_action(self):
  378. '''
  379. Tests that a SaltCloudSystemExit is raised when trying to call
  380. get_vm_id with --action or -a.
  381. '''
  382. self.assertRaises(SaltCloudSystemExit,
  383. opennebula.get_vm_id,
  384. call='action')
  385. def test_get_vm_id_no_name(self):
  386. '''
  387. Tests that a SaltCloudSystemExit is raised when no name is provided.
  388. '''
  389. self.assertRaises(SaltCloudSystemExit,
  390. opennebula.get_vm_id,
  391. None,
  392. call='foo')
  393. def test_get_vm_id_not_found(self):
  394. '''
  395. Tests that a SaltCloudSystemExit is raised when no name is provided.
  396. '''
  397. with patch('salt.cloud.clouds.opennebula.list_nodes',
  398. MagicMock(return_value={'test-vm': {'id': '100'}})):
  399. self.assertRaises(SaltCloudSystemExit,
  400. opennebula.get_vm_id,
  401. kwargs={'name': 'test'},
  402. call='function')
  403. def test_get_vm_id_success(self):
  404. '''
  405. Tests that the function returns successfully.
  406. '''
  407. with patch('salt.cloud.clouds.opennebula.list_nodes',
  408. MagicMock(return_value={'test-vm': {'id': '100'}})):
  409. mock_id = '100'
  410. mock_kwargs = {'name': 'test-vm'}
  411. self.assertEqual(opennebula.get_vm_id(mock_kwargs, 'foo'),
  412. mock_id)
  413. def test_get_vn_id_action(self):
  414. '''
  415. Tests that a SaltCloudSystemExit is raised when trying to call
  416. get_vn_id with --action or -a.
  417. '''
  418. self.assertRaises(SaltCloudSystemExit,
  419. opennebula.get_vn_id,
  420. call='action')
  421. def test_get_vn_id_no_name(self):
  422. '''
  423. Tests that a SaltCloudSystemExit is raised when no name is provided.
  424. '''
  425. self.assertRaises(SaltCloudSystemExit,
  426. opennebula.get_vn_id,
  427. None,
  428. call='foo')
  429. def test_get_vn_id_not_found(self):
  430. '''
  431. Tests that a SaltCloudSystemExit is raised when no name is provided.
  432. '''
  433. with patch('salt.cloud.clouds.opennebula.list_vns',
  434. MagicMock(return_value={'test-vn': {'id': '100'}})):
  435. self.assertRaises(SaltCloudSystemExit,
  436. opennebula.get_vn_id,
  437. kwargs={'name': 'test'},
  438. call='function')
  439. def test_get_vn_id_success(self):
  440. '''
  441. Tests that the function returns successfully.
  442. '''
  443. with patch('salt.cloud.clouds.opennebula.list_vns',
  444. MagicMock(return_value={'test-vn': {'id': '100'}})):
  445. mock_id = '100'
  446. mock_kwargs = {'name': 'test-vn'}
  447. self.assertEqual(opennebula.get_vn_id(mock_kwargs, 'foo'),
  448. mock_id)
  449. # TODO: Write tests for create function
  450. def test_destroy_function_error(self):
  451. '''
  452. Tests that a SaltCloudSystemExit is raised when --function or -f is provided.
  453. '''
  454. self.assertRaises(SaltCloudSystemExit, opennebula.destroy, 'my-vm', 'function')
  455. def test_image_allocate_function_error(self):
  456. '''
  457. Tests that a SaltCloudSystemExit is raised when something other than
  458. --function or -f is provided.
  459. '''
  460. self.assertRaises(SaltCloudSystemExit, opennebula.image_allocate, 'foo')
  461. def test_image_allocate_no_name_or_datastore_id(self):
  462. '''
  463. Tests that a SaltCloudSystemExit is raised when a neither a datastore_id
  464. nor a datastore_name is provided.
  465. '''
  466. self.assertRaises(SaltCloudSystemExit, opennebula.image_allocate, 'function')
  467. def test_image_allocate_no_path_or_data(self):
  468. '''
  469. Tests that a SaltCloudSystemExit is raised when neither the path nor data args
  470. are provided.
  471. '''
  472. self.assertRaises(SaltCloudSystemExit,
  473. opennebula.image_allocate,
  474. 'function',
  475. kwargs={'datastore_id': '5'})
  476. def test_image_clone_function_error(self):
  477. '''
  478. Tests that a SaltCloudSystemExit is raised when something other than
  479. --function or -f is provided.
  480. '''
  481. self.assertRaises(SaltCloudSystemExit, opennebula.image_clone, 'foo')
  482. def test_image_clone_no_name(self):
  483. '''
  484. Tests that a SaltCloudSystemExit is raised when a name isn't provided.
  485. '''
  486. self.assertRaises(SaltCloudSystemExit, opennebula.image_clone, 'function')
  487. def test_image_clone_no_image_id_or_image_name(self):
  488. '''
  489. Tests that a SaltCloudSystemExit is raised when neither the image_id nor
  490. the image_name args are provided.
  491. '''
  492. self.assertRaises(SaltCloudSystemExit,
  493. opennebula.image_clone,
  494. 'function',
  495. kwargs={'name': 'test'})
  496. @skipIf(True, 'Need to figure out how to mock calls to the O.N. API first.')
  497. def test_image_clone_success(self):
  498. '''
  499. Tests that image_clone returns successfully
  500. '''
  501. with patch('image.clone', MagicMock(return_value=[True, 11, 0])):
  502. name = 'test-image'
  503. expected = {
  504. 'action': 'image.clone',
  505. 'cloned': 'True',
  506. 'cloned_image_id': '11',
  507. 'cloned_image_name': name,
  508. 'error_code': '0',
  509. }
  510. ret = opennebula.image_clone('function', kwargs={'name': name, 'image_id': 1})
  511. self.assertEqual(expected, ret)
  512. def test_image_delete_function_error(self):
  513. '''
  514. Tests that a SaltCloudSystemExit is raised when something other than
  515. --function or -f is provided.
  516. '''
  517. self.assertRaises(SaltCloudSystemExit, opennebula.image_delete, 'foo')
  518. def test_image_delete_no_name_or_image_id(self):
  519. '''
  520. Tests that a SaltCloudSystemExit is raised when a neither an image_id
  521. nor a name is provided.
  522. '''
  523. self.assertRaises(SaltCloudSystemExit, opennebula.image_delete, 'function')
  524. def test_image_info_function_error(self):
  525. '''
  526. Tests that a SaltCloudSystemExit is raised when something other than
  527. --function or -f is provided.
  528. '''
  529. self.assertRaises(SaltCloudSystemExit, opennebula.image_info, 'foo')
  530. def test_image_info_no_image_id_or_image_name(self):
  531. '''
  532. Tests that a SaltCloudSystemExit is raised when a neither an image_id
  533. nor a name is provided.
  534. '''
  535. self.assertRaises(SaltCloudSystemExit, opennebula.image_info, 'function')
  536. def test_image_persist_function_error(self):
  537. '''
  538. Tests that a SaltCloudSystemExit is raised when something other than
  539. --function or -f is provided.
  540. '''
  541. self.assertRaises(SaltCloudSystemExit, opennebula.image_persistent, 'foo')
  542. def test_image_persist_no_persist(self):
  543. '''
  544. Tests that a SaltCloudSystemExit is raised when the persist kwarg is missing.
  545. '''
  546. self.assertRaises(SaltCloudSystemExit, opennebula.image_persistent, 'function')
  547. def test_image_persist_no_name_or_image_id(self):
  548. '''
  549. Tests that a SaltCloudSystemExit is raised when a neither an image_id
  550. nor a name is provided.
  551. '''
  552. self.assertRaises(SaltCloudSystemExit,
  553. opennebula.image_delete,
  554. 'function',
  555. kwargs={'persist': False})
  556. def test_image_snapshot_delete_function_error(self):
  557. '''
  558. Tests that a SaltCloudSystemExit is raised when something other than
  559. --function or -f is provided.
  560. '''
  561. self.assertRaises(SaltCloudSystemExit,
  562. opennebula.image_snapshot_delete,
  563. call='foo')
  564. def test_image_snapshot_delete_no_snapshot_id(self):
  565. '''
  566. Tests that a SaltCloudSystemExit is raised when the snapshot_id kwarg is
  567. missing.
  568. '''
  569. self.assertRaises(SaltCloudSystemExit,
  570. opennebula.image_snapshot_delete,
  571. call='function',
  572. kwargs=None)
  573. def test_image_snapshot_delete_no_image_name_or_image_id(self):
  574. '''
  575. Tests that a SaltCloudSystemExit is raised when the image_id and image_name
  576. kwargs are missing.
  577. '''
  578. self.assertRaises(SaltCloudSystemExit,
  579. opennebula.image_snapshot_delete,
  580. call='function',
  581. kwargs={'snapshot_id': 0})
  582. def test_image_snapshot_revert_function_error(self):
  583. '''
  584. Tests that a SaltCloudSystemExit is raised when something other than
  585. --function or -f is provided.
  586. '''
  587. self.assertRaises(SaltCloudSystemExit,
  588. opennebula.image_snapshot_revert,
  589. call='foo')
  590. def test_image_snapshot_revert_no_snapshot_id(self):
  591. '''
  592. Tests that a SaltCloudSystemExit is raised when the snapshot_id kwarg is
  593. missing.
  594. '''
  595. self.assertRaises(SaltCloudSystemExit,
  596. opennebula.image_snapshot_revert,
  597. call='function',
  598. kwargs=None)
  599. def test_image_snapshot_revert_no_image_name_or_image_id(self):
  600. '''
  601. Tests that a SaltCloudSystemExit is raised when the image_id and image_name
  602. kwargs are missing.
  603. '''
  604. self.assertRaises(SaltCloudSystemExit,
  605. opennebula.image_snapshot_revert,
  606. call='function',
  607. kwargs={'snapshot_id': 0})
  608. def test_image_snapshot_flatten_function_error(self):
  609. '''
  610. Tests that a SaltCloudSystemExit is raised when something other than
  611. --function or -f is provided.
  612. '''
  613. self.assertRaises(SaltCloudSystemExit,
  614. opennebula.image_snapshot_flatten,
  615. call='foo')
  616. def test_image_snapshot_flatten_no_snapshot_id(self):
  617. '''
  618. Tests that a SaltCloudSystemExit is raised when the snapshot_id kwarg is
  619. missing.
  620. '''
  621. self.assertRaises(SaltCloudSystemExit,
  622. opennebula.image_snapshot_flatten,
  623. call='function',
  624. kwargs=None)
  625. def test_image_snapshot_flatten_no_image_name_or_image_id(self):
  626. '''
  627. Tests that a SaltCloudSystemExit is raised when the image_id and image_name
  628. kwargs are missing.
  629. '''
  630. self.assertRaises(SaltCloudSystemExit,
  631. opennebula.image_snapshot_flatten,
  632. call='function',
  633. kwargs={'snapshot_id': 0})
  634. def test_image_update_function_error(self):
  635. '''
  636. Tests that a SaltCloudSystemExit is raised when something other than
  637. --function or -f is provided.
  638. '''
  639. self.assertRaises(SaltCloudSystemExit, opennebula.image_update, 'foo')
  640. def test_image_update_no_update_type(self):
  641. '''
  642. Tests that a SaltCloudSystemExit is raised when the update_type kwarg is
  643. missing.
  644. '''
  645. self.assertRaises(SaltCloudSystemExit, opennebula.image_update, 'function')
  646. def test_image_update_bad_update_type_value(self):
  647. '''
  648. Tests that a SaltCloudSystemExit is raised when the update_type kwarg is
  649. not a valid value.
  650. '''
  651. self.assertRaises(SaltCloudSystemExit,
  652. opennebula.image_update,
  653. 'function',
  654. kwargs={'update_type': 'foo'})
  655. def test_image_update_no_image_id_or_image_name(self):
  656. '''
  657. Tests that a SaltCloudSystemExit is raised when the image_id and image_name
  658. kwargs are missing.
  659. '''
  660. self.assertRaises(SaltCloudSystemExit,
  661. opennebula.image_update,
  662. 'function',
  663. kwargs={'update_type': 'merge'})
  664. def test_image_update_no_data_or_path(self):
  665. '''
  666. Tests that a SaltCloudSystemExit is raised when the data and path
  667. kwargs are missing.
  668. '''
  669. self.assertRaises(SaltCloudSystemExit,
  670. opennebula.image_update,
  671. 'function',
  672. kwargs={'update_type': 'merge', 'image_id': '0'})
  673. def test_show_instance_action_error(self):
  674. '''
  675. Tests that a SaltCloudSystemExit is raised when something other than
  676. --action or -a is provided.
  677. '''
  678. self.assertRaises(SaltCloudSystemExit,
  679. opennebula.show_instance,
  680. VM_NAME,
  681. call='foo')
  682. def test_show_instance_success(self):
  683. '''
  684. Tests that the node was found successfully.
  685. '''
  686. with patch('salt.cloud.clouds.opennebula._get_node',
  687. MagicMock(return_value={'my-vm': {'name': 'my-vm', 'id': 0}})):
  688. ret = {'my-vm': {'name': 'my-vm', 'id': 0}}
  689. self.assertEqual(opennebula.show_instance('my-vm', call='action'), ret)
  690. def test_secgroup_allocate_function_error(self):
  691. '''
  692. Tests that a SaltCloudSystemExit is raised when something other than
  693. --function or -f is provided.
  694. '''
  695. self.assertRaises(SaltCloudSystemExit, opennebula.secgroup_allocate, 'foo')
  696. def test_secgroup_allocate_no_data_or_path(self):
  697. '''
  698. Tests that a SaltCloudSystemExit is raised when the data and path
  699. kwargs are missing.
  700. '''
  701. self.assertRaises(SaltCloudSystemExit, opennebula.secgroup_allocate, 'function')
  702. def test_secgroup_clone_function_error(self):
  703. '''
  704. Tests that a SaltCloudSystemExit is raised when something other than
  705. --function or -f is provided.
  706. '''
  707. self.assertRaises(SaltCloudSystemExit, opennebula.secgroup_clone, 'foo')
  708. def test_secgroup_clone_no_name(self):
  709. '''
  710. Tests that a SaltCloudSystemExit is raised when the name kwarg is
  711. missing.
  712. '''
  713. self.assertRaises(SaltCloudSystemExit, opennebula.secgroup_clone, 'function')
  714. def test_secgroup_clone_no_secgroup_id_or_secgroup_name(self):
  715. '''
  716. Tests that a SaltCloudSystemExit is raised when the secgroup_id and
  717. secgroup_name kwargs are missing.
  718. '''
  719. self.assertRaises(SaltCloudSystemExit,
  720. opennebula.secgroup_clone,
  721. 'function',
  722. kwargs={'name': 'test'})
  723. def test_secgroup_delete_function_error(self):
  724. '''
  725. Tests that a SaltCloudSystemExit is raised when something other than
  726. --function or -f is provided.
  727. '''
  728. self.assertRaises(SaltCloudSystemExit, opennebula.secgroup_delete, 'foo')
  729. def test_secgroup_delete_no_secgroup_id_or_name(self):
  730. '''
  731. Tests that a SaltCloudSystemExit is raised when the secgroup_id and
  732. name kwargs are missing.
  733. '''
  734. self.assertRaises(SaltCloudSystemExit, opennebula.secgroup_clone, 'function')
  735. def test_secgroup_info_function_error(self):
  736. '''
  737. Tests that a SaltCloudSystemExit is raised when something other than
  738. --function or -f is provided.
  739. '''
  740. self.assertRaises(SaltCloudSystemExit, opennebula.secgroup_info, 'foo')
  741. def test_secgroup_info_no_secgroup_id_or_name(self):
  742. '''
  743. Tests that a SaltCloudSystemExit is raised when the secgroup_id and
  744. name kwargs are missing.
  745. '''
  746. self.assertRaises(SaltCloudSystemExit, opennebula.secgroup_info, 'function')
  747. def test_secgroup_update_function_error(self):
  748. '''
  749. Tests that a SaltCloudSystemExit is raised when something other than
  750. --function or -f is provided.
  751. '''
  752. self.assertRaises(SaltCloudSystemExit, opennebula.secgroup_update, 'foo')
  753. def test_secgroup_update_no_update_type(self):
  754. '''
  755. Tests that a SaltCloudSystemExit is raised when the update_type arg is
  756. missing.
  757. '''
  758. self.assertRaises(SaltCloudSystemExit, opennebula.secgroup_update, 'function')
  759. def test_secgroup_update_bad_update_type_value(self):
  760. '''
  761. Tests that a SaltCloudSystemExit is raised when the update_type contains
  762. an invalid value.
  763. '''
  764. self.assertRaises(SaltCloudSystemExit,
  765. opennebula.secgroup_update,
  766. 'function',
  767. kwargs={'update_type': 'foo'})
  768. def test_secgroup_update_no_secgroup_id_or_secgroup_name(self):
  769. '''
  770. Tests that a SaltCloudSystemExit is raised when the secgroup_id and
  771. secgroup_name kwargs are missing.
  772. '''
  773. self.assertRaises(SaltCloudSystemExit,
  774. opennebula.secgroup_update,
  775. 'function',
  776. kwargs={'update_type': 'merge'})
  777. def test_secgroup_update_no_data_or_path(self):
  778. '''
  779. Tests that a SaltCloudSystemExit is raised when the data and
  780. path kwargs are missing.
  781. '''
  782. self.assertRaises(SaltCloudSystemExit,
  783. opennebula.secgroup_update,
  784. 'function',
  785. kwargs={'update_type': 'merge', 'secgroup_id': '0'})
  786. def test_template_allocate_function_error(self):
  787. '''
  788. Tests that a SaltCloudSystemExit is raised when something other than
  789. --function or -f is provided.
  790. '''
  791. self.assertRaises(SaltCloudSystemExit, opennebula.template_allocate, 'foo')
  792. def test_template_allocate_no_data_or_path(self):
  793. '''
  794. Tests that a SaltCloudSystemExit is raised when the data and
  795. path kwargs are missing.
  796. '''
  797. self.assertRaises(SaltCloudSystemExit, opennebula.template_allocate, 'function')
  798. def test_template_clone_function_error(self):
  799. '''
  800. Tests that a SaltCloudSystemExit is raised when something other than
  801. --function or -f is provided.
  802. '''
  803. self.assertRaises(SaltCloudSystemExit, opennebula.template_clone, 'foo')
  804. def test_template_clone_no_name(self):
  805. '''
  806. Tests that a SaltCloudSystemExit is raised when the name arg is missing.
  807. '''
  808. self.assertRaises(SaltCloudSystemExit, opennebula.template_clone, 'function')
  809. def test_template_clone_no_template_name_or_template_id(self):
  810. '''
  811. Tests that a SaltCloudSystemExit is raised when the template_name and
  812. template_id args are missing.
  813. '''
  814. self.assertRaises(SaltCloudSystemExit,
  815. opennebula.template_clone,
  816. 'function',
  817. kwargs={'name': 'foo'})
  818. def test_template_delete_function_error(self):
  819. '''
  820. Tests that a SaltCloudSystemExit is raised when something other than
  821. --function or -f is provided.
  822. '''
  823. self.assertRaises(SaltCloudSystemExit, opennebula.template_delete, 'foo')
  824. def test_template_delete_no_name_or_template_id(self):
  825. '''
  826. Tests that a SaltCloudSystemExit is raised when the name and
  827. template_id args are missing.
  828. '''
  829. self.assertRaises(SaltCloudSystemExit, opennebula.template_delete, 'function')
  830. def test_template_instantiate_function_error(self):
  831. '''
  832. Tests that a SaltCloudSystemExit is raised when something other than
  833. --function or -f is provided.
  834. '''
  835. self.assertRaises(SaltCloudSystemExit, opennebula.template_instantiate, 'foo')
  836. def test_template_instantiate_no_vm_name(self):
  837. '''
  838. Tests that a SaltCloudSystemExit is raised when the vm_name arg is missing.
  839. '''
  840. self.assertRaises(SaltCloudSystemExit,
  841. opennebula.template_instantiate,
  842. 'function',
  843. None)
  844. def test_template_instantiate_no_template_id_or_template_name(self):
  845. '''
  846. Tests that a SaltCloudSystemExit is raised when the template_name and
  847. template_id args are missing.
  848. '''
  849. self.assertRaises(SaltCloudSystemExit,
  850. opennebula.template_instantiate,
  851. 'function',
  852. kwargs={'vm_name': 'test'})
  853. def test_template_update_function_error(self):
  854. '''
  855. Tests that a SaltCloudSystemExit is raised when something other than
  856. --function or -f is provided.
  857. '''
  858. self.assertRaises(SaltCloudSystemExit,
  859. opennebula.template_update,
  860. call='foo')
  861. def test_template_update_bad_update_type_value(self):
  862. '''
  863. Tests that a SaltCloudSystemExit is raised when the update_type contains
  864. and invalid value.
  865. '''
  866. self.assertRaises(SaltCloudSystemExit,
  867. opennebula.template_update,
  868. call='function',
  869. kwargs={'update_type': 'foo'})
  870. def test_template_update_no_template_id_or_template_name(self):
  871. '''
  872. Tests that a SaltCloudSystemExit is raised when the template_id and the
  873. template_name args are missing.
  874. '''
  875. self.assertRaises(SaltCloudSystemExit,
  876. opennebula.template_update,
  877. call='function',
  878. kwargs={'update_type': 'merge'})
  879. def test_template_update_no_data_or_path(self):
  880. '''
  881. Tests that a SaltCloudSystemExit is raised when the data and the
  882. path args are missing.
  883. '''
  884. self.assertRaises(SaltCloudSystemExit,
  885. opennebula.template_update,
  886. call='function',
  887. kwargs={'update_type': 'merge',
  888. 'template_id': '0'})
  889. def test_vm_action_error(self):
  890. '''
  891. Tests that a SaltCloudSystemExit is raised when something other than
  892. --action or -a is provided.
  893. '''
  894. self.assertRaises(SaltCloudSystemExit,
  895. opennebula.vm_action,
  896. VM_NAME,
  897. call='foo')
  898. def test_vm_action_no_action(self):
  899. '''
  900. Tests that a SaltCloudSystemExit is raised when the action arg is missing
  901. '''
  902. self.assertRaises(SaltCloudSystemExit,
  903. opennebula.vm_action,
  904. VM_NAME,
  905. call='action')
  906. def test_vm_allocate_function_error(self):
  907. '''
  908. Tests that a SaltCloudSystemExit is raised when something other than
  909. --function or -f is provided.
  910. '''
  911. self.assertRaises(SaltCloudSystemExit, opennebula.vm_allocate, 'foo')
  912. def test_vm_allocate_no_data_or_path(self):
  913. '''
  914. Tests that a SaltCloudSystemExit is raised when the data and
  915. path kwargs are missing.
  916. '''
  917. self.assertRaises(SaltCloudSystemExit, opennebula.vm_allocate, 'function')
  918. def test_vm_attach_action_error(self):
  919. '''
  920. Tests that a SaltCloudSystemExit is raised when something other than
  921. --action or -a is provided.
  922. '''
  923. self.assertRaises(SaltCloudSystemExit,
  924. opennebula.vm_attach,
  925. VM_NAME,
  926. call='foo')
  927. def test_vm_attach_no_data_or_path(self):
  928. '''
  929. Tests that a SaltCloudSystemExit is raised when the data and
  930. path kwargs are missing.
  931. '''
  932. self.assertRaises(SaltCloudSystemExit,
  933. opennebula.vm_attach,
  934. VM_NAME,
  935. call='action')
  936. def test_vm_attach_nic_action_error(self):
  937. '''
  938. Tests that a SaltCloudSystemExit is raised when something other than
  939. --action or -a is provided.
  940. '''
  941. self.assertRaises(SaltCloudSystemExit,
  942. opennebula.vm_attach_nic,
  943. VM_NAME,
  944. call='foo')
  945. def test_vm_attach_nic_no_data_or_path(self):
  946. '''
  947. Tests that a SaltCloudSystemExit is raised when the data and
  948. path kwargs are missing.
  949. '''
  950. self.assertRaises(SaltCloudSystemExit,
  951. opennebula.vm_attach_nic,
  952. VM_NAME,
  953. call='action')
  954. def test_vm_deploy_action_error(self):
  955. '''
  956. Tests that a SaltCloudSystemExit is raised when something other than
  957. --action or -a is provided.
  958. '''
  959. self.assertRaises(SaltCloudSystemExit,
  960. opennebula.vm_deploy,
  961. VM_NAME,
  962. call='foo')
  963. def test_vm_deploy_no_host_id_or_host_name(self):
  964. '''
  965. Tests that a SaltCloudSystemExit is raised when the host_id and the
  966. host_name args are missing.
  967. '''
  968. self.assertRaises(SaltCloudSystemExit,
  969. opennebula.vm_deploy,
  970. VM_NAME,
  971. call='action',
  972. kwargs=None)
  973. def test_vm_detach_action_error(self):
  974. '''
  975. Tests that a SaltCloudSystemExit is raised when something other than
  976. --action or -a is provided.
  977. '''
  978. self.assertRaises(SaltCloudSystemExit,
  979. opennebula.vm_detach,
  980. VM_NAME,
  981. call='foo')
  982. def test_vm_detach_no_disk_id(self):
  983. '''
  984. Tests that a SaltCloudSystemExit is raised when the disk_id ar is missing.
  985. '''
  986. self.assertRaises(SaltCloudSystemExit,
  987. opennebula.vm_detach,
  988. VM_NAME,
  989. call='action')
  990. def test_vm_detach_nic_action_error(self):
  991. '''
  992. Tests that a SaltCloudSystemExit is raised when something other than
  993. --action or -a is provided.
  994. '''
  995. self.assertRaises(SaltCloudSystemExit,
  996. opennebula.vm_detach_nic,
  997. VM_NAME,
  998. call='foo')
  999. def test_vm_detach_nic_no_nic_id(self):
  1000. '''
  1001. Tests that a SaltCloudSystemExit is raised when the nic_id arg is missing.
  1002. '''
  1003. self.assertRaises(SaltCloudSystemExit,
  1004. opennebula.vm_detach_nic,
  1005. VM_NAME,
  1006. call='action')
  1007. def test_vm_disk_save_action_error(self):
  1008. '''
  1009. Tests that a SaltCloudSystemExit is raised when something other than
  1010. --action or -a is provided.
  1011. '''
  1012. self.assertRaises(SaltCloudSystemExit,
  1013. opennebula.vm_disk_save,
  1014. VM_NAME,
  1015. call='foo')
  1016. def test_vm_disk_save_no_disk_id(self):
  1017. '''
  1018. Tests that a SaltCloudSystemExit is raised when the disk_id arg is missing.
  1019. '''
  1020. self.assertRaises(SaltCloudSystemExit,
  1021. opennebula.vm_disk_save,
  1022. VM_NAME,
  1023. call='action',
  1024. kwargs={'image_name': 'foo'})
  1025. def test_vm_disk_save_no_image_name(self):
  1026. '''
  1027. Tests that a SaltCloudSystemExit is raised when the image_name arg is missing.
  1028. '''
  1029. self.assertRaises(SaltCloudSystemExit,
  1030. opennebula.vm_disk_save,
  1031. VM_NAME,
  1032. call='action',
  1033. kwargs={'disk_id': '0'})
  1034. def test_vm_disk_snapshot_create_action_error(self):
  1035. '''
  1036. Tests that a SaltCloudSystemExit is raised when something other than
  1037. --action or -a is provided.
  1038. '''
  1039. self.assertRaises(SaltCloudSystemExit,
  1040. opennebula.vm_disk_snapshot_create,
  1041. VM_NAME,
  1042. call='foo')
  1043. def test_vm_disk_snapshot_create_no_disk_id(self):
  1044. '''
  1045. Tests that a SaltCloudSystemExit is raised when the disk_id arg is missing.
  1046. '''
  1047. self.assertRaises(SaltCloudSystemExit,
  1048. opennebula.vm_disk_snapshot_create,
  1049. VM_NAME,
  1050. call='action',
  1051. kwargs={'description': 'foo'})
  1052. def test_vm_disk_snapshot_create_no_description(self):
  1053. '''
  1054. Tests that a SaltCloudSystemExit is raised when the image_name arg is missing.
  1055. '''
  1056. self.assertRaises(SaltCloudSystemExit,
  1057. opennebula.vm_disk_snapshot_create,
  1058. VM_NAME,
  1059. call='action',
  1060. kwargs={'disk_id': '0'})
  1061. def test_vm_disk_snapshot_delete_action_error(self):
  1062. '''
  1063. Tests that a SaltCloudSystemExit is raised when something other than
  1064. --action or -a is provided.
  1065. '''
  1066. self.assertRaises(SaltCloudSystemExit,
  1067. opennebula.vm_disk_snapshot_delete,
  1068. VM_NAME,
  1069. call='foo')
  1070. def test_vm_disk_snapshot_delete_no_disk_id(self):
  1071. '''
  1072. Tests that a SaltCloudSystemExit is raised when the disk_id arg is missing.
  1073. '''
  1074. self.assertRaises(SaltCloudSystemExit,
  1075. opennebula.vm_disk_snapshot_delete,
  1076. VM_NAME,
  1077. call='action',
  1078. kwargs={'snapshot_id': '0'})
  1079. def test_vm_disk_snapshot_delete_no_snapshot_id(self):
  1080. '''
  1081. Tests that a SaltCloudSystemExit is raised when the snapshot_id arg is missing.
  1082. '''
  1083. self.assertRaises(SaltCloudSystemExit,
  1084. opennebula.vm_disk_snapshot_delete,
  1085. VM_NAME,
  1086. call='action',
  1087. kwargs={'disk_id': '0'})
  1088. def test_vm_disk_snapshot_revert_action_error(self):
  1089. '''
  1090. Tests that a SaltCloudSystemExit is raised when something other than
  1091. --action or -a is provided.
  1092. '''
  1093. self.assertRaises(SaltCloudSystemExit,
  1094. opennebula.vm_disk_snapshot_revert,
  1095. VM_NAME,
  1096. call='foo')
  1097. def test_vm_disk_snapshot_revert_no_disk_id(self):
  1098. '''
  1099. Tests that a SaltCloudSystemExit is raised when the disk_id arg is missing.
  1100. '''
  1101. self.assertRaises(SaltCloudSystemExit,
  1102. opennebula.vm_disk_snapshot_revert,
  1103. VM_NAME,
  1104. call='action',
  1105. kwargs={'snapshot_id': '0'})
  1106. def test_vm_disk_snapshot_revert_no_snapshot_id(self):
  1107. '''
  1108. Tests that a SaltCloudSystemExit is raised when the snapshot_id arg is missing.
  1109. '''
  1110. self.assertRaises(SaltCloudSystemExit,
  1111. opennebula.vm_disk_snapshot_revert,
  1112. VM_NAME,
  1113. call='action',
  1114. kwargs={'disk_id': '0'})
  1115. def test_vm_info_action_error(self):
  1116. '''
  1117. Tests that a SaltCloudSystemExit is raised when something other than
  1118. --action or -a is provided.
  1119. '''
  1120. self.assertRaises(SaltCloudSystemExit,
  1121. opennebula.vm_info,
  1122. VM_NAME,
  1123. call='foo')
  1124. def test_vm_migrate_action_error(self):
  1125. '''
  1126. Tests that a SaltCloudSystemExit is raised when something other than
  1127. --action or -a is provided.
  1128. '''
  1129. self.assertRaises(SaltCloudSystemExit,
  1130. opennebula.vm_migrate,
  1131. VM_NAME,
  1132. call='foo')
  1133. def test_vm_migrate_no_datastore_id_or_datastore_name(self):
  1134. '''
  1135. Tests that a SaltCLoudSystemExit is raised when the datastore_id and the
  1136. datastore_name args are missing.
  1137. '''
  1138. self.assertRaises(SaltCloudSystemExit,
  1139. opennebula.vm_migrate,
  1140. VM_NAME,
  1141. call='action',
  1142. kwargs=None)
  1143. def test_vm_migrate_no_host_id_or_host_name(self):
  1144. '''
  1145. Tests that a SaltCloudSystemExit is raised when the the host_id and the
  1146. host_name args are missing.
  1147. '''
  1148. self.assertRaises(SaltCloudSystemExit,
  1149. opennebula.vm_migrate,
  1150. VM_NAME,
  1151. call='action',
  1152. kwargs={'datastore_id': '0'})
  1153. def test_vm_monitoring_action_error(self):
  1154. '''
  1155. Tests that a SaltCloudSystemExit is raised when something other than
  1156. --action or -a is provided.
  1157. '''
  1158. self.assertRaises(SaltCloudSystemExit,
  1159. opennebula.vm_monitoring,
  1160. VM_NAME,
  1161. call='foo')
  1162. def test_vm_resize_action_error(self):
  1163. '''
  1164. Tests that a SaltCloudSystemExit is raised when something other than
  1165. --action or -a is provided.
  1166. '''
  1167. self.assertRaises(SaltCloudSystemExit,
  1168. opennebula.vm_resize,
  1169. VM_NAME,
  1170. call='foo')
  1171. def test_vm_resize_no_data_or_path(self):
  1172. '''
  1173. Tests that a SaltCloudSystemExit is raised when the data and path args
  1174. are missing.
  1175. '''
  1176. self.assertRaises(SaltCloudSystemExit,
  1177. opennebula.vm_resize,
  1178. VM_NAME,
  1179. call='action',
  1180. kwargs=None)
  1181. def test_vm_snapshot_create_action_error(self):
  1182. '''
  1183. Tests that a SaltCloudSystemExit is raised when something other than
  1184. --action or -a is provided.
  1185. '''
  1186. self.assertRaises(SaltCloudSystemExit,
  1187. opennebula.vm_snapshot_create,
  1188. VM_NAME,
  1189. call='foo')
  1190. def test_vm_snapshot_create_no_snapshot_name(self):
  1191. '''
  1192. Tests that a SaltCloudSystemExit is raised when the snapshot_name arg
  1193. is missing.
  1194. '''
  1195. self.assertRaises(SaltCloudSystemExit,
  1196. opennebula.vm_snapshot_create,
  1197. VM_NAME,
  1198. call='action',
  1199. kwargs=None)
  1200. def test_vm_snapshot_delete_action_error(self):
  1201. '''
  1202. Tests that a SaltCloudSystemExit is raised when something other than
  1203. --action or -a is provided.
  1204. '''
  1205. self.assertRaises(SaltCloudSystemExit,
  1206. opennebula.vm_snapshot_delete,
  1207. VM_NAME,
  1208. call='foo')
  1209. def test_vm_snapshot_delete_no_snapshot_id(self):
  1210. '''
  1211. Tests that a SaltCloudSystemExit is raised when the snapshot_id arg
  1212. is missing.
  1213. '''
  1214. self.assertRaises(SaltCloudSystemExit,
  1215. opennebula.vm_snapshot_delete,
  1216. VM_NAME,
  1217. call='action',
  1218. kwargs=None)
  1219. def test_vm_snapshot_revert_action_error(self):
  1220. '''
  1221. Tests that a SaltCloudSystemExit is raised when something other than
  1222. --action or -a is provided.
  1223. '''
  1224. self.assertRaises(SaltCloudSystemExit,
  1225. opennebula.vm_snapshot_revert,
  1226. VM_NAME,
  1227. call='foo')
  1228. def test_vm_snapshot_revert_no_snapshot_id(self):
  1229. '''
  1230. Tests that a SaltCloudSystemExit is raised when the snapshot_id arg
  1231. is missing.
  1232. '''
  1233. self.assertRaises(SaltCloudSystemExit,
  1234. opennebula.vm_snapshot_revert,
  1235. VM_NAME,
  1236. call='action',
  1237. kwargs=None)
  1238. def test_vm_update_action_error(self):
  1239. '''
  1240. Tests that a SaltCloudSystemExit is raised when something other than
  1241. --action or -a is provided.
  1242. '''
  1243. self.assertRaises(SaltCloudSystemExit,
  1244. opennebula.vm_update,
  1245. VM_NAME,
  1246. call='foo')
  1247. def test_vm_update_no_update_type(self):
  1248. '''
  1249. Tests that a SaltCloudSystemExit is raised when the update_type arg
  1250. is missing.
  1251. '''
  1252. self.assertRaises(SaltCloudSystemExit,
  1253. opennebula.vm_update,
  1254. VM_NAME,
  1255. call='action',
  1256. kwargs=None)
  1257. def test_vm_update_bad_update_type_value(self):
  1258. '''
  1259. Tests that a SaltCloudSystemExit is raised when the update_type kwarg is
  1260. not a valid value.
  1261. '''
  1262. self.assertRaises(SaltCloudSystemExit,
  1263. opennebula.vm_update,
  1264. VM_NAME,
  1265. call='action',
  1266. kwargs={'update_type': 'foo'})
  1267. def test_vm_update_no_data_or_path(self):
  1268. '''
  1269. Tests that a SaltCloudSystemExit is raised when the data and path args
  1270. are missing.
  1271. '''
  1272. self.assertRaises(SaltCloudSystemExit,
  1273. opennebula.vm_update,
  1274. VM_NAME,
  1275. call='action',
  1276. kwargs={'update_type': 'merge'})
  1277. def test_vn_add_ar_function_error(self):
  1278. '''
  1279. Tests that a SaltCloudSystemExit is raised when something other than
  1280. --function or -f is provided.
  1281. '''
  1282. self.assertRaises(SaltCloudSystemExit,
  1283. opennebula.vn_add_ar,
  1284. call='foo')
  1285. def test_vn_add_ar_no_vn_id_or_vn_name(self):
  1286. '''
  1287. Tests that a SaltCloudSystemExit is raised when the vn_id and vn_name
  1288. args are missing.
  1289. '''
  1290. self.assertRaises(SaltCloudSystemExit,
  1291. opennebula.vn_add_ar,
  1292. call='function',
  1293. kwargs=None)
  1294. def test_vn_add_ar_no_path_or_data(self):
  1295. '''
  1296. Tests that a SaltCloudSystemExit is raised when the path and data
  1297. args are missing.
  1298. '''
  1299. self.assertRaises(SaltCloudSystemExit,
  1300. opennebula.vn_add_ar,
  1301. call='function',
  1302. kwargs={'vn_id': '0'})
  1303. def test_vn_allocate_function_error(self):
  1304. '''
  1305. Tests that a SaltCloudSystemExit is raised when something other than
  1306. --function or -f is provided.
  1307. '''
  1308. self.assertRaises(SaltCloudSystemExit,
  1309. opennebula.vn_allocate,
  1310. call='foo')
  1311. def test_vn_allocate_no_data_or_path(self):
  1312. '''
  1313. Tests that a SaltCloudSystemExit is raised when the path and data
  1314. args are missing.
  1315. '''
  1316. self.assertRaises(SaltCloudSystemExit,
  1317. opennebula.vn_allocate,
  1318. call='function',
  1319. kwargs=None)
  1320. def test_vn_delete_function_error(self):
  1321. '''
  1322. Tests that a SaltCloudSystemExit is raised when something other than
  1323. --function or -f is provided.
  1324. '''
  1325. self.assertRaises(SaltCloudSystemExit,
  1326. opennebula.vn_delete,
  1327. call='foo')
  1328. def test_vn_delete_no_vn_id_or_name(self):
  1329. '''
  1330. Tests that a SaltCloudSystemExit is raised when the vn_id and name
  1331. args are missing.
  1332. '''
  1333. self.assertRaises(SaltCloudSystemExit,
  1334. opennebula.vn_delete,
  1335. call='function',
  1336. kwargs=None)
  1337. def test_vn_free_ar_function_error(self):
  1338. '''
  1339. Tests that a SaltCloudSystemExit is raised when something other than
  1340. --function or -f is provided.
  1341. '''
  1342. self.assertRaises(SaltCloudSystemExit,
  1343. opennebula.vn_free_ar,
  1344. call='foo')
  1345. def test_vn_free_ar_no_ar_id(self):
  1346. '''
  1347. Tests that a SaltCloudSystemExit is raised when the ar_id is missing.
  1348. '''
  1349. self.assertRaises(SaltCloudSystemExit,
  1350. opennebula.vn_free_ar,
  1351. call='function',
  1352. kwargs=None)
  1353. def test_vn_free_ar_no_vn_id_or_vn_name(self):
  1354. '''
  1355. Tests that a SaltCloudSystemExit is raised when the vn_id and vn_name
  1356. args are missing.
  1357. '''
  1358. self.assertRaises(SaltCloudSystemExit,
  1359. opennebula.vn_free_ar,
  1360. call='function',
  1361. kwargs={'ar_id': '0'})
  1362. def test_vn_hold_function_error(self):
  1363. '''
  1364. Tests that a SaltCloudSystemExit is raised when something other than
  1365. --function or -f is provided.
  1366. '''
  1367. self.assertRaises(SaltCloudSystemExit,
  1368. opennebula.vn_hold,
  1369. call='foo')
  1370. def test_vn_hold_no_vn_id_or_vn_name(self):
  1371. '''
  1372. Tests that a SaltCloudSystemExit is raised when the vn_id and vn_name
  1373. args are missing.
  1374. '''
  1375. self.assertRaises(SaltCloudSystemExit,
  1376. opennebula.vn_hold,
  1377. call='function',
  1378. kwargs=None)
  1379. def test_vn_hold_no_data_or_path(self):
  1380. '''
  1381. Tests that a SaltCloudSystemExit is raised when the data and path
  1382. args are missing.
  1383. '''
  1384. self.assertRaises(SaltCloudSystemExit,
  1385. opennebula.vn_hold,
  1386. call='function',
  1387. kwargs={'vn_id': '0'})
  1388. def test_vn_info_function_error(self):
  1389. '''
  1390. Tests that a SaltCloudSystemExit is raised when something other than
  1391. --function or -f is provided.
  1392. '''
  1393. self.assertRaises(SaltCloudSystemExit,
  1394. opennebula.vn_info,
  1395. call='foo')
  1396. def test_vn_info_no_vn_id_or_vn_name(self):
  1397. '''
  1398. Tests that a SaltCloudSystemExit is raised when the vn_id and vn_name
  1399. args are missing.
  1400. '''
  1401. self.assertRaises(SaltCloudSystemExit,
  1402. opennebula.vn_info,
  1403. call='function',
  1404. kwargs=None)
  1405. def test_vn_release_function_error(self):
  1406. '''
  1407. Tests that a SaltCloudSystemExit is raised when something other than
  1408. --function or -f is provided.
  1409. '''
  1410. self.assertRaises(SaltCloudSystemExit,
  1411. opennebula.vn_release,
  1412. call='foo')
  1413. def test_vn_release_no_vn_id_or_vn_name(self):
  1414. '''
  1415. Tests that a SaltCloudSystemExit is raised when the vn_id and vn_name
  1416. args are missing.
  1417. '''
  1418. self.assertRaises(SaltCloudSystemExit,
  1419. opennebula.vn_release,
  1420. call='function',
  1421. kwargs=None)
  1422. def test_vn_release_no_data_or_path(self):
  1423. '''
  1424. Tests that a SaltCloudSystemExit is raised when the data and path
  1425. args are missing.
  1426. '''
  1427. self.assertRaises(SaltCloudSystemExit,
  1428. opennebula.vn_release,
  1429. call='function',
  1430. kwargs={'vn_id': '0'})
  1431. def test_vn_reserve_function_error(self):
  1432. '''
  1433. Tests that a SaltCloudSystemExit is raised when something other than
  1434. --function or -f is provided.
  1435. '''
  1436. self.assertRaises(SaltCloudSystemExit,
  1437. opennebula.vn_reserve,
  1438. call='foo')
  1439. def test_vn_reserve_no_vn_id_or_vn_name(self):
  1440. '''
  1441. Tests that a SaltCloudSystemExit is raised when the vn_id and vn_name
  1442. args are missing.
  1443. '''
  1444. self.assertRaises(SaltCloudSystemExit,
  1445. opennebula.vn_reserve,
  1446. call='function',
  1447. kwargs=None)
  1448. def test_vn_reserve_no_data_or_path(self):
  1449. '''
  1450. Tests that a SaltCloudSystemExit is raised when the data and path
  1451. args are missing.
  1452. '''
  1453. self.assertRaises(SaltCloudSystemExit,
  1454. opennebula.vn_reserve,
  1455. call='function',
  1456. kwargs={'vn_id': '0'})
  1457. @skipIf(not HAS_XML_LIBS, 'cannot find lxml python library')
  1458. def test__get_xml(self):
  1459. '''
  1460. Tests that invalid XML raises SaltCloudSystemExit.
  1461. '''
  1462. self.assertRaises(SaltCloudSystemExit,
  1463. opennebula._get_xml,
  1464. "[VirtualMachinePoolInfo] User couldn't be"
  1465. " authenticated, aborting call.")