SERVER-127113: Add bazel targets for extension resmoke suites (#54033)

GitOrigin-RevId: db2bf329f8a21a54fd8ef8143b1918e56647c40e
This commit is contained in:
Sean Lyons 2026-05-20 13:49:00 -04:00 committed by MongoDB Bot
parent 41b16e48d9
commit 5e6e35755f
11 changed files with 201 additions and 29 deletions

View File

@ -195,7 +195,10 @@ def resmoke_suite_test(
python_imports_target = name + "_python_imports"
_collect_python_imports(
name = python_imports_target,
data = data,
data = select({
"//bazel/resmoke:skip_deps_for_cquery_enabled": [],
"//conditions:default": data,
}),
tags = ["manual"],
)
@ -245,6 +248,9 @@ def resmoke_suite_test(
"//jstests/libs:authTestsKey",
"//jstests/libs:key1",
"//jstests/libs:key2",
"//jstests/with_mongot:keyfile_for_testing",
"//src/mongo/db/modules/enterprise/jstests/encryptdb/libs:ekf2",
"//src/mongo/db/modules/enterprise/jstests/encryptdb/libs:ekf",
"//src/third_party/schemastore.org:schemas",
"//x509:generate_main_certificates",
]
@ -256,12 +262,19 @@ def resmoke_suite_test(
for dep in multiversion_deps
]
merged_data = data + [d for d in srcs if d not in data] + [d for d in default_data if d not in data and d not in srcs] + multiversion_deps + multiversion_config + multiversion_exclude_tags
# Data that is always safe for cquery (no C++ toolchain needed): auto-derived srcs,
# default resmoke infrastructure, and multiversion artifacts.
cquery_safe_data = [d for d in srcs if d not in data] + [d for d in default_data if d not in data and d not in srcs] + multiversion_deps + multiversion_config + multiversion_exclude_tags
py_test(
name = name,
srcs = [resmoke_shim],
data = merged_data + select({
data = select({
# Skip user-provided data during cquery — it may include targets that require
# C++ toolchain resolution, which fails when --noincompatible_enable_cc_toolchain_resolution is set.
"//bazel/resmoke:skip_deps_for_cquery_enabled": cquery_safe_data,
"//conditions:default": data + cquery_safe_data,
}) + select({
"//bazel/resmoke:installed_dist_test_enabled": ["//:installed-dist-test"],
"//conditions:default": [],
}),

View File

@ -45,16 +45,22 @@ mongo_js_library(
"//jstests/concurrency/fsm_utils:all_subpackage_javascript_files",
"//jstests/concurrency/fsm_workload_helpers",
"//jstests/concurrency/fsm_workload_modifiers:all_subpackage_javascript_files",
"//jstests/concurrency/fsm_workloads:all_subpackage_javascript_files",
"//jstests/core/libs:all_subpackage_javascript_files",
"//jstests/disk/libs:all_subpackage_javascript_files",
"//jstests/fle2/libs:all_subpackage_javascript_files",
"//jstests/multiVersion/libs:all_subpackage_javascript_files",
"//jstests/noPassthrough/libs:all_subpackage_javascript_files",
"//jstests/ocsp/lib:all_subpackage_javascript_files",
"//jstests/sharding/analyze_shard_key/libs:all_subpackage_javascript_files",
"//jstests/sharding/libs:all_subpackage_javascript_files",
"//jstests/ssl/libs",
"//jstests/with_mongot/e2e_lib",
"//jstests/with_mongot/mongotmock/lib",
"//jstests/with_mongot/search_mocked/ssl/lib:all_subpackage_javascript_files",
"//src/mongo/db/modules/enterprise/jstests/encryptdb/libs:all_subpackage_javascript_files",
"//src/mongo/db/modules/enterprise/jstests/fle/lib:all_subpackage_javascript_files",
"//src/mongo/db/modules/enterprise/jstests/hot_backups/libs:all_subpackage_javascript_files",
"//src/mongo/db/modules/enterprise/jstests/libs:all_subpackage_javascript_files",
],
)

View File

@ -5,7 +5,6 @@ from buildscripts.resmokelib.extensions.add_extensions_signature_pub_key_path im
)
from buildscripts.resmokelib.extensions.constants import (
CONF_IN_PATH,
CONF_OUT_DIR,
EVERGREEN_SEARCH_DIRS,
LOCAL_SEARCH_DIRS,
TEST_PUBLIC_KEY_PATH,
@ -18,6 +17,7 @@ from buildscripts.resmokelib.extensions.find_and_generate_extension_configs impo
)
from buildscripts.resmokelib.extensions.generate_extension_configs import (
generate_extension_configs,
get_conf_out_dir,
)
__all__ = [
@ -26,9 +26,9 @@ __all__ = [
"normalize_load_extensions",
"delete_extension_configs",
"generate_extension_configs",
"get_conf_out_dir",
"add_extensions_signature_pub_key_path",
"CONF_IN_PATH",
"CONF_OUT_DIR",
"LOCAL_SEARCH_DIRS",
"EVERGREEN_SEARCH_DIRS",
"TEST_PUBLIC_KEY_PATH",

View File

@ -1,27 +1,33 @@
"""Constants for testing extensions locally and in Evergreen."""
import os
import tempfile
temp_dir = tempfile.gettempdir()
cwd = os.getcwd()
# Directory for generated extension .conf files.
CONF_OUT_DIR = os.path.join(temp_dir, "mongo", "extensions")
# Path to the source YAML with extension options.
CONF_IN_PATH = os.path.join(
cwd, "src", "mongo", "db", "extension", "test_examples", "configurations.yml"
)
# Directories to search for .so files in Evergreen and locally.
EVERGREEN_SEARCH_DIRS = [os.path.join(cwd, "dist-test", "lib")]
LOCAL_SEARCH_DIRS = [
os.path.join(cwd, "bazel-bin", "install-dist-test", "lib"),
os.path.join(cwd, "bazel-bin", "install-extensions", "lib"),
]
# Directories to search for .so files in Evergreen and locally.
_test_srcdir = os.environ.get("TEST_SRCDIR")
if _test_srcdir:
# In the Bazel test sandbox, extensions are available in runfiles at their workspace-relative
# path.
EVERGREEN_SEARCH_DIRS = [
os.path.join(_test_srcdir, "_main", "install-extensions", "lib"),
]
LOCAL_SEARCH_DIRS = [
os.path.join(_test_srcdir, "_main", "install-extensions", "lib"),
]
else:
EVERGREEN_SEARCH_DIRS = [os.path.join(cwd, "dist-test", "lib")]
LOCAL_SEARCH_DIRS = [
os.path.join(cwd, "bazel-bin", "install-dist-test", "lib"),
os.path.join(cwd, "bazel-bin", "install-extensions", "lib"),
]
# Path to test extensions signing public key.
TEST_PUBLIC_KEY_PATH = os.path.join(

View File

@ -4,17 +4,16 @@ import logging
import os
import sys
from buildscripts.resmokelib.extensions.constants import (
CONF_OUT_DIR,
)
from buildscripts.resmokelib.extensions.generate_extension_configs import get_conf_out_dir
def delete_extension_configs(extension_names: str, logger: logging.Logger):
"""Delete extension .conf files."""
conf_out_dir = get_conf_out_dir()
extension_names = [item.strip() for item in extension_names.split(",")]
for name in extension_names:
file_name = f"{name}.conf"
file_path = os.path.join(CONF_OUT_DIR, file_name)
file_path = os.path.join(conf_out_dir, file_name)
try:
os.remove(file_path)
logger.info("Deleted extension configuration file %s", file_path)

View File

@ -4,13 +4,26 @@ import logging
import os
import shutil
import sys
import tempfile
import yaml
from buildscripts.resmokelib.extensions.constants import (
CONF_IN_PATH,
CONF_OUT_DIR,
)
from buildscripts.resmokelib.extensions.constants import CONF_IN_PATH
def get_conf_out_dir() -> str:
"""Return the directory for generated extension .conf files.
Checks for the temp dir explicitly. Using tempfile.gettempdir() caches its result, and
the temporary directory may be adjusted early by resmoke or other test setup.
"""
tmpdir = (
os.environ.get("TMPDIR")
or os.environ.get("TEMP")
or os.environ.get("TMP")
or tempfile.gettempdir()
)
return os.path.join(tmpdir, "mongo", "extensions")
def generate_extension_configs(
@ -48,7 +61,8 @@ def generate_extension_configs(
extension_names = []
# Create a clean output directory.
os.makedirs(CONF_OUT_DIR, exist_ok=True)
conf_out_dir = get_conf_out_dir()
os.makedirs(conf_out_dir, exist_ok=True)
for so_file in so_files:
# path/to/libfoo_mongo_extension.so -> libfoo_mongo_extension
@ -62,7 +76,7 @@ def generate_extension_configs(
# Add the parsed extension name to the list.
extension_names.append(extension_name_with_suffix)
conf_file_path = os.path.join(CONF_OUT_DIR, f"{extension_name_with_suffix}.conf")
conf_file_path = os.path.join(conf_out_dir, f"{extension_name_with_suffix}.conf")
try:
# Create the .conf file for the extension.
with open(conf_file_path, "w+") as conf_file:
@ -83,7 +97,7 @@ def generate_extension_configs(
)
except (IOError, OSError) as e:
# Clean up created directories on failure.
shutil.rmtree(CONF_OUT_DIR)
shutil.rmtree(conf_out_dir)
raise RuntimeError(
f"Failed to create .conf file for extension {extension_name} at {conf_file_path}"
) from e

View File

@ -222,7 +222,7 @@ class MongotLauncher(object):
"""
executable = self.fixturelib.default_if_none(
executable, self.config.DEFAULT_MONGOD_EXECUTABLE
executable, self.config.DEFAULT_MONGOT_EXECUTABLE
)
mongot_options = self.fixturelib.default_if_none(mongot_options, {}).copy()

View File

@ -1,4 +1,7 @@
load("@aspect_rules_js//js:defs.bzl", "js_library")
load("//bazel:mongo_js_rules.bzl", "all_subpackage_javascript_files")
package(default_visibility = ["//visibility:public"])
js_library(
name = "all_javascript_files",
@ -9,5 +12,6 @@ js_library(
"//bazel/config:ppc_or_s390x": ["@platforms//:incompatible"],
"//conditions:default": [],
}),
visibility = ["//visibility:public"],
)
all_subpackage_javascript_files()

View File

@ -72,3 +72,121 @@ resmoke_suite_test(
"//src/mongo/shell:mongo",
],
)
resmoke_suite_test(
name = "extensions_sharded_cluster",
config = "//buildscripts/resmokeconfig:suites/extensions_sharded_cluster.yml",
data = [
"//:install-extensions",
"//src/mongo/db/extension/test_examples:resmoke_data",
],
tags = [
"ci-default",
"extensions",
],
target_compatible_with = select({
"@platforms//os:macos": ["@platforms//:incompatible"],
"@platforms//os:windows": ["@platforms//:incompatible"],
"//bazel/platforms:amazon_linux_2": ["@platforms//:incompatible"],
"//conditions:default": [],
}),
deps = [
"//src/mongo/db:mongod",
"//src/mongo/s:mongos",
"//src/mongo/shell:mongo",
],
)
resmoke_suite_test(
name = "extensions_sharded_collections",
config = "//buildscripts/resmokeconfig:suites/extensions_sharded_collections.yml",
data = [
"//:install-extensions",
"//src/mongo/db/extension/test_examples:resmoke_data",
],
tags = [
"ci-default",
"extensions",
],
target_compatible_with = select({
"@platforms//os:macos": ["@platforms//:incompatible"],
"@platforms//os:windows": ["@platforms//:incompatible"],
"//bazel/platforms:amazon_linux_2": ["@platforms//:incompatible"],
"//conditions:default": [],
}),
deps = [
"//src/mongo/db:mongod",
"//src/mongo/s:mongos",
"//src/mongo/shell:mongo",
],
)
resmoke_suite_test(
name = "extensions_single_node",
config = "//buildscripts/resmokeconfig:suites/extensions_single_node.yml",
data = [
"//:install-extensions",
"//src/mongo/db/extension/test_examples:resmoke_data",
],
tags = [
"ci-default",
"extensions",
],
target_compatible_with = select({
"@platforms//os:macos": ["@platforms//:incompatible"],
"@platforms//os:windows": ["@platforms//:incompatible"],
"//bazel/platforms:amazon_linux_2": ["@platforms//:incompatible"],
"//conditions:default": [],
}),
deps = [
"//src/mongo/db:mongod",
"//src/mongo/shell:mongo",
],
)
resmoke_suite_test(
name = "extensions_single_shard",
config = "//buildscripts/resmokeconfig:suites/extensions_single_shard.yml",
data = [
"//:install-extensions",
"//src/mongo/db/extension/test_examples:resmoke_data",
],
tags = [
"ci-default",
"extensions",
],
target_compatible_with = select({
"@platforms//os:macos": ["@platforms//:incompatible"],
"@platforms//os:windows": ["@platforms//:incompatible"],
"//bazel/platforms:amazon_linux_2": ["@platforms//:incompatible"],
"//conditions:default": [],
}),
deps = [
"//src/mongo/db:mongod",
"//src/mongo/s:mongos",
"//src/mongo/shell:mongo",
],
)
resmoke_suite_test(
name = "extensions_standalone",
config = "//buildscripts/resmokeconfig:suites/extensions_standalone.yml",
data = [
"//:install-extensions",
"//src/mongo/db/extension/test_examples:resmoke_data",
],
tags = [
"ci-default",
"extensions",
],
target_compatible_with = select({
"@platforms//os:macos": ["@platforms//:incompatible"],
"@platforms//os:windows": ["@platforms//:incompatible"],
"//bazel/platforms:amazon_linux_2": ["@platforms//:incompatible"],
"//conditions:default": [],
}),
deps = [
"//src/mongo/db:mongod",
"//src/mongo/shell:mongo",
],
)

View File

@ -2,6 +2,10 @@ load("//bazel:mongo_js_rules.bzl", "all_subpackage_javascript_files", "mongo_js_
package(default_visibility = ["//visibility:public"])
exports_files(
["keyfile_for_testing"],
)
mongo_js_library(
name = "common_utils",
srcs = ["common_utils.js"],

View File

@ -11,6 +11,14 @@ exports_files(
]),
)
filegroup(
name = "resmoke_data",
srcs = [
"configurations.yml",
"//src/mongo/db/extension/test_examples/test_extensions_signing_keys:test_extensions_signing_public_key.asc",
],
)
# This sets up the valid extension targets to use in the top level `dist-test`
# and `extensions` targets. Using Bazel's transition system, this rule ensures
# that the extensions are built with the correct configuration. All extensions