Commit 543bfe26 authored by Francis Dupont's avatar Francis Dupont

[65-libyang-option-data] Created a pre test directory to check sysrepo setup

parent 47fb8c4e
......@@ -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
......
SUBDIRS = . tests
SUBDIRS = . pretests tests
AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
AM_CPPFLAGS += $(BOOST_INCLUDES) $(SYSREPO_CPPFLAGS)
......
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)
// 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);
}
......@@ -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.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment