Browse Source

[3508] Changes after review

 - Daemon::getVersion() added
 - exists => exits in docs
 - fixed comment in dhcp_test_lib.sh.in
Tomek Mrugalski 10 years ago
parent
commit
3f46c74ffa

+ 2 - 2
doc/guide/ddns.xml

@@ -82,13 +82,13 @@
           </listitem>
           <listitem>
             <simpara>
-              <command>-v</command> - prints out Kea version and exists.
+              <command>-v</command> - prints out Kea version and exits.
             </simpara>
           </listitem>
           <listitem>
             <simpara>
               <command>-V</command> - prints out Kea extended version with
-              additional parameters and exists.
+              additional parameters and exits.
             </simpara>
           </listitem>
       </itemizedlist>

+ 2 - 2
doc/guide/dhcp4-srv.xml

@@ -46,13 +46,13 @@
           </listitem>
           <listitem>
             <simpara>
-              <command>-v</command> - prints out Kea version and exists.
+              <command>-v</command> - prints out Kea version and exits.
             </simpara>
           </listitem>
           <listitem>
             <simpara>
               <command>-V</command> - prints out Kea extended version with
-              additional parameters and exists.
+              additional parameters and exits.
             </simpara>
           </listitem>
       </itemizedlist>

+ 2 - 2
doc/guide/dhcp6-srv.xml

@@ -44,13 +44,13 @@
           </listitem>
           <listitem>
             <simpara>
-              <command>-v</command> - prints out Kea version and exists.
+              <command>-v</command> - prints out Kea version and exits.
             </simpara>
           </listitem>
           <listitem>
             <simpara>
               <command>-V</command> - prints out Kea extended version with
-              additional parameters and exists.
+              additional parameters and exits.
             </simpara>
           </listitem>
       </itemizedlist>

+ 22 - 18
src/bin/d2/d_controller.cc

@@ -125,20 +125,6 @@ DControllerBase::launch(int argc, char* argv[], const bool test_mode) {
 }
 
 void
-DControllerBase::printVersion(bool extended) const {
-    std::cout << VERSION << std::endl;
-    if (extended) {
-        std::cout << EXTENDED_VERSION << std::endl;
-
-        // @todo print more details (is it Botan or OpenSSL build,
-        // with or without MySQL/Postgres? What compilation options were
-        // used? etc)
-    }
-
-    exit(EXIT_SUCCESS);
-}
-
-void
 DControllerBase::parseArgs(int argc, char* argv[])
 {
     // Iterate over the given command line options. If its a stock option
@@ -156,12 +142,14 @@ DControllerBase::parseArgs(int argc, char* argv[])
             break;
 
         case 'v':
-            printVersion(false); // print just Kea version and exit
-            break; // break not really needed, print_version never returns
+            // Print just Kea version and exit
+            std::cout << getVersion(false) << std::endl;
+            exit(EXIT_SUCCESS);
 
         case 'V':
-            printVersion(true); // print extended Kea version and exit
-            break; // break not really needed, print_version never returns
+            // Print extended Kea version and exit
+            std::cout << getVersion(true) << std::endl;
+            exit(EXIT_SUCCESS);
             
         case 'c':
             // config file name
@@ -448,3 +436,19 @@ dhcp::Daemon::loggerInit(const char* log_name, bool verbose) {
 }
 
 }; // namespace isc
+
+std::string
+isc::dhcp::Daemon::getVersion(bool extended) {
+    std::stringstream tmp;
+
+    tmp << VERSION;
+    if (extended) {
+        tmp << std::endl << EXTENDED_VERSION;
+
+        // @todo print more details (is it Botan or OpenSSL build,
+        // with or without MySQL/Postgres? What compilation options were
+        // used? etc)
+    }
+
+    return (tmp.str());
+}

+ 0 - 6
src/bin/d2/d_controller.h

@@ -457,12 +457,6 @@ protected:
     /// This is intended to be used for specific usage violation messages.
     void usage(const std::string& text);
 
-    /// @brief Prints version number to stdout and exit.
-    ///
-    /// Note: This method never returns, it terminates the process.
-    /// @param extended print additional information?
-    void printVersion(bool extended) const;
-
 private:
     /// @brief Name of the service under control.
     /// This name is used as the configuration module name and appears in log

+ 16 - 0
src/bin/dhcp4/dhcp4_srv.cc

@@ -2032,5 +2032,21 @@ Dhcpv4Srv::d2ClientErrorHandler(const
     CfgMgr::instance().getD2ClientMgr().suspendUpdates();
 }
 
+std::string
+Daemon::getVersion(bool extended) {
+    std::stringstream tmp;
+
+    tmp << VERSION;
+    if (extended) {
+        tmp << endl << EXTENDED_VERSION;
+
+        // @todo print more details (is it Botan or OpenSSL build,
+        // with or without MySQL/Postgres? What compilation options were
+        // used? etc)
+    }
+
+    return (tmp.str());
+}
+
 }   // namespace dhcp
 }   // namespace isc

+ 4 - 22
src/bin/dhcp4/main.cc

@@ -60,24 +60,6 @@ usage() {
 }
 } // end of anonymous namespace
 
-/// @brief Prints Kea version on stdout and exits.
-///
-/// Note: This function never returns. It terminates the process.
-/// @param extended print additional information?
-void
-printVersion(bool extended) {
-    cout << VERSION << endl;
-    if (extended) {
-        cout << EXTENDED_VERSION << endl;
-
-        // @todo print more details (is it Botan or OpenSSL build,
-        // with or without MySQL/Postgres? What compilation options were
-        // used? etc)
-    }
-
-    exit(EXIT_SUCCESS);
-}
-
 int
 main(int argc, char* argv[]) {
     int ch;
@@ -95,12 +77,12 @@ main(int argc, char* argv[]) {
             break;
 
         case 'v':
-            printVersion(false); // print just Kea version and exit
-            break; // break not really needed, print_version never returns
+            cout << Daemon::getVersion(false) << endl;
+            return (EXIT_SUCCESS);
 
         case 'V':
-            printVersion(true); // print extended Kea version and exit
-            break; // break not really needed, print_version never returns
+            cout << Daemon::getVersion(false) << endl;
+            return (EXIT_SUCCESS);
 
         case 'p':
             try {

+ 16 - 0
src/bin/dhcp6/dhcp6_srv.cc

@@ -2692,5 +2692,21 @@ Dhcpv6Srv::d2ClientErrorHandler(const
     CfgMgr::instance().getD2ClientMgr().suspendUpdates();
 }
 
+std::string
+Daemon::getVersion(bool extended) {
+    std::stringstream tmp;
+
+    tmp << VERSION;
+    if (extended) {
+        tmp << endl << EXTENDED_VERSION;
+
+        // @todo print more details (is it Botan or OpenSSL build,
+        // with or without MySQL/Postgres? What compilation options were
+        // used? etc)
+    }
+
+    return (tmp.str());
+}
+
 };
 };

+ 4 - 22
src/bin/dhcp6/main.cc

@@ -60,24 +60,6 @@ usage() {
 }
 } // end of anonymous namespace
 
-/// @brief Prints Kea version on stdout and exits.
-///
-/// Note: This function never returns. It terminates the process.
-/// @param extended print additional information?
-void
-printVersion(bool extended) {
-    cout << VERSION << endl;
-    if (extended) {
-        cout << EXTENDED_VERSION << endl;
-
-        // @todo print more details (is it Botan or OpenSSL build,
-        // with or without MySQL/Postgres? What compilation options were
-        // used? etc)
-    }
-
-    exit(EXIT_SUCCESS);
-}
-
 int
 main(int argc, char* argv[]) {
     int ch;
@@ -95,12 +77,12 @@ main(int argc, char* argv[]) {
             break;
 
         case 'v':
-            printVersion(false); // print just Kea version and exit
-            break; // break not really needed, print_version never returns
+            cout << Daemon::getVersion(false) << endl;
+            return (EXIT_SUCCESS);
 
         case 'V':
-            printVersion(true); // print extended Kea version and exit
-            break; // break not really needed, print_version never returns
+            cout << Daemon::getVersion(true) << endl;
+            return (EXIT_SUCCESS);
 
         case 'p': // port number
             try {

+ 11 - 0
src/lib/dhcpsrv/daemon.h

@@ -151,6 +151,17 @@ public:
         return (verbose_);
     }
 
+    /// @brief returns Kea version on stdout and exits.
+    ///
+    /// With extended == false, this method returns a simple string
+    /// containing version number. With extended == true, it returns
+    /// also additional information about sources. It is expected to
+    /// return extra information about dependencies and used DB backends.
+    ///
+    /// @param extended print additional information?
+    /// @return text string
+    static std::string getVersion(bool extended);
+
 protected:
 
     /// @brief Invokes handler for the next received signal.

+ 9 - 0
src/lib/dhcpsrv/tests/daemon_unittest.cc

@@ -23,8 +23,17 @@ using namespace isc;
 using namespace isc::dhcp;
 using namespace isc::data;
 
+std::string isc::dhcp::Daemon::getVersion(bool extended) {
+    if (extended) {
+        return (std::string("EXTENDED"));
+    } else {
+        return (std::string("BASIC"));
+    }
+}
+
 namespace {
 
+
 // Very simple test. Checks whether Daemon can be instantiated and its
 // default parameters are sane
 TEST(DaemonTest, constructor) {

+ 1 - 1
src/lib/testutils/dhcp_test_lib.sh.in

@@ -402,7 +402,7 @@ must be a number"
     kill -${sig} ${_GET_PIDS}
 }
 
-# This test verifies that DHCPv4 server is reporting its version properly.
+# This test verifies that the binary is reporting its version properly.
 version_test() {
     test_name=${1}  # Test name