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

refs #8488
This commit is contained in:
Michael Friedrich 2015-02-20 21:01:07 +01:00
parent d1d488a30d
commit 4e1c754786
4 changed files with 39 additions and 35 deletions

View File

@ -236,7 +236,7 @@ int NodeUpdateConfigCommand::Run(const boost::program_options::variables_map& vm
host_imports->Add("satellite-host"); //default host node template host_imports->Add("satellite-host"); //default host node template
host_attrs->Set("import", host_imports); 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") Log(LogCritical, "cli")
<< "Cannot add node host '" << zone << "' to the config repository!\n"; << "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_imports->Add("satellite-host"); //default host node template
host_attrs->Set("import", host_imports); 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? */ /* 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_imports->Add("satellite-service"); //default service node template
service_attrs->Set("import", service_imports); 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; continue;
} }
} }
@ -376,7 +376,7 @@ int NodeUpdateConfigCommand::Run(const boost::program_options::variables_map& vm
Log(LogInformation, "cli") Log(LogInformation, "cli")
<< "Adding endpoint '" << endpoint << "' to the repository."; << "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") Log(LogCritical, "cli")
<< "Cannot add node endpoint '" << endpoint << "' to the config repository!\n"; << "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") Log(LogInformation, "cli")
<< "Adding zone '" << zone << "' to the repository."; << "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") Log(LogCritical, "cli")
<< "Cannot add node zone '" << zone << "' to the config repository!\n"; << "Cannot add node zone '" << zone << "' to the config repository!\n";
} }

View File

@ -548,7 +548,7 @@ bool NodeUtility::CheckAgainstBlackAndWhiteList(const String& type, const String
{ {
Array::Ptr lists = GetBlackAndWhiteList(type); Array::Ptr lists = GetBlackAndWhiteList(type);
Log(LogInformation, "cli") Log(LogNotice, "cli")
<< "Checking object against " << type << "."; << "Checking object against " << type << ".";
ObjectLock olock(lists); ObjectLock olock(lists);

View File

@ -199,7 +199,8 @@ public:
}; };
/* modify objects and write changelog */ /* 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; String pattern;
@ -227,39 +228,41 @@ bool RepositoryUtility::AddObject(const std::vector<String>& object_paths, const
change->Set("command", "add"); change->Set("command", "add");
change->Set("attrs", attrs); change->Set("attrs", attrs);
String fname, fragment; if (check_config) {
BOOST_FOREACH(boost::tie(fname, fragment), ConfigFragmentRegistry::GetInstance()->GetItems()) { String fname, fragment;
Expression *expression = ConfigCompiler::CompileText(fname, fragment); BOOST_FOREACH(boost::tie(fname, fragment), ConfigFragmentRegistry::GetInstance()->GetItems()) {
if (expression) { Expression *expression = ConfigCompiler::CompileText(fname, fragment);
ScriptFrame frame; if (expression) {
expression->Evaluate(frame); ScriptFrame frame;
delete expression; expression->Evaluate(frame);
delete expression;
}
} }
}
ConfigType::Ptr ctype = ConfigType::GetByName(type); ConfigType::Ptr ctype = ConfigType::GetByName(type);
if (!ctype) if (!ctype)
Log(LogCritical, "cli") Log(LogCritical, "cli")
<< "No validation type available for '" << type << "'."; << "No validation type available for '" << type << "'.";
else { else {
Dictionary::Ptr vattrs = attrs->ShallowClone(); Dictionary::Ptr vattrs = attrs->ShallowClone();
vattrs->Set("__name", vattrs->Get("name")); vattrs->Set("__name", vattrs->Get("name"));
vattrs->Remove("name"); vattrs->Remove("name");
vattrs->Remove("import"); vattrs->Remove("import");
vattrs->Set("type", type); vattrs->Set("type", type);
Type::Ptr dtype = Type::GetByName(type); Type::Ptr dtype = Type::GetByName(type);
Object::Ptr object = dtype->Instantiate(); Object::Ptr object = dtype->Instantiate();
Deserialize(object, vattrs, false, FAConfig); Deserialize(object, vattrs, false, FAConfig);
try { try {
RepositoryTypeRuleUtilities utils; RepositoryTypeRuleUtilities utils;
ctype->ValidateItem(name, object, DebugInfo(), &utils); ctype->ValidateItem(name, object, DebugInfo(), &utils);
} catch (const ScriptError& ex) { } catch (const ScriptError& ex) {
Log(LogCritical, "config", DiagnosticInformation(ex)); Log(LogCritical, "config", DiagnosticInformation(ex));
return false; return false;
}
} }
} }

View File

@ -52,7 +52,8 @@ public:
static void PrintChangeLog(std::ostream& fp); 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 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); static bool CheckChangeExists(const Dictionary::Ptr& change, const Array::Ptr& changes);