[icinga-checkins] icinga.org: icinga2/fix/cli-node-update-8488: Cli: Don' t validate config objects in 'node update-config'

git at icinga.org git at icinga.org
Fri Feb 20 21:01:55 CET 2015


Module: icinga2
Branch: fix/cli-node-update-8488
Commit: 23005e173929dd2614acf6728282904d54478875
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=23005e173929dd2614acf6728282904d54478875

Author: Michael Friedrich <michael.friedrich at gmail.com>
Date:   Fri Feb 20 21:01:07 2015 +0100

Cli: Don't validate config objects in 'node update-config'

refs #8488

---

 lib/cli/nodeupdateconfigcommand.cpp |   10 +++---
 lib/cli/nodeutility.cpp             |    2 +-
 lib/cli/repositoryutility.cpp       |   67 ++++++++++++++++++-----------------
 lib/cli/repositoryutility.hpp       |    3 +-
 4 files changed, 43 insertions(+), 39 deletions(-)

diff --git a/lib/cli/nodeupdateconfigcommand.cpp b/lib/cli/nodeupdateconfigcommand.cpp
index 741800d..905f578 100644
--- a/lib/cli/nodeupdateconfigcommand.cpp
+++ b/lib/cli/nodeupdateconfigcommand.cpp
@@ -236,7 +236,7 @@ int NodeUpdateConfigCommand::Run(const boost::program_options::variables_map& vm
 		host_imports->Add("satellite-host"); //default host node template
 		host_attrs->Set("import", host_imports);
 
-		if (!RepositoryUtility::AddObject(object_paths, zone, "Host", host_attrs, changes)) {
+		if (!RepositoryUtility::AddObject(object_paths, zone, "Host", host_attrs, changes, false)) {
 			Log(LogCritical, "cli")
 			    << "Cannot add node host '" << zone << "' to the config repository!\n";
 		}
@@ -295,7 +295,7 @@ int NodeUpdateConfigCommand::Run(const boost::program_options::variables_map& vm
 					host_imports->Add("satellite-host"); //default host node template
 					host_attrs->Set("import", host_imports);
 
-					RepositoryUtility::AddObject(object_paths, host, "Host", host_attrs, changes);
+					RepositoryUtility::AddObject(object_paths, host, "Host", host_attrs, changes, false);
 				}
 
 				/* special condition: what if the host was blacklisted before, but the services should be generated? */
@@ -353,7 +353,7 @@ int NodeUpdateConfigCommand::Run(const boost::program_options::variables_map& vm
 					service_imports->Add("satellite-service"); //default service node template
 					service_attrs->Set("import", service_imports);
 
-					if (!RepositoryUtility::AddObject(object_paths, service, "Service", service_attrs, changes))
+					if (!RepositoryUtility::AddObject(object_paths, service, "Service", service_attrs, changes, false))
 						continue;
 				}
 			}
@@ -376,7 +376,7 @@ int NodeUpdateConfigCommand::Run(const boost::program_options::variables_map& vm
 		Log(LogInformation, "cli")
 		    << "Adding endpoint '" << endpoint << "' to the repository.";
 
-		if (!RepositoryUtility::AddObject(object_paths, endpoint, "Endpoint", endpoint_attrs, changes)) {
+		if (!RepositoryUtility::AddObject(object_paths, endpoint, "Endpoint", endpoint_attrs, changes, false)) {
 			Log(LogCritical, "cli")
 			    << "Cannot add node endpoint '" << endpoint << "' to the config repository!\n";
 		}
@@ -411,7 +411,7 @@ int NodeUpdateConfigCommand::Run(const boost::program_options::variables_map& vm
 		Log(LogInformation, "cli")
 		    << "Adding zone '" << zone << "' to the repository.";
 
-		if (!RepositoryUtility::AddObject(object_paths, zone, "Zone", zone_attrs, changes)) {
+		if (!RepositoryUtility::AddObject(object_paths, zone, "Zone", zone_attrs, changes, false)) {
 			Log(LogCritical, "cli")
 			    << "Cannot add node zone '" << zone << "' to the config repository!\n";
 		}
diff --git a/lib/cli/nodeutility.cpp b/lib/cli/nodeutility.cpp
index 648e4e0..8b27452 100644
--- a/lib/cli/nodeutility.cpp
+++ b/lib/cli/nodeutility.cpp
@@ -548,7 +548,7 @@ bool NodeUtility::CheckAgainstBlackAndWhiteList(const String& type, const String
 {
 	Array::Ptr lists = GetBlackAndWhiteList(type);
 
-	Log(LogInformation, "cli")
+	Log(LogNotice, "cli")
 	    << "Checking object against " << type << ".";
 
 	ObjectLock olock(lists);
diff --git a/lib/cli/repositoryutility.cpp b/lib/cli/repositoryutility.cpp
index 12a44f8..fe1c189 100644
--- a/lib/cli/repositoryutility.cpp
+++ b/lib/cli/repositoryutility.cpp
@@ -199,7 +199,8 @@ public:
 };
 
 /* modify objects and write changelog */
-bool RepositoryUtility::AddObject(const std::vector<String>& object_paths, const String& name, const String& type, const Dictionary::Ptr& attrs, const Array::Ptr& changes)
+bool RepositoryUtility::AddObject(const std::vector<String>& object_paths, const String& name, const String& type,
+    const Dictionary::Ptr& attrs, const Array::Ptr& changes, bool check_config)
 {
 	String pattern;
 
@@ -227,39 +228,41 @@ bool RepositoryUtility::AddObject(const std::vector<String>& object_paths, const
 	change->Set("command", "add");
 	change->Set("attrs", attrs);
 
-	String fname, fragment;
-	BOOST_FOREACH(boost::tie(fname, fragment), ConfigFragmentRegistry::GetInstance()->GetItems()) {
-		Expression *expression = ConfigCompiler::CompileText(fname, fragment);
-		if (expression) {
-			ScriptFrame frame;
-			expression->Evaluate(frame);
-			delete expression;
+	if (check_config) {
+		String fname, fragment;
+		BOOST_FOREACH(boost::tie(fname, fragment), ConfigFragmentRegistry::GetInstance()->GetItems()) {
+			Expression *expression = ConfigCompiler::CompileText(fname, fragment);
+			if (expression) {
+				ScriptFrame frame;
+				expression->Evaluate(frame);
+				delete expression;
+			}
 		}
-	}
-
-	ConfigType::Ptr ctype = ConfigType::GetByName(type);
-
-	if (!ctype)
-		Log(LogCritical, "cli")
-		    << "No validation type available for '" << type << "'.";
-	else {
-		Dictionary::Ptr vattrs = attrs->ShallowClone();
-		vattrs->Set("__name", vattrs->Get("name"));
-		vattrs->Remove("name");
-		vattrs->Remove("import");
-		vattrs->Set("type", type);
 
-		Type::Ptr dtype = Type::GetByName(type);
-
-		Object::Ptr object = dtype->Instantiate();
-		Deserialize(object, vattrs, false, FAConfig);
-
-		try {
-			RepositoryTypeRuleUtilities utils;
-			ctype->ValidateItem(name, object, DebugInfo(), &utils);
-		} catch (const ScriptError& ex) {
-			Log(LogCritical, "config", DiagnosticInformation(ex));
-			return false;
+		ConfigType::Ptr ctype = ConfigType::GetByName(type);
+
+		if (!ctype)
+			Log(LogCritical, "cli")
+			    << "No validation type available for '" << type << "'.";
+		else {
+			Dictionary::Ptr vattrs = attrs->ShallowClone();
+			vattrs->Set("__name", vattrs->Get("name"));
+			vattrs->Remove("name");
+			vattrs->Remove("import");
+			vattrs->Set("type", type);
+
+			Type::Ptr dtype = Type::GetByName(type);
+
+			Object::Ptr object = dtype->Instantiate();
+			Deserialize(object, vattrs, false, FAConfig);
+
+			try {
+				RepositoryTypeRuleUtilities utils;
+				ctype->ValidateItem(name, object, DebugInfo(), &utils);
+			} catch (const ScriptError& ex) {
+				Log(LogCritical, "config", DiagnosticInformation(ex));
+				return false;
+			}
 		}
 	}
 
diff --git a/lib/cli/repositoryutility.hpp b/lib/cli/repositoryutility.hpp
index 7e24cdd..ba6653d 100644
--- a/lib/cli/repositoryutility.hpp
+++ b/lib/cli/repositoryutility.hpp
@@ -52,7 +52,8 @@ public:
 
 	static void PrintChangeLog(std::ostream& fp);
 
-	static bool AddObject(const std::vector<String>& object_paths, const String& name, const String& type, const Dictionary::Ptr& attrs, const Array::Ptr& changes);
+	static bool AddObject(const std::vector<String>& object_paths, const String& name, const String& type, const Dictionary::Ptr& attrs,
+	    const Array::Ptr& changes, bool check_config = true);
 	static bool RemoveObject(const String& name, const String& type, const Dictionary::Ptr& attrs, const Array::Ptr& changes);
 
 	static bool CheckChangeExists(const Dictionary::Ptr& change, const Array::Ptr& changes);



More information about the icinga-checkins mailing list