def validate_options(self): if self.options.cloud_provider: # Turn on expensive tests execution os.environ['EXPENSIVE_TESTS'] = 'True' if self.options.coverage and any(( self.options.name, os.geteuid() != 0, not self.options.run_destructive)) \ and self._check_enabled_suites(include_unit=True): self.error('No sense in generating the tests coverage report when ' 'not running the full test suite, including the ' 'destructive tests, as \'root\'. It would only produce ' 'incorrect results.') # When no tests are specifically enumerated on the command line, setup # a default run: +unit -cloud_provider if not self.options.name and not \ self._check_enabled_suites(include_unit=True, include_cloud_provider=True): self._enable_suites(include_unit=True) self.start_coverage( branch=True, source=[os.path.join(SALT_ROOT, 'salt')], ) # Transplant configuration TestDaemon.transplant_configs(transport=self.options.transport)
def validate_options(self): if self.options.cloud_provider_tests: # Turn on expensive tests execution os.environ['EXPENSIVE_TESTS'] = 'True' if self.options.coverage and any(( self.options.module, self.options.cli, self.options.client, self.options.shell, self.options.unit, self.options.state, self.options.runners, self.options.renderers, self.options.loader, self.options.name, self.options.outputter, self.options.fileserver, self.options.wheel, self.options.api, os.geteuid() != 0, not self.options.run_destructive)): self.error( 'No sense in generating the tests coverage report when ' 'not running the full test suite, including the ' 'destructive tests, as \'root\'. It would only produce ' 'incorrect results.' ) # Set test suite defaults if no specific suite options are provided if not any((self.options.module, self.options.client, self.options.cli, self.options.shell, self.options.unit, self.options.state, self.options.runners, self.options.loader, self.options.name, self.options.outputter, self.options.cloud_provider_tests, self.options.fileserver, self.options.wheel, self.options.api, self.options.renderers)): self.options.module = True self.options.cli = True self.options.client = True self.options.shell = True self.options.unit = True self.options.runners = True self.options.renderers = True self.options.state = True self.options.loader = True self.options.outputter = True self.options.fileserver = True self.options.wheel = True self.options.api = True self.start_coverage( branch=True, source=[os.path.join(SALT_ROOT, 'salt')], ) # Transplant configuration TestDaemon.transplant_configs(transport=self.options.transport)
def validate_options(self): if self.options.cloud_provider_tests: # Turn on expensive tests execution os.environ['EXPENSIVE_TESTS'] = 'True' if self.options.coverage and any(( self.options.module, self.options.cli, self.options.client, self.options.shell, self.options.unit, self.options.state, self.options.runners, self.options.loader, self.options.name, self.options.outputter, self.options.fileserver, self.options.wheel, self.options.api, os.geteuid() != 0, not self.options.run_destructive)): self.error( 'No sense in generating the tests coverage report when ' 'not running the full test suite, including the ' 'destructive tests, as \'root\'. It would only produce ' 'incorrect results.' ) # Set test suite defaults if no specific suite options are provided if not any((self.options.module, self.options.client, self.options.cli, self.options.shell, self.options.unit, self.options.state, self.options.runners, self.options.loader, self.options.name, self.options.outputter, self.options.cloud_provider_tests, self.options.fileserver, self.options.wheel, self.options.api)): self.options.module = True self.options.cli = True self.options.client = True self.options.shell = True self.options.unit = True self.options.runners = True self.options.state = True self.options.loader = True self.options.outputter = True self.options.fileserver = True self.options.wheel = True self.options.api = True self.start_coverage( branch=True, source=[os.path.join(SALT_ROOT, 'salt')], ) # Transplant configuration TestDaemon.transplant_configs(transport=self.options.transport)
def start_daemons_only(self): if not salt.utils.is_windows(): self.set_filehandle_limits('integration') try: print_header( ' * Setting up Salt daemons for interactive use', top=False, width=getattr(self.options, 'output_columns', PNUM) ) except TypeError: print_header(' * Setting up Salt daemons for interactive use', top=False) with TestDaemon(self): print_header(' * Salt daemons started') master_conf = TestDaemon.config('master') minion_conf = TestDaemon.config('minion') sub_minion_conf = TestDaemon.config('sub_minion') syndic_conf = TestDaemon.config('syndic') syndic_master_conf = TestDaemon.config('syndic_master') print_header(' * Syndic master configuration values (MoM)', top=False) print('interface: {0}'.format(syndic_master_conf['interface'])) print('publish port: {0}'.format(syndic_master_conf['publish_port'])) print('return port: {0}'.format(syndic_master_conf['ret_port'])) print('\n') print_header(' * Syndic configuration values', top=True) print('interface: {0}'.format(syndic_conf['interface'])) print('syndic master: {0}'.format(syndic_conf['syndic_master'])) print('syndic master port: {0}'.format(syndic_conf['syndic_master_port'])) print('\n') print_header(' * Master configuration values', top=True) print('interface: {0}'.format(master_conf['interface'])) print('publish port: {0}'.format(master_conf['publish_port'])) print('return port: {0}'.format(master_conf['ret_port'])) print('\n') print_header(' * Minion configuration values', top=True) print('interface: {0}'.format(minion_conf['interface'])) print('master: {0}'.format(minion_conf['master'])) print('master port: {0}'.format(minion_conf['master_port'])) if minion_conf['ipc_mode'] == 'tcp': print('tcp pub port: {0}'.format(minion_conf['tcp_pub_port'])) print('tcp pull port: {0}'.format(minion_conf['tcp_pull_port'])) print('\n') print_header(' * Sub Minion configuration values', top=True) print('interface: {0}'.format(sub_minion_conf['interface'])) print('master: {0}'.format(sub_minion_conf['master'])) print('master port: {0}'.format(sub_minion_conf['master_port'])) if sub_minion_conf['ipc_mode'] == 'tcp': print('tcp pub port: {0}'.format(sub_minion_conf['tcp_pub_port'])) print('tcp pull port: {0}'.format(sub_minion_conf['tcp_pull_port'])) print('\n') print_header(' Your client configuration is at {0}'.format(TestDaemon.config_location())) print('To access the minion: salt -c {0} minion test.ping'.format(TestDaemon.config_location())) while True: time.sleep(1)
def run_integration_tests(opts=None): ''' Execute the integration tests suite ''' if not opts: opts = {} print('~' * PNUM) print('Setting up Salt daemons to execute tests') print('~' * PNUM) with TestDaemon(): if opts.get('module', True): moduleloader = saltunittest.TestLoader() moduletests = moduleloader.discover( os.path.join(TEST_DIR, 'integration', 'modules'), '*.py') print('~' * PNUM) print('Starting Module Tests') print('~' * PNUM) saltunittest.TextTestRunner(verbosity=1).run(moduletests) if opts.get('client', True): clientloader = saltunittest.TestLoader() clienttests = clientloader.discover( os.path.join(TEST_DIR, 'integration', 'client'), '*.py') print('~' * PNUM) print('Starting Client Tests') print('~' * PNUM) saltunittest.TextTestRunner(verbosity=1).run(clienttests) if opts.get('shell', True): shellloader = saltunittest.TestLoader() shelltests = shellloader.discover( os.path.join(TEST_DIR, 'integration', 'shell'), '*.py') print('~' * PNUM) print('Starting Shell Tests') print('~' * PNUM) saltunittest.TextTestRunner(verbosity=1).run(shelltests)
def run_integration_tests(opts): ''' Execute the integration tests suite ''' print('~' * PNUM) print('Setting up Salt daemons to execute tests') print('~' * PNUM) status = [] if not any([opts.client, opts.module, opts.runner, opts.shell, opts.state, opts.name]): return status with TestDaemon(clean=opts.clean): if opts.name: results = run_suite(opts, '', opts.name) status.append(results) if opts.runner: status.append(run_integration_suite(opts, 'runners', 'Runner')) if opts.module: status.append(run_integration_suite(opts, 'modules', 'Module')) if opts.state: status.append(run_integration_suite(opts, 'states', 'State')) if opts.client: status.append(run_integration_suite(opts, 'client', 'Client')) if opts.shell: status.append(run_integration_suite(opts, 'shell', 'Shell')) return status
def test_daemon(request): from collections import namedtuple from integration import TestDaemon, PNUM values = (('transport', request.config.getoption('--transport')), ('sysinfo', request.config.getoption('--sysinfo')), ('no_colors', request.config.getoption('--no-colors')), ('output_columns', request.config.getoption('--output-columns')), ('ssh', request.config.getoption('--ssh'))) options = namedtuple('options', [n for n, v in values])(*[v for n, v in values]) fake_parser = namedtuple('parser', 'options')(options) # Transplant configuration TestDaemon.transplant_configs(transport=fake_parser.options.transport) tg = TestDaemon(fake_parser) with tg: yield TestDaemon.clean()
def validate_options(self): if self.options.cloud_provider: # Turn on expensive tests execution os.environ['EXPENSIVE_TESTS'] = 'True' import salt.utils if salt.utils.is_windows(): import salt.utils.win_functions current_user = salt.utils.win_functions.get_current_user() if current_user == 'SYSTEM': is_admin = True else: is_admin = salt.utils.win_functions.is_admin(current_user) else: is_admin = os.geteuid() == 0 if self.options.coverage and any(( self.options.name, is_admin, not self.options.run_destructive)) \ and self._check_enabled_suites(include_unit=True): self.error( 'No sense in generating the tests coverage report when ' 'not running the full test suite, including the ' 'destructive tests, as \'root\'. It would only produce ' 'incorrect results.' ) # When no tests are specifically enumerated on the command line, setup # a default run: +unit -cloud_provider if not self.options.name and not \ self._check_enabled_suites(include_unit=True, include_cloud_provider=True): self._enable_suites(include_unit=True) self.start_coverage( branch=True, source=[os.path.join(SALT_ROOT, 'salt')], ) # Print out which version of python this test suite is running on print(' * Python Version: {0}'.format(' '.join(sys.version.split()))) # Transplant configuration TestDaemon.transplant_configs(transport=self.options.transport)
def run_integration_tests(self): ''' Execute the integration tests suite ''' named_tests = [] named_unit_test = [] if self.options.name: for test in self.options.name: if test.startswith('unit.'): named_unit_test.append(test) continue named_tests.append(test) if (self.options.unit or named_unit_test) and not named_tests and not \ self._check_enabled_suites(include_cloud_provider=True): # We're either not running any integration test suites, or we're # only running unit tests by passing --unit or by passing only # `unit.<whatever>` to --name. We don't need the tests daemon # running return [True] if not salt.utils.is_windows(): self.set_filehandle_limits('integration') try: print_header(' * Setting up Salt daemons to execute tests', top=False, width=getattr(self.options, 'output_columns', PNUM)) except TypeError: print_header(' * Setting up Salt daemons to execute tests', top=False) status = [] # Return an empty status if no tests have been enabled if not self._check_enabled_suites( include_cloud_provider=True) and not self.options.name: return status with TestDaemon(self): if self.options.name: for name in self.options.name: if name.startswith('unit.'): continue results = self.run_suite('', name, suffix='test_*.py', load_from_name=True) status.append(results) for suite in TEST_SUITES: if suite != 'unit' and getattr(self.options, suite): status.append( self.run_integration_suite(**TEST_SUITES[suite])) return status
def start_daemons_only(self): self.prep_filehandles() try: print_header(' * Setting up Salt daemons for interactive use', top=False, width=getattr(self.options, 'output_columns', PNUM)) except TypeError: print_header(' * Setting up Salt daemons for interactive use', top=False) with TestDaemon(self): print_header(' * Salt daemons started') master_conf = TestDaemon.config('master') minion_conf = TestDaemon.config('minion') syndic_conf = TestDaemon.config('syndic') syndic_master_conf = TestDaemon.config('syndic_master') print_header(' * Syndic master configuration values', top=False) print('interface: {0}'.format(syndic_master_conf['interface'])) print('publish port: {0}'.format( syndic_master_conf['publish_port'])) print('return port: {0}'.format(syndic_master_conf['ret_port'])) print('\n') print_header(' * Master configuration values', top=True) print('interface: {0}'.format(master_conf['interface'])) print('publish port: {0}'.format(master_conf['publish_port'])) print('return port: {0}'.format(master_conf['ret_port'])) print('\n') print_header(' * Minion configuration values', top=True) print('interface: {0}'.format(minion_conf['interface'])) print('\n') print_header(' * Syndic configuration values', top=True) print('interface: {0}'.format(syndic_conf['interface'])) print('syndic master port: {0}'.format( syndic_conf['syndic_master'])) print('\n') print_header(' Your client configuration is at {0}'.format( TestDaemon.config_location())) print('To access the minion: `salt -c {0} minion test.ping'.format( TestDaemon.config_location())) while True: time.sleep(1)
def start_daemons_only(self): if not salt.utils.is_windows(): self.prep_filehandles() try: print_header( ' * Setting up Salt daemons for interactive use', top=False, width=getattr(self.options, 'output_columns', PNUM) ) except TypeError: print_header(' * Setting up Salt daemons for interactive use', top=False) with TestDaemon(self): print_header(' * Salt daemons started') master_conf = TestDaemon.config('master') minion_conf = TestDaemon.config('minion') syndic_conf = TestDaemon.config('syndic') syndic_master_conf = TestDaemon.config('syndic_master') print_header(' * Syndic master configuration values', top=False) print('interface: {0}'.format(syndic_master_conf['interface'])) print('publish port: {0}'.format(syndic_master_conf['publish_port'])) print('return port: {0}'.format(syndic_master_conf['ret_port'])) print('\n') print_header(' * Master configuration values', top=True) print('interface: {0}'.format(master_conf['interface'])) print('publish port: {0}'.format(master_conf['publish_port'])) print('return port: {0}'.format(master_conf['ret_port'])) print('\n') print_header(' * Minion configuration values', top=True) print('interface: {0}'.format(minion_conf['interface'])) print('\n') print_header(' * Syndic configuration values', top=True) print('interface: {0}'.format(syndic_conf['interface'])) print('syndic master port: {0}'.format(syndic_conf['syndic_master'])) print('\n') print_header(' Your client configuration is at {0}'.format(TestDaemon.config_location())) print('To access the minion: `salt -c {0} minion test.ping'.format(TestDaemon.config_location())) while True: time.sleep(1)
def post_execution_cleanup(self): SaltCoverageTestingParser.post_execution_cleanup(self) if self.options.clean: TestDaemon.clean()
print('ERROR: Failed to raise the max open files setting -> {0}'. format(err)) print('Please issue the following command on your console:') print(' ulimit -n {0}'.format(REQUIRED_OPEN_FILES)) sys.exit(1) finally: print('~' * PNUM) print_header('Setting up Salt daemons to execute tests', top=False) status = [] if not any([ opts.client, opts.module, opts.runner, opts.shell, opts.state, opts.name ]): return status with TestDaemon(opts=opts): if opts.name: for name in opts.name: results = run_suite(opts, '', name) status.append(results) if opts.runner: status.append(run_integration_suite(opts, 'runners', 'Runner')) if opts.module: status.append(run_integration_suite(opts, 'modules', 'Module')) if opts.state: status.append(run_integration_suite(opts, 'states', 'State')) if opts.client: status.append(run_integration_suite(opts, 'client', 'Client')) if opts.shell: status.append(run_integration_suite(opts, 'shell', 'Shell')) return status
print('Please issue the following command on your console:') print(' ulimit -n {0}'.format(REQUIRED_OPEN_FILES)) sys.exit(1) finally: print('~' * PNUM) print('~' * PNUM) print('Setting up Salt daemons to execute tests') print('~' * PNUM) status = [] if not any([ opts.client, opts.module, opts.runner, opts.shell, opts.state, opts.name ]): return status with TestDaemon(clean=opts.clean): if opts.name: results = run_suite(opts, '', opts.name) status.append(results) if opts.runner: status.append(run_integration_suite(opts, 'runners', 'Runner')) if opts.module: status.append(run_integration_suite(opts, 'modules', 'Module')) if opts.state: status.append(run_integration_suite(opts, 'states', 'State')) if opts.client: status.append(run_integration_suite(opts, 'client', 'Client')) if opts.shell: status.append(run_integration_suite(opts, 'shell', 'Shell')) return status
def test_daemon(add_options, request): from integration import TestDaemon return TestDaemon(request.instance)
def exit(self, status=0, msg=None): TestDaemon.cleanup_runtime_config_instane() SaltTestsuiteParser.exit(self, status, msg)
def run_integration_tests(self): ''' Execute the integration tests suite ''' named_tests = [] named_unit_test = [] if self.options.name: for test in self.options.name: if test.startswith('unit.'): named_unit_test.append(test) continue named_tests.append(test) if (self.options.unit or named_unit_test) and not \ (self.options.runners or self.options.state or self.options.module or self.options.cli or self.options.client or self.options.loader or self.options.outputter or self.options.fileserver or self.options.wheel or self.options.cloud_provider_tests or named_tests): # We're either not running any of runners, state, module and client # tests, or, we're only running unittests by passing --unit or by # passing only `unit.<whatever>` to --name. # We don't need the tests daemon running return [True] self.prep_filehandles() try: print_header(' * Setting up Salt daemons to execute tests', top=False, width=getattr(self.options, 'output_columns', PNUM)) except TypeError: print_header(' * Setting up Salt daemons to execute tests', top=False) status = [] if not any([ self.options.cli, self.options.client, self.options.module, self.options.runners, self.options.shell, self.options.state, self.options.loader, self.options.outputter, self.options.name, self.options.cloud_provider_tests, self.options.api, self.options.fileserver, self.options.wheel ]): return status with TestDaemon(self): if self.options.name: for name in self.options.name: if name.startswith('unit.'): continue results = self.run_suite('', name, load_from_name=True) status.append(results) if self.options.loader: status.append(self.run_integration_suite('loader', 'Loader')) if self.options.runners: status.append(self.run_integration_suite('runners', 'Runners')) if self.options.module: status.append(self.run_integration_suite('modules', 'Module')) if self.options.state: status.append(self.run_integration_suite('states', 'State')) if self.options.cli: status.append(self.run_integration_suite('cli', 'CLI')) if self.options.client: status.append(self.run_integration_suite('client', 'Client')) if self.options.shell: status.append(self.run_integration_suite('shell', 'Shell')) if self.options.outputter: status.append(self.run_integration_suite( 'output', 'Outputter')) if self.options.fileserver: status.append( self.run_integration_suite('fileserver', 'Fileserver')) if self.options.wheel: status.append(self.run_integration_suite('wheel', 'Wheel')) if self.options.cloud_provider_tests: status.append( self.run_integration_suite('cloud/providers', 'Cloud Provider')) if self.options.api: status.append(self.run_integration_suite('netapi', 'NetAPI')) return status
class CallTest(integration.ShellCase, integration.ShellCaseCommonTestsMixIn): _call_binary_ = 'salt-call' def test_default_output(self): out = self.run_call('test.fib 3') self.assertEqual( "local: !!python/tuple\n- [0, 1, 1, 2]", '\n'.join(out[:-3]) ) def test_text_output(self): out = self.run_call('--text-out test.fib 3') self.assertEqual("local: ([0, 1, 1, 2]", ''.join(out).rsplit(",", 1)[0]) @skipIf(sys.platform.startswith('win'), 'This test does not apply on Win') def test_user_delete_kw_output(self): ret = self.run_call('-d user.delete') self.assertIn( 'salt \'*\' user.delete name remove=True force=True', ''.join(ret) ) if __name__ == "__main__": loader = TestLoader() tests = loader.loadTestsFromTestCase(CallTest) print('Setting up Salt daemons to execute tests') with TestDaemon(): runner = TextTestRunner(verbosity=1).run(tests) sys.exit(runner.wasSuccessful())
def run_integration_tests(self): ''' Execute the integration tests suite ''' named_tests = [] named_unit_test = [] if self.options.name: for test in self.options.name: if test.startswith('unit.'): named_unit_test.append(test) continue named_tests.append(test) if (self.options.unit or named_unit_test) and not \ (self.options.runners or self.options.state or self.options.module or self.options.cli or self.options.client or self.options.loader or self.options.outputter or self.options.fileserver or self.options.wheel or self.options.cloud_provider_tests or named_tests): # We're either not running any of runners, state, module and client # tests, or, we're only running unittests by passing --unit or by # passing only `unit.<whatever>` to --name. # We don't need the tests daemon running return [True] smax_open_files, hmax_open_files = resource.getrlimit( resource.RLIMIT_NOFILE) if smax_open_files < REQUIRED_OPEN_FILES: print(' * Max open files setting is too low({0}) for running the ' 'tests'.format(smax_open_files)) print(' * Trying to raise the limit to {0}'.format( REQUIRED_OPEN_FILES)) if hmax_open_files < 4096: hmax_open_files = 4096 # Decent default? try: resource.setrlimit(resource.RLIMIT_NOFILE, (REQUIRED_OPEN_FILES, hmax_open_files)) except Exception as err: print('ERROR: Failed to raise the max open files setting -> ' '{0}'.format(err)) print('Please issue the following command on your console:') print(' ulimit -n {0}'.format(REQUIRED_OPEN_FILES)) self.exit() finally: print('~' * getattr(self.options, 'output_columns', PNUM)) try: print_header(' * Setting up Salt daemons to execute tests', top=False, width=getattr(self.options, 'output_columns', PNUM)) except TypeError: print_header(' * Setting up Salt daemons to execute tests', top=False) status = [] if not any([ self.options.cli, self.options.client, self.options.module, self.options.runners, self.options.shell, self.options.state, self.options.loader, self.options.outputter, self.options.name, self.options.cloud_provider_tests, self.options.api, self.options.fileserver, self.options.wheel ]): return status with TestDaemon(self): if self.options.name: for name in self.options.name: if name.startswith('unit.'): continue results = self.run_suite('', name, load_from_name=True) status.append(results) if self.options.loader: status.append(self.run_integration_suite('loader', 'Loader')) if self.options.runners: status.append(self.run_integration_suite('runners', 'Runners')) if self.options.module: status.append(self.run_integration_suite('modules', 'Module')) if self.options.state: status.append(self.run_integration_suite('states', 'State')) if self.options.cli: status.append(self.run_integration_suite('cli', 'CLI')) if self.options.client: status.append(self.run_integration_suite('client', 'Client')) if self.options.shell: status.append(self.run_integration_suite('shell', 'Shell')) if self.options.outputter: status.append(self.run_integration_suite( 'output', 'Outputter')) if self.options.fileserver: status.append( self.run_integration_suite('fileserver', 'Fileserver')) if self.options.wheel: status.append(self.run_integration_suite('wheel', 'Wheel')) if self.options.cloud_provider_tests: status.append( self.run_integration_suite('cloud/providers', 'Cloud Provider')) if self.options.api: status.append(self.run_integration_suite('netapi', 'NetAPI')) return status