def mongos_program(logger, executable=None, process_kwargs=None, **kwargs): """Return a Process instance that starts a mongos with arguments constructed from 'kwargs'.""" executable = utils.default_if_none(executable, config.DEFAULT_MONGOS_EXECUTABLE) args = [executable] # Apply the --setParameter command line argument. Command line options to resmoke.py override # the YAML configuration. suite_set_parameters = kwargs.pop("set_parameters", {}) if config.MONGOS_SET_PARAMETERS is not None: suite_set_parameters.update( utils.load_yaml(config.MONGOS_SET_PARAMETERS)) # Set default log verbosity levels if none were specified. if "logComponentVerbosity" not in suite_set_parameters: suite_set_parameters[ "logComponentVerbosity"] = default_mongos_log_component_verbosity( ) _add_testing_set_parameters(suite_set_parameters) _apply_set_parameters(args, suite_set_parameters) # Apply the rest of the command line arguments. _apply_kwargs(args, kwargs) _set_keyfile_permissions(kwargs) process_kwargs = utils.default_if_none(process_kwargs, {}) return make_process(logger, args, **process_kwargs)
def __init__( # pylint: disable=too-many-arguments self, logger, job_num, mongod_executable=None, mongod_options=None, dbpath_prefix=None, preserve_dbpath=False): """Initialize MongoDFixture with different options for the mongod process.""" self.mongod_options = utils.default_if_none(mongod_options, {}) interface.Fixture.__init__(self, logger, job_num, dbpath_prefix=dbpath_prefix) if "dbpath" in self.mongod_options and dbpath_prefix is not None: raise ValueError("Cannot specify both mongod_options.dbpath and dbpath_prefix") # Default to command line options if the YAML configuration is not passed in. self.mongod_executable = utils.default_if_none(mongod_executable, config.MONGOD_EXECUTABLE) self.mongod_options = utils.default_if_none(mongod_options, {}).copy() # The dbpath in mongod_options takes precedence over other settings to make it easier for # users to specify a dbpath containing data to test against. if "dbpath" not in self.mongod_options: self.mongod_options["dbpath"] = os.path.join(self._dbpath_prefix, config.FIXTURE_SUBDIR) self._dbpath = self.mongod_options["dbpath"] if config.ALWAYS_USE_LOG_FILES: self.mongod_options["logpath"] = self._dbpath + "/mongod.log" self.mongod_options["logappend"] = "" self.preserve_dbpath = True else: self.preserve_dbpath = preserve_dbpath self.mongod = None self.port = None
def __init__( # pylint: disable=too-many-arguments self, exec_logger, suite, config=None, fixture=None, hooks=None, archive_instance=None, archive=None): """Initialize the TestSuiteExecutor with the test suite to run.""" self.logger = exec_logger if _config.SHELL_CONN_STRING is not None: # Specifying the shellConnString command line option should override the fixture # specified in the YAML configuration to be the external fixture. self.fixture_config = { "class": fixtures.EXTERNAL_FIXTURE_CLASS, "shell_conn_string": _config.SHELL_CONN_STRING } else: self.fixture_config = fixture self.hooks_config = utils.default_if_none(hooks, []) self.test_config = utils.default_if_none(config, {}) self.archival = None if archive_instance: self.archival = archival.HookTestArchival(suite, self.hooks_config, archive_instance, archive) self._suite = suite self.test_queue_logger = logging.loggers.new_testqueue_logger(suite.test_kind) self._jobs = []
def _task_or_test_stats( # pylint: disable=too-many-arguments,too-many-locals self, endpoint_name, project, after_date, before_date, group_num_days=None, requesters=None, sort=None, limit=None, tests=None, tasks=None, variants=None, distros=None, group_by=None): """Get the task_stats or test_stats from Evergreen. :param endpoint_name: API endpoint string. :param project: API project string name. :param after_date: After date string query parameter. :param before_date: Before date string query parameter. :param group_num_days: Group number days query parameter. :param requesters: List of requesters for query parameter. :param sort: Sort string query parameter. :param limit: Limit query parameter. :param tests: List of tests for query parameter (for 'test_stats' only). :param tasks: List of tasks for query parameter. :param variants: List of variants for query parameter. :param distros: List of distros for query parameter. :param group_by: Groups by string query parameter. :return: List of stats. """ endpoints = ["test_stats", "task_stats"] if endpoint_name not in endpoints: raise ValueError( "Endpoint name must be one of {}".format(endpoints)) if endpoint_name == "task_stats" and tests: raise ValueError( "The task_stats endpoint does not support the 'tests' query parameter" ) params = { "sort": utils.default_if_none(sort, self.DEFAULT_SORT), "limit": utils.default_if_none(limit, self.DEFAULT_LIMIT), "before_date": before_date, "after_date": after_date, "group_num_days": utils.default_if_none(group_num_days, self.DEFAULT_GROUP_NUM_DAYS) } # yapf: disable _add_list_param( params, "requesters", utils.default_if_none(requesters, self.DEFAULT_REQUESTERS)) _add_list_param(params, "tests", tests) _add_list_param(params, "tasks", tasks) _add_list_param(params, "variants", variants) _add_list_param(params, "distros", distros) if group_by: params["group_by"] = group_by url = "{}/rest/v2/projects/{}/{}".format(self.api_server, project, endpoint_name) return self._paginate(url, params)
def _get_data_dir(self, global_vars): """Return the value that mongo shell should set for the MongoRunner.dataDir property.""" # Command line options override the YAML configuration. data_dir_prefix = utils.default_if_none(config.DBPATH_PREFIX, global_vars.get("MongoRunner.dataDir")) data_dir_prefix = utils.default_if_none(data_dir_prefix, config.DEFAULT_DBPATH_PREFIX) return os.path.join(data_dir_prefix, "job%d" % self.fixture.job_num, config.MONGO_RUNNER_SUBDIR)
def post(self, endpoint, data=None, headers=None, timeout_secs=_TIMEOUT_SECS): """Send a POST request to the specified endpoint with the supplied data. Return the response, either as a string or a JSON object based on the content type. """ data = utils.default_if_none(data, []) data = json.dumps(data) headers = utils.default_if_none(headers, {}) headers["Content-Type"] = "application/json; charset=utf-8" url = self._make_url(endpoint) with warnings.catch_warnings(): if urllib3_exceptions is not None: try: warnings.simplefilter( "ignore", urllib3_exceptions.InsecurePlatformWarning) except AttributeError: # Versions of urllib3 prior to 1.10.3 didn't define InsecurePlatformWarning. # Versions of requests prior to 2.6.0 didn't have a vendored copy of urllib3 # that defined InsecurePlatformWarning. pass try: warnings.simplefilter( "ignore", urllib3_exceptions.InsecureRequestWarning) except AttributeError: # Versions of urllib3 prior to 1.9 didn't define InsecureRequestWarning. # Versions of requests prior to 2.4.0 didn't have a vendored copy of urllib3 # that defined InsecureRequestWarning. pass response = self.session.post(url, data=data, headers=headers, timeout=timeout_secs, auth=self.auth_handler, verify=True) response.raise_for_status() if not response.encoding: response.encoding = "utf-8" headers = response.headers if headers["Content-Type"].startswith("application/json"): return response.json() return response.text
def __init__(self, logger, js_filename, shell_executable=None, shell_options=None): """Initialize the _SingleJSTestCase with the JS file to run.""" interface.ProcessTestCase.__init__(self, logger, "JSTest", js_filename) # Command line options override the YAML configuration. self.shell_executable = utils.default_if_none(config.MONGO_EXECUTABLE, shell_executable) self.js_filename = js_filename self.shell_options = utils.default_if_none(shell_options, {}).copy()
def __init__(self, logger, dbtest_suite, dbtest_executable=None, dbtest_options=None): """Initialize the DBTestCase with the dbtest suite to run.""" interface.ProcessTestCase.__init__(self, logger, "dbtest suite", dbtest_suite) # Command line options override the YAML configuration. self.dbtest_executable = utils.default_if_none(config.DBTEST_EXECUTABLE, dbtest_executable) self.dbtest_suite = dbtest_suite self.dbtest_options = utils.default_if_none(dbtest_options, {}).copy()
def __init__(self, logger, test_kind, test_name, test_runner_file, shell_executable=None, shell_options=None): """Initializes the JSRunnerFileTestCase with the 'test_name' file.""" interface.ProcessTestCase.__init__(self, logger, test_kind, test_name) # Command line options override the YAML configuration. self.shell_executable = utils.default_if_none(config.MONGO_EXECUTABLE, shell_executable) self.shell_options = utils.default_if_none(shell_options, {}).copy() self.test_runner_file = test_runner_file
def __init__( # pylint: disable=too-many-arguments self, logger, test_kind, test_name, test_runner_file, shell_executable=None, shell_options=None): """Initialize the JSRunnerFileTestCase with the 'test_name' file.""" interface.ProcessTestCase.__init__(self, logger, test_kind, test_name) # Command line options override the YAML configuration. self.shell_executable = utils.default_if_none(config.MONGO_EXECUTABLE, shell_executable) self.shell_options = utils.default_if_none(shell_options, {}).copy() self.test_runner_file = test_runner_file
def __init__(self, logger, genny_workload, genny_executable=None, genny_options=None): """Init the GennyTestCase with the genny workload to run.""" interface.ProcessTestCase.__init__(self, logger, "Genny workload", genny_workload) self.genny_executable = utils.default_if_none(config.GENNY_EXECUTABLE, genny_executable) self.genny_options = utils.default_if_none(genny_options, {}).copy() self.genny_options["workload-file"] = genny_workload
def __init__(self, binary=None, roots=None, include_suites=None): """Initialize _DbTestSelectorConfig.""" _SelectorConfig.__init__(self, roots=roots) self.include_suites = utils.default_if_none(include_suites, []) # Command line option overrides the YAML configuration. binary = utils.default_if_none(config.DBTEST_EXECUTABLE, binary) # Use the default if nothing specified. binary = utils.default_if_none(binary, config.DEFAULT_DBTEST_EXECUTABLE) # Ensure that executable files on Windows have a ".exe" extension. if sys.platform == "win32" and os.path.splitext(binary)[1] != ".exe": binary += ".exe" self.binary = binary
def __init__(self, logger, job_num, dbpath_prefix, mongos_executable=None, mongos_options=None): """Initialize _MongoSFixture.""" interface.Fixture.__init__(self, logger, job_num) # Default to command line options if the YAML configuration is not passed in. self.mongos_executable = utils.default_if_none(mongos_executable, config.MONGOS_EXECUTABLE) self.mongos_options = make_historic(utils.default_if_none(mongos_options, {})).copy() self.mongos = None self.port = None self._dbpath_prefix = dbpath_prefix
def get_logger_config(group_id=None, test_id=None, process_name=None, prefix=None, trial=None): # pylint: disable=too-many-locals """Return the jasper logger config.""" import jasper.jasper_pb2 as pb username = os.getenv("CEDAR_USERNAME", default="") api_key = os.getenv("CEDAR_API_KEY", default="") test_id = utils.default_if_none(test_id, "") process_name = utils.default_if_none(process_name, "") prefix = utils.default_if_none(prefix, "") trial = utils.default_if_none(trial, 0) logger_config = pb.LoggerConfig() log_level = pb.LogLevel(threshold=30, default=30) log_format = pb.LogFormat.Value("LOGFORMATPLAIN") if config.EVERGREEN_TASK_ID and group_id is not None: buildlogger_info = pb.BuildloggerV3Info( project=config.EVERGREEN_PROJECT_NAME, version=config.EVERGREEN_VERSION_ID, variant=config.EVERGREEN_VARIANT_NAME, task_name=config.EVERGREEN_TASK_NAME, task_id=config.EVERGREEN_TASK_ID, execution=config.EVERGREEN_EXECUTION, test_name=str(test_id), proc_name=process_name, trial=trial, format=log_format, tags=[str(group_id)], prefix=prefix, base_address=config.CEDAR_URL, rpc_port=config.CEDAR_RPC_PORT, username=username, api_key=api_key) buildlogger_options = pb.BuildloggerV3Options( buildloggerv3=buildlogger_info, level=log_level) logger_config.buildloggerv3.CopyFrom(buildlogger_options) else: buffered = pb.BufferOptions() base_opts = pb.BaseOptions(format=log_format, level=log_level, buffer=buffered) log_opts = pb.DefaultLoggerOptions(prefix=prefix, base=base_opts) logger_config.default.CopyFrom(log_opts) return logger_config
def __init__( # pylint: disable=too-many-arguments self, root=None, roots=None, include_files=None, exclude_files=None, include_tags=None, exclude_tags=None, include_with_any_tags=None, exclude_with_any_tags=None, tag_file=None): """Initialize the _SelectorConfig from the configuration elements. Args: root: the path to a file containing the list of root tests. Incompatible with 'roots'. roots: a list of root tests. Incompatible with 'root'. include_files: a list of paths or glob patterns the tests must be included in. exclude_files: a list of paths or glob patterns the tests must not be included in. include_tags: a str or dict representing a tag matching expression that the tags of the selected tests must match. Incompatible with 'exclude_tags'. exclude_tags: a str or dict representing a tag matching expression that the tags of the selected tests must not match. Incompatible with 'include_tags'. include_with_any_tags: a list of tags. All selected tests must have at least one them. exclude_with_any_tags: a list of tags. No selected tests can have any of them. tag_file: filename of a tag file associating tests to tags. """ # Incompatible arguments check. if root and roots: raise ValueError( "root and roots cannot be specified at the same time") if include_tags and exclude_tags: raise ValueError( "include_tags and exclude_tags cannot be specified at the same time" ) self.root = root self.roots = roots self.tag_file = tag_file self.include_files = utils.default_if_none(include_files, []) self.exclude_files = utils.default_if_none(exclude_files, []) include_with_any_tags = self.__merge_lists( include_with_any_tags, config.INCLUDE_WITH_ANY_TAGS) exclude_with_any_tags = self.__merge_lists( exclude_with_any_tags, config.EXCLUDE_WITH_ANY_TAGS) # This is functionally similar to `include_tags` but contains a list of tags rather # than an expression. include_with_all_tags = config.INCLUDE_TAGS self.tags_expression = self.__make_tags_expression( include_tags, exclude_tags, include_with_any_tags, exclude_with_any_tags, include_with_all_tags)
def configure(self, fixture, *args, **kwargs): interface.ProcessTestCase.configure(self, fixture, *args, **kwargs) # 1. Set the default benchmark options, including the out file path, which is based on the # executable path. Keep the existing extension (if any) to simplify parsing. bm_options = { "benchmark_out": self.report_name(), "benchmark_min_time": _config.DEFAULT_BENCHMARK_MIN_TIME.total_seconds(), "benchmark_repetitions": _config.DEFAULT_BENCHMARK_REPETITIONS, # TODO: remove the following line once we bump our Google Benchmark version to one that # contains the fix for https://github.com/google/benchmark/issues/559 . "benchmark_color": False } # 2. Override Benchmark options with options set through `program_options` in the suite # configuration. suite_bm_options = utils.default_if_none(self.suite_bm_options, {}) bm_options.update(suite_bm_options) # 3. Override Benchmark options with options set through resmoke's command line. resmoke_bm_options = { "benchmark_filter": _config.BENCHMARK_FILTER, "benchmark_list_tests": _config.BENCHMARK_LIST_TESTS, "benchmark_min_time": _config.BENCHMARK_MIN_TIME, "benchmark_out_format": _config.BENCHMARK_OUT_FORMAT, "benchmark_repetitions": _config.BENCHMARK_REPETITIONS } for key, value in resmoke_bm_options.items(): if value is not None: # 4. sanitize options before passing them to Benchmark's command line. if key == "benchmark_min_time": value = value.total_seconds() bm_options[key] = value self.bm_options = bm_options
def configure(self, fixture, *args, **kwargs): """Configure BenchrunEmbeddedTestCase.""" interface.ProcessTestCase.configure(self, fixture, *args, **kwargs) # 1. Set the default benchmark options. benchrun_options = {"time": _config.DEFAULT_BENCHMARK_MIN_TIME.total_seconds()} # 2. Override Benchmark options with options set through `program_options` in the suite # configuration. suite_benchrun_options = utils.default_if_none(self.suite_benchrun_options, {}) benchrun_options.update(suite_benchrun_options) # 3. Override Benchmark options with options set through resmoke's command line. resmoke_benchrun_options = {"dbpath": self.dbpath, "time": _config.BENCHMARK_MIN_TIME} for key, value in resmoke_benchrun_options.items(): if value is not None: # 4. sanitize options before passing them to Benchmark's command line. if key == "time": value = value.total_seconds() benchrun_options[key] = value self.benchrun_options = benchrun_options # Create the dbpath. self._clear_dbpath() try: os.makedirs(self.dbpath) except os.error: # Directory already exists. pass
def __init__(self, suite, hooks, archive_instance, archive_config): #pylint: disable=unused-argument """Initialize HookTestArchival.""" self.archive_instance = archive_instance archive_config = utils.default_if_none(archive_config, {}) self.on_success = archive_config.get("on_success", False) self.tests = [] self.archive_all = False if "tests" in archive_config: # 'tests' is either a list of tests to archive or a bool (archive all if True). if not isinstance(archive_config["tests"], bool): for test in archive_config["tests"]: self.tests += globstar.glob(test) elif archive_config["tests"]: self.archive_all = True self.hooks = [] if "hooks" in archive_config: # 'hooks' is either a list of hooks to archive or a bool (archive all if True). if not isinstance(archive_config["hooks"], bool): self.hooks = archive_config["hooks"] elif archive_config["hooks"]: for hook in hooks: self.hooks.append(hook["class"]) self._tests_repeat = {} self._lock = threading.Lock()
def __init__(self, logger, json_test_file, program_options=None): """Initialize the TestCase with the executable to run.""" interface.ProcessTestCase.__init__(self, logger, "SDAM Json Test", json_test_file) self.program_executable = self._find_executable() self.json_test_file = os.path.normpath(json_test_file) self.program_options = utils.default_if_none(program_options, {}).copy()
def __init__(self, logger, args, env=None, env_vars=None, cwd=None): """Initialize the process with the specified logger, arguments, and environment.""" # Ensure that executable files that don't already have an # extension on Windows have a ".exe" extension. if sys.platform == "win32" and not os.path.splitext(args[0])[1]: args[0] += ".exe" self.logger = logger self.args = args self.env = utils.default_if_none(env, os.environ.copy()) if not self.env.get('RESMOKE_PARENT_PROCESS'): self.env['RESMOKE_PARENT_PROCESS'] = os.environ.get('RESMOKE_PARENT_PROCESS', str(os.getpid())) if not self.env.get('RESMOKE_PARENT_CTIME'): self.env['RESMOKE_PARENT_CTIME'] = os.environ.get('RESMOKE_PARENT_CTIME', str(psutil.Process().create_time())) if env_vars is not None: self.env.update(env_vars) self.pid = None self._process = None self._recorder = None self._stdout_pipe = None self._stderr_pipe = None self._cwd = cwd
def _mongos_program(logger, job_num, test_id=None, executable=None, process_kwargs=None, **kwargs): """Return a Process instance that starts a mongos with arguments constructed from 'kwargs'.""" executable = utils.default_if_none(executable, config.DEFAULT_MONGOS_EXECUTABLE) # Apply the --setParameter command line argument. Command line options to resmoke.py override # the YAML configuration. suite_set_parameters = kwargs.setdefault("set_parameters", {}) if config.MONGOS_SET_PARAMETERS is not None: suite_set_parameters.update( utils.load_yaml(config.MONGOS_SET_PARAMETERS)) # Set default log verbosity levels if none were specified. if "logComponentVerbosity" not in suite_set_parameters: suite_set_parameters[ "logComponentVerbosity"] = default_mongos_log_component_verbosity( ) standalone.add_testing_set_parameters(suite_set_parameters) return core.programs.mongos_program(logger, job_num, test_id, executable, process_kwargs, **kwargs)
def mongos_program( # pylint: disable=too-many-arguments logger, job_num, test_id=None, executable=None, process_kwargs=None, mongos_options=None): """Return a Process instance that starts a mongos with arguments constructed from 'kwargs'.""" args = [executable] mongos_options = mongos_options.copy() if "port" not in mongos_options: mongos_options["port"] = network.PortAllocator.next_fixture_port( job_num) suite_set_parameters = mongos_options.get("set_parameters", {}) _apply_set_parameters(args, suite_set_parameters) mongos_options.pop("set_parameters") # Apply the rest of the command line arguments. _apply_kwargs(args, mongos_options) _set_keyfile_permissions(mongos_options) process_kwargs = make_historic(utils.default_if_none(process_kwargs, {})) process_kwargs["job_num"] = job_num process_kwargs["test_id"] = test_id return make_process(logger, args, **process_kwargs), mongos_options["port"]
def __init__(self, logger, program_executable, program_options=None): """Initialize the CPPUnitTestCase with the executable to run.""" interface.ProcessTestCase.__init__(self, logger, "C++ unit test", program_executable) self.program_executable = program_executable self.program_options = utils.default_if_none(program_options, {}).copy()
def dbtest_program(logger, job_num, test_id=None, executable=None, suites=None, process_kwargs=None, **kwargs): # pylint: disable=too-many-arguments """Return a Process instance that starts a dbtest with arguments constructed from 'kwargs'.""" executable = utils.default_if_none(executable, config.DEFAULT_DBTEST_EXECUTABLE) args = [executable] if suites is not None: args.extend(suites) kwargs["enableMajorityReadConcern"] = config.MAJORITY_READ_CONCERN if config.STORAGE_ENGINE is not None: kwargs["storageEngine"] = config.STORAGE_ENGINE if config.FLOW_CONTROL is not None: kwargs["flowControl"] = (config.FLOW_CONTROL == "on") return generic_program(logger, args, job_num, test_id=test_id, process_kwargs=process_kwargs, **kwargs)
def mongod_program(logger, job_num, executable, process_kwargs, mongod_options): """ Return a Process instance that starts mongod arguments constructed from 'mongod_options'. @param logger - The logger to pass into the process. @param executable - The mongod executable to run. @param process_kwargs - A dict of key-value pairs to pass to the process. @param mongod_options - A HistoryDict describing the various options to pass to the mongod. """ args = [executable] mongod_options = mongod_options.copy() if "port" not in mongod_options: mongod_options["port"] = network.PortAllocator.next_fixture_port( job_num) suite_set_parameters = mongod_options.get("set_parameters", {}) _apply_set_parameters(args, suite_set_parameters) mongod_options.pop("set_parameters") # Apply the rest of the command line arguments. _apply_kwargs(args, mongod_options) _set_keyfile_permissions(mongod_options) process_kwargs = make_historic(utils.default_if_none(process_kwargs, {})) process_kwargs["job_num"] = job_num if config.EXPORT_MONGOD_CONFIG == "regular": mongod_options.dump_history(f"{logger.name}_config.yml") elif config.EXPORT_MONGOD_CONFIG == "detailed": mongod_options.dump_history(f"{logger.name}_config.yml", include_location=True) return make_process(logger, args, **process_kwargs), mongod_options["port"]
def __init__(self, logger, mongos_options): """Initialize the mongos test and saves the options.""" self.mongos_executable = utils.default_if_none(config.MONGOS_EXECUTABLE, config.DEFAULT_MONGOS_EXECUTABLE) # Use the executable as the test name. interface.ProcessTestCase.__init__(self, logger, "mongos test", self.mongos_executable) self.options = mongos_options.copy()
def __init__(self, logger, mongoebench_config_file, program_options=None): """Initialize the BenchrunEmbeddedTestCase with the executable to run.""" interface.ProcessTestCase.__init__(self, logger, "Benchmark embedded test", mongoebench_config_file) parser.validate_benchmark_options() self.benchrun_config_file = mongoebench_config_file # Command line options override the YAML configuration. self.benchrun_executable = utils.default_if_none( _config.MONGOEBENCH_EXECUTABLE, _config.DEFAULT_MONGOEBENCH_EXECUTABLE) self.benchrun_repetitions = utils.default_if_none( _config.BENCHMARK_REPETITIONS, _config.DEFAULT_BENCHMARK_REPETITIONS) self.suite_benchrun_options = program_options self.benchrun_threads = 1 if program_options and "threads" in program_options: self.benchrun_threads = program_options["threads"] self.report_root = _config.BENCHRUN_REPORT_ROOT self.benchrun_options = {} # Set the dbpath. dbpath = utils.default_if_none(_config.DBPATH_PREFIX, _config.DEFAULT_DBPATH_PREFIX) self.dbpath = os.path.join(dbpath, "mongoebench") self.android_device = _config.BENCHRUN_DEVICE == "Android" # If Android device, then the test runs via adb shell. if self.android_device: self.adb = adb_monitor.Adb() self.android_benchrun_root = _config.BENCHRUN_EMBEDDED_ROOT self.device_report_root = posixpath.join( self.android_benchrun_root, "results") self.dbpath = posixpath.join(self.android_benchrun_root, "db") self.benchrun_config_file = posixpath.join( self.android_benchrun_root, "testcases", os.path.basename(self.benchrun_config_file)) ld_library_path = "LD_LIBRARY_PATH={}".format( posixpath.join(self.android_benchrun_root, "sdk")) mongoebench = posixpath.join(self.android_benchrun_root, "sdk", "mongoebench") self.benchrun_executable = "adb shell {} {}".format( ld_library_path, mongoebench)
def build_fixture(self, logger, job_num, fixturelib, *args, **kwargs): """Build a sharded cluster.""" mixed_bin_versions = kwargs.get("mixed_bin_versions", config.MIXED_BIN_VERSIONS) old_bin_version = kwargs.pop("old_bin_version", config.MULTIVERSION_BIN_VERSION) is_multiversion = mixed_bin_versions is not None num_shards = kwargs.pop("num_shards", 1) num_shards_option = config.NUM_SHARDS num_shards = num_shards if not num_shards_option else num_shards_option kwargs["num_shards"] = num_shards num_rs_nodes_per_shard = kwargs.pop("num_rs_nodes_per_shard", 1) num_rs_nodes_per_shard_option = config.NUM_REPLSET_NODES num_rs_nodes_per_shard = num_rs_nodes_per_shard if not num_rs_nodes_per_shard_option else num_rs_nodes_per_shard_option kwargs["num_rs_nodes_per_shard"] = num_rs_nodes_per_shard num_mongos = kwargs.pop("num_mongos", 1) kwargs["num_mongos"] = num_mongos mongos_executable = default_if_none( kwargs.get("mongos_executable"), config.MONGOS_EXECUTABLE, config.DEFAULT_MONGOS_EXECUTABLE) if is_multiversion: len_versions = len(mixed_bin_versions) num_mongods = num_shards * num_rs_nodes_per_shard if len_versions != num_mongods: msg = ("The number of binary versions specified: {} do not match the number of" " nodes in the sharded cluster: {}.").format(len_versions, num_mongods) raise errors.ServerFailure(msg) from buildscripts.resmokelib import multiversionconstants mongos_executable = { config.MultiversionOptions.LAST_LTS: multiversionconstants.LAST_LTS_MONGOS_BINARY, config.MultiversionOptions.LAST_CONTINUOUS: multiversionconstants.LAST_CONTINUOUS_MONGOS_BINARY }[old_bin_version] kwargs["mongos_executable"] = mongos_executable sharded_cluster = _FIXTURES[self.REGISTERED_NAME](logger, job_num, fixturelib, *args, **kwargs) config_svr = self._new_configsvr(sharded_cluster, is_multiversion) sharded_cluster.install_configsvr(config_svr) for rs_shard_index in range(num_shards): rs_shard = self._new_rs_shard(sharded_cluster, mixed_bin_versions, rs_shard_index, num_rs_nodes_per_shard) sharded_cluster.install_rs_shard(rs_shard) for mongos_index in range(num_mongos): mongos = self._new_mongos(sharded_cluster, mongos_executable, mongos_index, num_mongos) sharded_cluster.install_mongos(mongos) return sharded_cluster
def find_excludes(selector_file: str) -> Tuple[List, List, List]: """Parse etc/burn_in_tests.yml. Returns lists of excluded suites, tasks & tests.""" if not selector_file: return [], [], [] LOGGER.debug("reading configuration", config_file=selector_file) with open(selector_file, "r") as fstream: yml = yaml.safe_load(fstream) try: js_test = yml["selector"]["js_test"] except KeyError: raise Exception(f"The selector file {selector_file} is missing the 'selector.js_test' key") return (default_if_none(js_test.get("exclude_suites"), []), default_if_none(js_test.get("exclude_tasks"), []), default_if_none(js_test.get("exclude_tests"), []))
def genny_program(logger, executable=None, process_kwargs=None, **kwargs): """Return a Process instance that starts a genny executable with arguments constructed from 'kwargs'.""" executable = utils.default_if_none(executable, config.DEFAULT_GENNY_EXECUTABLE) args = [executable] return generic_program(logger, args, process_kwargs=process_kwargs, **kwargs)
def __init__(self, logger, program_executable, program_options=None): """Initialize the CPPLibfuzzerTestCase with the executable to run.""" interface.ProcessTestCase.__init__(self, logger, "C++ libfuzzer test", program_executable) self.program_executable = program_executable self.program_options = utils.default_if_none(program_options, {}).copy() self.corpus_directory = "corpus/corpus-" + self.short_name() os.makedirs(self.corpus_directory, exist_ok=True)
def _task_or_test_stats( # pylint: disable=too-many-arguments,too-many-locals self, endpoint_name, project, after_date, before_date, group_num_days=None, requesters=None, sort=None, limit=None, tests=None, tasks=None, variants=None, distros=None, group_by=None): """Get the task_stats or test_stats from Evergreen. :param endpoint_name: API endpoint string. :param project: API project string name. :param after_date: After date string query parameter. :param before_date: Before date string query parameter. :param group_num_days: Group number days query parameter. :param requesters: List of requesters for query parameter. :param sort: Sort string query parameter. :param limit: Limit query parameter. :param tests: List of tests for query parameter (for 'test_stats' only). :param tasks: List of tasks for query parameter. :param variants: List of variants for query parameter. :param distros: List of distros for query parameter. :param group_by: Groups by string query parameter. :return: List of stats. """ endpoints = ["test_stats", "task_stats"] if endpoint_name not in endpoints: raise ValueError("Endpoint name must be one of {}".format(endpoints)) if endpoint_name == "task_stats" and tests: raise ValueError("The task_stats endpoint does not support the 'tests' query parameter") params = { "sort": utils.default_if_none(sort, self.DEFAULT_SORT), "limit": utils.default_if_none(limit, self.DEFAULT_LIMIT), "before_date": before_date, "after_date": after_date, "group_num_days": utils.default_if_none(group_num_days, self.DEFAULT_GROUP_NUM_DAYS) } # yapf: disable _add_list_param(params, "requesters", utils.default_if_none(requesters, self.DEFAULT_REQUESTERS)) _add_list_param(params, "tests", tests) _add_list_param(params, "tasks", tasks) _add_list_param(params, "variants", variants) _add_list_param(params, "distros", distros) if group_by: params["group_by"] = group_by url = "{}/rest/v2/projects/{}/{}".format(self.api_server, project, endpoint_name) return self._paginate(url, params)
def __init__(self, logger, mongoebench_config_file, program_options=None): """Initialize the BenchrunEmbeddedTestCase with the executable to run.""" interface.ProcessTestCase.__init__(self, logger, "Benchmark embedded test", mongoebench_config_file) parser.validate_benchmark_options() self.benchrun_config_file = mongoebench_config_file # Command line options override the YAML configuration. self.benchrun_executable = utils.default_if_none(_config.MONGOEBENCH_EXECUTABLE, _config.DEFAULT_MONGOEBENCH_EXECUTABLE) self.benchrun_repetitions = utils.default_if_none(_config.BENCHMARK_REPETITIONS, _config.DEFAULT_BENCHMARK_REPETITIONS) self.suite_benchrun_options = program_options self.benchrun_threads = 1 if program_options and "threads" in program_options: self.benchrun_threads = program_options["threads"] self.report_root = _config.BENCHRUN_REPORT_ROOT self.benchrun_options = {} # Set the dbpath. dbpath = utils.default_if_none(_config.DBPATH_PREFIX, _config.DEFAULT_DBPATH_PREFIX) self.dbpath = os.path.join(dbpath, "mongoebench") self.android_device = _config.BENCHRUN_DEVICE == "Android" # If Android device, then the test runs via adb shell. if self.android_device: self.adb = adb_monitor.Adb() self.android_benchrun_root = _config.BENCHRUN_EMBEDDED_ROOT self.device_report_root = posixpath.join(self.android_benchrun_root, "results") self.dbpath = posixpath.join(self.android_benchrun_root, "db") self.benchrun_config_file = posixpath.join(self.android_benchrun_root, "testcases", os.path.basename(self.benchrun_config_file)) ld_library_path = "LD_LIBRARY_PATH={}".format( posixpath.join(self.android_benchrun_root, "sdk")) mongoebench = posixpath.join(self.android_benchrun_root, "sdk", "mongoebench") self.benchrun_executable = "adb shell {} {}".format(ld_library_path, mongoebench)
def __init__(self, logger, mongoebench_config_file, program_options=None): """Initialize the BenchrunEmbeddedTestCase with the executable to run.""" interface.ProcessTestCase.__init__(self, logger, "Benchmark embedded test", mongoebench_config_file) parser.validate_benchmark_options() self.benchrun_config_file = mongoebench_config_file # Command line options override the YAML configuration. self.benchrun_executable = utils.default_if_none(_config.MONGOEBENCH_EXECUTABLE, _config.DEFAULT_MONGOEBENCH_EXECUTABLE) self.benchrun_repetitions = utils.default_if_none(_config.BENCHMARK_REPETITIONS, _config.DEFAULT_BENCHMARK_REPETITIONS) self.suite_benchrun_options = program_options self.benchrun_threads = 1 if program_options and "threads" in program_options: self.benchrun_threads = program_options["threads"] self.benchrun_options = {} # Set the dbpath. dbpath = utils.default_if_none(_config.DBPATH_PREFIX, _config.DEFAULT_DBPATH_PREFIX) self.dbpath = os.path.join(dbpath, "mongoebench")
def __init__( #pylint: disable=too-many-arguments self, hook_logger, fixture, exclude_dbs=None, same_collection=False, same_db=False): """Initialize CleanupConcurrencyWorkloads.""" description = "CleanupConcurrencyWorkloads drops all databases in the fixture" interface.Hook.__init__(self, hook_logger, fixture, description) protected_dbs = ["admin", "config", "local", "$external"] self.exclude_dbs = list(set().union(protected_dbs, utils.default_if_none(exclude_dbs, []))) self.same_collection_name = None self.same_db_name = None if same_db or same_collection: # The db name is defined in jstests/concurrency/fsm_utils/name_utils.js. self.same_db_name = "fsmdb0" if same_collection: # The collection name is defined in jstests/concurrency/fsm_utils/name_utils.js. self.same_collection_name = "fsmcoll0"
def configure(self, fixture, *args, **kwargs): """Configure BenchrunEmbeddedTestCase.""" interface.ProcessTestCase.configure(self, fixture, *args, **kwargs) # 1. Set the default benchmark options. benchrun_options = {"time": _config.DEFAULT_BENCHMARK_MIN_TIME.total_seconds()} # 2. Override Benchmark options with options set through `program_options` in the suite # configuration. suite_benchrun_options = utils.default_if_none(self.suite_benchrun_options, {}) benchrun_options.update(suite_benchrun_options) # 3. Override Benchmark options with options set through resmoke's command line. resmoke_benchrun_options = {"dbpath": self.dbpath, "time": _config.BENCHMARK_MIN_TIME} for key, value in list(resmoke_benchrun_options.items()): if value is not None: # 4. sanitize options before passing them to Benchmark's command line. if key == "time": value = value.total_seconds() benchrun_options[key] = value self.benchrun_options = benchrun_options # Create the test report directory. utils.rmtree(self._report_dir(), ignore_errors=True) try: os.makedirs(self._report_dir()) except os.error: # Directory already exists. pass # Create the dbpath. if self.android_device: self.adb.shell("rm -fr {}".format(self.dbpath)) self.adb.shell("mkdir {}".format(self.dbpath)) else: utils.rmtree(self.dbpath, ignore_errors=True) try: os.makedirs(self.dbpath) except os.error: # Directory already exists. pass