1
0

test_opennebula.py 57 KB

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