From: Francis Dupont Date: Sat, 22 Sep 2018 16:45:30 +0000 (+0200) Subject: [65-libyang-option-data] Created a pre test directory to check sysrepo setup X-Git-Tag: 65-libyang-option-data_before_rebase~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=543bfe26905f7efef44e342bf4fd07560063bbca;p=thirdparty%2Fkea.git [65-libyang-option-data] Created a pre test directory to check sysrepo setup --- diff --git a/configure.ac b/configure.ac index b784dfc19a..35525467b2 100644 --- a/configure.ac +++ b/configure.ac @@ -1602,6 +1602,7 @@ AC_CONFIG_FILES([Makefile src/lib/util/threads/tests/Makefile src/lib/util/unittests/Makefile src/lib/yang/Makefile + src/lib/yang/pretests/Makefile src/lib/yang/tests/Makefile src/share/Makefile src/share/database/Makefile diff --git a/src/lib/yang/Makefile.am b/src/lib/yang/Makefile.am index 5b44159b88..7218d77642 100644 --- a/src/lib/yang/Makefile.am +++ b/src/lib/yang/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = . tests +SUBDIRS = . pretests tests AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib AM_CPPFLAGS += $(BOOST_INCLUDES) $(SYSREPO_CPPFLAGS) diff --git a/src/lib/yang/pretests/Makefile.am b/src/lib/yang/pretests/Makefile.am new file mode 100644 index 0000000000..a3d841dabc --- /dev/null +++ b/src/lib/yang/pretests/Makefile.am @@ -0,0 +1,9 @@ +CLEANFILES = *.gcno *.gcda + +TESTS = sysrepo_setup_tests +sysrepo_setup_tests_SOURCES = sysrepo_setup_tests.cc +sysrepo_setup_tests_CPPFLAGS = $(SYSREPO_CPPFLAGS) +sysrepo_setup_tests_LDFLAGS = $(AM_LDFLAGS) +sysrepo_setup_tests_LDADD = $(SYSREPO_LIBS) + +noinst_PROGRAMS = $(TESTS) diff --git a/src/lib/yang/pretests/sysrepo_setup_tests.cc b/src/lib/yang/pretests/sysrepo_setup_tests.cc new file mode 100644 index 0000000000..360d64291e --- /dev/null +++ b/src/lib/yang/pretests/sysrepo_setup_tests.cc @@ -0,0 +1,120 @@ +// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC") +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include + +#include + +using namespace std; + +const string TEST_MODULE = "keatest-module"; +const string IETF_MODULE = "ietf-dhcpv6-server"; +const string KEA_DHCP4_MODULE = "kea-dhcp4-server"; +const string KEA_DHCP6_MODULE = "kea-dhcp6-server"; +const string KEA_CTRL_AGENT_MODULE = "kea-ctrl-agent"; +const string KEA_D2_MODULE = "kea-dhcp-ddns"; + +/// @brief Checks sysrepo setup: +/// - connection establishment +/// - daemon required +/// - session establishment +/// - test module +/// - IETF module +/// - Kea modules. +int main() { + S_Connection conn; + try { + conn.reset(new Connection("sysrepo setup check")); + } catch (const sysrepo_exception& ex) { + cerr << "Can't connect to sysrepo: " << ex.what() << endl; + exit(-1); + } + try { + conn.reset(new Connection("sysrepo setup check", + SR_CONN_DAEMON_REQUIRED)); + } catch (const sysrepo_exception& ex) { + cerr <<"Can't require sysrepo daemon: " <list_schemas(); + } catch (const sysrepo_exception& ex) { + cerr << "Can't list available schemas: " << ex.what() << endl; + } + bool found_test = false; + bool found_ietf = false; + bool found_kea4 = false; + bool found_kea6 = false; + bool found_keaca = false; + bool found_kea2 = false; + for (size_t i = 0; i < schemas->schema_cnt(); ++i) { + string module = schemas->schema(i)->module_name(); + size_t rev = module.find("@"); + if (rev != string::npos) { + module = module.substr(0, rev); + } + if (module == TEST_MODULE) { + found_test = true; + } else if (module == IETF_MODULE) { + found_ietf = true; + } else if (module == KEA_DHCP4_MODULE) { + found_kea4 = true; + } else if (module == KEA_DHCP6_MODULE) { + found_kea6 = true; + } else if (module == KEA_CTRL_AGENT_MODULE) { + found_keaca = true; + } else if (module == KEA_D2_MODULE) { + found_kea2 = true; + } + } + + if (!found_test) { + cerr << "Module used in unit-tests " << TEST_MODULE + << " is not installed. The environment is not suitable for " + << "running unit-tests. Please locate " << TEST_MODULE + << ".yang and issue the following command:" << endl + << "sysrepoctl --i -g " << TEST_MODULE << ".yang" << endl; + exit(-4); + } + + if (!found_ietf) { + cerr << "Please install " << IETF_MODULE << " module" << endl; + exit(-5); + } + + if (!found_kea4) { + cerr <<"Please install " << KEA_DHCP4_MODULE << " module" << endl; + exit(-6); + } + + if (!found_kea6) { + cerr <<"Please install " << KEA_DHCP6_MODULE << " module" << endl; + exit(-7); + } + + if (!found_keaca) { + cerr <<"Please install " << KEA_CTRL_AGENT_MODULE << " module" << endl; + exit(-8); + } + + if (!found_kea2) { + cerr <<"Please install " << KEA_D2_MODULE<< " module" << endl; + exit(-9); + } + + exit(0); +} diff --git a/src/lib/yang/tests/translator_unittests.cc b/src/lib/yang/tests/translator_unittests.cc index 074afc1628..3329ad2c98 100644 --- a/src/lib/yang/tests/translator_unittests.cc +++ b/src/lib/yang/tests/translator_unittests.cc @@ -18,56 +18,6 @@ using namespace isc::yang; namespace { -const std::string TEST_MODULE="keatest-module"; - - -/// @brief checks if specified schema is installed and available in sysrepo -/// -/// @name name of the schema to be checked (without .yang) -/// @verbose print installed schemas? -/// @return true if installed, false otherwise. -bool schemaInstalled(const std::string& name, bool verbose = false) { - // Get a connection. - S_Connection conn(new Connection("translator unittests")); - // Get a session. - S_Session sess(new Session(conn, SR_DS_CANDIDATE)); - - S_Yang_Schemas schemas = sess->list_schemas(); - - size_t schema_cnt = schemas->schema_cnt(); - - if (verbose) { - cout << "There are " << schema_cnt << " YANG schema(s) installed:" << endl; - } - - bool found = false; - for (int i = 0; i < schema_cnt; i++) { - string installed_name(schemas->schema(i)->module_name()); - if (installed_name == name) { - found = true; - } - - if (verbose) { - std::cout << "Schema " << i << ": " << installed_name << endl; - } - } - - return (found); -} - -// This test verifies if the test schema is installed and accessible. -TEST(TranslatorBasicTest, environmentCheck1) { - - EXPECT_TRUE(schemaInstalled(TEST_MODULE)) - << "\nERROR: Module used in unit-tests " << TEST_MODULE - << " is not installed. The environment is not suitable for\n" - << "ERROR: running unit-tests. Please locate " << TEST_MODULE <<".yang " - << "and issue the following command:\n" - << "ERROR: sysrepoctl --install --yang=" << TEST_MODULE << ".yang\n" - << "ERROR:\n" - << "ERROR: Following tests will most likely fail.\n"; -} - // Test constructor. TEST(TranslatorBasicTest, constructor) { // Get a connection.