1
0

test_mac_brew_pkg.py 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. # -*- coding: utf-8 -*-
  2. """
  3. :codeauthor: Nicole Thomas <nicole@saltstack.com>
  4. """
  5. from __future__ import absolute_import, print_function, unicode_literals
  6. from salt.exceptions import CommandExecutionError
  7. from salt.ext import six
  8. from tests.support.case import ModuleCase
  9. from tests.support.helpers import (
  10. destructiveTest,
  11. runs_on,
  12. skip_if_binaries_missing,
  13. skip_if_not_root,
  14. slowTest,
  15. )
  16. # Brew doesn't support local package installation - So, let's
  17. # Grab some small packages available online for brew
  18. ADD_PKG = "algol68g"
  19. DEL_PKG = "acme"
  20. @destructiveTest
  21. @skip_if_not_root
  22. @skip_if_binaries_missing("brew")
  23. @runs_on(kernel="Darwin")
  24. class BrewModuleTest(ModuleCase):
  25. """
  26. Integration tests for the brew module
  27. """
  28. @slowTest
  29. def test_brew_install(self):
  30. """
  31. Tests the installation of packages
  32. """
  33. try:
  34. self.run_function("pkg.install", [ADD_PKG])
  35. pkg_list = self.run_function("pkg.list_pkgs")
  36. try:
  37. self.assertIn(ADD_PKG, pkg_list)
  38. except AssertionError:
  39. self.run_function("pkg.remove", [ADD_PKG])
  40. raise
  41. except CommandExecutionError:
  42. self.run_function("pkg.remove", [ADD_PKG])
  43. raise
  44. @slowTest
  45. def test_remove(self):
  46. """
  47. Tests the removal of packages
  48. """
  49. try:
  50. # Install a package to delete - If unsuccessful, skip the test
  51. self.run_function("pkg.install", [DEL_PKG])
  52. pkg_list = self.run_function("pkg.list_pkgs")
  53. if DEL_PKG not in pkg_list:
  54. self.run_function("pkg.install", [DEL_PKG])
  55. self.skipTest("Failed to install a package to delete")
  56. # Now remove the installed package
  57. self.run_function("pkg.remove", [DEL_PKG])
  58. del_list = self.run_function("pkg.list_pkgs")
  59. self.assertNotIn(DEL_PKG, del_list)
  60. except CommandExecutionError:
  61. self.run_function("pkg.remove", [DEL_PKG])
  62. raise
  63. @slowTest
  64. def test_version(self):
  65. """
  66. Test pkg.version for mac. Installs a package and then checks we can get
  67. a version for the installed package.
  68. """
  69. try:
  70. self.run_function("pkg.install", [ADD_PKG])
  71. pkg_list = self.run_function("pkg.list_pkgs")
  72. version = self.run_function("pkg.version", [ADD_PKG])
  73. try:
  74. self.assertTrue(
  75. version,
  76. msg=(
  77. "version: {0} is empty,\
  78. or other issue is present".format(
  79. version
  80. )
  81. ),
  82. )
  83. self.assertIn(
  84. ADD_PKG,
  85. pkg_list,
  86. msg=(
  87. "package: {0} is not in\
  88. the list of installed packages: {1}".format(
  89. ADD_PKG, pkg_list
  90. )
  91. ),
  92. )
  93. # make sure the version is accurate and is listed in the pkg_list
  94. self.assertIn(
  95. version,
  96. six.text_type(pkg_list[ADD_PKG]),
  97. msg=(
  98. "The {0} version: {1} is \
  99. not listed in the pkg_list: {2}".format(
  100. ADD_PKG, version, pkg_list[ADD_PKG]
  101. )
  102. ),
  103. )
  104. except AssertionError:
  105. self.run_function("pkg.remove", [ADD_PKG])
  106. raise
  107. except CommandExecutionError:
  108. self.run_function("pkg.remove", [ADD_PKG])
  109. raise
  110. @slowTest
  111. def test_latest_version(self):
  112. """
  113. Test pkg.latest_version:
  114. - get the latest version available
  115. - install the package
  116. - get the latest version available
  117. - check that the latest version is empty after installing it
  118. """
  119. try:
  120. self.run_function("pkg.remove", [ADD_PKG])
  121. uninstalled_latest = self.run_function("pkg.latest_version", [ADD_PKG])
  122. self.run_function("pkg.install", [ADD_PKG])
  123. installed_latest = self.run_function("pkg.latest_version", [ADD_PKG])
  124. version = self.run_function("pkg.version", [ADD_PKG])
  125. try:
  126. self.assertTrue(isinstance(uninstalled_latest, six.string_types))
  127. self.assertEqual(installed_latest, version)
  128. except AssertionError:
  129. self.run_function("pkg.remove", [ADD_PKG])
  130. raise
  131. except CommandExecutionError:
  132. self.run_function("pkg.remove", [ADD_PKG])
  133. raise
  134. @slowTest
  135. def test_refresh_db(self):
  136. """
  137. Integration test to ensure pkg.refresh_db works with brew
  138. """
  139. refresh_brew = self.run_function("pkg.refresh_db")
  140. self.assertTrue(refresh_brew)
  141. @slowTest
  142. def test_list_upgrades(self):
  143. """
  144. Test pkg.list_upgrades: data is in the form {'name1': 'version1',
  145. 'name2': 'version2', ... }
  146. """
  147. try:
  148. upgrades = self.run_function("pkg.list_upgrades")
  149. try:
  150. self.assertTrue(isinstance(upgrades, dict))
  151. if upgrades:
  152. for name in upgrades:
  153. self.assertTrue(isinstance(name, six.string_types))
  154. self.assertTrue(isinstance(upgrades[name], six.string_types))
  155. except AssertionError:
  156. self.run_function("pkg.remove", [ADD_PKG])
  157. raise
  158. except CommandExecutionError:
  159. self.run_function("pkg.remove", [ADD_PKG])
  160. raise
  161. @slowTest
  162. def test_info_installed(self):
  163. """
  164. Test pkg.info_installed: info returned has certain fields used by
  165. mac_brew.latest_version
  166. """
  167. try:
  168. self.run_function("pkg.install", [ADD_PKG])
  169. info = self.run_function("pkg.info_installed", [ADD_PKG])
  170. try:
  171. self.assertTrue(ADD_PKG in info)
  172. self.assertTrue("versions" in info[ADD_PKG])
  173. self.assertTrue("revision" in info[ADD_PKG])
  174. self.assertTrue("stable" in info[ADD_PKG]["versions"])
  175. except AssertionError:
  176. self.run_function("pkg.remove", [ADD_PKG])
  177. raise
  178. except CommandExecutionError:
  179. self.run_function("pkg.remove", [ADD_PKG])
  180. raise
  181. def tearDown(self):
  182. """
  183. Clean up after tests
  184. """
  185. pkg_list = self.run_function("pkg.list_pkgs")
  186. # Remove any installed packages
  187. if ADD_PKG in pkg_list:
  188. self.run_function("pkg.remove", [ADD_PKG])
  189. if DEL_PKG in pkg_list:
  190. self.run_function("pkg.remove", [DEL_PKG])