BIND 10 trac1976, updated. 9d269c5437c03247628e8d73ebda85a2e1e7ef72 [1976] Tests for reconfiguration and multiple lists

BIND 10 source code commits bind10-changes at lists.isc.org
Thu Jun 21 09:56:22 UTC 2012


The branch, trac1976 has been updated
       via  9d269c5437c03247628e8d73ebda85a2e1e7ef72 (commit)
       via  18da2727080b2f1c4fbac21fb46371fb11311264 (commit)
      from  0e5ceb2ea0871dfd07db2eb8548ba7454df0fa02 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 9d269c5437c03247628e8d73ebda85a2e1e7ef72
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Thu Jun 21 11:51:37 2012 +0200

    [1976] Tests for reconfiguration and multiple lists
    
    It works all by itself

commit 18da2727080b2f1c4fbac21fb46371fb11311264
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Thu Jun 21 11:36:52 2012 +0200

    [1976] Configuring a class the first time
    
    We can now create a list for a class and set it through configuration.

-----------------------------------------------------------------------

Summary of changes:
 src/bin/auth/auth_srv.cc                           |    6 +-
 src/bin/auth/auth_srv.h                            |    4 +-
 src/bin/auth/datasrc_configurator.h                |   20 +++++-
 .../auth/tests/datasrc_configurator_unittest.cc    |   75 +++++++++++++++++++-
 4 files changed, 97 insertions(+), 8 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/bin/auth/auth_srv.cc b/src/bin/auth/auth_srv.cc
index dc53f3c..5458316 100644
--- a/src/bin/auth/auth_srv.cc
+++ b/src/bin/auth/auth_srv.cc
@@ -1038,12 +1038,12 @@ AuthSrv::setClientList(const RRClass& rrclass,
     }
 }
 
-boost::shared_ptr<const ClientList>
-AuthSrv::getClientList(const RRClass& rrclass) const {
+boost::shared_ptr<ClientList>
+AuthSrv::getClientList(const RRClass& rrclass) {
     const map<RRClass, boost::shared_ptr<ClientList> >::const_iterator
         it(impl_->client_lists_.find(rrclass));
     if (it == impl_->client_lists_.end()) {
-        return (boost::shared_ptr<const ClientList>());
+        return (boost::shared_ptr<ClientList>());
     } else {
         return (it->second);
     }
diff --git a/src/bin/auth/auth_srv.h b/src/bin/auth/auth_srv.h
index 9be51a5..ff0ed5b 100644
--- a/src/bin/auth/auth_srv.h
+++ b/src/bin/auth/auth_srv.h
@@ -436,8 +436,8 @@ public:
     ///
     /// \param rrclass The class for which to get the list.
     /// \return The list, or NULL if no list is set for the class.
-    boost::shared_ptr<const isc::datasrc::ClientList>
-        getClientList(const isc::dns::RRClass& rrclass) const;
+    boost::shared_ptr<isc::datasrc::ClientList>
+        getClientList(const isc::dns::RRClass& rrclass);
 
     /// \brief Returns a list of classes that have a client list.
     ///
diff --git a/src/bin/auth/datasrc_configurator.h b/src/bin/auth/datasrc_configurator.h
index 40eb9ff..76c47a2 100644
--- a/src/bin/auth/datasrc_configurator.h
+++ b/src/bin/auth/datasrc_configurator.h
@@ -49,6 +49,7 @@ private:
     }
     static Server* server_;
     static isc::config::ModuleCCSession* session_;
+    typedef boost::shared_ptr<List> ListPtr;
 public:
     /// \brief Initializes the class.
     ///
@@ -108,8 +109,23 @@ public:
     /// \param config The configuration value to parse. It is in the form
     ///     as an update from the config manager.
     /// \throw InvalidOperation if it is called when not initialized.
-    static void reconfigure(const isc::data::ConstElementPtr& ) {
-
+    static void reconfigure(const isc::data::ConstElementPtr& config) {
+        // TODO: The InvalidOperation thing
+        typedef std::map<std::string, isc::data::ConstElementPtr> Map;
+        const Map& map(config->mapValue());
+        for (Map::const_iterator it(map.begin()); it != map.end(); ++ it) {
+            isc::dns::RRClass rrclass(it->first);
+            ListPtr list(server_->getClientList(rrclass));
+            bool need_set(false);
+            if (!list) {
+                list.reset(new List);
+                need_set = true;
+            }
+            list->configure(*it->second, true);
+            if (need_set) {
+                server_->setClientList(rrclass, list);
+            }
+        }
     }
 };
 
diff --git a/src/bin/auth/tests/datasrc_configurator_unittest.cc b/src/bin/auth/tests/datasrc_configurator_unittest.cc
index 107049a..d1f0383 100644
--- a/src/bin/auth/tests/datasrc_configurator_unittest.cc
+++ b/src/bin/auth/tests/datasrc_configurator_unittest.cc
@@ -19,27 +19,51 @@
 
 #include <gtest/gtest.h>
 #include <memory>
+#include <boost/shared_ptr.hpp>
 
 using namespace isc;
 using namespace isc::cc;
 using namespace isc::config;
 using namespace isc::data;
+using namespace isc::dns;
 using namespace std;
+using namespace boost;
 
 namespace {
 
 class DatasrcConfiguratorTest;
 
 class FakeList {
-
+public:
+    void configure(const Element& configuration, bool allow_cache) {
+        EXPECT_TRUE(allow_cache);
+        conf_ = configuration.get(0)->get("type")->stringValue();
+    }
+    const string& getConf() const {
+        return (conf_);
+    }
+private:
+    string conf_;
 };
 
+typedef shared_ptr<FakeList> ListPtr;
+
 // We use the test fixture as both parameters, this makes it possible
 // to easily fake all needed methods and look that they were called.
 typedef DataSourceConfiguratorGeneric<DatasrcConfiguratorTest,
         FakeList> Configurator;
 
 class DatasrcConfiguratorTest : public ::testing::Test {
+public:
+    // These pretend to be the server
+    ListPtr getClientList(const RRClass& rrclass) {
+        log_ += "get " + rrclass.toText() + "\n";
+        return (lists_[rrclass]);
+    }
+    void setClientList(const RRClass& rrclass, const ListPtr& list) {
+        log_ += "set " + rrclass.toText() + " " + list->getConf() + "\n";
+        lists_[rrclass] = list;
+    }
 protected:
     DatasrcConfiguratorTest() :
         session(ElementPtr(new ListElement), ElementPtr(new ListElement),
@@ -74,9 +98,21 @@ protected:
     void SetUp() {
         init();
     }
+    void doInInit() {
+        const ElementPtr
+            config(Element::fromJSON("{\"IN\": [{\"type\": \"xxx\"}]}"));
+        session.addMessage(createCommand("config_update", config), "data_sources",
+                           "*");
+        mccs->checkCommand();
+        // Check it called the correct things (check that there's no IN yet and
+        // set a new one.
+        EXPECT_EQ("get IN\nset IN xxx\n", log_);
+    }
     FakeSession session;
     auto_ptr<ModuleCCSession> mccs;
     const string specfile;
+    map<RRClass, ListPtr> lists_;
+    string log_;
 };
 
 // Check the initialization (and deinitialization)
@@ -97,4 +133,41 @@ TEST_F(DatasrcConfiguratorTest, initialization) {
     EXPECT_TRUE(session.haveSubscription("data_sources", "*"));
 }
 
+// Push there a configuration with a single list.
+TEST_F(DatasrcConfiguratorTest, createList) {
+    doInInit();
+}
+
+TEST_F(DatasrcConfiguratorTest, modifyList) {
+    // First, initialize the list
+    doInInit();
+    // And now change the configuration of the list
+    const ElementPtr
+        config(Element::fromJSON("{\"IN\": [{\"type\": \"yyy\"}]}"));
+    session.addMessage(createCommand("config_update", config), "data_sources",
+                       "*");
+    log_ = "";
+    mccs->checkCommand();
+    // This one does not set
+    EXPECT_EQ("get IN\n", log_);
+    // But this should contain the yyy configuration
+    EXPECT_EQ("yyy", lists_[RRClass::IN()]->getConf());
+}
+
+// Check we can have multiple lists at once
+TEST_F(DatasrcConfiguratorTest, multiple) {
+    const ElementPtr
+        config(Element::fromJSON("{\"IN\": [{\"type\": \"yyy\"}], "
+                                 "\"CH\": [{\"type\": \"xxx\"}]}"));
+    session.addMessage(createCommand("config_update", config), "data_sources",
+                       "*");
+    mccs->checkCommand();
+    // This one does not set
+    EXPECT_EQ("get CH\nset CH xxx\nget IN\nset IN yyy\n", log_);
+    // We should have both there
+    EXPECT_EQ("yyy", lists_[RRClass::IN()]->getConf());
+    EXPECT_EQ("xxx", lists_[RRClass::CH()]->getConf());
+    EXPECT_EQ(2, lists_.size());
+}
+
 }



More information about the bind10-changes mailing list