Fuel tests
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

run_system_test.py 7.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. #!/usr/bin/env python
  2. from __future__ import print_function
  3. import sys
  4. import argparse
  5. import pytest
  6. from proboscis import TestProgram
  7. from proboscis import register
  8. from fuelweb_test.helpers.utils import pretty_log
  9. from gates_tests.helpers.utils import map_test_review_in_fuel_library
  10. from gates_tests.helpers.utils import \
  11. map_test_review_in_openstack_puppet_projects
  12. from system_test import register_system_test_cases
  13. from system_test import get_groups
  14. from system_test import define_custom_groups
  15. from system_test import discover_import_tests
  16. from system_test import tests_directory
  17. from system_test import collect_yamls
  18. from system_test import get_path_to_config
  19. from system_test import get_list_confignames
  20. from system_test import get_basepath
  21. from system_test.core.repository import split_group_config
  22. basedir = get_basepath()
  23. def print_explain(names):
  24. groups_nums = get_groups()
  25. if not isinstance(names, list):
  26. names = [names]
  27. out = []
  28. for name in [split_group_config(i)[0] if split_group_config(i) else i
  29. for i in names]:
  30. for i in groups_nums[name]:
  31. if hasattr(i, 'home'):
  32. out.append((i.home._proboscis_entry_.parent.home, i.home))
  33. else:
  34. out.append(i)
  35. print(pretty_log(out))
  36. def clean_argv_proboscis():
  37. """Removing argv params unused by Proboscis"""
  38. argv = sys.argv
  39. if '--with-config' in argv:
  40. idx = argv.index('--with-config')
  41. argv.pop(idx)
  42. argv.pop(idx)
  43. if '--explain' in argv:
  44. idx = argv.index('--explain')
  45. argv.pop(idx)
  46. return argv
  47. def cli():
  48. cli = argparse.ArgumentParser(prog="System test runner",
  49. description="Command line tool for run Fuel "
  50. "System Test")
  51. commands = cli.add_subparsers(title="Operation commands",
  52. dest="command")
  53. cli_run = commands.add_parser('run',
  54. help="Run test",
  55. description="Run some test group")
  56. cli_run.add_argument("run_groups", nargs='*', default=None, )
  57. cli_run.add_argument("--with-config", default=False, type=str,
  58. action="store", dest="config_name",
  59. help="Select name of yaml config.")
  60. cli_run.add_argument("--explain", default=False, action="store_true",
  61. help="Show explain for running groups. "
  62. "Will not start Proboscis.")
  63. cli_run.add_argument("--show-plan", default=False, action="store_true",
  64. help="Show Proboscis test plan.")
  65. cli_run.add_argument("--with-xunit", default=False, action="store_true",
  66. help="Use xuint report.")
  67. cli_run.add_argument("--nologcapture", default=False, action="store_true",
  68. help="Disable log capture for Proboscis.")
  69. cli_run.add_argument("-q", default=False, action="store_true",
  70. dest="quite",
  71. help="Run Proboscis in quite mode.")
  72. cli_run.add_argument("-a", default=False, action="store_true",
  73. dest="nose_attr",
  74. help="Provide Nose attr to Proboscis.")
  75. cli_run.add_argument("-A", default=False, action="store_true",
  76. dest="eval_nose",
  77. help="Eval Nose attr to Proboscis.")
  78. cli_run.add_argument("--groups", default=None, action="append", type=str,
  79. help="Test group for testing. "
  80. "(backward compatibility)")
  81. cli_explain_group = commands.add_parser("explain-group",
  82. help="Explain selected group.")
  83. cli_explain_group.add_argument("name",
  84. help="Group name.")
  85. commands.add_parser("show-all-groups",
  86. help="Show all Proboscis groups")
  87. commands.add_parser("show-fuelweb-groups",
  88. help="Show Proboscis groups defined in fuelweb suite")
  89. commands.add_parser("show-systest-groups",
  90. help="Show Proboscis groups defined in Systest suite")
  91. commands.add_parser("show-systest-configs",
  92. help="Show configurations for Systest suite")
  93. if len(sys.argv) == 1:
  94. cli.print_help()
  95. sys.exit(1)
  96. return cli.parse_args()
  97. def run(**kwargs):
  98. config_name = kwargs.get('config_name', None)
  99. groups = kwargs.get('run_groups', [])
  100. old_groups = kwargs.get('groups', None)
  101. explain = kwargs.get('explain', None)
  102. groups_to_run = []
  103. groups.extend(old_groups or [])
  104. # Collect from pytest only once!
  105. pytest.main(['--collect-only', 'fuel_tests', ])
  106. from fuel_tests.tests.conftest import test_names
  107. for g in set(groups):
  108. if g in test_names:
  109. sys.exit(pytest.main('-m {}'.format(g)))
  110. if config_name:
  111. register_system_test_cases(
  112. groups=[g],
  113. configs=[config_name])
  114. groups_to_run.append("{0}({1})".format(g, config_name))
  115. else:
  116. register_system_test_cases(groups=[g])
  117. groups_to_run.append(g)
  118. if not set([split_group_config(i)[0] if split_group_config(i) else i
  119. for i in groups_to_run]) < set(get_groups()):
  120. sys.exit('There are no cases mapped to current group, '
  121. 'please be sure that you put right test group name.')
  122. if explain:
  123. print_explain(groups)
  124. else:
  125. register(groups=["run_system_test"], depends_on_groups=groups_to_run)
  126. TestProgram(groups=['run_system_test'],
  127. argv=clean_argv_proboscis()).run_and_exit()
  128. def explain_group(**kwargs):
  129. """Explain selected group."""
  130. name = kwargs.get('name', None)
  131. print_explain(name)
  132. def show_all_groups(**kwargs):
  133. """Show all Proboscis groups"""
  134. groups_nums = get_groups()
  135. out = {k: len(v) for k, v in groups_nums.items()}
  136. print(pretty_log(out))
  137. def show_fuelweb_groups(**kwargs):
  138. """Show Proboscis groups defined in fuelweb suite"""
  139. groups_nums = get_groups()
  140. out = {k: len(v) for k, v in groups_nums.items()
  141. if not k.startswith('system_test')}
  142. print(pretty_log(out))
  143. def show_systest_groups(**kwargs):
  144. """Show Proboscis groups defined in Systest suite"""
  145. groups_nums = get_groups()
  146. out = {k: len(v) for k, v in groups_nums.items()
  147. if k.startswith('system_test')}
  148. print(pretty_log(out))
  149. def show_systest_configs(**kwargs):
  150. """Show configurations for Systest suite"""
  151. tests_configs = collect_yamls(get_path_to_config())
  152. for c in get_list_confignames(tests_configs):
  153. print(c)
  154. COMMAND_MAP = {
  155. "run": run,
  156. "explain-group": explain_group,
  157. "show-all-groups": show_all_groups,
  158. "show-fuelweb-groups": show_fuelweb_groups,
  159. "show-systest-groups": show_systest_groups,
  160. "show-systest-configs": show_systest_configs
  161. }
  162. def shell():
  163. args = cli()
  164. discover_import_tests(basedir, tests_directory)
  165. define_custom_groups()
  166. map_test_review_in_fuel_library(**vars(args))
  167. map_test_review_in_openstack_puppet_projects(**vars(args))
  168. COMMAND_MAP[args.command](**vars(args))
  169. if __name__ == '__main__':
  170. shell()