1
0

test_man.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. # -*- coding: utf-8 -*-
  2. """
  3. Tests for existence of manpages
  4. """
  5. from __future__ import absolute_import, print_function, unicode_literals
  6. import os
  7. import pprint
  8. import salt.utils.platform
  9. from salt.modules.virtualenv_mod import KNOWN_BINARY_NAMES
  10. from tests.support.helpers import VirtualEnv, slowTest
  11. from tests.support.runtests import RUNTIME_VARS
  12. from tests.support.unit import TestCase, skipIf
  13. @skipIf(salt.utils.platform.is_windows(), "minion is windows")
  14. @skipIf(salt.utils.platform.is_aix(), "minion is AIX")
  15. @skipIf(
  16. salt.utils.path.which_bin(KNOWN_BINARY_NAMES) is None, "virtualenv not installed"
  17. )
  18. class ManPagesTest(TestCase):
  19. @slowTest
  20. def test_man_pages(self):
  21. """
  22. Make sure that man pages are installed
  23. """
  24. # Map filenames to search strings which should be in the manpage
  25. manpages = {
  26. "salt-cp.1": ["salt-cp Documentation", "copies files from the master"],
  27. "salt-cloud.1": [
  28. "Salt Cloud Command",
  29. "Provision virtual machines in the cloud",
  30. ],
  31. "salt-call.1": ["salt-call Documentation", "run module functions locally"],
  32. "salt-api.1": [
  33. "salt-api Command",
  34. "Start interfaces used to remotely connect",
  35. ],
  36. "salt-unity.1": ["salt-unity Command", "unified invocation wrapper"],
  37. "salt-syndic.1": ["salt-syndic Documentation", "Salt syndic daemon"],
  38. "salt-ssh.1": ["salt-ssh Documentation", "executed using only SSH"],
  39. "salt-run.1": ["salt-run Documentation", "frontend command for executing"],
  40. "salt-proxy.1": ["salt-proxy Documentation", "proxies these commands"],
  41. "salt-minion.1": ["salt-minion Documentation", "Salt minion daemon"],
  42. "salt-master.1": ["salt-master Documentation", "Salt master daemon"],
  43. "salt-key.1": [
  44. "salt-key Documentation",
  45. "management of Salt server public keys",
  46. ],
  47. "salt.1": ["allows for commands to be executed"],
  48. "salt.7": ["Salt Documentation"],
  49. "spm.1": [
  50. "Salt Package Manager Command",
  51. "command for managing Salt packages",
  52. ],
  53. }
  54. with VirtualEnv() as venv:
  55. rootdir = os.path.join(venv.venv_dir, "installed")
  56. venv.run(
  57. venv.venv_python,
  58. "setup.py",
  59. "install",
  60. "--root={}".format(rootdir),
  61. cwd=RUNTIME_VARS.CODE_DIR,
  62. )
  63. manpage_fns = set(manpages)
  64. manpage_paths = {}
  65. for root, _, files in os.walk(rootdir):
  66. if not manpage_fns:
  67. # All manpages found, no need to keep walking
  68. break
  69. # Using list because we will be modifying the set during iteration
  70. for manpage_fn in list(manpage_fns):
  71. if manpage_fn in files:
  72. manpage_path = salt.utils.path.join(root, manpage_fn)
  73. manpage_paths[manpage_fn] = manpage_path
  74. manpage_fns.remove(manpage_fn)
  75. assert (
  76. not manpage_fns
  77. ), "The following manpages were not found under {}: {}".format(
  78. rootdir, ", ".join(sorted(manpage_fns))
  79. )
  80. failed = {}
  81. for manpage in sorted(manpages):
  82. with salt.utils.files.fopen(manpage_paths[manpage]) as fp_:
  83. contents = salt.utils.stringutils.to_unicode(fp_.read())
  84. # Check for search string in contents
  85. for search_string in manpages[manpage]:
  86. if search_string not in contents:
  87. failed.setdefault(manpage, []).append(
  88. "No match for search string '{}' found in {}".format(
  89. search_string, manpage_paths[manpage]
  90. )
  91. )
  92. # Check for correct install dir
  93. path = "/man{}/".format(manpage.rsplit(".", 1)[-1])
  94. if path not in manpage_paths[manpage]:
  95. failed.setdefault(manpage, []).append(
  96. "{} not found in manpage path {}".format(
  97. path, manpage_paths[manpage]
  98. )
  99. )
  100. assert not failed, "One or more manpages failed:\n{}".format(
  101. pprint.pformat(failed)
  102. )