diff options
author | David Bradford <david.bradford@mongodb.com> | 2019-05-30 13:57:18 -0400 |
---|---|---|
committer | David Bradford <david.bradford@mongodb.com> | 2019-05-30 13:57:18 -0400 |
commit | ae44f7bf27b002e8c6b82205b652114c13db5857 (patch) | |
tree | f93d5c329c17a1a8663b98ce2e6ddd2961963616 /buildscripts/validate_mongocryptd.py | |
parent | a1c1cd1e00a43eb470df756304cea0642a3ca4dc (diff) | |
download | mongo-ae44f7bf27b002e8c6b82205b652114c13db5857.tar.gz |
SERVER-41390: Only validate_mongocryptd if variant has a push task
Diffstat (limited to 'buildscripts/validate_mongocryptd.py')
-rw-r--r-- | buildscripts/validate_mongocryptd.py | 71 |
1 files changed, 58 insertions, 13 deletions
diff --git a/buildscripts/validate_mongocryptd.py b/buildscripts/validate_mongocryptd.py index 2b8ba49c8b9..c1610c14f2d 100644 --- a/buildscripts/validate_mongocryptd.py +++ b/buildscripts/validate_mongocryptd.py @@ -29,11 +29,61 @@ from __future__ import absolute_import, print_function, unicode_literals import argparse +import os import sys import yaml +# 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.ciconfig.evergreen import parse_evergreen_file +# pylint: enable=wrong-import-position + # Name of map to search for in the variables map in evergreen.yml MONGOCRYPTD_VARIANTS = "mongocryptd_variants" +PUSH_TASK_NAME = "push" + + +def can_validation_be_skipped(evg_config, variant): + """ + Determine if the given build variant needs to be validated. + + A build variant does not need to be validated if it does not run the 'push' task or + if it does not exist in the configuration (it is dynamically created). + + :param evg_config: Evergreen configuration. + :param variant: Build variant to check. + :return: True if validation can be skipped. + """ + variant_config = evg_config.get_variant(variant) + if not variant_config: + return True + + if PUSH_TASK_NAME not in variant_config.task_names: + return True + + return False + + +def read_variable_from_yml(filename, variable_name): + """ + Read the given variable from the given yaml file. + + :param filename: Yaml file to read from. + :param variable_name: Variable to read from file. + :return: Value of variable or None. + """ + with open(filename, 'r') as fh: + nodes = yaml.safe_load(fh) + + variables = nodes["variables"] + + for var in variables: + if variable_name in var: + return var[variable_name] + return None def main(): @@ -43,27 +93,22 @@ def main(): parser = argparse.ArgumentParser(description='MongoDB CryptD Check Tool.') parser.add_argument('file', type=str, help="etc/evergreen.yml file") - parser.add_argument('--variant', type=str, help="Build variant to check for") args = parser.parse_args() - # This will raise an exception if the YAML parse fails - with open(args.file, 'r') as fh: - nodes = yaml.load(fh) - - variables = nodes["variables"] - - for var in variables: - if MONGOCRYPTD_VARIANTS in var: - expected_variants = var[MONGOCRYPTD_VARIANTS] - break - else: + expected_variants = read_variable_from_yml(args.file, MONGOCRYPTD_VARIANTS) + if not expected_variants: print("ERROR: Could not find node %s in file '%s'" % (MONGOCRYPTD_VARIANTS, args.file), file=sys.stderr) sys.exit(1) - if not args.variant in expected_variants: + evg_config = parse_evergreen_file(args.file) + if can_validation_be_skipped(evg_config, args.variant): + print(f"Skipping validation on buildvariant {args.variant}") + sys.exit(0) + + if args.variant not in expected_variants: print("ERROR: Expected to find variant %s in list %s" % (args.variant, expected_variants), file=sys.stderr) print( |