test_opennebula.py 61 KB

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