From 4e1c754786b9d9b851e666cd58369b23e46011c6 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Fri, 20 Feb 2015 21:01:07 +0100 Subject: [PATCH] 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 741800def..905f57858 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 648e4e0ca..8b2745205 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 12a44f868..fe1c1891d 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& object_paths, const String& name, const String& type, const Dictionary::Ptr& attrs, const Array::Ptr& changes) +bool RepositoryUtility::AddObject(const std::vector& 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& 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 7e24cdd7f..ba6653d00 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& object_paths, const String& name, const String& type, const Dictionary::Ptr& attrs, const Array::Ptr& changes); + static bool AddObject(const std::vector& 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); -- 2.49.0