Browse Source

[trac931] Tweaks of addRemoteConfig

Small refactoring, one more test
Michal 'vorner' Vaner 14 years ago
parent
commit
e3a81c18ff

+ 7 - 11
src/lib/config/ccsession.cc

@@ -370,14 +370,11 @@ ModuleCCSession::checkCommand() {
     return (0);
     return (0);
 }
 }
 
 
-std::string
-ModuleCCSession::fetchRemoteSpec(const std::string& module, bool is_filename,
-                                 ModuleSpec& spec)
-{
+ModuleSpec
+ModuleCCSession::fetchRemoteSpec(const std::string& module, bool is_filename) {
     if (is_filename) {
     if (is_filename) {
         // It is a filename, simply load it.
         // It is a filename, simply load it.
-        spec = readModuleSpecification(module);
-        return (spec.getModuleName());
+        return (readModuleSpecification(module));
     } else {
     } else {
         // It's module name, request it from config manager
         // It's module name, request it from config manager
 
 
@@ -394,12 +391,12 @@ ModuleCCSession::fetchRemoteSpec(const std::string& module, bool is_filename,
         ConstElementPtr spec_data = parseAnswer(rcode, answer);
         ConstElementPtr spec_data = parseAnswer(rcode, answer);
         if (rcode == 0 && spec_data) {
         if (rcode == 0 && spec_data) {
             // received OK, construct the spec out of it
             // received OK, construct the spec out of it
-            spec = ModuleSpec(spec_data);
+            ModuleSpec spec = ModuleSpec(spec_data);
             if (module != spec.getModuleName()) {
             if (module != spec.getModuleName()) {
                 // It's a different module!
                 // It's a different module!
                 isc_throw(CCSessionError, "Module name mismatch");
                 isc_throw(CCSessionError, "Module name mismatch");
             }
             }
-            return (module);
+            return (spec);
         } else {
         } else {
             isc_throw(CCSessionError, "Error getting config for " +
             isc_throw(CCSessionError, "Error getting config for " +
                       module + ": " + answer->str());
                       module + ": " + answer->str());
@@ -414,9 +411,8 @@ ModuleCCSession::addRemoteConfig(const std::string& spec_name,
                                  bool spec_is_filename)
                                  bool spec_is_filename)
 {
 {
     // First get the module name, specification and default config
     // First get the module name, specification and default config
-    ModuleSpec rmod_spec;
-    const std::string module_name(fetchRemoteSpec(spec_name, spec_is_filename,
-                                                  rmod_spec));
+    const ModuleSpec rmod_spec(fetchRemoteSpec(spec_name, spec_is_filename));
+    const std::string module_name(rmod_spec.getModuleName());
     ConfigData rmod_config(rmod_spec);
     ConfigData rmod_config(rmod_spec);
 
 
     // Get the current configuration values from config manager
     // Get the current configuration values from config manager

+ 1 - 2
src/lib/config/ccsession.h

@@ -340,8 +340,7 @@ private:
     void updateRemoteConfig(const std::string& module_name,
     void updateRemoteConfig(const std::string& module_name,
                             isc::data::ConstElementPtr new_config);
                             isc::data::ConstElementPtr new_config);
 
 
-    std::string fetchRemoteSpec(const std::string& module, bool is_filename,
-                                ModuleSpec& spec);
+    ModuleSpec fetchRemoteSpec(const std::string& module, bool is_filename);
 };
 };
 
 
 }
 }

+ 12 - 0
src/lib/config/tests/ccsession_unittests.cc

@@ -434,6 +434,18 @@ TEST_F(CCSessionTest, remoteConfig) {
     }
     }
 
 
     {
     {
+        SCOPED_TRACE("With bad module name");
+        // It is almost the same as above, but we supply wrong module name.
+        // It should fail.
+        // Try adding it with downloading the spec from config manager
+        ModuleSpec spec(moduleSpecFromFile(ccspecfile("spec2.spec")));
+        session.getMessages()->add(createAnswer(0, spec.getFullSpec()));
+
+        EXPECT_THROW(module_name = mccs.addRemoteConfig("Spec1", NULL, false),
+                     CCSessionError);
+    }
+
+    {
         // Try adding it with a handler.
         // Try adding it with a handler.
         // Pass non-default value to see the handler is called after
         // Pass non-default value to see the handler is called after
         // downloading the configuration, not too soon.
         // downloading the configuration, not too soon.