Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions config/ac_lua_extensions.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

AC_DEFUN([AC_LUA_EXTENSIONS],
[
AC_MSG_CHECKING(for --with-lua-extensions)
AC_ARG_WITH(lua-extensions,
AC_HELP_STRING([--with-lua-extensions=],
[enable or disable lua extensions build]),
[ case "$withval" in
yes)
ac_with_lua_extensions=yes
;;
no)
ac_with_lua_extensions=no
;;
*)
ac_with_lua_extensions=yes
;;
esac ]
)
AC_MSG_RESULT(${ac_with_lua_extensions=no})
])
60 changes: 60 additions & 0 deletions config/x_ac_lua.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
##*****************************************************************************
# AUTHOR:
# Mark Grondona <mgrondona@llnl.gov>
#
# SYNOPSIS:
# AC_LUA
#
# DESCRIPTION:
# Check for presence of lua libs and headers
##*****************************************************************************


AC_DEFUN([X_AC_LUA],
[
x_ac_lua_pkg_name="lua"
#check for 5.3 then 5.2 then 5.1
PKG_CHECK_EXISTS([lua5.3], [x_ac_lua_pkg_name=lua5.3],
[PKG_CHECK_EXISTS([lua-5.3], [x_ac_lua_pkg_name=lua-5.3],
[PKG_CHECK_EXISTS([lua5.2], [x_ac_lua_pkg_name=lua5.2],
[PKG_CHECK_EXISTS([lua-5.2], [x_ac_lua_pkg_name=lua-5.2],
[PKG_CHECK_EXISTS([lua5.1], [x_ac_lua_pkg_name=lua5.1],
[PKG_CHECK_EXISTS([lua-5.1], [x_ac_lua_pkg_name=lua-5.1],
[x_ac_lua_pkg_name="lua >= 5.1"])])])])])])
PKG_CHECK_MODULES([lua], ${x_ac_lua_pkg_name},
[x_ac_have_lua="yes"],
[x_ac_have_lua="no"])

if test "x$x_ac_have_lua" = "xyes"; then
saved_CFLAGS="$CFLAGS"
saved_LIBS="$LIBS"
lua_CFLAGS="$lua_CFLAGS"
CFLAGS="$CFLAGS $lua_CFLAGS"
LIBS="$LIBS $lua_LIBS"
AC_MSG_CHECKING([for whether we can link to liblua])
AC_TRY_LINK(
[#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
],
[lua_State *L = luaL_newstate (); luaL_openlibs(L);
],
[], [x_ac_have_lua="no"])

AC_MSG_RESULT([$x_ac_have_lua $x_ac_lua_pkg_name])
if test "x$x_ac_have_lua" = "xno"; then
AC_MSG_WARN([unable to link against lua libraries])
else
AC_DEFINE(HAVE_LUA, 1, [Define to 1 if we have the Lua library])
# We can not define something here to determine version for systems
# that use just liblua we will not know what version we are using.
# Use LUA_VERSION_NUM as in lua.h it will always be right.
fi
CFLAGS="$saved_CFLAGS"
LIBS="$saved_LIBS"
else
AC_MSG_WARN([unable to locate lua package])
fi

AM_CONDITIONAL(HAVE_LUA, test "x$x_ac_have_lua" = "xyes")
])
21 changes: 21 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ PYTHONGENDERS_MINOR=2
PYTHONGENDERS_VERSION=$PYTHONGENDERS_MAJOR.$PYTHONGENDERS_MINOR
AC_SUBST([PYTHONGENDERS_VERSION])


##
# Checks for programs.
##
Expand All @@ -86,6 +87,7 @@ AC_PATH_PROG([JAVAH], [javah])
AC_PATH_PROG([JAVA], [java])
AC_PATH_PROG([JAR], [jar])
AC_PATH_PROG([JAVADOC], [javadoc])
AC_PATH_PROG([JAVADOC], [lua])
AC_DEBUG

##
Expand Down Expand Up @@ -206,6 +208,24 @@ AM_CONDITIONAL(WITH_CPLUSPLUS_EXTENSIONS, [test "$ac_with_cplusplus_extensions"
AC_JAVA_EXTENSIONS
AM_CONDITIONAL(WITH_JAVA_EXTENSIONS, [test "$ac_with_java_extensions" = "yes"])

#
# Check for lua, which means create commanline conditional
#
AC_LUA_EXTENSIONS
AM_CONDITIONAL(WITH_LUA_EXTENSIONS, [test "$ac_with_lua_extensions" = "yes"])
#
# expand lua
#
if test "x$ac_with_lua_extensions" = "xyes" ; then
# beware, the ACTION-IF-NOT-FOUND is not working
AX_PROG_LUA([5.3],,,:)
# The test of headers fail, if LUA_VERSION is empty
if test LUA_VERSION ; then
AX_LUA_HEADERS
AX_LUA_LIBS
fi
fi

##
# Checks for typedefs, structures, and compiler characteristics.
##
Expand Down Expand Up @@ -246,6 +266,7 @@ AC_CONFIG_FILES( \
src/extensions/perl/Genders/Makefile \
src/extensions/perl/Genders/Genders.pm \
src/extensions/python/Makefile \
src/extensions/lua/Makefile \
src/extensions/python/genderssetup.py \
src/extensions/java/Makefile \
src/testsuite/Makefile \
Expand Down
110 changes: 110 additions & 0 deletions genders.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
Name: genders
Version: 1.26
Release: 1
Summary: Static cluster configuration database
URL: https://github.com/chaos/genders
Group: System Environment/Base
License: GPL
Source: %{name}-%{version}.tar.gz
Requires: perl
BuildRequires: bison flex
BuildRequires: perl(ExtUtils::MakeMaker)
BuildRequires: python
BuildRequires: python-devel
BuildRequires: libtool
BuildRoot: %{_tmppath}/%{name}-%{version}

%description
Genders is a static cluster configuration database used for cluster
configuration management. It is used by a variety of tools and
scripts for management of large clusters. The genders database is
typically replicated on every node of the cluster. It describes the
layout and configuration of the cluster so that tools and scripts can
sense the variations of cluster nodes. By abstracting this information
into a plain text file, it becomes possible to change the
configuration of a cluster by modifying only one file.

%package compat
Summary: Compatibility library
Group: System Environment/Base
%description compat
genders API that is compatible with earlier releases of genders

%{!?_with_perl_extensions: %{!?_without_perl_extensions: %define _with_perl_extensions --with-perl-extensions}}
%{!?_with_python_extensions: %{!?_without_python_extensions: %define _with_python_extensions --with-python-extensions}}
%{!?_with_cplusplus_extensions: %{!?_without_cplusplus_extensions: %define _with_cplusplus_extensions --with-cplusplus-extensions}}
%{!?_with_java_extensions: %{!?_without_java_extensions: %define _without_java_extensions --without-java-extensions}}
%{!?_with_lua_extensions: %{!?_without_lua_extensions: %define _without_lua_extensions --without-lua-extensions}}

# choose vendor arch by default
%{!?_with_perl_site_arch: %{!?_with_perl_vendor_arch: %define _with_perl_vendor_arch --with-perl-vendor-arch}}

%prep
%setup -q -n %{name}-%{version}

%build
%configure --program-prefix=%{?_program_prefix:%{_program_prefix}} \
--with-extension-destdir="$RPM_BUILD_ROOT" \
%{?_with_perl_extensions} \
%{?_without_perl_extensions} \
%{?_with_perl_site_arch} \
%{?_without_perl_site_arch} \
%{?_with_perl_vendor_arch} \
%{?_without_perl_vendor_arch} \
%{?_with_python_extensions} \
%{?_without_python_extensions} \
%{?_with_cplusplus_extensions} \
%{?_without_cplusplus_extensions} \
%{?_with_java_extensions} \
%{?_without_java_extensions}\
%{?_with_lua_extensions} \
%{?_without_lua_extension}
make

%install
rm -rf $RPM_BUILD_ROOT
DESTDIR="$RPM_BUILD_ROOT" make install

%files
%defattr(-,root,root)
%doc README NEWS ChangeLog DISCLAIMER DISCLAIMER.UC COPYING TUTORIAL genders.sample
%if %{?_with_java_extensions:1}%{!?_with_java_extensions:0}
%dir %{_datadir}/doc/%{name}-%{version}-javadoc/
%doc %{_datadir}/doc/%{name}-%{version}-javadoc/*
%endif
# It doesn't matter if the user chooses a 32bit or 64bit target. The
# packaging must work off whatever Perl is installed.
%if %{?_with_perl_site_arch:1}%{!?_with_perl_site_arch:0}
%define _perldir %(perl -e 'use Config; $T=$Config{installsitearch}; $P=$Config{siteprefix}; $T=~/$P\\/(.*)/; print "%{_prefix}/$1\\n"')
%endif
%if %{?_with_perl_vendor_arch:1}%{!?_with_perl_vendor_arch:0}
%define _perldir %(perl -e 'use Config; $T=$Config{installvendorarch}; $P=$Config{vendorprefix}; $T=~/$P\\/(.*)/; print "%{_prefix}/$1\\n"')
%endif
%{_mandir}/man1/*
%{_mandir}/man3/genders*
%{_mandir}/man3/libgenders*
%{_includedir}/*
%{_bindir}/*
%{_libdir}/libgenders.*
%if %{?_with_perl_extensions:1}%{!?_with_perl_extensions:0}
%{_mandir}/man3/Libgenders*
%{_mandir}/man3/Genders*
%{_perldir}/*
%endif
%if %{?_with_python_extensions:1}%{!?_with_python_extensions:0}
%{_exec_prefix}/lib*/python*
%endif
%if %{?_with_cplusplus_extensions:1}%{!?_with_cplusplus_extensions:0}
%{_libdir}/libgendersplusplus.*
%endif
%if %{?_with_java_extensions:1}%{!?_with_java_extensions:0}
%{_javadir}/*
%{_libdir}/libGendersjni.*
%endif

%files compat
%defattr(-,root,root)
%{_mandir}/man3/gendlib*
%{_prefix}/lib/genders/*


2 changes: 1 addition & 1 deletion src/extensions/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
## Process this file with automake to produce Makefile.in.
##*****************************************************************************

SUBDIRS = cplusplus java perl python
SUBDIRS = cplusplus java perl python lua
134 changes: 134 additions & 0 deletions src/extensions/lua/GendersTest/GendersTest.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
#!/usr/bin/lua

db_file = "testgenders"

genders_lib = require("genders")
genders_handle = nil

-- wrapper to for using pcall
function wrapper_new()
genders_handle = genders_lib.new(db_file)
end

str_err = ""
str_out = ""

no_load = nil
error_status = 0

getter_funcs = {"getnumattrs","getnumnodes","getnodes"}
list_nodes = {"foobar","hype355","null"}
list_attr = {"foobar","mgmt"}
-- attr <-> value mismatch as this is dict!
list_attrval = {["foobaar"] = "cfhost", ["hypei"] = "cfhost"}
list_query = { "mgmt","mgmt||login","mhmt&&login","~mgmt"}

local open_lib, genders_handle = pcall(genders_lib.new,db_file,genders_lib)
if open_lib then
print("Loaded database \""..db_file.."\"")
for _, func_name in ipairs(getter_funcs) do
local str = "return function(handle) return pcall(handle."..func_name..",handle) end"
local wrap_func = assert(load(str))
local func = wrap_func()
local ok,ret_val = func(genders_handle)
if ok then
if type(ret_val) ~= "table" then
print(func_name.." :: "..ret_val)
else
local tmp_str = func_name.." :: "
for _,val in ipairs(ret_val) do
tmp_str = tmp_str..val..", "
end
print(tmp_str)
end
else
error_status = 1
str_err = "Could not call "..func_name..": "..ret_val
end
end
local ok, ret_val = pcall(genders_handle.getnodes,genders_handle,"mgmt")
if ok then
local tmp_str = "getnodes(\"mgmt\") :: " for _,val in ipairs(ret_val) do tmp_str = tmp_str..val..", " end
print(tmp_str)
else
error_status = 1
str_err = "Could not call: getnodes(\"mgmt\")"..ret_val
end
local ok, ret_val = pcall(genders_handle.getnodes,genders_handle,"foobarlalala")
if ok then
local tmp_str = "getnodes(\"foobarlalala\") :: " for _,val in ipairs(ret_val) do tmp_str = tmp_str..val..", " end
print(tmp_str)
else
error_status = 1
str_err = "Could not call: getnodes(\"foobarlalala\")"..ret_val
end
local ok, ret_val = pcall(genders_handle.getnodes,genders_handle,"cfhost","foobar")
if ok then
local tmp_str = "getnodes(\"cfhost\",\"foobar\") :: " for _,val in ipairs(ret_val) do tmp_str = tmp_str..val..", " end
print(tmp_str)
else
error_status = 1
str_err = "Could not call: getnodes(\"cfhost\",\"foobar\")"..ret_val
end
local ok, ret_val = pcall(genders_handle.getnodes,genders_handle,"cfhost","hypei")
if ok then
local tmp_str = "getnodes(\"cfhost\",\"hypei\") :: " for _,val in ipairs(ret_val) do tmp_str = tmp_str..val..", " end
print(tmp_str)
else
error_status = 1
str_err = "Could not call: getnodes(\"cfhost\",\"hypei\")"..ret_val
end
local ok, ret_val = pcall(genders_handle.getattr,genders_handle,"hype355")
if ok then
local tmp_str = "getattr(\"hype355\") :: " for key,value in pairs(ret_val) do tmp_str = tmp_str..key if value == "" then tmp_str = tmp_str..", " else tmp_str = tmp_str.."="..value.."," end end
print(tmp_str)
else
error_status = 1
str_err = "Could not call: getattr(\"hype355\")"..ret_val
end
for _,node in ipairs(list_nodes) do
local ok, ret_val = pcall(genders_handle.isnode,genders_handle,node)
if ok then
if ret_val then print("isnode("..node..") = true") else print("isnode("..node..") = false") end
else
error_status = 1
str_err = "Could not call: isnode("..node..") "..ret_val
end
end
for _,attr in ipairs(list_attr) do
local ok, ret_val = pcall(genders_handle.isattr,genders_handle,attr)
if ok then
if ret_val then print("isattr("..attr..") = true") else print("isattr("..attr..") = false") end
else
error_status = 1
str_err = "Could not call: isattr("..attr..") "..ret_val
end
end
for value,attr in pairs(list_attrval) do
local ok, ret_val = pcall(genders_handle.isattrval,genders_handle,attr,value)
if ok then
if ret_val then print("isattrval("..attr..","..value..") = true") else print("isattrval("..attr..","..value..") = false") end
else
error_status = 1
str_err = "Could not call: isattr("..attr..") "..ret_val
end
end
for _,qry in ipairs(list_query) do
local ok, ret_val = pcall(genders_handle.query,genders_handle,qry)
if ok then
local tmp_str = "query("..qry..") :: " for _,val in pairs(ret_val) do tmp_str = tmp_str..val..", " end
print(tmp_str)
else
error_status = 1
str_err = "Could not call: query("..qry..")"..ret_val
end
end
else
str_err = "Failure in loading database \""..db_file.."\""
error_status = 1
end
if error_status == 0 then
print("No errors")
else
print("Collected errors are: "..str_err)
end
Loading