Browse Source

[trac3664] Cleanup

Cleanup spaces and such to meet coding specs

Remove testing artifacts

Update man page documenation
Shawn Routhier 10 years ago
parent
commit
4cbdce8e5e
5 changed files with 196 additions and 177 deletions
  1. 71 9
      src/bin/lfc/kea-lfc.xml
  2. 69 92
      src/bin/lfc/lfc.cc
  3. 2 19
      src/bin/lfc/lfc.h
  4. 1 2
      src/bin/lfc/main.cc
  5. 53 55
      src/bin/lfc/tests/lfc_controller_unittests.cc

+ 71 - 9
src/bin/lfc/kea-lfc.xml

@@ -44,18 +44,18 @@
   <refsynopsisdiv>
     <cmdsynopsis>
       <command>kea-lfc</command>
+      <arg><option>-4|-6</option></arg>
+      <arg><option>-c <replaceable class="parameter">config-file</replaceable></option></arg>
+      <arg><option>-p <replaceable class="parameter">previous-file</replaceable></option></arg>
+      <arg><option>-i <replaceable class="parameter">copy-file</replaceable></option></arg>
+      <arg><option>-o <replaceable class="parameter">output-file</replaceable></option></arg>
+      <arg><option>-f <replaceable class="parameter">finish-file</replaceable></option></arg>
       <arg><option>-v</option></arg>
+      <arg><option>-V</option></arg>
+      <arg><option>-d</option></arg>
     </cmdsynopsis>
   </refsynopsisdiv>
 
-  <refsynopsisdiv>
-    <cmdsynopsis>
-      <command>kea-lfc</command>
-      <arg><option>-s</option></arg>
-    </cmdsynopsis>
-  </refsynopsisdiv>
-
-
   <refsect1>
     <title>DESCRIPTION</title>
     <para>
@@ -76,7 +76,7 @@
     <variablelist>
 
       <varlistentry>
-        <term><option>-v</option></term>
+        <term><option>-d</option></term>
         <listitem><para>
           Verbose mode sets the logging level to debug. This is primarily
           for development purposes in stand-alone mode.
@@ -84,6 +84,27 @@
       </varlistentry>
 
       <varlistentry>
+        <term><option>-v</option></term>
+        <listitem><para>
+          version causes the version stamp to be printed.
+        </para></listitem>
+      </varlistentry>
+
+      <varlistentry>
+        <term><option>-V</option></term>
+        <listitem><para>
+          Version causes a longer form of the version stamp to be printed.
+        </para></listitem>
+      </varlistentry>
+
+      <varlistentry>
+        <term><option>-4 | -6</option></term>
+        <listitem><para>
+          The protocol version of the lease files, must be one of 4 or 6.
+        </para></listitem>
+      </varlistentry>
+
+      <varlistentry>
         <term><option>-c</option></term>
         <listitem><para>
           Configuration file including the configuration for LFC process.
@@ -91,6 +112,47 @@
         </para></listitem>
       </varlistentry>
 
+      <varlistentry>
+        <term><option>-p</option></term>
+        <listitem><para>
+          Previous lease file - When LFC starts this is the result of any previous
+	  run of LFC.
+        </para></listitem>
+      </varlistentry>
+
+      <varlistentry>
+        <term><option>-i</option></term>
+        <listitem><para>
+          Input or copy of lease file - Before the DHCP serves invokes LFC it will move
+	  the current lease file to this file and then call LFC with the new file.
+        </para></listitem>
+      </varlistentry>
+
+      <varlistentry>
+        <term><option>-o</option></term>
+        <listitem><para>
+          Output lease file - The temporary file LFC should use to write the leases.
+          Upon completion this file will be moved to the finish file (see below).
+        </para></listitem>
+      </varlistentry>
+
+      <varlistentry>
+        <term><option>-f</option></term>
+        <listitem><para>
+          Finish or completion file - Another temporary file LFC uses for bookkeeping.
+          When LFC completes writing the output file it moves it to this file name.
+          After LFC finishes deleting the other files (previous and input) it moves
+          this file to previous lease file.
+        </para></listitem>
+      </varlistentry>
+
+      <varlistentry>
+        <term><option>-c</option></term>
+        <listitem><para>
+          
+        </para></listitem>
+      </varlistentry>
+
     </variablelist>
   </refsect1>
 

+ 69 - 92
src/bin/lfc/lfc.cc

@@ -12,11 +12,11 @@
 // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 // PERFORMANCE OF THIS SOFTWARE.
 
-#include <config.h>
 #include <lfc/lfc.h>
 #include <exceptions/exceptions.h>
 #include <log/logger_support.h>
 #include <log/logger_manager.h>
+#include <config.h>
 #include <iostream>
 
 using namespace std;
@@ -33,12 +33,10 @@ const char* lfcController::lfc_bin_name_ = "kea-lfc";
 
 lfcController::lfcController()
     : protocol_version_(0), verbose_(false), config_file_(""), previous_file_(""),
-      copy_file_(""), output_file_(""), finish_file_(""), pid_file_("./test_pid") {
-    std::cerr << "created lfc" << std::endl;
+      copy_file_(""), output_file_(""), finish_file_(""), pid_file_("") {
 }
 
 lfcController::~lfcController() {
-    std::cerr << "destroyed lfc" << std::endl;
 }
 
 void
@@ -49,85 +47,82 @@ lfcController::launch(int argc, char* argv[], const bool test_mode) {
     usage(ex.what());
     throw;  // rethrow it
   }
-
-  std::cerr << "launched lfc" << std::endl;
 }
 
 void
-lfcController::parseArgs(int argc, char* argv[])
-{
+lfcController::parseArgs(int argc, char* argv[]) {
     int ch;
 
     while ((ch = getopt(argc, argv, "46dvVp:i:o:c:f:")) != -1) {
         switch (ch) {
-	case '4':
+        case '4':
             // Process DHCPv4 lease files.
             protocol_version_ = 4;
             break;
 
-	case '6':
+        case '6':
             // Process DHCPv6 lease files.
             protocol_version_ = 6;
             break;
 
-	case 'v':
+        case 'v':
             // Print just Kea vesion and exit.
-	    std::cout << getVersion(false) << std::endl;
+            std::cout << getVersion(false) << std::endl;
             exit(EXIT_SUCCESS);
 
-	case 'V':
+        case 'V':
             // Print extended  Kea vesion and exit.
-	    std::cout << getVersion(true) << std::endl;
+            std::cout << getVersion(true) << std::endl;
             exit(EXIT_SUCCESS);
 
-	case 'd':
-	    // Verbose output.
-	    verbose_ = true;
-	    break;
-
-	case 'p':
-	    // Previous file name.
-	    if (optarg == NULL) {
-	        isc_throw(InvalidUsage, "Previous file name missing");
-	    }
-	    previous_file_ = optarg;
-	    break;
-	    
-	case 'i':
-	    // Copy file name.
-	    if (optarg == NULL) {
-	        isc_throw(InvalidUsage, "Copy file name missing");
-	    }
-	    copy_file_ = optarg;
-	    break;
-
-	case 'o':
-	    // Output file name.
-	    if (optarg == NULL) {
-	        isc_throw(InvalidUsage, "Output file name missing");
-	    }
-	    output_file_ = optarg;
-	    break;
-
-	case 'f':
-	    // Output file name.
-	    if (optarg == NULL) {
-	        isc_throw(InvalidUsage, "Finish file name missing");
-	    }
-	    finish_file_ = optarg;
-	    break;
-
-	case 'c':
-	    // Previous file name.
-	    if (optarg == NULL) {
-	        isc_throw(InvalidUsage, "Configuration file name missing");
-	    }
-	    config_file_ = optarg;
-	    break;
-
-	default:
-	    usage("");
-	}
+        case 'd':
+            // Verbose output.
+            verbose_ = true;
+            break;
+
+        case 'p':
+            // Previous file name.
+            if (optarg == NULL) {
+                isc_throw(InvalidUsage, "Previous file name missing");
+            }
+            previous_file_ = optarg;
+            break;
+
+        case 'i':
+            // Copy file name.
+            if (optarg == NULL) {
+                isc_throw(InvalidUsage, "Copy file name missing");
+            }
+            copy_file_ = optarg;
+            break;
+
+        case 'o':
+            // Output file name.
+            if (optarg == NULL) {
+                isc_throw(InvalidUsage, "Output file name missing");
+            }
+            output_file_ = optarg;
+            break;
+
+        case 'f':
+            // Output file name.
+            if (optarg == NULL) {
+                isc_throw(InvalidUsage, "Finish file name missing");
+            }
+            finish_file_ = optarg;
+            break;
+
+        case 'c':
+            // Previous file name.
+            if (optarg == NULL) {
+                isc_throw(InvalidUsage, "Configuration file name missing");
+            }
+            config_file_ = optarg;
+            break;
+
+        default:
+            usage("");
+        }
     }
 
     // Check for extraneous parameters.
@@ -140,57 +135,39 @@ lfcController::parseArgs(int argc, char* argv[])
     }
 
     if (previous_file_.empty()) {
-        isc_throw(InvalidUsage, "Previous file not specified");	
+        isc_throw(InvalidUsage, "Previous file not specified");
     }
 
     if (copy_file_.empty()) {
-        isc_throw(InvalidUsage, "Copy file not specified");	
+        isc_throw(InvalidUsage, "Copy file not specified");
     }
 
     if (output_file_.empty()) {
-        isc_throw(InvalidUsage, "Output file not specified");	
+        isc_throw(InvalidUsage, "Output file not specified");
     }
 
     if (finish_file_.empty()) {
-        isc_throw(InvalidUsage, "Finish file not specified");	
+        isc_throw(InvalidUsage, "Finish file not specified");
     }
 
     if (config_file_.empty()) {
-        isc_throw(InvalidUsage, "Config file not specified");	
+        isc_throw(InvalidUsage, "Config file not specified");
     }
 
     // If verbose is set echo the input information
     if (verbose_ == true) {
       std::cerr << "Protocol version:    " << protocol_version_ << std::endl
-	        << "Previous lease file: " << previous_file_ << std::endl
-	        << "Copy lease file:     " << copy_file_ << std::endl
-	        << "Output lease file:   " << output_file_ << std::endl
-	        << "Finishn file:        " << finish_file_ << std::endl
-	        << "Config file:         " << config_file_ << std::endl
-	        << "PID file:            " << pid_file_ << std::endl;
+                << "Previous lease file: " << previous_file_ << std::endl
+                << "Copy lease file:     " << copy_file_ << std::endl
+                << "Output lease file:   " << output_file_ << std::endl
+                << "Finishn file:        " << finish_file_ << std::endl
+                << "Config file:         " << config_file_ << std::endl
+                << "PID file:            " << pid_file_ << std::endl;
     }
 }
 
-bool
-lfcController::pidCheck(const std::string & pid_file)
-{
-    return (false);
-}
-
-bool
-lfcController::pidWrite(const std::string & pid_file)
-{
-    return (true);
-}
-
-void
-lfcController::pidDelete(const std::string & pid_file)
-{
-}
-
 void
-lfcController::usage(const std::string & text)
-{
+lfcController::usage(const std::string& text) {
     if (text != "") {
         std::cerr << "Usage error: " << text << std::endl;
     }

+ 2 - 19
src/bin/lfc/lfc.h

@@ -16,7 +16,6 @@
 #define LFC_H
 
 #include <boost/shared_ptr.hpp>
-
 #include <exceptions/exceptions.h>
 
 namespace isc {
@@ -53,9 +52,9 @@ public:
     ///
     /// 1. parse command line arguments
     /// 2. verifies that it is the only instance
-    /// 3. creates pid file
+    /// 3. creates pid file (TBD)
     /// .... TBD
-    /// 4. remove pid file
+    /// 4. remove pid file (TBD)
     /// 5. exit to the caller
     void launch(int argc, char* argv[], const bool test_mode);
 
@@ -63,21 +62,6 @@ public:
     /// step taken after the process has been launched.
     void parseArgs(int argc, char* argv[]);
 
-    /// @brief Use the pid file to determine if there is another instance
-    ///
-    /// @param pid_file is the name of the file which holds the pid to check
-    /// returns true if there is a process with that pid
-    bool pidCheck(const std::string & pid_file);
-
-    /// @brief Extract the pid and Write it out to the pid file
-    ///
-    /// @param pid_file is the name of the file in which to write the pid
-    /// returns true if the write was successful
-    bool pidWrite(const std::string & pid_file);
-
-    /// @brief Get rid of the pid file we created earlier
-    void pidDelete(const std::string & pid_file);
-
     /// @brief Prints the program usage text to std error.
     ///
     /// @param text is a string message which will preceded the usage text.
@@ -157,4 +141,3 @@ private:
 }; // namespace isc
 
 #endif
-

+ 1 - 2
src/bin/lfc/main.cc

@@ -12,12 +12,11 @@
 // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 // PERFORMANCE OF THIS SOFTWARE.
 
-#include <config.h>
 #include <lfc/lfc.h>
 #include <exceptions/exceptions.h>
 #include <log/logger_support.h>
 #include <log/logger_manager.h>
-
+#include <config.h>
 #include <iostream>
 
 using namespace isc::lfc;

+ 53 - 55
src/bin/lfc/tests/lfc_controller_unittests.cc

@@ -12,9 +12,9 @@
 // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 // PERFORMANCE OF THIS SOFTWARE.
 
+#include <lfc/lfc.h>
 #include <log/logger_support.h>
 #include <gtest/gtest.h>
-#include <lfc/lfc.h>
 
 using namespace isc::lfc;
 using namespace std;
@@ -23,14 +23,13 @@ TEST(lfcControllerTest, initialValues) {
     lfcController lfcController;
 
     // Verify that we start with everything empty
-    EXPECT_TRUE(lfcController.getProtocolVersion() == 0);
-    EXPECT_TRUE(lfcController.getConfigFile() == "");
-    EXPECT_TRUE(lfcController.getPreviousFile() == "");
-    EXPECT_TRUE(lfcController.getCopyFile() == "");
-    EXPECT_TRUE(lfcController.getOutputFile() == "");
-    EXPECT_TRUE(lfcController.getFinishFile() == "");
-    // Currently defaulting pid file for testing
-    // EXPECT_TRUE(lfcController.getPidFile() == "");
+    EXPECT_EQ(lfcController.getProtocolVersion(), 0);
+    EXPECT_EQ(lfcController.getConfigFile(), "");
+    EXPECT_EQ(lfcController.getPreviousFile(), "");
+    EXPECT_EQ(lfcController.getCopyFile(), "");
+    EXPECT_EQ(lfcController.getOutputFile(), "");
+    EXPECT_EQ(lfcController.getFinishFile(), "");
+    EXPECT_EQ(lfcController.getPidFile(), "");
 }
 
 TEST(lfcControllerTest, fullCommandLine) {
@@ -38,28 +37,28 @@ TEST(lfcControllerTest, fullCommandLine) {
 
     // Verify that standard options can be parsed without error
     char* argv[] = { const_cast<char*>("progName"),
-		     const_cast<char*>("-4"),
-		     const_cast<char*>("-p"),
-		     const_cast<char*>("previous"),
-		     const_cast<char*>("-i"),
-		     const_cast<char*>("copy"),
-		     const_cast<char*>("-o"),
-		     const_cast<char*>("output"),
-		     const_cast<char*>("-c"),
-		     const_cast<char*>("config"),
-		     const_cast<char*>("-f"),
-		     const_cast<char*>("finish") };
+                     const_cast<char*>("-4"),
+                     const_cast<char*>("-p"),
+                     const_cast<char*>("previous"),
+                     const_cast<char*>("-i"),
+                     const_cast<char*>("copy"),
+                     const_cast<char*>("-o"),
+                     const_cast<char*>("output"),
+                     const_cast<char*>("-c"),
+                     const_cast<char*>("config"),
+                     const_cast<char*>("-f"),
+                     const_cast<char*>("finish") };
     int argc = 12;
 
     EXPECT_NO_THROW(lfcController.parseArgs(argc, argv));
 
     // The parsed data
-    EXPECT_TRUE(lfcController.getProtocolVersion() == 4);
-    EXPECT_TRUE(lfcController.getConfigFile() == "config");
-    EXPECT_TRUE(lfcController.getPreviousFile() == "previous");
-    EXPECT_TRUE(lfcController.getCopyFile() == "copy");
-    EXPECT_TRUE(lfcController.getOutputFile() == "output");
-    EXPECT_TRUE(lfcController.getFinishFile() == "finish");
+    EXPECT_EQ(lfcController.getProtocolVersion(), 4);
+    EXPECT_EQ(lfcController.getConfigFile(), "config");
+    EXPECT_EQ(lfcController.getPreviousFile(), "previous");
+    EXPECT_EQ(lfcController.getCopyFile(), "copy");
+    EXPECT_EQ(lfcController.getOutputFile(), "output");
+    EXPECT_EQ(lfcController.getFinishFile(), "finish");
 }
 
 TEST(lfcControllerTest, notEnoughData) {
@@ -68,17 +67,17 @@ TEST(lfcControllerTest, notEnoughData) {
     // The standard options we shall test what happens
     // if we don't include all of them
     char* argv[] = { const_cast<char*>("progName"),
-		     const_cast<char*>("-4"),
-		     const_cast<char*>("-p"),
-		     const_cast<char*>("previous"),
-		     const_cast<char*>("-i"),
-		     const_cast<char*>("copy"),
-		     const_cast<char*>("-o"),
-		     const_cast<char*>("output"),
-		     const_cast<char*>("-c"),
-		     const_cast<char*>("config"),
-		     const_cast<char*>("-f"),
-		     const_cast<char*>("finish") };
+                     const_cast<char*>("-4"),
+                     const_cast<char*>("-p"),
+                     const_cast<char*>("previous"),
+                     const_cast<char*>("-i"),
+                     const_cast<char*>("copy"),
+                     const_cast<char*>("-o"),
+                     const_cast<char*>("output"),
+                     const_cast<char*>("-c"),
+                     const_cast<char*>("config"),
+                     const_cast<char*>("-f"),
+                     const_cast<char*>("finish") };
     int argc = 1;
 
     EXPECT_THROW(lfcController.parseArgs(argc, argv), InvalidUsage);
@@ -121,20 +120,20 @@ TEST(lfcControllerTest, tooMuchData) {
     // The standard options plus some others
 
     char* argv[] = { const_cast<char*>("progName"),
-		     const_cast<char*>("-4"),
-		     const_cast<char*>("-p"),
-		     const_cast<char*>("previous"),
-		     const_cast<char*>("-i"),
-		     const_cast<char*>("copy"),
-		     const_cast<char*>("-o"),
-		     const_cast<char*>("output"),
-		     const_cast<char*>("-c"),
-		     const_cast<char*>("config"),
-		     const_cast<char*>("-f"),
-		     const_cast<char*>("finish"),
-		     const_cast<char*>("some"),
-		     const_cast<char*>("other"),
-		     const_cast<char*>("args"),		     
+                     const_cast<char*>("-4"),
+                     const_cast<char*>("-p"),
+                     const_cast<char*>("previous"),
+                     const_cast<char*>("-i"),
+                     const_cast<char*>("copy"),
+                     const_cast<char*>("-o"),
+                     const_cast<char*>("output"),
+                     const_cast<char*>("-c"),
+                     const_cast<char*>("config"),
+                     const_cast<char*>("-f"),
+                     const_cast<char*>("finish"),
+                     const_cast<char*>("some"),
+                     const_cast<char*>("other"),
+                     const_cast<char*>("args"),
     };
     int argc = 15;
 
@@ -147,12 +146,11 @@ TEST(lfcControllerTest, someBadData) {
     // The standard options plus some others
 
     char* argv[] = { const_cast<char*>("progName"),
-		     const_cast<char*>("some"),
-		     const_cast<char*>("bad"),
-		     const_cast<char*>("args"),		     
+                     const_cast<char*>("some"),
+                     const_cast<char*>("bad"),
+                     const_cast<char*>("args"),
     };
     int argc = 4;
 
     EXPECT_THROW(lfcController.parseArgs(argc, argv), InvalidUsage);
 }
-//-4 -p previous -i copy -o output -c config -f finish -d