1
0

test_esxi.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. # -*- coding: utf-8 -*-
  2. """
  3. Unit tests for salt.utils.proxy
  4. :codeauthor: :email:`Gareth J. Greenaway <gareth@saltstack.com>`
  5. """
  6. from __future__ import absolute_import, print_function, unicode_literals
  7. import logging
  8. import salt.grains.esxi as esxi_grains
  9. from tests.support.mixins import LoaderModuleMockMixin
  10. from tests.support.mock import patch
  11. from tests.support.unit import TestCase
  12. log = logging.getLogger(__name__)
  13. class EsxiGrainsTestCase(TestCase, LoaderModuleMockMixin):
  14. def setup_loader_modules(self):
  15. module_globals = {
  16. "__salt__": {},
  17. "__opts__": {
  18. "proxy": {
  19. "proxytype": "esxi",
  20. "host": "esxi.domain.com",
  21. "username": "username",
  22. "passwords": ["password1"],
  23. }
  24. },
  25. "__pillar__": {
  26. "proxy": {
  27. "proxytype": "esxi",
  28. "host": "esxi.domain.com",
  29. "username": "username",
  30. "passwords": ["password1"],
  31. }
  32. },
  33. }
  34. return {esxi_grains: module_globals}
  35. def test_virtual(self):
  36. with patch("salt.utils.proxy.is_proxytype", return_value=True, autospec=True):
  37. ret = esxi_grains.__virtual__()
  38. self.assertEqual(ret, "esxi")
  39. def test_kernel(self):
  40. with patch("salt.utils.proxy.is_proxytype", return_value=True, autospec=True):
  41. ret = esxi_grains.kernel()
  42. self.assertEqual(ret, {"kernel": "proxy"})
  43. def test_osfamily(self):
  44. with patch("salt.utils.proxy.is_proxytype", return_value=True, autospec=True):
  45. ret = esxi_grains.os_family()
  46. self.assertEqual(ret, {"os_family": "proxy"})
  47. def test_os(self):
  48. grain_cache_return = {
  49. "name": "VMware vCenter Server",
  50. "fullName": "VMware vCenter Server 6.7.0 build-15679289",
  51. "vendor": "VMware, Inc.",
  52. "version": "6.7.0",
  53. "build": "15679289",
  54. "localeVersion": "INTL",
  55. "localeBuild": "000",
  56. "osType": "linux-x64",
  57. "productLineId": "vpx",
  58. "apiType": "VirtualCenter",
  59. "apiVersion": "6.7.3",
  60. "instanceUuid": "058ed113-1820-41dc-a8a9-8a5dd48632a4",
  61. "licenseProductName": "VMware VirtualCenter Server",
  62. "licenseProductVersion": "6.0",
  63. }
  64. expected = {"os": "VMware vCenter Server 6.7.0 build-15679289"}
  65. with patch("salt.utils.proxy.is_proxytype", return_value=True, autospec=True):
  66. with patch(
  67. "salt.modules.vsphere.system_info", return_value=grain_cache_return
  68. ):
  69. ret = esxi_grains.os()
  70. self.assertEqual(ret, expected)
  71. def test_esxi(self):
  72. grain_cache_return = {
  73. "name": "VMware vCenter Server",
  74. "fullName": "VMware vCenter Server 6.7.0 build-15679289",
  75. "vendor": "VMware, Inc.",
  76. "version": "6.7.0",
  77. "build": "15679289",
  78. "localeVersion": "INTL",
  79. "localeBuild": "000",
  80. "osType": "linux-x64",
  81. "productLineId": "vpx",
  82. "apiType": "VirtualCenter",
  83. "apiVersion": "6.7.3",
  84. "instanceUuid": "058ed113-1820-41dc-a8a9-8a5dd48632a4",
  85. "licenseProductName": "VMware VirtualCenter Server",
  86. "licenseProductVersion": "6.0",
  87. }
  88. with patch("salt.utils.proxy.is_proxytype", return_value=True, autospec=True):
  89. with patch(
  90. "salt.modules.vsphere.system_info", return_value=grain_cache_return
  91. ):
  92. ret = esxi_grains.esxi()
  93. self.assertEqual(ret, grain_cache_return)