From 6b345dcbf68297b41fa19eb2fad550019c63da51 Mon Sep 17 00:00:00 2001 From: Shawn Routhier Date: Thu, 15 Jan 2015 21:32:11 -0800 Subject: [PATCH 01/10] [trac3664] Scaffolding for the lfc program Add the lfc directory and update the auto tool files to process it. --- configure.ac | 2 + src/bin/Makefile.am | 2 +- src/bin/lfc/Makefile.am | 75 +++++++++++++++++++++++++++++++++++ src/bin/lfc/lfc_lfc.cc | 22 ++++++++++ src/bin/lfc/lfc_lfc.h | 29 ++++++++++++++ src/bin/lfc/lfc_messages.mes | 17 ++++++++ src/bin/lfc/main.cc | 50 +++++++++++++++++++++++ src/bin/lfc/tests/Makefile.am | 69 ++++++++++++++++++++++++++++++++ 8 files changed, 265 insertions(+), 1 deletion(-) create mode 100644 src/bin/lfc/Makefile.am create mode 100644 src/bin/lfc/lfc_lfc.cc create mode 100644 src/bin/lfc/lfc_lfc.h create mode 100644 src/bin/lfc/lfc_messages.mes create mode 100644 src/bin/lfc/main.cc create mode 100644 src/bin/lfc/tests/Makefile.am diff --git a/configure.ac b/configure.ac index a583ae05b0..b49136501a 100644 --- a/configure.ac +++ b/configure.ac @@ -1393,6 +1393,8 @@ AC_CONFIG_FILES([compatcheck/Makefile src/bin/keactrl/keactrl.conf src/bin/keactrl/tests/Makefile src/bin/keactrl/tests/keactrl_tests.sh + src/bin/lfc/Makefile + src/bin/lfc/tests/Makefile src/bin/perfdhcp/Makefile src/bin/perfdhcp/tests/Makefile src/bin/perfdhcp/tests/testdata/Makefile diff --git a/src/bin/Makefile.am b/src/bin/Makefile.am index 372b59b4a0..c254189add 100644 --- a/src/bin/Makefile.am +++ b/src/bin/Makefile.am @@ -1,5 +1,5 @@ # The following build order must be maintained. -SUBDIRS = dhcp4 dhcp6 d2 perfdhcp admin +SUBDIRS = dhcp4 dhcp6 d2 perfdhcp admin lfc if CONFIG_BACKEND_JSON SUBDIRS += keactrl diff --git a/src/bin/lfc/Makefile.am b/src/bin/lfc/Makefile.am new file mode 100644 index 0000000000..eb9527f891 --- /dev/null +++ b/src/bin/lfc/Makefile.am @@ -0,0 +1,75 @@ +#SUBDIRS = . tests +SUBDIRS = . + +AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib +AM_CPPFLAGS += -I$(top_srcdir)/src/bin -I$(top_builddir)/src/bin +AM_CPPFLAGS += $(BOOST_INCLUDES) + +AM_CXXFLAGS = $(KEA_CXXFLAGS) +if USE_CLANGPP +# Disable unused parameter warning caused by some Boost headers when compiling with clang +AM_CXXFLAGS += -Wno-unused-parameter +endif + +if USE_STATIC_LINK +AM_LDFLAGS = -static +endif + +CLEANFILES = lfc_messages.h lfc_messages.cc s-messages + +man_MANS = kea-lfc.8 +DISTCLEANFILES = $(man_MANS) +EXTRA_DIST = $(man_MANS) kea-lfc.xml + +if GENERATE_DOCS +kea-lfc.8: kea-lfc.xml + @XSLTPROC@ --novalid --xinclude --nonet -o $@ \ + http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl \ + $(srcdir)/kea-lfc.xml + +else + +$(man_MANS): + @echo Man generation disabled. Creating dummy $@. Configure with --enable-generate-docs to enable it. + @echo Man generation disabled. Remove this file, configure with --enable-generate-docs, and rebuild Kea > $@ + +endif + +lfc_messages.h lfc_messages.cc: s-messages + +s-messages: lfc_messages.mes + $(top_builddir)/src/lib/log/compiler/message $(top_srcdir)/src/bin/lfc/lfc_messages.mes + touch $@ + +BUILT_SOURCES = lfc_messages.h lfc_messages.cc + +# convenience archive + +noinst_LTLIBRARIES = liblfc.la + +liblfc_la_SOURCES = +liblfc_la_SOURCES += lfc_lfc.h +liblfc_la_SOURCES += lfc_lfc.cc + +nodist_liblfc_la_SOURCES = lfc_messages.h lfc_messages.cc +EXTRA_DIST += lfc_messages.mes + +sbin_PROGRAMS = kea-lfc + +kea_lfc_SOURCES = main.cc + +kea_lfc_LDADD = liblfc.la +kea_lfc_LDADD += $(top_builddir)/src/lib/log/libkea-log.la +kea_lfc_LDADD += $(top_builddir)/src/lib/exceptions/libkea-exceptions.la +kea_lfc_LDADD += $(top_builddir)/src/lib/cc/libkea-cc.la +kea_lfc_LDADD += $(top_builddir)/src/lib/asiodns/libkea-asiodns.la +kea_lfc_LDADD += $(top_builddir)/src/lib/asiolink/libkea-asiolink.la +kea_lfc_LDADD += $(top_builddir)/src/lib/config/libkea-cfgclient.la +kea_lfc_LDADD += $(top_builddir)/src/lib/dhcp_ddns/libkea-dhcp_ddns.la +kea_lfc_LDADD += $(top_builddir)/src/lib/dhcp/libkea-dhcp++.la +kea_lfc_LDADD += $(top_builddir)/src/lib/dhcpsrv/libkea-dhcpsrv.la +kea_lfc_LDADD += $(top_builddir)/src/lib/dns/libkea-dns++.la +kea_lfc_LDADD += $(top_builddir)/src/lib/util/libkea-util.la +kea_lfc_LDADD += $(top_builddir)/src/lib/hooks/libkea-hooks.la + +kea_lfcdir = $(pkgdatadir) diff --git a/src/bin/lfc/lfc_lfc.cc b/src/bin/lfc/lfc_lfc.cc new file mode 100644 index 0000000000..6ded0e4e5c --- /dev/null +++ b/src/bin/lfc/lfc_lfc.cc @@ -0,0 +1,22 @@ +// Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC") +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THIS SOFTWARE. + +#include + +namespace isc { +namespace lfc { + + +}; // namespace isc::lfc +}; // namespace isc diff --git a/src/bin/lfc/lfc_lfc.h b/src/bin/lfc/lfc_lfc.h new file mode 100644 index 0000000000..06c6136052 --- /dev/null +++ b/src/bin/lfc/lfc_lfc.h @@ -0,0 +1,29 @@ +// Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC") +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THIS SOFTWARE. + +#ifndef LFC_LFC_H +#define LFC_LFC_H + +#include + +#include + +namespace isc { +namespace lfc { + +}; // namespace isc:lfc +}; // namespace isc + +#endif + diff --git a/src/bin/lfc/lfc_messages.mes b/src/bin/lfc/lfc_messages.mes new file mode 100644 index 0000000000..94c6f46373 --- /dev/null +++ b/src/bin/lfc/lfc_messages.mes @@ -0,0 +1,17 @@ +# Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC") +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +# PERFORMANCE OF THIS SOFTWARE. + +$NAMESPACE isc::lfc +% LFC_TEST_MESSAGE test messages +This is a test and placeholder debug message diff --git a/src/bin/lfc/main.cc b/src/bin/lfc/main.cc new file mode 100644 index 0000000000..2b3d06f5cf --- /dev/null +++ b/src/bin/lfc/main.cc @@ -0,0 +1,50 @@ +// Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC") +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THIS SOFTWARE. + +#include +#include +#include +#include +#include + +#include + +using namespace isc::lfc; +using namespace std; + +/// This file contains the entry point (main() function for the +/// standard LFC process, kea-lfc, component of the Kea software suite. +/// It fetches the lfccontroller singleton instance and invokes its launch +/// method. +/// The exit value of the program will be EXIT_SUCCESS if there were no +/// errors, EXIT_FAILURE otherwise. +int main(int argc, char* argv[]) { + int ret = EXIT_SUCCESS; + + // Instantiate/fetch the lfc application controller singleton. + // DControllerBasePtr& controller = D2Controller::instance(); + + // Launch the controller passing in command line arguments. + // Exit program with the controller's return code. + try { + // 'false' value disables test mode. + //controller->launch(argc, argv, false); + std::cerr << "Service started:" << std::endl; + } catch (const isc::Exception& ex) { + std::cerr << "Service failed:" << ex.what() << std::endl; + ret = EXIT_FAILURE; + } + + return (ret); +} diff --git a/src/bin/lfc/tests/Makefile.am b/src/bin/lfc/tests/Makefile.am new file mode 100644 index 0000000000..42b0d5beff --- /dev/null +++ b/src/bin/lfc/tests/Makefile.am @@ -0,0 +1,69 @@ +SHTESTS = + +noinst_SCRIPTS = lfc_tests.sh + +EXTRA_DIST = lfc_tests.sh.in + +# test using command-line arguments, so use check-local target instead of TESTS +check-local: + for shtest in $(SHTESTS) ; do \ + echo Running test: $$shtest ; \ + export KEA_LOCKFILE_DIR=$(abs_top_builddir); \ + ${SHELL} $(abs_builddir)/$$shtest || exit ; \ + done + +AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib +AM_CPPFLAGS += -I$(top_builddir)/src/bin # for generated spec_config.h header +AM_CPPFLAGS += -I$(top_srcdir)/src/bin +AM_CPPFLAGS += -I$(top_builddir)/src/lib/cc +AM_CPPFLAGS += -I$(top_srcdir)/src/lib/asiolink +AM_CPPFLAGS += $(BOOST_INCLUDES) +AM_CPPFLAGS += -DTEST_DATA_DIR=\"$(abs_top_srcdir)/src/lib/testutils/testdata\" +AM_CPPFLAGS += -DTEST_DATA_BUILDDIR=\"$(abs_top_builddir)/src/bin/lfc/tests\" +AM_CPPFLAGS += -DINSTALL_PROG=\"$(abs_top_srcdir)/install-sh\" + +CLEANFILES = $(builddir)/interfaces.txt $(builddir)/logger_lockfile + +DISTCLEANFILES = lfc_process_tests.sh + +AM_CXXFLAGS = $(KEA_CXXFLAGS) +if USE_CLANGPP +# Disable unused parameter warning caused by some Boost headers when compiling with clang +AM_CXXFLAGS += -Wno-unused-parameter +endif + +if USE_STATIC_LINK +AM_LDFLAGS = -static +endif + +TESTS_ENVIRONMENT = \ + $(LIBTOOL) --mode=execute $(VALGRIND_COMMAND) + +TESTS = +if HAVE_GTEST + +TESTS += lfc_unittests + +#lfc_unittests_SOURCES = d_test_stubs.cc d_test_stubs.h + +lfc_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES) +lfc_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS) +lfc_unittests_LDADD = $(GTEST_LDADD) +lfc_unittests_LDADD += $(top_builddir)/src/bin/d2/libd2.la +lfc_unittests_LDADD += $(top_builddir)/src/lib/exceptions/libkea-exceptions.la +lfc_unittests_LDADD += $(top_builddir)/src/lib/log/libkea-log.la +lfc_unittests_LDADD += $(top_builddir)/src/lib/asiodns/libkea-asiodns.la +lfc_unittests_LDADD += $(top_builddir)/src/lib/asiolink/libkea-asiolink.la +lfc_unittests_LDADD += $(top_builddir)/src/lib/cc/libkea-cc.la +lfc_unittests_LDADD += $(top_builddir)/src/lib/config/libkea-cfgclient.la +lfc_unittests_LDADD += $(top_builddir)/src/lib/dhcp_ddns/libkea-dhcp_ddns.la +lfc_unittests_LDADD += $(top_builddir)/src/lib/dhcp/libkea-dhcp++.la +lfc_unittests_LDADD += $(top_builddir)/src/lib/dhcpsrv/libkea-dhcpsrv.la +lfc_unittests_LDADD += $(top_builddir)/src/lib/dhcpsrv/testutils/libdhcpsrvtest.la +lfc_unittests_LDADD += $(top_builddir)/src/lib/dns/libkea-dns++.la +lfc_unittests_LDADD += $(top_builddir)/src/lib/util/libkea-util.la +lfc_unittests_LDADD += $(top_builddir)/src/lib/hooks/libkea-hooks.la + +endif + +noinst_PROGRAMS = $(TESTS) From c9ce195564155bd1f3d2852cbe9c95390bedce88 Mon Sep 17 00:00:00 2001 From: Shawn Routhier Date: Tue, 20 Jan 2015 00:28:49 -0800 Subject: [PATCH 02/10] [trac3664] Add the command line processing Continue adding the boiler plate files and add the function to parse the command line arguments. --- src/bin/lfc/Makefile.am | 4 +- src/bin/lfc/kea-lfc.xml | 108 +++++++++++++++++++++ src/bin/lfc/lfc.cc | 208 ++++++++++++++++++++++++++++++++++++++++ src/bin/lfc/lfc.h | 92 ++++++++++++++++++ src/bin/lfc/lfc_lfc.cc | 22 ----- src/bin/lfc/lfc_lfc.h | 29 ------ src/bin/lfc/main.cc | 10 +- 7 files changed, 415 insertions(+), 58 deletions(-) create mode 100644 src/bin/lfc/kea-lfc.xml create mode 100644 src/bin/lfc/lfc.cc create mode 100644 src/bin/lfc/lfc.h delete mode 100644 src/bin/lfc/lfc_lfc.cc delete mode 100644 src/bin/lfc/lfc_lfc.h diff --git a/src/bin/lfc/Makefile.am b/src/bin/lfc/Makefile.am index eb9527f891..7c058018eb 100644 --- a/src/bin/lfc/Makefile.am +++ b/src/bin/lfc/Makefile.am @@ -48,8 +48,8 @@ BUILT_SOURCES = lfc_messages.h lfc_messages.cc noinst_LTLIBRARIES = liblfc.la liblfc_la_SOURCES = -liblfc_la_SOURCES += lfc_lfc.h -liblfc_la_SOURCES += lfc_lfc.cc +liblfc_la_SOURCES += lfc.h +liblfc_la_SOURCES += lfc.cc nodist_liblfc_la_SOURCES = lfc_messages.h lfc_messages.cc EXTRA_DIST += lfc_messages.mes diff --git a/src/bin/lfc/kea-lfc.xml b/src/bin/lfc/kea-lfc.xml new file mode 100644 index 0000000000..97c67fcd67 --- /dev/null +++ b/src/bin/lfc/kea-lfc.xml @@ -0,0 +1,108 @@ +]> + + + + + + Feb 1, 2015 + + + + kea-lfc + 8 + Kea + + + + kea-lfc + Lease File Cleanup process in Kea + + + + + 2015 + Internet Systems Consortium, Inc. ("ISC") + + + + + + kea-lfc + + + + + + + kea-lfc + + + + + + + DESCRIPTION + + The kea-lfc service process removes redundant + information for the files used to provide persistent storage for + the memfile data base back end. The service is written to run as + a stand alone process. While it can be started externally it + should be started by the Kea DHCP servers as desired and required. + + + + + + ARGUMENTS + + The arguments are as follows: + + + + + + + Verbose mode sets the logging level to debug. This is primarily + for development purposes in stand-alone mode. + + + + + + + Configuration file including the configuration for LFC process. + It may also contain configuration entries for other Kea services. + + + + + + + + HISTORY + + The kea-lfc process was first coded in January + 2015 by the ISC Kea/DHCP team. + + + diff --git a/src/bin/lfc/lfc.cc b/src/bin/lfc/lfc.cc new file mode 100644 index 0000000000..3d5512ff2d --- /dev/null +++ b/src/bin/lfc/lfc.cc @@ -0,0 +1,208 @@ +// Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC") +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THIS SOFTWARE. + +#include +#include +#include +#include +#include +//#include +#include + +using namespace std; + +namespace isc { +namespace lfc { + +/// @brief Defines the application name, it may be used to locate +/// configuration data and appears in log statements. +const char* lfc::lfc_app_name_ = "DhcpLFC"; + +/// @brief Defines the executable name. +const char*lfc::lfc_bin_name_ = "kea-lfc"; + +lfc::lfc() + : dhcp_version_(0), verbose_(false), config_file_(""), + previous_file_(""), copy_file_(""), output_file_("") { + std::cerr << "created lfc" << std::endl; +} + +lfc::~lfc() { + std::cerr << "destroyed lfc" << std::endl; +} + +void +lfc::launch(int argc, char* argv[], const bool test_mode) { + try { + parseArgs(argc, argv); + } catch (const InvalidUsage& ex) { + usage(ex.what()); + throw; // rethrow it + } + + std::cerr << "launched lfc" << std::endl; +} + +void +lfc::parseArgs(int argc, char* argv[]) +{ + int ch; + + while ((ch = getopt(argc, argv, "46dvVp:i:o:c:")) != -1) { + switch (ch) { + case '4': + // Process DHCPv4 lease files. + dhcp_version_ = 4; + break; + + case '6': + // Process DHCPv6 lease files. + dhcp_version_ = 6; + break; + + case 'v': + // Print just Kea vesion and exit. + // std::cout << getVersion(false) << std::endl; + exit(EXIT_SUCCESS); + + case 'V': + // Print extended Kea vesion and exit. + //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 'c': + // Previous file name. + if (optarg == NULL) { + isc_throw(InvalidUsage, "Configuration file name missing"); + } + config_file_ = optarg; + break; + + default: + usage(""); + } + } + + // Check for extraneous parameters. + if (argc > optind) { + isc_throw(InvalidUsage, "Extraneous parameters."); + } + + if (dhcp_version_ == 0) { + isc_throw(InvalidUsage, "DHCP version required"); + } + + if (previous_file_.empty()) { + isc_throw(InvalidUsage, "Previous file not specified"); + } + + if (copy_file_.empty()) { + isc_throw(InvalidUsage, "Copy file not specified"); + } + + if (output_file_.empty()) { + isc_throw(InvalidUsage, "Output file not specified"); + } + + if (config_file_.empty()) { + isc_throw(InvalidUsage, "Config file not specified"); + } + + // If verbose is set echo the input information + if (verbose_ == true) { + std::cerr << "Protocol version: " << dhcp_version_ << std::endl + << "Previous lease file: " << previous_file_ << std::endl + << "Copy lease file: " << copy_file_ << std::endl + << "Output lease file: " << output_file_ << std::endl + << "Config file: " << config_file_ << std::endl; + } +} + +void +lfc::pidCheck() +{ +} + +void +lfc::pidDelete() +{ +} + +void +lfc::usage(const std::string & text) +{ + if (text != "") { + std::cerr << "Usage error: " << text << std::endl; + } + + std::cerr << "Usage: " << lfc_bin_name_ << std::endl + << " [-4|-6] -p file -i file -o file -c file" << std::endl + << " -4 or -6 clean a set of v4 or v6 lease files" << std::endl + << " -p : previous lease file" << std::endl + << " -i : copy of lease file" << std::endl + << " -o : output lease file" << std::endl + << " -c : configuration file" << std::endl + << " -v: print version number and exit" << std::endl + << " -V: print extended version inforamtion and exit" << std::endl + << " -d: optional, verbose output " << std::endl + << std::endl; +} + +}; // namespace isc::lfc +}; // 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()); +//} diff --git a/src/bin/lfc/lfc.h b/src/bin/lfc/lfc.h new file mode 100644 index 0000000000..4f38e5468f --- /dev/null +++ b/src/bin/lfc/lfc.h @@ -0,0 +1,92 @@ +// Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC") +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THIS SOFTWARE. + +#ifndef LFC_H +#define LFC_H + +#include + +#include + +namespace isc { +namespace lfc { + +/// @brief Exception thrown when the command line is invalid. +class InvalidUsage : public isc::Exception { +public: + InvalidUsage(const char* file, size_t line, const char* what) : + isc::Exception(file, line, what) { }; +}; + +//class lfcBase; +//typedef boost::shared_ptr lfcBasePtr; + +class lfc { +public: + /// @brief Defines the application name, it may be used to locate + /// configuration data and appears in log statements. + static const char* lfc_app_name_; + + /// @brief Defines the executable name, by convention this should match + /// the executable name. + static const char* lfc_bin_name_; + + /// @brief Constructor + lfc(); + + /// @brief Destructor + ~lfc(); + + /// @brief Acts as the primary entry point to start execution + /// of the process. Provides the control logic: + /// + /// 1. parse command line arguments + /// 2. verifies that it is the only instance + /// 3. creates pid file + /// .... TBD + /// 4. remove pid file + /// 5. exit to the caller + void launch(int argc, char* argv[], const bool test_mode); + + /// @brief Process the command line arguments. It is the first + /// step taken after the process has been launched. + void parseArgs(int argc, char* argv[]); + + /// @brief Use the pid to determine if there is another instance + /// and create a pid file if we are alone. + void pidCheck(); + + /// @brief Get rid of the pid file we created earlier + void pidDelete(); + + /// #brief prints the program usage text to std error. + /// + /// @param text is a string message which will preceded the usage text. + /// This is intended to be used for specific usage violation messages. + void usage(const std::string& text); + +private: + int dhcp_version_; + bool verbose_; + std::string config_file_; + std::string previous_file_; + std::string copy_file_; + std::string output_file_; +}; + +}; // namespace isc:lfc +}; // namespace isc + +#endif + diff --git a/src/bin/lfc/lfc_lfc.cc b/src/bin/lfc/lfc_lfc.cc deleted file mode 100644 index 6ded0e4e5c..0000000000 --- a/src/bin/lfc/lfc_lfc.cc +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC") -// -// Permission to use, copy, modify, and/or distribute this software for any -// purpose with or without fee is hereby granted, provided that the above -// copyright notice and this permission notice appear in all copies. -// -// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH -// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, -// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM -// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE -// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -// PERFORMANCE OF THIS SOFTWARE. - -#include - -namespace isc { -namespace lfc { - - -}; // namespace isc::lfc -}; // namespace isc diff --git a/src/bin/lfc/lfc_lfc.h b/src/bin/lfc/lfc_lfc.h deleted file mode 100644 index 06c6136052..0000000000 --- a/src/bin/lfc/lfc_lfc.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC") -// -// Permission to use, copy, modify, and/or distribute this software for any -// purpose with or without fee is hereby granted, provided that the above -// copyright notice and this permission notice appear in all copies. -// -// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH -// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, -// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM -// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE -// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -// PERFORMANCE OF THIS SOFTWARE. - -#ifndef LFC_LFC_H -#define LFC_LFC_H - -#include - -#include - -namespace isc { -namespace lfc { - -}; // namespace isc:lfc -}; // namespace isc - -#endif - diff --git a/src/bin/lfc/main.cc b/src/bin/lfc/main.cc index 2b3d06f5cf..9f1b455285 100644 --- a/src/bin/lfc/main.cc +++ b/src/bin/lfc/main.cc @@ -13,7 +13,7 @@ // PERFORMANCE OF THIS SOFTWARE. #include -#include +#include #include #include #include @@ -31,16 +31,16 @@ using namespace std; /// errors, EXIT_FAILURE otherwise. int main(int argc, char* argv[]) { int ret = EXIT_SUCCESS; + lfc lfc; - // Instantiate/fetch the lfc application controller singleton. - // DControllerBasePtr& controller = D2Controller::instance(); + // Instantiate/fetch the lfc application controller. + // lfc& lfc = lfc::lfc(); // Launch the controller passing in command line arguments. // Exit program with the controller's return code. try { // 'false' value disables test mode. - //controller->launch(argc, argv, false); - std::cerr << "Service started:" << std::endl; + lfc.launch(argc, argv, false); } catch (const isc::Exception& ex) { std::cerr << "Service failed:" << ex.what() << std::endl; ret = EXIT_FAILURE; From 6bb231d222007f65b727b972508ccbc948a34cd5 Mon Sep 17 00:00:00 2001 From: Shawn Routhier Date: Tue, 20 Jan 2015 22:37:10 -0800 Subject: [PATCH 03/10] [trac3664] Code updates and add unittests for parsing Add the structure for doing unittests and add some tests to exercise parseArgs(). Rename the class to lfcController to be more in line with the coding spec. --- src/bin/lfc/Makefile.am | 3 +- src/bin/lfc/lfc.cc | 99 ++++++----- src/bin/lfc/lfc.h | 86 +++++++++- src/bin/lfc/main.cc | 7 +- src/bin/lfc/tests/Makefile.am | 11 +- src/bin/lfc/tests/lfc_controller_unittests.cc | 158 ++++++++++++++++++ src/bin/lfc/tests/lfc_unittests.cc | 30 ++++ 7 files changed, 332 insertions(+), 62 deletions(-) create mode 100644 src/bin/lfc/tests/lfc_controller_unittests.cc create mode 100644 src/bin/lfc/tests/lfc_unittests.cc diff --git a/src/bin/lfc/Makefile.am b/src/bin/lfc/Makefile.am index 7c058018eb..c2926f6f39 100644 --- a/src/bin/lfc/Makefile.am +++ b/src/bin/lfc/Makefile.am @@ -1,5 +1,4 @@ -#SUBDIRS = . tests -SUBDIRS = . +SUBDIRS = . tests AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib AM_CPPFLAGS += -I$(top_srcdir)/src/bin -I$(top_builddir)/src/bin diff --git a/src/bin/lfc/lfc.cc b/src/bin/lfc/lfc.cc index 3d5512ff2d..cb031e2154 100644 --- a/src/bin/lfc/lfc.cc +++ b/src/bin/lfc/lfc.cc @@ -17,7 +17,6 @@ #include #include #include -//#include #include using namespace std; @@ -27,23 +26,23 @@ namespace lfc { /// @brief Defines the application name, it may be used to locate /// configuration data and appears in log statements. -const char* lfc::lfc_app_name_ = "DhcpLFC"; +const char* lfcController::lfc_app_name_ = "DhcpLFC"; /// @brief Defines the executable name. -const char*lfc::lfc_bin_name_ = "kea-lfc"; +const char* lfcController::lfc_bin_name_ = "kea-lfc"; -lfc::lfc() - : dhcp_version_(0), verbose_(false), config_file_(""), - previous_file_(""), copy_file_(""), output_file_("") { +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; } -lfc::~lfc() { +lfcController::~lfcController() { std::cerr << "destroyed lfc" << std::endl; } void -lfc::launch(int argc, char* argv[], const bool test_mode) { +lfcController::launch(int argc, char* argv[], const bool test_mode) { try { parseArgs(argc, argv); } catch (const InvalidUsage& ex) { @@ -55,30 +54,30 @@ lfc::launch(int argc, char* argv[], const bool test_mode) { } void -lfc::parseArgs(int argc, char* argv[]) +lfcController::parseArgs(int argc, char* argv[]) { int ch; - while ((ch = getopt(argc, argv, "46dvVp:i:o:c:")) != -1) { + while ((ch = getopt(argc, argv, "46dvVp:i:o:c:f:")) != -1) { switch (ch) { case '4': // Process DHCPv4 lease files. - dhcp_version_ = 4; + protocol_version_ = 4; break; case '6': // Process DHCPv6 lease files. - dhcp_version_ = 6; + protocol_version_ = 6; break; 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': // Print extended Kea vesion and exit. - //std::cout << getVersion(true) << std::endl; + std::cout << getVersion(true) << std::endl; exit(EXIT_SUCCESS); case 'd': @@ -110,6 +109,14 @@ lfc::parseArgs(int argc, char* argv[]) 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) { @@ -128,7 +135,7 @@ lfc::parseArgs(int argc, char* argv[]) isc_throw(InvalidUsage, "Extraneous parameters."); } - if (dhcp_version_ == 0) { + if (protocol_version_ == 0) { isc_throw(InvalidUsage, "DHCP version required"); } @@ -144,43 +151,57 @@ lfc::parseArgs(int argc, char* argv[]) isc_throw(InvalidUsage, "Output file not specified"); } + if (finish_file_.empty()) { + isc_throw(InvalidUsage, "Finish file not specified"); + } + if (config_file_.empty()) { isc_throw(InvalidUsage, "Config file not specified"); } // If verbose is set echo the input information if (verbose_ == true) { - std::cerr << "Protocol version: " << dhcp_version_ << std::endl + 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 - << "Config file: " << config_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 -lfc::pidCheck() +lfcController::pidDelete(const std::string & pid_file) { } void -lfc::pidDelete() -{ -} - -void -lfc::usage(const std::string & text) +lfcController::usage(const std::string & text) { if (text != "") { std::cerr << "Usage error: " << text << std::endl; } std::cerr << "Usage: " << lfc_bin_name_ << std::endl - << " [-4|-6] -p file -i file -o file -c file" << std::endl + << " [-4|-6] -p file -i file -o file -f file -c file" << std::endl << " -4 or -6 clean a set of v4 or v6 lease files" << std::endl << " -p : previous lease file" << std::endl << " -i : copy of lease file" << std::endl << " -o : output lease file" << std::endl + << " -f : finish file" << std::endl << " -c : configuration file" << std::endl << " -v: print version number and exit" << std::endl << " -V: print extended version inforamtion and exit" << std::endl @@ -188,21 +209,17 @@ lfc::usage(const std::string & text) << std::endl; } +std::string +lfcController::getVersion(bool extended) { + std::stringstream tmp; + + tmp << VERSION; + if (extended) { + tmp << std::endl << EXTENDED_VERSION; + } + + return (tmp.str()); +} + }; // namespace isc::lfc }; // 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()); -//} diff --git a/src/bin/lfc/lfc.h b/src/bin/lfc/lfc.h index 4f38e5468f..4c0deb4623 100644 --- a/src/bin/lfc/lfc.h +++ b/src/bin/lfc/lfc.h @@ -32,7 +32,7 @@ public: //class lfcBase; //typedef boost::shared_ptr lfcBasePtr; -class lfc { +class lfcController { public: /// @brief Defines the application name, it may be used to locate /// configuration data and appears in log statements. @@ -43,10 +43,10 @@ public: static const char* lfc_bin_name_; /// @brief Constructor - lfc(); + lfcController(); /// @brief Destructor - ~lfc(); + ~lfcController(); /// @brief Acts as the primary entry point to start execution /// of the process. Provides the control logic: @@ -63,26 +63,94 @@ public: /// step taken after the process has been launched. void parseArgs(int argc, char* argv[]); - /// @brief Use the pid to determine if there is another instance - /// and create a pid file if we are alone. - void pidCheck(); + /// @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(); + void pidDelete(const std::string & pid_file); - /// #brief prints the program usage text to std error. + /// @brief Prints the program usage text to std error. /// /// @param text is a string message which will preceded the usage text. /// This is intended to be used for specific usage violation messages. void usage(const std::string& text); + /// @brief Gets the Kea version number for printing + /// + /// @param extended is a boolean indicating if the version string + /// should be short (false) or extended (true) + std::string getVersion(bool extended); + + // The following are primarly for the test code and not expected + // to be used in normal situations + + /// @brief Gets the protocol version of the leaes files + /// + /// @return Returns the value of the protocol version + int getProtocolVersion() { + return (protocol_version_); + } + + /// @brief Gets the config file name + /// + /// @return Returns the name of the config file + std::string getConfigFile() const { + return (config_file_); + } + + /// @brief Gets the prevous file name + /// + /// @return Returns the name of the previous file + std::string getPreviousFile() const { + return (previous_file_); + } + + /// @brief Gets the copy file name + /// + /// @return Returns the name of the copy file + std::string getCopyFile() const { + return (copy_file_); + } + + /// @brief Gets the output file name + /// + /// @return Returns the name of the output file + std::string getOutputFile() const { + return (output_file_); + } + + /// @brief Gets the finish file name + /// + /// @return Returns the name of the finish file + std::string getFinishFile() const { + return (finish_file_); + } + + /// @brief Gets the pid file name + /// + /// @return Returns the name of the pid file + std::string getPidFile() const { + return (pid_file_); + } + private: - int dhcp_version_; + int protocol_version_; bool verbose_; std::string config_file_; std::string previous_file_; std::string copy_file_; std::string output_file_; + std::string finish_file_; + std::string pid_file_; }; }; // namespace isc:lfc diff --git a/src/bin/lfc/main.cc b/src/bin/lfc/main.cc index 9f1b455285..7328f945e7 100644 --- a/src/bin/lfc/main.cc +++ b/src/bin/lfc/main.cc @@ -31,16 +31,13 @@ using namespace std; /// errors, EXIT_FAILURE otherwise. int main(int argc, char* argv[]) { int ret = EXIT_SUCCESS; - lfc lfc; - - // Instantiate/fetch the lfc application controller. - // lfc& lfc = lfc::lfc(); + lfcController lfcController; // Launch the controller passing in command line arguments. // Exit program with the controller's return code. try { // 'false' value disables test mode. - lfc.launch(argc, argv, false); + lfcController.launch(argc, argv, false); } catch (const isc::Exception& ex) { std::cerr << "Service failed:" << ex.what() << std::endl; ret = EXIT_FAILURE; diff --git a/src/bin/lfc/tests/Makefile.am b/src/bin/lfc/tests/Makefile.am index 42b0d5beff..23ea485887 100644 --- a/src/bin/lfc/tests/Makefile.am +++ b/src/bin/lfc/tests/Makefile.am @@ -1,8 +1,8 @@ SHTESTS = -noinst_SCRIPTS = lfc_tests.sh +noinst_SCRIPTS = -EXTRA_DIST = lfc_tests.sh.in +EXTRA_DIST = # test using command-line arguments, so use check-local target instead of TESTS check-local: @@ -24,7 +24,7 @@ AM_CPPFLAGS += -DINSTALL_PROG=\"$(abs_top_srcdir)/install-sh\" CLEANFILES = $(builddir)/interfaces.txt $(builddir)/logger_lockfile -DISTCLEANFILES = lfc_process_tests.sh +DISTCLEANFILES = AM_CXXFLAGS = $(KEA_CXXFLAGS) if USE_CLANGPP @@ -44,12 +44,13 @@ if HAVE_GTEST TESTS += lfc_unittests -#lfc_unittests_SOURCES = d_test_stubs.cc d_test_stubs.h +lfc_unittests_SOURCES = lfc_unittests.cc +lfc_unittests_SOURCES += lfc_controller_unittests.cc lfc_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES) lfc_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS) lfc_unittests_LDADD = $(GTEST_LDADD) -lfc_unittests_LDADD += $(top_builddir)/src/bin/d2/libd2.la +lfc_unittests_LDADD += $(top_builddir)/src/bin/lfc/liblfc.la lfc_unittests_LDADD += $(top_builddir)/src/lib/exceptions/libkea-exceptions.la lfc_unittests_LDADD += $(top_builddir)/src/lib/log/libkea-log.la lfc_unittests_LDADD += $(top_builddir)/src/lib/asiodns/libkea-asiodns.la diff --git a/src/bin/lfc/tests/lfc_controller_unittests.cc b/src/bin/lfc/tests/lfc_controller_unittests.cc new file mode 100644 index 0000000000..3069a2ac52 --- /dev/null +++ b/src/bin/lfc/tests/lfc_controller_unittests.cc @@ -0,0 +1,158 @@ +// Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC") +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THIS SOFTWARE. + +#include +#include +#include + +using namespace isc::lfc; +using namespace std; + +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() == ""); +} + +TEST(lfcControllerTest, fullCommandLine) { + lfcController lfcController; + + // Verify that standard options can be parsed without error + char* argv[] = { const_cast("progName"), + const_cast("-4"), + const_cast("-p"), + const_cast("previous"), + const_cast("-i"), + const_cast("copy"), + const_cast("-o"), + const_cast("output"), + const_cast("-c"), + const_cast("config"), + const_cast("-f"), + const_cast("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"); +} + +TEST(lfcControllerTest, notEnoughData) { + lfcController lfcController; + + // The standard options we shall test what happens + // if we don't include all of them + char* argv[] = { const_cast("progName"), + const_cast("-4"), + const_cast("-p"), + const_cast("previous"), + const_cast("-i"), + const_cast("copy"), + const_cast("-o"), + const_cast("output"), + const_cast("-c"), + const_cast("config"), + const_cast("-f"), + const_cast("finish") }; + int argc = 1; + + EXPECT_THROW(lfcController.parseArgs(argc, argv), InvalidUsage); + + argc = 2; + EXPECT_THROW(lfcController.parseArgs(argc, argv), InvalidUsage); + + argc = 3; + EXPECT_THROW(lfcController.parseArgs(argc, argv), InvalidUsage); + + argc = 4; + EXPECT_THROW(lfcController.parseArgs(argc, argv), InvalidUsage); + + argc = 5; + EXPECT_THROW(lfcController.parseArgs(argc, argv), InvalidUsage); + + argc = 6; + EXPECT_THROW(lfcController.parseArgs(argc, argv), InvalidUsage); + + argc = 7; + EXPECT_THROW(lfcController.parseArgs(argc, argv), InvalidUsage); + + argc = 8; + EXPECT_THROW(lfcController.parseArgs(argc, argv), InvalidUsage); + + argc = 9; + EXPECT_THROW(lfcController.parseArgs(argc, argv), InvalidUsage); + + argc = 10; + EXPECT_THROW(lfcController.parseArgs(argc, argv), InvalidUsage); + + argc = 11; + EXPECT_THROW(lfcController.parseArgs(argc, argv), InvalidUsage); + +} + +TEST(lfcControllerTest, tooMuchData) { + lfcController lfcController; + + // The standard options plus some others + + char* argv[] = { const_cast("progName"), + const_cast("-4"), + const_cast("-p"), + const_cast("previous"), + const_cast("-i"), + const_cast("copy"), + const_cast("-o"), + const_cast("output"), + const_cast("-c"), + const_cast("config"), + const_cast("-f"), + const_cast("finish"), + const_cast("some"), + const_cast("other"), + const_cast("args"), + }; + int argc = 15; + + EXPECT_THROW(lfcController.parseArgs(argc, argv), InvalidUsage); +} + +TEST(lfcControllerTest, someBadData) { + lfcController lfcController; + + // The standard options plus some others + + char* argv[] = { const_cast("progName"), + const_cast("some"), + const_cast("bad"), + const_cast("args"), + }; + int argc = 4; + + EXPECT_THROW(lfcController.parseArgs(argc, argv), InvalidUsage); +} +//-4 -p previous -i copy -o output -c config -f finish -d diff --git a/src/bin/lfc/tests/lfc_unittests.cc b/src/bin/lfc/tests/lfc_unittests.cc new file mode 100644 index 0000000000..a2bb34bc26 --- /dev/null +++ b/src/bin/lfc/tests/lfc_unittests.cc @@ -0,0 +1,30 @@ +// Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC") +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THIS SOFTWARE. + +#include +#include + +int +main(int argc, char* argv[]) { + + ::testing::InitGoogleTest(&argc, argv); + + // See the documentation of the KEA_* environment variables in + // src/lib/log/README for info on how to tweak logging + isc::log::initLogger(); + + int result = RUN_ALL_TESTS(); + + return (result); +} From 4cbdce8e5e20f6e74faee0f449d97d2a8074d6cb Mon Sep 17 00:00:00 2001 From: Shawn Routhier Date: Wed, 21 Jan 2015 19:33:32 -0800 Subject: [PATCH 04/10] [trac3664] Cleanup Cleanup spaces and such to meet coding specs Remove testing artifacts Update man page documenation --- src/bin/lfc/kea-lfc.xml | 80 ++++++++-- src/bin/lfc/lfc.cc | 151 ++++++++---------- src/bin/lfc/lfc.h | 21 +-- src/bin/lfc/main.cc | 3 +- src/bin/lfc/tests/lfc_controller_unittests.cc | 108 ++++++------- 5 files changed, 191 insertions(+), 172 deletions(-) diff --git a/src/bin/lfc/kea-lfc.xml b/src/bin/lfc/kea-lfc.xml index 97c67fcd67..5473c3cec5 100644 --- a/src/bin/lfc/kea-lfc.xml +++ b/src/bin/lfc/kea-lfc.xml @@ -44,18 +44,18 @@ kea-lfc + + + + + + + + - - - kea-lfc - - - - - DESCRIPTION @@ -76,13 +76,34 @@ - + Verbose mode sets the logging level to debug. This is primarily for development purposes in stand-alone mode. + + + + version causes the version stamp to be printed. + + + + + + + Version causes a longer form of the version stamp to be printed. + + + + + + + The protocol version of the lease files, must be one of 4 or 6. + + + @@ -91,6 +112,47 @@ + + + + Previous lease file - When LFC starts this is the result of any previous + run of LFC. + + + + + + + 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. + + + + + + + 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). + + + + + + + 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. + + + + + + + + + + diff --git a/src/bin/lfc/lfc.cc b/src/bin/lfc/lfc.cc index cb031e2154..f8e3b450e4 100644 --- a/src/bin/lfc/lfc.cc +++ b/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 #include #include #include #include +#include #include 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 '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 'p': + // Previous file name. + if (optarg == NULL) { + isc_throw(InvalidUsage, "Previous file name missing"); + } + previous_file_ = optarg; + break; - case 'o': - // Output file name. - if (optarg == NULL) { - isc_throw(InvalidUsage, "Output file name missing"); - } - output_file_ = optarg; - break; + case 'i': + // Copy file name. + if (optarg == NULL) { + isc_throw(InvalidUsage, "Copy file name missing"); + } + copy_file_ = optarg; + break; - case 'f': - // Output file name. - if (optarg == NULL) { - isc_throw(InvalidUsage, "Finish file name missing"); - } - finish_file_ = optarg; - break; + case 'o': + // Output file name. + if (optarg == NULL) { + isc_throw(InvalidUsage, "Output file name missing"); + } + output_file_ = optarg; + break; - case 'c': - // Previous file name. - if (optarg == NULL) { - isc_throw(InvalidUsage, "Configuration file name missing"); - } - config_file_ = optarg; - break; + case 'f': + // Output file name. + if (optarg == NULL) { + isc_throw(InvalidUsage, "Finish file name missing"); + } + finish_file_ = optarg; + break; - default: - usage(""); - } + 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; } diff --git a/src/bin/lfc/lfc.h b/src/bin/lfc/lfc.h index 4c0deb4623..ec79f7a187 100644 --- a/src/bin/lfc/lfc.h +++ b/src/bin/lfc/lfc.h @@ -16,7 +16,6 @@ #define LFC_H #include - #include 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 - diff --git a/src/bin/lfc/main.cc b/src/bin/lfc/main.cc index 7328f945e7..4cc2964bea 100644 --- a/src/bin/lfc/main.cc +++ b/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 #include #include #include #include - +#include #include using namespace isc::lfc; diff --git a/src/bin/lfc/tests/lfc_controller_unittests.cc b/src/bin/lfc/tests/lfc_controller_unittests.cc index 3069a2ac52..76753dbb9c 100644 --- a/src/bin/lfc/tests/lfc_controller_unittests.cc +++ b/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 #include #include -#include 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("progName"), - const_cast("-4"), - const_cast("-p"), - const_cast("previous"), - const_cast("-i"), - const_cast("copy"), - const_cast("-o"), - const_cast("output"), - const_cast("-c"), - const_cast("config"), - const_cast("-f"), - const_cast("finish") }; + const_cast("-4"), + const_cast("-p"), + const_cast("previous"), + const_cast("-i"), + const_cast("copy"), + const_cast("-o"), + const_cast("output"), + const_cast("-c"), + const_cast("config"), + const_cast("-f"), + const_cast("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("progName"), - const_cast("-4"), - const_cast("-p"), - const_cast("previous"), - const_cast("-i"), - const_cast("copy"), - const_cast("-o"), - const_cast("output"), - const_cast("-c"), - const_cast("config"), - const_cast("-f"), - const_cast("finish") }; + const_cast("-4"), + const_cast("-p"), + const_cast("previous"), + const_cast("-i"), + const_cast("copy"), + const_cast("-o"), + const_cast("output"), + const_cast("-c"), + const_cast("config"), + const_cast("-f"), + const_cast("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("progName"), - const_cast("-4"), - const_cast("-p"), - const_cast("previous"), - const_cast("-i"), - const_cast("copy"), - const_cast("-o"), - const_cast("output"), - const_cast("-c"), - const_cast("config"), - const_cast("-f"), - const_cast("finish"), - const_cast("some"), - const_cast("other"), - const_cast("args"), + const_cast("-4"), + const_cast("-p"), + const_cast("previous"), + const_cast("-i"), + const_cast("copy"), + const_cast("-o"), + const_cast("output"), + const_cast("-c"), + const_cast("config"), + const_cast("-f"), + const_cast("finish"), + const_cast("some"), + const_cast("other"), + const_cast("args"), }; int argc = 15; @@ -147,12 +146,11 @@ TEST(lfcControllerTest, someBadData) { // The standard options plus some others char* argv[] = { const_cast("progName"), - const_cast("some"), - const_cast("bad"), - const_cast("args"), + const_cast("some"), + const_cast("bad"), + const_cast("args"), }; int argc = 4; EXPECT_THROW(lfcController.parseArgs(argc, argv), InvalidUsage); } -//-4 -p previous -i copy -o output -c config -f finish -d From ca04fa118463493c32522169dedaae3308f656d5 Mon Sep 17 00:00:00 2001 From: Marcin Siodelski Date: Thu, 22 Jan 2015 16:31:04 +0100 Subject: [PATCH 05/10] [3664] Minor changes as a result of the review. - Fixed identation in configure.ac - Added kea-lfc to Doxygen - Corrected some little typos in the kea-lfc man page - Removed unnecessary headers and libraries - lfc.h updated - one comment, one method made const - added anonymous namespace for lfc_controller_unittests.cc --- configure.ac | 4 ++-- doc/Doxyfile | 1 + src/bin/lfc/Makefile.am | 6 ------ src/bin/lfc/kea-lfc.xml | 12 ++---------- src/bin/lfc/lfc.cc | 2 -- src/bin/lfc/lfc.h | 16 ++++++++-------- src/bin/lfc/tests/Makefile.am | 7 ------- src/bin/lfc/tests/lfc_controller_unittests.cc | 5 ++++- 8 files changed, 17 insertions(+), 36 deletions(-) diff --git a/configure.ac b/configure.ac index b49136501a..6ddd3f6dbe 100644 --- a/configure.ac +++ b/configure.ac @@ -1393,8 +1393,8 @@ AC_CONFIG_FILES([compatcheck/Makefile src/bin/keactrl/keactrl.conf src/bin/keactrl/tests/Makefile src/bin/keactrl/tests/keactrl_tests.sh - src/bin/lfc/Makefile - src/bin/lfc/tests/Makefile + src/bin/lfc/Makefile + src/bin/lfc/tests/Makefile src/bin/perfdhcp/Makefile src/bin/perfdhcp/tests/Makefile src/bin/perfdhcp/tests/testdata/Makefile diff --git a/doc/Doxyfile b/doc/Doxyfile index a78375eef1..b27ce0eb31 100644 --- a/doc/Doxyfile +++ b/doc/Doxyfile @@ -650,6 +650,7 @@ INPUT = ../src/bin/d2 \ ../src/bin/dhcp6 \ ../src/bin/perfdhcp \ ../src/bin/sockcreator \ + ../src/bin/lfc \ ../src/hooks/dhcp/user_chk \ ../src/lib/asiolink \ ../src/lib/cc \ diff --git a/src/bin/lfc/Makefile.am b/src/bin/lfc/Makefile.am index c2926f6f39..0b30b18167 100644 --- a/src/bin/lfc/Makefile.am +++ b/src/bin/lfc/Makefile.am @@ -60,15 +60,9 @@ kea_lfc_SOURCES = main.cc kea_lfc_LDADD = liblfc.la kea_lfc_LDADD += $(top_builddir)/src/lib/log/libkea-log.la kea_lfc_LDADD += $(top_builddir)/src/lib/exceptions/libkea-exceptions.la -kea_lfc_LDADD += $(top_builddir)/src/lib/cc/libkea-cc.la -kea_lfc_LDADD += $(top_builddir)/src/lib/asiodns/libkea-asiodns.la kea_lfc_LDADD += $(top_builddir)/src/lib/asiolink/libkea-asiolink.la -kea_lfc_LDADD += $(top_builddir)/src/lib/config/libkea-cfgclient.la -kea_lfc_LDADD += $(top_builddir)/src/lib/dhcp_ddns/libkea-dhcp_ddns.la kea_lfc_LDADD += $(top_builddir)/src/lib/dhcp/libkea-dhcp++.la kea_lfc_LDADD += $(top_builddir)/src/lib/dhcpsrv/libkea-dhcpsrv.la -kea_lfc_LDADD += $(top_builddir)/src/lib/dns/libkea-dns++.la kea_lfc_LDADD += $(top_builddir)/src/lib/util/libkea-util.la -kea_lfc_LDADD += $(top_builddir)/src/lib/hooks/libkea-hooks.la kea_lfcdir = $(pkgdatadir) diff --git a/src/bin/lfc/kea-lfc.xml b/src/bin/lfc/kea-lfc.xml index 5473c3cec5..67c40b4724 100644 --- a/src/bin/lfc/kea-lfc.xml +++ b/src/bin/lfc/kea-lfc.xml @@ -61,7 +61,7 @@ The kea-lfc service process removes redundant information for the files used to provide persistent storage for - the memfile data base back end. The service is written to run as + the memfile data base backend. The service is written to run as a stand alone process. While it can be started externally it should be started by the Kea DHCP servers as desired and required. @@ -123,7 +123,7 @@ - Input or copy of lease file - Before the DHCP serves invokes LFC it will move + Input or copy of lease file - Before the DHCP server invokes LFC it will move the current lease file to this file and then call LFC with the new file. @@ -145,14 +145,6 @@ this file to previous lease file. - - - - - - - - diff --git a/src/bin/lfc/lfc.cc b/src/bin/lfc/lfc.cc index f8e3b450e4..8fc26d0f24 100644 --- a/src/bin/lfc/lfc.cc +++ b/src/bin/lfc/lfc.cc @@ -14,8 +14,6 @@ #include #include -#include -#include #include #include diff --git a/src/bin/lfc/lfc.h b/src/bin/lfc/lfc.h index ec79f7a187..a85bb96fd5 100644 --- a/src/bin/lfc/lfc.h +++ b/src/bin/lfc/lfc.h @@ -50,12 +50,12 @@ public: /// @brief Acts as the primary entry point to start execution /// of the process. Provides the control logic: /// - /// 1. parse command line arguments - /// 2. verifies that it is the only instance - /// 3. creates pid file (TBD) - /// .... TBD - /// 4. remove pid file (TBD) - /// 5. exit to the caller + /// -# parse command line arguments + /// -# verifies that it is the only instance + /// -# creates pid file (TBD) + /// -# .... TBD + /// -# remove pid file (TBD) + /// -# exit to the caller void launch(int argc, char* argv[], const bool test_mode); /// @brief Process the command line arguments. It is the first @@ -80,7 +80,7 @@ public: /// @brief Gets the protocol version of the leaes files /// /// @return Returns the value of the protocol version - int getProtocolVersion() { + int getProtocolVersion() const { return (protocol_version_); } @@ -137,7 +137,7 @@ private: std::string pid_file_; }; -}; // namespace isc:lfc +}; // namespace isc::lfc }; // namespace isc #endif diff --git a/src/bin/lfc/tests/Makefile.am b/src/bin/lfc/tests/Makefile.am index 23ea485887..9e799a2d81 100644 --- a/src/bin/lfc/tests/Makefile.am +++ b/src/bin/lfc/tests/Makefile.am @@ -53,17 +53,10 @@ lfc_unittests_LDADD = $(GTEST_LDADD) lfc_unittests_LDADD += $(top_builddir)/src/bin/lfc/liblfc.la lfc_unittests_LDADD += $(top_builddir)/src/lib/exceptions/libkea-exceptions.la lfc_unittests_LDADD += $(top_builddir)/src/lib/log/libkea-log.la -lfc_unittests_LDADD += $(top_builddir)/src/lib/asiodns/libkea-asiodns.la lfc_unittests_LDADD += $(top_builddir)/src/lib/asiolink/libkea-asiolink.la -lfc_unittests_LDADD += $(top_builddir)/src/lib/cc/libkea-cc.la -lfc_unittests_LDADD += $(top_builddir)/src/lib/config/libkea-cfgclient.la -lfc_unittests_LDADD += $(top_builddir)/src/lib/dhcp_ddns/libkea-dhcp_ddns.la lfc_unittests_LDADD += $(top_builddir)/src/lib/dhcp/libkea-dhcp++.la lfc_unittests_LDADD += $(top_builddir)/src/lib/dhcpsrv/libkea-dhcpsrv.la -lfc_unittests_LDADD += $(top_builddir)/src/lib/dhcpsrv/testutils/libdhcpsrvtest.la -lfc_unittests_LDADD += $(top_builddir)/src/lib/dns/libkea-dns++.la lfc_unittests_LDADD += $(top_builddir)/src/lib/util/libkea-util.la -lfc_unittests_LDADD += $(top_builddir)/src/lib/hooks/libkea-hooks.la endif diff --git a/src/bin/lfc/tests/lfc_controller_unittests.cc b/src/bin/lfc/tests/lfc_controller_unittests.cc index 76753dbb9c..de5f0f91f8 100644 --- a/src/bin/lfc/tests/lfc_controller_unittests.cc +++ b/src/bin/lfc/tests/lfc_controller_unittests.cc @@ -13,12 +13,13 @@ // PERFORMANCE OF THIS SOFTWARE. #include -#include #include using namespace isc::lfc; using namespace std; +namespace { + TEST(lfcControllerTest, initialValues) { lfcController lfcController; @@ -154,3 +155,5 @@ TEST(lfcControllerTest, someBadData) { EXPECT_THROW(lfcController.parseArgs(argc, argv), InvalidUsage); } + +} // end of anonymous namespace From 11e2738768a189676ed0c60f2f4dcef2712728f0 Mon Sep 17 00:00:00 2001 From: Shawn Routhier Date: Thu, 22 Jan 2015 21:54:22 -0800 Subject: [PATCH 06/10] [trac3664] Update per review comments --- src/bin/lfc/.gitignore | 5 + src/bin/lfc/Makefile.am | 4 +- src/bin/lfc/kea-lfc.xml | 50 ++++++--- src/bin/lfc/{lfc.cc => lfc_controller.cc} | 40 ++++--- src/bin/lfc/{lfc.h => lfc_controller.h} | 75 ++++++++----- src/bin/lfc/main.cc | 10 +- src/bin/lfc/tests/.gitignore | 1 + src/bin/lfc/tests/lfc_controller_unittests.cc | 106 +++++++----------- 8 files changed, 165 insertions(+), 126 deletions(-) create mode 100644 src/bin/lfc/.gitignore rename src/bin/lfc/{lfc.cc => lfc_controller.cc} (85%) rename src/bin/lfc/{lfc.h => lfc_controller.h} (59%) create mode 100644 src/bin/lfc/tests/.gitignore diff --git a/src/bin/lfc/.gitignore b/src/bin/lfc/.gitignore new file mode 100644 index 0000000000..1c52fb03e2 --- /dev/null +++ b/src/bin/lfc/.gitignore @@ -0,0 +1,5 @@ +/kea-lfc +/kea-lfc.8 +/lfc_messages.cc +/lfc_messages.h +/s-messages \ No newline at end of file diff --git a/src/bin/lfc/Makefile.am b/src/bin/lfc/Makefile.am index 0b30b18167..77ae8bfdd0 100644 --- a/src/bin/lfc/Makefile.am +++ b/src/bin/lfc/Makefile.am @@ -47,8 +47,8 @@ BUILT_SOURCES = lfc_messages.h lfc_messages.cc noinst_LTLIBRARIES = liblfc.la liblfc_la_SOURCES = -liblfc_la_SOURCES += lfc.h -liblfc_la_SOURCES += lfc.cc +liblfc_la_SOURCES += lfc_controller.h +liblfc_la_SOURCES += lfc_controller.cc nodist_liblfc_la_SOURCES = lfc_messages.h lfc_messages.cc EXTRA_DIST += lfc_messages.mes diff --git a/src/bin/lfc/kea-lfc.xml b/src/bin/lfc/kea-lfc.xml index 67c40b4724..d7cb9bb274 100644 --- a/src/bin/lfc/kea-lfc.xml +++ b/src/bin/lfc/kea-lfc.xml @@ -1,6 +1,6 @@ ]> + []>