]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[65-libyang-option-data] Created a pre test directory to check sysrepo setup
authorFrancis Dupont <fdupont@isc.org>
Sat, 22 Sep 2018 16:45:30 +0000 (18:45 +0200)
committerFrancis Dupont <fdupont@isc.org>
Sat, 22 Sep 2018 16:45:30 +0000 (18:45 +0200)
configure.ac
src/lib/yang/Makefile.am
src/lib/yang/pretests/Makefile.am [new file with mode: 0644]
src/lib/yang/pretests/sysrepo_setup_tests.cc [new file with mode: 0644]
src/lib/yang/tests/translator_unittests.cc

index b784dfc19a970b5b0ea1dd7cd33d160bb6f886fc..35525467b2f97bcbf687c7e433c09b4d3381282e 100644 (file)
@@ -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
index 5b44159b887d60eae8a0d8563aa05e5cdf508481..7218d77642497a1cbf142fb7047c4a3f9b8e24ef 100644 (file)
@@ -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 (file)
index 0000000..a3d841d
--- /dev/null
@@ -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 (file)
index 0000000..360d642
--- /dev/null
@@ -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 <config.h>
+
+#include <sysrepo-cpp/Session.h>
+
+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: " <<ex.what() << endl
+             << endl
+             << "Sysrepo daemon is required or actions will be local to "
+             << "the local library instance" << endl;
+        exit(-2);
+    }
+    S_Session sess;
+    try {
+        sess.reset(new Session(conn, SR_DS_CANDIDATE));
+    } catch (const sysrepo_exception& ex) {
+        cerr << "Can't establish a sysrepo session: " << ex.what() << endl;
+        exit(-3);
+    }
+    S_Yang_Schemas schemas;
+    try {
+        schemas = sess->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);
+}
index 074afc1628bb2b4b3f4336945280b34387b01616..3329ad2c9885905d18464e87034fc09dde044510 100644 (file)
@@ -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.