def test_simple_success(self): func = self.god.create_mock_function('func') func.expect_call(3) subcommand.parallel_simple(func, (3,)) self.god.check_playback()
def upkeep(self, custom_repos=None): ''' Clean up custom upload/download areas ''' from autotest_lib.server import subcommand if not custom_repos: # Not all package types necessarily require or allow custom repos try: custom_repos = global_config.global_config.get_config_value( 'PACKAGES', 'custom_upload_location').split(',') except global_config.ConfigError: custom_repos = [] try: custom_download = global_config.global_config.get_config_value( 'PACKAGES', 'custom_download_location') custom_repos += [custom_download] except global_config.ConfigError: pass if not custom_repos: return subcommand.parallel_simple(trim_custom_directories, custom_repos, log=False)
def test_nolog_skips_subdirs(self): func = self.god.create_mock_function('func') args = range(3) for arg in args: subcommand.subcommand.expect_call(func, [arg], None).and_return(arg) subcommand.parallel.expect_call(args, None, return_results=False) subcommand.parallel_simple(func, args, log=False) self.god.check_playback()
def test_default_subdirs_constructor(self): func = self.god.create_mock_function('func') args = range(4) for arg in args: subcommand.subcommand.expect_call(func, [arg], str(arg)).and_return(arg) subcommand.parallel.expect_call(args, None, return_results=False) subcommand.parallel_simple(func, args) self.god.check_playback()
def test_custom_subdirs_constructor(self): func = self.god.create_mock_function('func') args = range(7) subdirs = ['subdir%s' % arg for arg in args] for arg, subdir in zip(args, subdirs): subcommand.subcommand.expect_call(func, [arg], subdir).and_return(arg) subcommand.parallel.expect_call(args, None, return_results=False) subcommand.parallel_simple( func, args, subdir_name_constructor=lambda x: 'subdir%s' % x) self.god.check_playback()
def parallel_simple(self, function, machines, log=True, timeout=None, return_results=False): """ Run 'function' using parallel_simple, with an extra wrapper to handle the necessary setup for continuous parsing, if possible. If continuous parsing is already properly initialized then this should just work. @param function: A callable to run in parallel given each machine. @param machines: A list of machine names to be passed one per subcommand invocation of function. @param log: If True, output will be written to output in a subdirectory named after each machine. @param timeout: Seconds after which the function call should timeout. @param return_results: If True instead of an AutoServError being raised on any error a list of the results|exceptions from the function called on each arg is returned. [default: False] @raises error.AutotestError: If any of the functions failed. """ wrapper = self._make_parallel_wrapper(function, machines, log) return subcommand.parallel_simple(wrapper, machines, log=log, timeout=timeout, return_results=return_results)
def test_simple_return_value(self): func = self.god.create_mock_function("func") result = 1000 func.expect_call(3).and_return(result) self.assertEquals(subcommand.parallel_simple(func, (3,), return_results=True), [result]) self.god.check_playback()
def test_simple_return_value(self): func = self.god.create_mock_function('func') result = 1000 func.expect_call(3).and_return(result) self.assertEquals(subcommand.parallel_simple(func, (3,), return_results=True), [result]) self.god.check_playback()
def upkeep(self, custom_repos=None): ''' Clean up custom upload/download areas ''' from autotest_lib.server import subcommand if not custom_repos: custom_repos = global_config.global_config.get_config_value('PACKAGES', 'custom_upload_location').split(',') custom_download = global_config.global_config.get_config_value( 'PACKAGES', 'custom_download_location') custom_repos += [custom_download] results = subcommand.parallel_simple(trim_custom_directories, custom_repos, log=False, )
def test_nolog(self): func, args = self._setup_many(3, False) subcommand.parallel_simple(func, args, log=False) self.god.check_playback()
def test_passthrough(self): func, args = self._setup_many(4, True) subcommand.parallel_simple(func, args) self.god.check_playback()