1
0

test_opennebula.py 57 KB

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