Browse Source

[5151] Some small fixes

Francis Dupont 8 years ago
parent
commit
3bd3068be8

+ 0 - 2
src/bin/dhcp4/ctrl_dhcp4_srv.cc

@@ -77,8 +77,6 @@ ControlledDhcpv4Srv::commandConfigGetHandler(const string&,
 ConstElementPtr
 ConstElementPtr
 ControlledDhcpv4Srv::commandConfigWriteHandler(const string&,
 ControlledDhcpv4Srv::commandConfigWriteHandler(const string&,
                                                ConstElementPtr args) {
                                                ConstElementPtr args) {
-    ConstElementPtr config = CfgMgr::instance().getCurrentCfg()->toElement();
-
     string filename;
     string filename;
 
 
     if (args) {
     if (args) {

+ 15 - 11
src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc

@@ -208,14 +208,14 @@ public:
     /// @param command command expected to be on the list.
     /// @param command command expected to be on the list.
     void checkListCommands(const ConstElementPtr& rsp, const std::string& command) {
     void checkListCommands(const ConstElementPtr& rsp, const std::string& command) {
         ConstElementPtr params;
         ConstElementPtr params;
-        int status_code;
+        int status_code = -1;
         EXPECT_NO_THROW(params = parseAnswer(status_code, rsp));
         EXPECT_NO_THROW(params = parseAnswer(status_code, rsp));
         EXPECT_EQ(CONTROL_RESULT_SUCCESS, status_code);
         EXPECT_EQ(CONTROL_RESULT_SUCCESS, status_code);
         ASSERT_TRUE(params);
         ASSERT_TRUE(params);
         ASSERT_EQ(Element::list, params->getType());
         ASSERT_EQ(Element::list, params->getType());
 
 
         int cnt = 0;
         int cnt = 0;
-        for (int i=0; i < params->size(); ++i) {
+        for (size_t i = 0; i < params->size(); ++i) {
             string tmp = params->get(i)->stringValue();
             string tmp = params->get(i)->stringValue();
             if (tmp == command) {
             if (tmp == command) {
                 // Command found, but that's not enough. Need to continue working
                 // Command found, but that's not enough. Need to continue working
@@ -237,7 +237,7 @@ public:
     void checkConfigWrite(const std::string& response_txt, int exp_status,
     void checkConfigWrite(const std::string& response_txt, int exp_status,
                           const std::string& exp_txt = "") {
                           const std::string& exp_txt = "") {
 
 
-        cout << "#### response=" << response_txt << endl;
+        // cout << "#### response=" << response_txt << endl;
 
 
         ConstElementPtr rsp;
         ConstElementPtr rsp;
         EXPECT_NO_THROW(rsp = Element::fromJSON(response_txt));
         EXPECT_NO_THROW(rsp = Element::fromJSON(response_txt));
@@ -253,13 +253,13 @@ public:
             // The parameters must include filename
             // The parameters must include filename
             ASSERT_TRUE(params);
             ASSERT_TRUE(params);
             ASSERT_TRUE(params->get("filename"));
             ASSERT_TRUE(params->get("filename"));
-            EXPECT_EQ(Element::string, params->get("filename")->getType());
+            ASSERT_EQ(Element::string, params->get("filename")->getType());
             EXPECT_EQ(exp_txt, params->get("filename")->stringValue());
             EXPECT_EQ(exp_txt, params->get("filename")->stringValue());
 
 
             // The parameters must include size. And the size
             // The parameters must include size. And the size
             // must indicate some content.
             // must indicate some content.
             ASSERT_TRUE(params->get("size"));
             ASSERT_TRUE(params->get("size"));
-            EXPECT_EQ(Element::integer, params->get("size")->getType());
+            ASSERT_EQ(Element::integer, params->get("size")->getType());
             int64_t size = params->get("size")->intValue();
             int64_t size = params->get("size")->intValue();
             EXPECT_LE(1, size);
             EXPECT_LE(1, size);
 
 
@@ -271,9 +271,13 @@ public:
             // Now check that it is the correct size as reported.
             // Now check that it is the correct size as reported.
             EXPECT_EQ(size, static_cast<int64_t>(f.tellg()));
             EXPECT_EQ(size, static_cast<int64_t>(f.tellg()));
 
 
-            // Finally, check that it's really a JSON.
-            ElementPtr from_file = Element::fromJSONFile(exp_txt);
-            ASSERT_TRUE(from_file);
+            // Check that it's really a JSON.
+            ElementPtr from_file = parseJSON(exp_txt);
+            EXPECT_TRUE(from_file);
+
+            // Finally check it is a DHCPv4 config
+            EXPECT_NO_THROW(from_file = parseDHCP4(exp_txt, true));
+            EXPECT_TRUE(from_file);
         } else if (exp_status == CONTROL_RESULT_ERROR) {
         } else if (exp_status == CONTROL_RESULT_ERROR) {
 
 
             // Let's check if the reason for failure was given.
             // Let's check if the reason for failure was given.
@@ -739,9 +743,9 @@ TEST_F(CtrlChannelDhcpv4SrvTest, listCommands) {
     checkListCommands(rsp, "statistic-reset-all");
     checkListCommands(rsp, "statistic-reset-all");
 }
 }
 
 
-// Tests if the server returns its configuration using get-config.
+// Tests if the server returns its configuration using config-get.
 // Note there are separate tests that verify if toElement() called by the
 // Note there are separate tests that verify if toElement() called by the
-// get-config handler are actually converting the configuration correctly.
+// config-get handler are actually converting the configuration correctly.
 TEST_F(CtrlChannelDhcpv4SrvTest, configGet) {
 TEST_F(CtrlChannelDhcpv4SrvTest, configGet) {
     createUnixChannelServer();
     createUnixChannelServer();
     std::string response;
     std::string response;
@@ -759,7 +763,7 @@ TEST_F(CtrlChannelDhcpv4SrvTest, configGet) {
 
 
     // Ok, now roughly check if the response seems legit.
     // Ok, now roughly check if the response seems legit.
     ASSERT_TRUE(cfg);
     ASSERT_TRUE(cfg);
-    EXPECT_EQ(Element::map, cfg->getType());
+    ASSERT_EQ(Element::map, cfg->getType());
     EXPECT_TRUE(cfg->get("Dhcp4"));
     EXPECT_TRUE(cfg->get("Dhcp4"));
 }
 }
 
 

+ 0 - 2
src/bin/dhcp6/ctrl_dhcp6_srv.cc

@@ -81,8 +81,6 @@ ControlledDhcpv6Srv::commandConfigGetHandler(const string&,
 
 
 ConstElementPtr
 ConstElementPtr
 ControlledDhcpv6Srv::commandConfigWriteHandler(const string&, ConstElementPtr args) {
 ControlledDhcpv6Srv::commandConfigWriteHandler(const string&, ConstElementPtr args) {
-    ConstElementPtr config = CfgMgr::instance().getCurrentCfg()->toElement();
-
     string filename;
     string filename;
 
 
     if (args) {
     if (args) {

+ 13 - 9
src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc

@@ -221,14 +221,14 @@ public:
     /// @param command command expected to be on the list.
     /// @param command command expected to be on the list.
     void checkListCommands(const ConstElementPtr& rsp, const std::string& command) {
     void checkListCommands(const ConstElementPtr& rsp, const std::string& command) {
         ConstElementPtr params;
         ConstElementPtr params;
-        int status_code;
+        int status_code = -1;
         EXPECT_NO_THROW(params = parseAnswer(status_code, rsp));
         EXPECT_NO_THROW(params = parseAnswer(status_code, rsp));
         EXPECT_EQ(CONTROL_RESULT_SUCCESS, status_code);
         EXPECT_EQ(CONTROL_RESULT_SUCCESS, status_code);
         ASSERT_TRUE(params);
         ASSERT_TRUE(params);
         ASSERT_EQ(Element::list, params->getType());
         ASSERT_EQ(Element::list, params->getType());
 
 
         int cnt = 0;
         int cnt = 0;
-        for (int i=0; i < params->size(); ++i) {
+        for (size_t i = 0; i < params->size(); ++i) {
             string tmp = params->get(i)->stringValue();
             string tmp = params->get(i)->stringValue();
             if (tmp == command) {
             if (tmp == command) {
                 // Command found, but that's not enough. Need to continue working
                 // Command found, but that's not enough. Need to continue working
@@ -264,13 +264,13 @@ public:
             // The parameters must include filename
             // The parameters must include filename
             ASSERT_TRUE(params);
             ASSERT_TRUE(params);
             ASSERT_TRUE(params->get("filename"));
             ASSERT_TRUE(params->get("filename"));
-            EXPECT_EQ(Element::string, params->get("filename")->getType());
+            ASSERT_EQ(Element::string, params->get("filename")->getType());
             EXPECT_EQ(exp_txt, params->get("filename")->stringValue());
             EXPECT_EQ(exp_txt, params->get("filename")->stringValue());
 
 
             // The parameters must include size. And the size
             // The parameters must include size. And the size
             // must indicate some content.
             // must indicate some content.
             ASSERT_TRUE(params->get("size"));
             ASSERT_TRUE(params->get("size"));
-            EXPECT_EQ(Element::integer, params->get("size")->getType());
+            ASSERT_EQ(Element::integer, params->get("size")->getType());
             int64_t size = params->get("size")->intValue();
             int64_t size = params->get("size")->intValue();
             EXPECT_LE(1, size);
             EXPECT_LE(1, size);
 
 
@@ -282,9 +282,13 @@ public:
             // Now check that it is the correct size as reported.
             // Now check that it is the correct size as reported.
             EXPECT_EQ(size, static_cast<int64_t>(f.tellg()));
             EXPECT_EQ(size, static_cast<int64_t>(f.tellg()));
 
 
-            // Finally, check that it's really a JSON.
-            ElementPtr from_file = Element::fromJSONFile(exp_txt);
-            ASSERT_TRUE(from_file);
+            // Check that it's really a JSON.
+            ElementPtr from_file = parseJSON(exp_txt);
+            EXPECT_TRUE(from_file);
+
+            // Finally check it is a DHCPv6 config
+            EXPECT_NO_THROW(from_file = parseDHCP6(exp_txt, true));
+            EXPECT_TRUE(from_file);
         } else if (exp_status == CONTROL_RESULT_ERROR) {
         } else if (exp_status == CONTROL_RESULT_ERROR) {
 
 
             // Let's check if the reason for failure was given.
             // Let's check if the reason for failure was given.
@@ -823,9 +827,9 @@ TEST_F(CtrlChannelDhcpv6SrvTest, commandsList) {
     checkListCommands(rsp, "statistic-reset-all");
     checkListCommands(rsp, "statistic-reset-all");
 }
 }
 
 
-// Tests if the server returns its configuration using get-config.
+// Tests if the server returns its configuration using config-get.
 // Note there are separate tests that verify if toElement() called by the
 // Note there are separate tests that verify if toElement() called by the
-// config-get handler are actually converting the configuration correctly.
+// get-config handler are actually converting the configuration correctly.
 TEST_F(CtrlChannelDhcpv6SrvTest, configGet) {
 TEST_F(CtrlChannelDhcpv6SrvTest, configGet) {
     createUnixChannelServer();
     createUnixChannelServer();
     std::string response;
     std::string response;