Browse Source

[1976] Support for reloading master files

They are special-cased on loading and they need to be special-cased on
reloading too.
Michal 'vorner' Vaner 12 years ago
parent
commit
16f8257f25
2 changed files with 49 additions and 12 deletions
  1. 17 12
      src/lib/datasrc/client_list.cc
  2. 32 0
      src/lib/datasrc/tests/client_list_unittest.cc

+ 17 - 12
src/lib/datasrc/client_list.cc

@@ -280,19 +280,24 @@ ConfigurableClientList::reload(const Name& name) {
         return (ZONE_NOT_CACHED);
     }
     DataSourceClient* client(info->data_src_client_);
-    if (!client) {
-        isc_throw(isc::NotImplemented,
-                  "Reloading of master files not implemented yet. "
-                  "Next commit or so.");
-    }
-    // Now do the final reload. If it does not exist in client,
-    // DataSourceError is thrown, which is exactly the result what we
-    // want, so no need to handle it.
-    ZoneIteratorPtr iterator(client->getIterator(name));
-    if (!iterator) {
-        isc_throw(isc::Unexpected, "Null iterator from " << name);
+    if (client) {
+        // Now do the final reload. If it does not exist in client,
+        // DataSourceError is thrown, which is exactly the result what we
+        // want, so no need to handle it.
+        ZoneIteratorPtr iterator(client->getIterator(name));
+        if (!iterator) {
+            isc_throw(isc::Unexpected, "Null iterator from " << name);
+        }
+        finder->load(*iterator);
+    } else {
+        // The MasterFiles special case
+        const string filename(finder->getFileName());
+        if (filename.empty()) {
+            isc_throw(isc::Unexpected, "Confused about missing both filename "
+                      "and data source");
+        }
+        finder->load(filename);
     }
-    finder->load(*iterator);
     return (ZONE_RELOADED);
 }
 

+ 32 - 0
src/lib/datasrc/tests/client_list_unittest.cc

@@ -878,4 +878,36 @@ TEST_F(ListTest, reloadNullIterator) {
               list_->find(name).finder_->find(name, RRType::SOA())->code);
 }
 
+// Test we can reload the master files too (special-cased)
+TEST_F(ListTest, reloadMasterFile) {
+    const ConstElementPtr elem(Element::fromJSON("["
+        "{"
+        "   \"type\": \"MasterFiles\","
+        "   \"cache-enable\": true,"
+        "   \"params\": {"
+        "       \".\": \"" TEST_DATA_DIR "/root.zone\""
+        "   }"
+        "}]"));
+    list_->configure(elem, true);
+    // Add an element there so it differs from the one in file.
+    EXPECT_EQ(ZoneFinder::NXDOMAIN,
+              list_->find(Name(".")).finder_->find(Name("nosuchdomain"),
+                                                   RRType::TXT())->code);
+    RRsetPtr txt(new RRset(Name("nosuchdomain"), RRClass::IN(), RRType::TXT(),
+                                RRTTL(3600)));
+    txt->addRdata(rdata::generic::TXT("test"));
+    dynamic_pointer_cast<InMemoryZoneFinder>(list_->find(Name(".")).finder_)->
+        add(txt);
+    // It is here now.
+    EXPECT_EQ(ZoneFinder::SUCCESS,
+              list_->find(Name(".")).finder_->find(Name("nosuchdomain"),
+                                                   RRType::TXT())->code);
+    // Do the reload.
+    EXPECT_EQ(ConfigurableClientList::ZONE_RELOADED, list_->reload(Name(".")));
+    // And our TXT record disappeared again, as it is not in the file.
+    EXPECT_EQ(ZoneFinder::NXDOMAIN,
+              list_->find(Name(".")).finder_->find(Name("nosuchdomain"),
+                                                   RRType::TXT())->code);
+}
+
 }