diff options
author | Moustafa Maher <m.maher@10gen.com> | 2021-03-30 16:42:52 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-04-01 23:25:03 +0000 |
commit | ebe3f4d45079332827a41596283d3b6f688c8cd3 (patch) | |
tree | 2271419268c22c646b2ac4fdb9aa3b90546dff13 /buildscripts/idl | |
parent | 39e9990a2fe1b72e5d776a86651469894d0d72af (diff) | |
download | mongo-ebe3f4d45079332827a41596283d3b6f688c8cd3.tar.gz |
SERVER-55524 Remove aborting for missing array in IDL compatibility checker
Diffstat (limited to 'buildscripts/idl')
8 files changed, 175 insertions, 268 deletions
diff --git a/buildscripts/idl/idl_check_compatibility.py b/buildscripts/idl/idl_check_compatibility.py index f57cf0663e9..4b9d1c5138d 100644 --- a/buildscripts/idl/idl_check_compatibility.py +++ b/buildscripts/idl/idl_check_compatibility.py @@ -35,11 +35,13 @@ This script accepts two directories as arguments, the "old" and the "new" IDL di Before running this script, run checkout_idl_files_from_past_releases.py to find and create directories containing the old IDL files from previous releases. """ +# pylint: disable=too-many-lines import argparse import os import sys from dataclasses import dataclass +from enum import Enum from typing import Dict, List, Optional, Tuple, Union from idl import parser, syntax, errors, common @@ -160,6 +162,14 @@ class FieldCompatibilityPair: field_name: str +class ArrayTypeCheckResult(Enum): + """Enumeration representing different return values of check_array_type.""" + + INVALID = 0 + TRUE = 1 + FALSE = 2 + + def get_new_commands( ctxt: IDLCompatibilityContext, new_idl_dir: str, import_directories: List[str] ) -> Tuple[Dict[str, syntax.Command], Dict[str, syntax.IDLParsedSpec], Dict[str, str]]: @@ -336,9 +346,13 @@ def check_reply_field_type(ctxt: IDLCompatibilityContext, field_pair: FieldCompa # pylint: disable=too-many-branches old_field = field_pair.old new_field = field_pair.new - if check_array_type(ctxt, "reply_field", old_field.field_type, new_field.field_type, - field_pair.cmd_name, 'type', old_field.idl_file_path, - new_field.idl_file_path, old_field.unstable): + array_check = check_array_type(ctxt, "reply_field", old_field.field_type, new_field.field_type, + field_pair.cmd_name, 'type', old_field.idl_file_path, + new_field.idl_file_path, old_field.unstable) + if array_check == ArrayTypeCheckResult.INVALID: + return + + if array_check == ArrayTypeCheckResult.TRUE: old_field.field_type = old_field.field_type.element_type new_field.field_type = new_field.field_type.element_type @@ -381,21 +395,27 @@ def check_array_type(ctxt: IDLCompatibilityContext, symbol: str, old_type: Optional[Union[syntax.Enum, syntax.Struct, syntax.Type]], new_type: Optional[Union[syntax.Enum, syntax.Struct, syntax.Type]], cmd_name: str, symbol_name: str, old_idl_file_path: str, - new_idl_file_path: str, old_field_unstable: bool) -> bool: - """Check compatibility between old and new ArrayTypes.""" + new_idl_file_path: str, old_field_unstable: bool) -> ArrayTypeCheckResult: + """ + Check compatibility between old and new ArrayTypes. + + :returns: + - ArrayTypeCheckResult.TRUE : when the old type and new type are of array type. + - ArrayTypeCheckResult.FALSE : when the old type and new type aren't of array type. + - ArrayTypeCheckResult.INVALID : when one of the types is not of array type while the other one is. + """ # pylint: disable=too-many-arguments,too-many-branches old_is_array = isinstance(old_type, syntax.ArrayType) new_is_array = isinstance(new_type, syntax.ArrayType) if not old_is_array and not new_is_array: - return False + return ArrayTypeCheckResult.FALSE if (not old_is_array or not new_is_array) and not old_field_unstable: ctxt.add_type_not_array_error(symbol, cmd_name, symbol_name, new_type.name, old_type.name, new_idl_file_path if old_is_array else old_idl_file_path) - ctxt.errors.dump_errors() - sys.exit(1) + return ArrayTypeCheckResult.INVALID - return True + return ArrayTypeCheckResult.TRUE def check_reply_field(ctxt: IDLCompatibilityContext, old_field: syntax.Field, @@ -582,10 +602,15 @@ def check_param_or_command_type(ctxt: IDLCompatibilityContext, field_pair: Field # pylint: disable=too-many-branches old_field = field_pair.old new_field = field_pair.new - if check_array_type(ctxt, "command_parameter" if is_command_parameter else "command_namespace", - old_field.field_type, new_field.field_type, field_pair.cmd_name, - field_pair.field_name if is_command_parameter else "type", - old_field.idl_file_path, new_field.idl_file_path, old_field.unstable): + array_check = check_array_type( + ctxt, "command_parameter" if is_command_parameter else "command_namespace", + old_field.field_type, new_field.field_type, field_pair.cmd_name, + field_pair.field_name if is_command_parameter else "type", old_field.idl_file_path, + new_field.idl_file_path, old_field.unstable) + if array_check == ArrayTypeCheckResult.INVALID: + return + + if array_check == ArrayTypeCheckResult.TRUE: old_field.field_type = old_field.field_type.element_type new_field.field_type = new_field.field_type.element_type diff --git a/buildscripts/idl/tests/compatibility_test_fail/abort/missing_array/command_parameter_no_array/command_parameter_no_array.idl b/buildscripts/idl/tests/compatibility_test_fail/abort/missing_array/command_parameter_no_array/command_parameter_no_array.idl deleted file mode 100644 index 7a8c5dfc3ae..00000000000 --- a/buildscripts/idl/tests/compatibility_test_fail/abort/missing_array/command_parameter_no_array/command_parameter_no_array.idl +++ /dev/null @@ -1,55 +0,0 @@ -# Copyright (C) 2021-present MongoDB, Inc. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the Server Side Public License, version 1, -# as published by MongoDB, Inc. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# Server Side Public License for more details. -# -# You should have received a copy of the Server Side Public License -# along with this program. If not, see -# <http://www.mongodb.com/licensing/server-side-public-license>. -# -# As a special exception, the copyright holders give permission to link the -# code of portions of this program with the OpenSSL library under certain -# conditions as described in each individual source file and distribute -# linked combinations including the program with the OpenSSL library. You -# must comply with the Server Side Public License in all respects for -# all of the code used other than as permitted herein. If you modify file(s) -# with this exception, you may extend this exception to your version of the -# file(s), but you are not obligated to do so. If you do not wish to do so, -# delete this exception statement from your version. If you delete this -# exception statement from all source files in the program, then also delete -# it in the license file. -# - -global: - cpp_namespace: "mongo" - -imports: - - "mongo/idl/basic_types.idl" - -structs: - ArrayTypeStruct: - description: "Struct with ArrayType field." - fields: - ArrayCommandParameter: - type: array<string> - -commands: - ArrayCommandParameterNoArray: - description: "command will abort because the command field type is not of ArrayType while - the other is of ArrayType." - command_name: arrayCommandParameterNoArray - namespace: type - type: array<ArrayTypeStruct> - cpp_name: arrayCommandParameterNoArray - strict: true - api_version: "1" - fields: - parameterStruct: - type: ArrayTypeStruct - reply_type: ArrayTypeStruct
\ No newline at end of file diff --git a/buildscripts/idl/tests/compatibility_test_fail/abort/missing_array/command_parameter_with_array/command_parameter_with_array.idl b/buildscripts/idl/tests/compatibility_test_fail/abort/missing_array/command_parameter_with_array/command_parameter_with_array.idl deleted file mode 100644 index abe02f63150..00000000000 --- a/buildscripts/idl/tests/compatibility_test_fail/abort/missing_array/command_parameter_with_array/command_parameter_with_array.idl +++ /dev/null @@ -1,55 +0,0 @@ -# Copyright (C) 2021-present MongoDB, Inc. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the Server Side Public License, version 1, -# as published by MongoDB, Inc. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# Server Side Public License for more details. -# -# You should have received a copy of the Server Side Public License -# along with this program. If not, see -# <http://www.mongodb.com/licensing/server-side-public-license>. -# -# As a special exception, the copyright holders give permission to link the -# code of portions of this program with the OpenSSL library under certain -# conditions as described in each individual source file and distribute -# linked combinations including the program with the OpenSSL library. You -# must comply with the Server Side Public License in all respects for -# all of the code used other than as permitted herein. If you modify file(s) -# with this exception, you may extend this exception to your version of the -# file(s), but you are not obligated to do so. If you do not wish to do so, -# delete this exception statement from your version. If you delete this -# exception statement from all source files in the program, then also delete -# it in the license file. -# - -global: - cpp_namespace: "mongo" - -imports: - - "mongo/idl/basic_types.idl" - -structs: - ArrayTypeStruct: - description: "Struct with ArrayType field." - fields: - ArrayCommandParameter: - type: array<string> - -commands: - ArrayCommandParameterNoArray: - description: "command will abort because the command field type of ArrayType while the other - is not of ArrayType." - command_name: arrayCommandParameterNoArray - namespace: type - type: array<ArrayTypeStruct> - cpp_name: arrayCommandParameterNoArray - strict: true - api_version: "1" - fields: - parameterStruct: - type: array<ArrayTypeStruct> - reply_type: ArrayTypeStruct
\ No newline at end of file diff --git a/buildscripts/idl/tests/compatibility_test_fail/abort/missing_array/command_type_no_array/command_type_no_array.idl b/buildscripts/idl/tests/compatibility_test_fail/abort/missing_array/command_type_no_array/command_type_no_array.idl deleted file mode 100644 index 6d5302f7a2a..00000000000 --- a/buildscripts/idl/tests/compatibility_test_fail/abort/missing_array/command_type_no_array/command_type_no_array.idl +++ /dev/null @@ -1,55 +0,0 @@ -# Copyright (C) 2021-present MongoDB, Inc. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the Server Side Public License, version 1, -# as published by MongoDB, Inc. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# Server Side Public License for more details. -# -# You should have received a copy of the Server Side Public License -# along with this program. If not, see -# <http://www.mongodb.com/licensing/server-side-public-license>. -# -# As a special exception, the copyright holders give permission to link the -# code of portions of this program with the OpenSSL library under certain -# conditions as described in each individual source file and distribute -# linked combinations including the program with the OpenSSL library. You -# must comply with the Server Side Public License in all respects for -# all of the code used other than as permitted herein. If you modify file(s) -# with this exception, you may extend this exception to your version of the -# file(s), but you are not obligated to do so. If you do not wish to do so, -# delete this exception statement from your version. If you delete this -# exception statement from all source files in the program, then also delete -# it in the license file. -# - -global: - cpp_namespace: "mongo" - -imports: - - "mongo/idl/basic_types.idl" - -structs: - ArrayTypeStruct: - description: "Struct with ArrayType field." - fields: - ArrayCommandParameter: - type: array<string> - -commands: - ArrayCommandTypeErrorNoArray: - description: "command will abort because the command type is not of ArrayType while - the other is of ArrayType." - command_name: arrayCommandTypeErrorNoArray - namespace: type - type: ArrayTypeStruct - cpp_name: arrayCommandTypeErrorNoArray - strict: true - api_version: "1" - fields: - parameterStruct: - type: array<ArrayTypeStruct> - reply_type: ArrayTypeStruct
\ No newline at end of file diff --git a/buildscripts/idl/tests/compatibility_test_fail/abort/missing_array/command_type_with_array/command_type_with_array.idl b/buildscripts/idl/tests/compatibility_test_fail/abort/missing_array/command_type_with_array/command_type_with_array.idl deleted file mode 100644 index 3ede8ce9c94..00000000000 --- a/buildscripts/idl/tests/compatibility_test_fail/abort/missing_array/command_type_with_array/command_type_with_array.idl +++ /dev/null @@ -1,55 +0,0 @@ -# Copyright (C) 2021-present MongoDB, Inc. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the Server Side Public License, version 1, -# as published by MongoDB, Inc. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# Server Side Public License for more details. -# -# You should have received a copy of the Server Side Public License -# along with this program. If not, see -# <http://www.mongodb.com/licensing/server-side-public-license>. -# -# As a special exception, the copyright holders give permission to link the -# code of portions of this program with the OpenSSL library under certain -# conditions as described in each individual source file and distribute -# linked combinations including the program with the OpenSSL library. You -# must comply with the Server Side Public License in all respects for -# all of the code used other than as permitted herein. If you modify file(s) -# with this exception, you may extend this exception to your version of the -# file(s), but you are not obligated to do so. If you do not wish to do so, -# delete this exception statement from your version. If you delete this -# exception statement from all source files in the program, then also delete -# it in the license file. -# - -global: - cpp_namespace: "mongo" - -imports: - - "mongo/idl/basic_types.idl" - -structs: - ArrayTypeStruct: - description: "Struct with ArrayType field." - fields: - ArrayCommandParameter: - type: array<string> - -commands: - ArrayCommandTypeErrorNoArray: - description: "command will abort because the command type is of ArrayType while - the other is not of ArrayType." - command_name: arrayCommandTypeErrorNoArray - namespace: type - type: array<ArrayTypeStruct> - cpp_name: arrayCommandTypeErrorNoArray - strict: true - api_version: "1" - fields: - parameterStruct: - type: array<ArrayTypeStruct> - reply_type: ArrayTypeStruct
\ No newline at end of file diff --git a/buildscripts/idl/tests/compatibility_test_fail/new/compatibility_test_fail_new.idl b/buildscripts/idl/tests/compatibility_test_fail/new/compatibility_test_fail_new.idl index 2fc2640fdff..b92612556a8 100644 --- a/buildscripts/idl/tests/compatibility_test_fail/new/compatibility_test_fail_new.idl +++ b/buildscripts/idl/tests/compatibility_test_fail/new/compatibility_test_fail_new.idl @@ -2306,3 +2306,59 @@ commands: strict: true api_version: "1" reply_type: NewlyAddedBsonSerializationTypeAnyReply + + ArrayCommandTypeErrorNoArrayOld: + description: "command will fail because the old command type is not of ArrayType while + the new is of ArrayType." + command_name: arrayCommandTypeErrorNoArrayOld + namespace: type + type: array<ArrayTypeStruct> + cpp_name: arrayCommandTypeErrorNoArrayOld + strict: true + api_version: "1" + fields: + parameterStruct: + type: array<ArrayTypeStruct> + reply_type: ArrayTypeStruct + + ArrayCommandTypeErrorNoArrayNew: + description: "command will fail because the new command type is not of ArrayType while + the old is of ArrayType." + command_name: arrayCommandTypeErrorNoArrayNew + namespace: type + type: ArrayTypeStruct + cpp_name: arrayCommandTypeErrorNoArrayNew + strict: true + api_version: "1" + fields: + parameterStruct: + type: array<ArrayTypeStruct> + reply_type: ArrayTypeStruct + + ArrayCommandParameterNoArrayOld: + description: "command will fail because the old command field type is not of ArrayType while + the new is of ArrayType." + command_name: arrayCommandParameterNoArrayOld + namespace: type + type: array<ArrayTypeStruct> + cpp_name: arrayCommandParameterNoArrayOld + strict: true + api_version: "1" + fields: + parameterStruct: + type: array<ArrayTypeStruct> + reply_type: ArrayTypeStruct + + ArrayCommandParameterNoArrayNew: + description: "command will fail because the new command field type is not of ArrayType while + the old is of ArrayType." + command_name: arrayCommandParameterNoArrayNew + namespace: type + type: array<ArrayTypeStruct> + cpp_name: arrayCommandParameterNoArrayNew + strict: true + api_version: "1" + fields: + parameterStruct: + type: ArrayTypeStruct + reply_type: ArrayTypeStruct
\ No newline at end of file diff --git a/buildscripts/idl/tests/compatibility_test_fail/old/compatibility_test_fail_old.idl b/buildscripts/idl/tests/compatibility_test_fail/old/compatibility_test_fail_old.idl index 3064ee29b8f..4d29cdfe451 100644 --- a/buildscripts/idl/tests/compatibility_test_fail/old/compatibility_test_fail_old.idl +++ b/buildscripts/idl/tests/compatibility_test_fail/old/compatibility_test_fail_old.idl @@ -2289,3 +2289,59 @@ commands: strict: true api_version: "1" reply_type: OkReply + + ArrayCommandTypeErrorNoArrayOld: + description: "command will fail because the old command type is not of ArrayType while + the new is of ArrayType." + command_name: arrayCommandTypeErrorNoArrayOld + namespace: type + type: ArrayTypeStruct + cpp_name: arrayCommandTypeErrorNoArrayOld + strict: true + api_version: "1" + fields: + parameterStruct: + type: array<ArrayTypeStruct> + reply_type: ArrayTypeStruct + + ArrayCommandTypeErrorNoArrayNew: + description: "command will fail because the new command type is not of ArrayType while + the old is of ArrayType." + command_name: arrayCommandTypeErrorNoArrayNew + namespace: type + type: array<ArrayTypeStruct> + cpp_name: arrayCommandTypeErrorNoArrayNew + strict: true + api_version: "1" + fields: + parameterStruct: + type: array<ArrayTypeStruct> + reply_type: ArrayTypeStruct + + ArrayCommandParameterNoArrayOld: + description: "command will fail because the old command field type is not of ArrayType while + the new is of ArrayType." + command_name: arrayCommandParameterNoArrayOld + namespace: type + type: array<ArrayTypeStruct> + cpp_name: arrayCommandParameterNoArrayOld + strict: true + api_version: "1" + fields: + parameterStruct: + type: ArrayTypeStruct + reply_type: ArrayTypeStruct + + ArrayCommandParameterNoArrayNew: + description: "command will fail because the new command field type is not of ArrayType while + the old is of ArrayType." + command_name: arrayCommandParameterNoArrayNew + namespace: type + type: array<ArrayTypeStruct> + cpp_name: arrayCommandParameterNoArrayNew + strict: true + api_version: "1" + fields: + parameterStruct: + type: array<ArrayTypeStruct> + reply_type: ArrayTypeStruct
\ No newline at end of file diff --git a/buildscripts/idl/tests/test_compatibility.py b/buildscripts/idl/tests/test_compatibility.py index 93da6030c14..45e429ba002 100644 --- a/buildscripts/idl/tests/test_compatibility.py +++ b/buildscripts/idl/tests/test_compatibility.py @@ -83,40 +83,6 @@ class TestIDLCompatibilityChecker(unittest.TestCase): path.join(dir_path, "compatibility_test_fail/abort/invalid_command_parameter_type"), ["src"]) - with self.assertRaises(SystemExit): - idl_check_compatibility.check_compatibility( - path.join(dir_path, - "compatibility_test_fail/abort/missing_array/command_parameter_no_array"), - path.join( - dir_path, - "compatibility_test_fail/abort/missing_array/command_parameter_with_array"), - ["src"]) - - with self.assertRaises(SystemExit): - idl_check_compatibility.check_compatibility( - path.join( - dir_path, - "compatibility_test_fail/abort/missing_array/command_parameter_with_array"), - path.join(dir_path, - "compatibility_test_fail/abort/missing_array/command_parameter_no_array"), - ["src"]) - - with self.assertRaises(SystemExit): - idl_check_compatibility.check_compatibility( - path.join(dir_path, - "compatibility_test_fail/abort/missing_array/command_type_no_array"), - path.join(dir_path, - "compatibility_test_fail/abort/missing_array/command_type_with_array"), - ["src"]) - - with self.assertRaises(SystemExit): - idl_check_compatibility.check_compatibility( - path.join(dir_path, - "compatibility_test_fail/abort/missing_array/command_type_with_array"), - path.join(dir_path, - "compatibility_test_fail/abort/missing_array/command_type_no_array"), - ["src"]) - # pylint: disable=too-many-locals,too-many-statements,invalid-name def test_should_fail(self): """Tests that incompatible old and new IDL commands should fail.""" @@ -126,7 +92,7 @@ class TestIDLCompatibilityChecker(unittest.TestCase): path.join(dir_path, "compatibility_test_fail/new"), ["src"]) self.assertTrue(error_collection.has_errors()) - self.assertTrue(error_collection.count() == 160) + self.assertTrue(error_collection.count() == 164) invalid_api_version_new_error = error_collection.get_error_by_command_name( "invalidAPIVersionNew") @@ -1217,6 +1183,30 @@ class TestIDLCompatibilityChecker(unittest.TestCase): idl_compatibility_errors.ERROR_ID_ADDED_ACCESS_CHECK_FIELD) self.assertRegex(str(added_access_check_field_error), "addedAccessCheckField") + missing_array_command_type_old_error = error_collection.get_error_by_command_name( + "arrayCommandTypeErrorNoArrayOld") + self.assertTrue(missing_array_command_type_old_error.error_id == + idl_compatibility_errors.ERROR_ID_TYPE_NOT_ARRAY) + self.assertRegex(str(missing_array_command_type_old_error), "array<ArrayTypeStruct>") + + missing_array_command_type_new_error = error_collection.get_error_by_command_name( + "arrayCommandTypeErrorNoArrayNew") + self.assertTrue(missing_array_command_type_new_error.error_id == + idl_compatibility_errors.ERROR_ID_TYPE_NOT_ARRAY) + self.assertRegex(str(missing_array_command_type_new_error), "array<ArrayTypeStruct>") + + missing_array_command_parameter_old_error = error_collection.get_error_by_command_name( + "arrayCommandParameterNoArrayOld") + self.assertTrue(missing_array_command_parameter_old_error.error_id == + idl_compatibility_errors.ERROR_ID_TYPE_NOT_ARRAY) + self.assertRegex(str(missing_array_command_parameter_old_error), "array<ArrayTypeStruct>") + + missing_array_command_parameter_new_error = error_collection.get_error_by_command_name( + "arrayCommandParameterNoArrayNew") + self.assertTrue(missing_array_command_parameter_new_error.error_id == + idl_compatibility_errors.ERROR_ID_TYPE_NOT_ARRAY) + self.assertRegex(str(missing_array_command_parameter_new_error), "array<ArrayTypeStruct>") + def test_error_reply(self): """Tests the compatibility checker with the ErrorReply struct.""" dir_path = path.dirname(path.realpath(__file__)) |