summaryrefslogtreecommitdiff
path: root/buildscripts/feature_flag_tags_check.py
diff options
context:
space:
mode:
authorMikhail Shchatko <mikhail.shchatko@mongodb.com>2021-07-15 13:14:05 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-07-23 07:30:05 +0000
commitfcdbc97ec75cad751764c43343e018d0ffd3f642 (patch)
tree902bf711dc6e14bc887e8aadb76e708ced0b703c /buildscripts/feature_flag_tags_check.py
parent00840fd3470baa28ff6ed6a50b8b59327e6bac45 (diff)
downloadmongo-fcdbc97ec75cad751764c43343e018d0ffd3f642.tar.gz
SERVER-55858 Enforce transition to requires-fcv after feature flag is changed from disabled to enabled by default
Diffstat (limited to 'buildscripts/feature_flag_tags_check.py')
-rwxr-xr-xbuildscripts/feature_flag_tags_check.py86
1 files changed, 86 insertions, 0 deletions
diff --git a/buildscripts/feature_flag_tags_check.py b/buildscripts/feature_flag_tags_check.py
new file mode 100755
index 00000000000..6142e658eab
--- /dev/null
+++ b/buildscripts/feature_flag_tags_check.py
@@ -0,0 +1,86 @@
+#!/usr/bin/env python3
+"""Feature flag tags check.
+
+Check that on changing feature flag from disabled to enabled by default in all js tests that
+had that feature flag in tags there is a tag that requires the latest FCV.
+"""
+
+import os
+import subprocess
+import sys
+
+# Get relative imports to work when the package is not installed on the PYTHONPATH.
+if __name__ == "__main__" and __package__ is None:
+ sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+
+# pylint: disable=wrong-import-position
+from buildscripts.resmokelib import selector
+from buildscripts.resmokelib.multiversionconstants import LATEST_FCV
+from buildscripts.resmokelib.utils import jscomment
+
+REQUIRES_FCV_TAG = f"requires_fcv_{LATEST_FCV}".replace(".", "")
+ENTERPRISE_DIR = "src/mongo/db/modules/enterprise"
+
+
+def _run_git_stash_cmd(args, cwd=None):
+ """Run git stash command."""
+ git_cmd = ["git", "stash"] + args
+ proc = subprocess.Popen(git_cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=cwd)
+ proc.communicate()
+
+
+def _git_stash(args):
+ """Run git stash command in he current and enterprise directory."""
+ _run_git_stash_cmd(args)
+ if os.path.isdir(ENTERPRISE_DIR):
+ _run_git_stash_cmd(args, cwd=ENTERPRISE_DIR)
+
+
+def get_tests_with_feature_flag_tags(feature_flags):
+ """Get the list of tests with feature flag tag."""
+ selector_config = {
+ "roots": ["jstests/**/*.js", f"{ENTERPRISE_DIR}/jstests/**/*.js"],
+ "include_with_any_tags": feature_flags,
+ }
+ tests, _ = selector.filter_tests("js_test", selector_config)
+ return tests
+
+
+def get_tests_missing_fcv_tag(tests):
+ """Get the list of tests missing requires FCV tag."""
+ found_tests = []
+ for test in tests:
+ try:
+ test_tags = jscomment.get_tags(test)
+ except FileNotFoundError:
+ continue
+ else:
+ if REQUIRES_FCV_TAG not in test_tags:
+ found_tests.append(test)
+ return found_tests
+
+
+def main():
+ """Run the main function."""
+ with open("base_all_feature_flags.txt", "r") as fh:
+ base_feature_flags = fh.read().split()
+ with open("patch_all_feature_flags.txt", "r") as fh:
+ patch_feature_flags = fh.read().split()
+ enabled_feature_flags = [flag for flag in base_feature_flags if flag not in patch_feature_flags]
+
+ if not enabled_feature_flags:
+ sys.exit(0)
+
+ _git_stash(["--", "jstests"])
+ tests_with_feature_flag_tag = get_tests_with_feature_flag_tags(enabled_feature_flags)
+ _git_stash(["pop"])
+ tests_missing_fcv_tag = get_tests_missing_fcv_tag(tests_with_feature_flag_tag)
+
+ if tests_missing_fcv_tag:
+ print(f"Found tests missing `{REQUIRES_FCV_TAG}` tag:\n" + "\n".join(tests_missing_fcv_tag))
+ sys.exit(1)
+ sys.exit(0)
+
+
+if __name__ == "__main__":
+ main()