Skip to content

Commit

Permalink
Cli: Don't validate config objects in 'node update-config'
Browse files Browse the repository at this point in the history
refs #8488
  • Loading branch information
dnsmichi committed Feb 20, 2015
1 parent d1d488a commit 4e1c754
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 39 deletions.
10 changes: 5 additions & 5 deletions lib/cli/nodeupdateconfigcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down Expand Up @@ -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? */
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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";
}
Expand Down Expand Up @@ -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";
}
Expand Down
2 changes: 1 addition & 1 deletion lib/cli/nodeutility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
67 changes: 35 additions & 32 deletions lib/cli/repositoryutility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ class RepositoryTypeRuleUtilities : public TypeRuleUtilities
};

/* 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;

Expand Down Expand Up @@ -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;
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion lib/cli/repositoryutility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ class RepositoryUtility

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);
Expand Down

0 comments on commit 4e1c754

Please sign in to comment.