diff options
author | Max Hirschhorn <max.hirschhorn@mongodb.com> | 2015-10-07 16:47:09 -0400 |
---|---|---|
committer | Max Hirschhorn <max.hirschhorn@mongodb.com> | 2015-10-07 16:47:09 -0400 |
commit | 738c366cc7a2af55dbeef2fce83a64653f5819e0 (patch) | |
tree | ef199b10eecf3e97bb5639644020017695a5ddc4 | |
parent | bb88c67087c358020e4ce5dfe82c9bdc1c3b207b (diff) | |
download | mongo-738c366cc7a2af55dbeef2fce83a64653f5819e0.tar.gz |
SERVER-20636 Move Command::testCommandsEnabled to its own library.
Resolves some linkage debt to make it easier to check whether test
commands are enabled in the server.
-rw-r--r-- | src/mongo/db/SConscript | 1 | ||||
-rw-r--r-- | src/mongo/db/auth/SConscript | 23 | ||||
-rw-r--r-- | src/mongo/db/auth/sasl_test_crutch.cpp | 34 | ||||
-rw-r--r-- | src/mongo/db/commands.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/commands.h | 27 | ||||
-rw-r--r-- | src/mongo/db/commands/SConscript | 7 | ||||
-rw-r--r-- | src/mongo/db/commands/test_commands_enabled.cpp | 37 | ||||
-rw-r--r-- | src/mongo/dbtests/dbtests.cpp | 2 |
8 files changed, 80 insertions, 55 deletions
diff --git a/src/mongo/db/SConscript b/src/mongo/db/SConscript index 84859814324..04f0b85061b 100644 --- a/src/mongo/db/SConscript +++ b/src/mongo/db/SConscript @@ -493,6 +493,7 @@ env.Library( ], LIBDEPS=[ '$BUILD_DIR/mongo/client/clientdriver', + '$BUILD_DIR/mongo/db/commands/test_commands_enabled', '$BUILD_DIR/mongo/logger/parse_log_component_settings', '$BUILD_DIR/mongo/scripting/scripting_common', '$BUILD_DIR/mongo/util/cmdline_utils/cmdline_utils', diff --git a/src/mongo/db/auth/SConscript b/src/mongo/db/auth/SConscript index cba1d318fc5..7056725bee2 100644 --- a/src/mongo/db/auth/SConscript +++ b/src/mongo/db/auth/SConscript @@ -112,12 +112,9 @@ env.Library('saslauth', 'authmocks', # Wat? 'sasl_options', '$BUILD_DIR/mongo/crypto/scramauth', + '$BUILD_DIR/mongo/db/commands/test_commands_enabled', '$BUILD_DIR/mongo/util/net/network', ], - LIBDEPS_TAGS=[ - # Depends on Commands::testCommandsEnabled, which is not uniquely defined - 'incomplete', - ], ) env.Library('authmongod', @@ -165,21 +162,17 @@ env.Library( ] ) -env.Library('sasltestcrutch', - ['sasl_test_crutch.cpp'], - LIBDEPS=[]) - env.CppUnitTest('action_set_test', 'action_set_test.cpp', - LIBDEPS=['authcore', 'authmocks', 'saslauth', 'sasltestcrutch']) + LIBDEPS=['authcore', 'authmocks', 'saslauth']) env.CppUnitTest('privilege_parser_test', 'privilege_parser_test.cpp', - LIBDEPS=['authcore', 'authmocks', 'saslauth', 'sasltestcrutch']) + LIBDEPS=['authcore', 'authmocks', 'saslauth']) env.CppUnitTest('role_graph_test', 'role_graph_test.cpp', - LIBDEPS=['authcore', 'authmocks', 'saslauth', 'sasltestcrutch']) + LIBDEPS=['authcore', 'authmocks', 'saslauth']) env.CppUnitTest('user_document_parser_test', 'user_document_parser_test.cpp', - LIBDEPS=['authcore', 'authmocks', 'saslauth', 'sasltestcrutch']) + LIBDEPS=['authcore', 'authmocks', 'saslauth']) env.CppUnitTest('user_set_test', 'user_set_test.cpp', - LIBDEPS=['authcore', 'authmocks', 'saslauth', 'sasltestcrutch']) + LIBDEPS=['authcore', 'authmocks', 'saslauth']) env.CppUnitTest('authorization_manager_test', 'authorization_manager_test.cpp', - LIBDEPS=['authcore', 'authmocks', 'saslauth', 'sasltestcrutch']) + LIBDEPS=['authcore', 'authmocks', 'saslauth']) env.CppUnitTest('authorization_session_test', 'authorization_session_test.cpp', - LIBDEPS=['authcore', 'authmocks', 'saslauth', 'sasltestcrutch']) + LIBDEPS=['authcore', 'authmocks', 'saslauth']) diff --git a/src/mongo/db/auth/sasl_test_crutch.cpp b/src/mongo/db/auth/sasl_test_crutch.cpp deleted file mode 100644 index d64877492aa..00000000000 --- a/src/mongo/db/auth/sasl_test_crutch.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/** -* Copyright (C) 2014 MongoDB Inc. -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU Affero General Public License, version 3, -* as published by the Free Software Foundation. -* -* 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 -* GNU Affero General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with this program. If not, see <http://www.gnu.org/licenses/>. -* -* 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 GNU Affero General 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. -*/ - -#include "mongo/platform/basic.h" -#include "mongo/db/commands.h" - -namespace mongo { -int Command::testCommandsEnabled = 0; -} diff --git a/src/mongo/db/commands.cpp b/src/mongo/db/commands.cpp index 256e3fd2ead..a61c4ac5c76 100644 --- a/src/mongo/db/commands.cpp +++ b/src/mongo/db/commands.cpp @@ -72,14 +72,12 @@ Command::CommandMap* Command::_commandsByBestName; Command::CommandMap* Command::_webCommands; Command::CommandMap* Command::_commands; -int Command::testCommandsEnabled = 0; - Counter64 Command::unknownCommands; static ServerStatusMetricField<Counter64> displayUnknownCommands("commands.<UNKNOWN>", &Command::unknownCommands); namespace { -ExportedServerParameter<int, ServerParameterType::kStartupOnly> testCommandsParameter( +ExportedServerParameter<bool, ServerParameterType::kStartupOnly> testCommandsParameter( ServerParameterSet::getGlobal(), "enableTestCommands", &Command::testCommandsEnabled); } diff --git a/src/mongo/db/commands.h b/src/mongo/db/commands.h index 8993f9e657a..8c47797ab41 100644 --- a/src/mongo/db/commands.h +++ b/src/mongo/db/commands.h @@ -358,8 +358,31 @@ public: */ static void appendCommandWCStatus(BSONObjBuilder& result, const Status& status); - // Set by command line. Controls whether or not testing-only commands should be available. - static int testCommandsEnabled; + /** + * If true, then testing commands are available. Defaults to false. + * + * Testing commands should conditionally register themselves by consulting this flag: + * + * MONGO_INITIALIZER(RegisterMyTestCommand)(InitializerContext* context) { + * if (Command::testCommandsEnabled) { + * // Leaked intentionally: a Command registers itself when constructed. + * new MyTestCommand(); + * } + * return Status::OK(); + * } + * + * To make testing commands available by default, change the value to true before running any + * mongo initializers: + * + * int myMain(int argc, char** argv, char** envp) { + * static StaticObserver StaticObserver; + * Command::testCommandsEnabled = true; + * ... + * runGlobalInitializersOrDie(argc, argv, envp); + * ... + * } + */ + static bool testCommandsEnabled; /** * Returns true if this a request for the 'help' information associated with the command. diff --git a/src/mongo/db/commands/SConscript b/src/mongo/db/commands/SConscript index a624cf909e8..e52ace00852 100644 --- a/src/mongo/db/commands/SConscript +++ b/src/mongo/db/commands/SConscript @@ -3,6 +3,13 @@ Import("env") env.Library( + target="test_commands_enabled", + source=[ + "test_commands_enabled.cpp", + ] +) + +env.Library( target='server_status_core', source=[ 'server_status_internal.cpp', diff --git a/src/mongo/db/commands/test_commands_enabled.cpp b/src/mongo/db/commands/test_commands_enabled.cpp new file mode 100644 index 00000000000..24803221c78 --- /dev/null +++ b/src/mongo/db/commands/test_commands_enabled.cpp @@ -0,0 +1,37 @@ +/** + * Copyright (C) 2015 MongoDB Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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 + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * 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 GNU Affero General 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. + */ + +#include "mongo/platform/basic.h" + +#include "mongo/db/commands.h" + +namespace mongo { + +bool Command::testCommandsEnabled = false; + +} // namespace mongo diff --git a/src/mongo/dbtests/dbtests.cpp b/src/mongo/dbtests/dbtests.cpp index 9ff7b31183e..1d80f0bc77c 100644 --- a/src/mongo/dbtests/dbtests.cpp +++ b/src/mongo/dbtests/dbtests.cpp @@ -98,7 +98,7 @@ Status createIndexFromSpec(OperationContext* txn, StringData ns, const BSONObj& int dbtestsMain(int argc, char** argv, char** envp) { static StaticObserver StaticObserver; - Command::testCommandsEnabled = 1; + Command::testCommandsEnabled = true; ::mongo::setupSynchronousSignalHandlers(); mongo::runGlobalInitializersOrDie(argc, argv, envp); repl::ReplSettings replSettings; |