summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHuayu Ouyang <huayu.ouyang@mongodb.com>2022-02-09 18:37:17 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-02-10 19:25:41 +0000
commit4e8111d689d91a6681b19605978dc124f67d15bb (patch)
tree1b4b3ec3ec5db1a17e34746f36dcd0bc14696cd5
parentd89391ea2b1f1dfc6da9a012c4371d65c47717b0 (diff)
downloadmongo-4e8111d689d91a6681b19605978dc124f67d15bb.tar.gz
SERVER-62621 IDL compatibility checker should check brand new commands
-rw-r--r--buildscripts/idl/idl_compatibility_errors.py14
-rw-r--r--buildscripts/idl/tests/compatibility_test_fail/newly_added_commands/newly_added_commands.idl124
-rw-r--r--buildscripts/idl/tests/test_compatibility.py59
-rwxr-xr-xevergreen/check_idl_compat.sh6
4 files changed, 196 insertions, 7 deletions
diff --git a/buildscripts/idl/idl_compatibility_errors.py b/buildscripts/idl/idl_compatibility_errors.py
index 9369f964d8b..2058b29a9f9 100644
--- a/buildscripts/idl/idl_compatibility_errors.py
+++ b/buildscripts/idl/idl_compatibility_errors.py
@@ -680,13 +680,13 @@ class IDLCompatibilityContext(object):
def add_reply_field_bson_any_not_allowed_error(self, command_name: str, field_name: str,
type_name: str, file: str) -> None:
"""
- Add an error about the old and new reply field bson serialization_type being 'any'.
+ Add an error about the reply field bson serialization_type being 'any'.
- Add an error about the old and new reply field type's bson serialization type being of
+ Add an error about the reply field type's bson serialization type being of
type 'any' when it is not explicitly allowed.
"""
self._add_error(ERROR_ID_REPLY_FIELD_BSON_SERIALIZATION_TYPE_ANY_NOT_ALLOWED, command_name,
- ("'%s' has an old and new reply field or sub-field '%s' of type '%s' "
+ ("'%s' has a reply field or sub-field '%s' of type '%s' "
"that has a bson serialization type 'any' when it "
"is not explicitly allowed.") % (command_name, field_name, type_name),
file)
@@ -830,22 +830,22 @@ class IDLCompatibilityContext(object):
is_command_parameter: bool) -> None:
# pylint: disable=too-many-arguments,invalid-name
"""
- Add an error about the old and new command or param type bson serialization_type being 'any'.
+ Add an error about the command or param type bson serialization_type being 'any'.
- Add an error about the old and new command or parameter type's bson serialization type
+ Add an error about the command or parameter type's bson serialization type
being of type 'any' when it is not explicitly allowed.
"""
if is_command_parameter:
self._add_error(ERROR_ID_COMMAND_PARAMETER_BSON_SERIALIZATION_TYPE_ANY_NOT_ALLOWED,
command_name,
- ("'%s' has an old and new field or sub-field '%s' of type "
+ ("'%s' has a field or sub-field '%s' of type "
"'%s' that has a bson "
"serialization type 'any' when it is not explicitly allowed.") %
(command_name, field_name, type_name), file)
else:
self._add_error(
ERROR_ID_COMMAND_TYPE_BSON_SERIALIZATION_TYPE_ANY_NOT_ALLOWED, command_name,
- ("'%s' or its sub-struct has an old and new type '%s' that has a bson "
+ ("'%s' or its sub-struct has a type '%s' that has a bson "
"serialization type 'any' when it is not explicitly allowed.") % (command_name,
type_name), file)
diff --git a/buildscripts/idl/tests/compatibility_test_fail/newly_added_commands/newly_added_commands.idl b/buildscripts/idl/tests/compatibility_test_fail/newly_added_commands/newly_added_commands.idl
new file mode 100644
index 00000000000..c07063ec61d
--- /dev/null
+++ b/buildscripts/idl/tests/compatibility_test_fail/newly_added_commands/newly_added_commands.idl
@@ -0,0 +1,124 @@
+# Copyright (C) 2022-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"
+ - "../buildscripts/idl/tests/compatibility_test_fail/new/imports.idl"
+
+types:
+ bsonSerializationTypeAny:
+ bson_serialization_type:
+ - int
+ - any
+ description: "The bson_serialization_type contains 'any'"
+ cpp_type: "std::int32_t"
+
+structs:
+ NewStructFieldNoUnstableField:
+ description: "new struct field has no unstable field specified"
+ fields:
+ newStructFieldNoUnstableField:
+ type: bool
+
+ NewStructFieldTypeContainsAny:
+ description: "new struct field type has bson_serialization_type with 'any'"
+ fields:
+ newStructFieldTypeContainsAny:
+ type: bsonSerializationTypeAny
+ unstable: false
+
+commands:
+ newCommandParameterNoUnstableField:
+ description: "newly added command has a parameter without the unstable field specified"
+ command_name: newCommandParameterNoUnstableField
+ namespace: ignored
+ cpp_name: newCommandParameterNoUnstableField
+ strict: true
+ api_version: "1"
+ fields:
+ flag1:
+ type: bool
+ reply_type: OkReply
+
+ newCommandReplyNoUnstableField:
+ description: "newly added command has a reply field without the unstable field specified"
+ command_name: newCommandReplyNoUnstableField
+ namespace: ignored
+ cpp_name: newCommandReplyNoUnstableField
+ strict: true
+ api_version: "1"
+ reply_type: NewStructFieldNoUnstableField
+
+ newCommandTypeStructFieldNoUnstableField:
+ description: "newly added command has a command type struct field without the unstable
+ field specified"
+ command_name: newCommandTypeStructFieldNoUnstableField
+ namespace: type
+ type: NewStructFieldNoUnstableField
+ cpp_name: newCommandTypeStructFieldNoUnstableField
+ strict: true
+ api_version: "1"
+ reply_type: OkReply
+
+ newCommandParameterBsonSerializationTypeAny:
+ description: "newly added command has a parameter type that has bson_serialization_type
+ with 'any'"
+ command_name: newCommandParameterBsonSerializationTypeAny
+ namespace: ignored
+ cpp_name: newCommandParameterBsonSerializationTypeAny
+ strict: true
+ api_version: "1"
+ fields:
+ flag1:
+ type: bsonSerializationTypeAny
+ unstable: false
+ reply_type: OkReply
+
+ newCommandReplyBsonSerializationTypeAny:
+ description: "newly added command has a reply field type that has bson_serialization_type
+ with 'any'"
+ command_name: newCommandReplyBsonSerializationTypeAny
+ namespace: ignored
+ cpp_name: newCommandReplyBsonSerializationTypeAny
+ strict: true
+ api_version: "1"
+ reply_type: NewStructFieldTypeContainsAny
+
+ newCommandTypeStructFieldBsonSerializationTypeAny:
+ description: "newly added command has a command struct field type that has
+ bson_serialization_type with 'any'"
+ command_name: newCommandTypeStructFieldBsonSerializationTypeAny
+ namespace: type
+ type: NewStructFieldTypeContainsAny
+ cpp_name: newCommandTypeStructFieldBsonSerializationTypeAny
+ strict: true
+ api_version: "1"
+ reply_type: OkReply
diff --git a/buildscripts/idl/tests/test_compatibility.py b/buildscripts/idl/tests/test_compatibility.py
index 5567c871bdb..b9e165166ab 100644
--- a/buildscripts/idl/tests/test_compatibility.py
+++ b/buildscripts/idl/tests/test_compatibility.py
@@ -83,6 +83,65 @@ class TestIDLCompatibilityChecker(unittest.TestCase):
path.join(dir_path, "compatibility_test_fail/abort/invalid_command_parameter_type"),
["src"], ["src"])
+ # pylint: disable=invalid-name
+ def test_newly_added_commands_should_fail(self):
+ """Tests that incompatible newly added commands should fail."""
+ dir_path = path.dirname(path.realpath(__file__))
+ error_collection = idl_check_compatibility.check_compatibility(
+ path.join(dir_path, "compatibility_test_fail/newly_added_commands"),
+ path.join(dir_path, "compatibility_test_fail/newly_added_commands"), ["src"], ["src"])
+
+ self.assertTrue(error_collection.has_errors())
+ self.assertEqual(error_collection.count(), 6)
+
+ new_parameter_no_unstable_field_error = error_collection.get_error_by_command_name(
+ "newCommandParameterNoUnstableField")
+ self.assertTrue(new_parameter_no_unstable_field_error.error_id ==
+ idl_compatibility_errors.ERROR_ID_NEW_PARAMETER_REQUIRES_UNSTABLE)
+ self.assertRegex(
+ str(new_parameter_no_unstable_field_error), "newCommandParameterNoUnstableField")
+
+ new_reply_no_unstable_field_error = error_collection.get_error_by_command_name(
+ "newCommandReplyNoUnstableField")
+ self.assertTrue(new_reply_no_unstable_field_error.error_id ==
+ idl_compatibility_errors.ERROR_ID_NEW_REPLY_FIELD_REQUIRES_UNSTABLE)
+ self.assertRegex(str(new_reply_no_unstable_field_error), "newCommandReplyNoUnstableField")
+
+ new_command_type_struct_no_unstable_field_error = error_collection.get_error_by_command_name(
+ "newCommandTypeStructFieldNoUnstableField")
+ self.assertTrue(new_command_type_struct_no_unstable_field_error.error_id ==
+ idl_compatibility_errors.ERROR_ID_NEW_COMMAND_TYPE_FIELD_REQUIRES_UNSTABLE)
+ self.assertRegex(
+ str(new_command_type_struct_no_unstable_field_error),
+ "newCommandTypeStructFieldNoUnstableField")
+
+ new_parameter_bson_serialization_type_any_error = error_collection.get_error_by_command_name(
+ "newCommandParameterBsonSerializationTypeAny")
+ self.assertTrue(
+ new_parameter_bson_serialization_type_any_error.error_id == idl_compatibility_errors.
+ ERROR_ID_COMMAND_PARAMETER_BSON_SERIALIZATION_TYPE_ANY_NOT_ALLOWED)
+ self.assertRegex(
+ str(new_parameter_bson_serialization_type_any_error),
+ "newCommandParameterBsonSerializationTypeAny")
+
+ new_reply_bson_serialization_type_any_error = error_collection.get_error_by_command_name(
+ "newCommandReplyBsonSerializationTypeAny")
+ self.assertTrue(
+ new_reply_bson_serialization_type_any_error.error_id ==
+ idl_compatibility_errors.ERROR_ID_REPLY_FIELD_BSON_SERIALIZATION_TYPE_ANY_NOT_ALLOWED)
+ self.assertRegex(
+ str(new_reply_bson_serialization_type_any_error),
+ "newCommandReplyBsonSerializationTypeAny")
+
+ new_command_type_struct_bson_serialization_type_any_error = error_collection.get_error_by_command_name(
+ "newCommandTypeStructFieldBsonSerializationTypeAny")
+ self.assertTrue(
+ new_command_type_struct_bson_serialization_type_any_error.error_id ==
+ idl_compatibility_errors.ERROR_ID_COMMAND_TYPE_BSON_SERIALIZATION_TYPE_ANY_NOT_ALLOWED)
+ self.assertRegex(
+ str(new_command_type_struct_bson_serialization_type_any_error),
+ "newCommandTypeStructFieldBsonSerializationTypeAny")
+
# 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."""
diff --git a/evergreen/check_idl_compat.sh b/evergreen/check_idl_compat.sh
index f2f5b1834aa..942c6518b9a 100755
--- a/evergreen/check_idl_compat.sh
+++ b/evergreen/check_idl_compat.sh
@@ -14,3 +14,9 @@ find idls -maxdepth 1 -mindepth 1 -type d | while read dir; do
# TODO (SERVER-61287): We haven't actually checked out old enterprise IDLs
$python buildscripts/idl/idl_check_compatibility.py -v --old-include "$dir/src" --old-include "$dir/src/mongo/db/modules/enterprise/src" --new-include src --new-include src/mongo/db/modules/enterprise/src "$dir/src" src
done
+
+# Run the idl compatibility checker script with the current src directory as both the "old" and
+# "new" versions. This is so that we can check that commands that were newly added since the last
+# release adhere to compatibility requirements.
+echo "Performing idl check compatibility for newly added commands since the last release:"
+$python buildscripts/idl/idl_check_compatibility.py -v --old-include src --old-include src/mongo/db/modules/enterprise/src --new-include src --new-include src/mongo/db/modules/enterprise/src src src