From 99a63ce0a562d9b26ef1ad68b9426d91e6ec35d7 Mon Sep 17 00:00:00 2001 From: JINMEI Tatuya Date: Fri, 1 Jul 2011 17:47:34 -0700 Subject: [PATCH] [trac983] added minimal set of files. right now this is mostly just a placeholder for subsequent development. --- configure.ac | 2 ++ src/lib/python/isc/Makefile.am | 2 +- src/lib/python/isc/acl/Makefile.am | 20 +++++++++++++ src/lib/python/isc/acl/__init__.py | 3 ++ src/lib/python/isc/acl/dns.cc | 38 ++++++++++++++++++++++++ src/lib/python/isc/acl/dns.py | 33 ++++++++++++++++++++ src/lib/python/isc/acl/tests/Makefile.am | 30 +++++++++++++++++++ src/lib/python/isc/acl/tests/dns_test.py | 25 ++++++++++++++++ 8 files changed, 152 insertions(+), 1 deletion(-) create mode 100644 src/lib/python/isc/acl/Makefile.am create mode 100644 src/lib/python/isc/acl/__init__.py create mode 100644 src/lib/python/isc/acl/dns.cc create mode 100644 src/lib/python/isc/acl/dns.py create mode 100644 src/lib/python/isc/acl/tests/Makefile.am create mode 100644 src/lib/python/isc/acl/tests/dns_test.py diff --git a/configure.ac b/configure.ac index 348708fde1..8ac0208c43 100644 --- a/configure.ac +++ b/configure.ac @@ -809,6 +809,8 @@ AC_CONFIG_FILES([Makefile src/lib/cc/tests/Makefile src/lib/python/Makefile src/lib/python/isc/Makefile + src/lib/python/isc/acl/Makefile + src/lib/python/isc/acl/tests/Makefile src/lib/python/isc/util/Makefile src/lib/python/isc/util/tests/Makefile src/lib/python/isc/datasrc/Makefile diff --git a/src/lib/python/isc/Makefile.am b/src/lib/python/isc/Makefile.am index bfc5a912cc..b391c1ee81 100644 --- a/src/lib/python/isc/Makefile.am +++ b/src/lib/python/isc/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = datasrc cc config log net notify util testutils +SUBDIRS = datasrc cc config log net notify util testutils acl python_PYTHON = __init__.py diff --git a/src/lib/python/isc/acl/Makefile.am b/src/lib/python/isc/acl/Makefile.am new file mode 100644 index 0000000000..b6acc53336 --- /dev/null +++ b/src/lib/python/isc/acl/Makefile.am @@ -0,0 +1,20 @@ +SUBDIRS = . tests + +AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib +#Do we need boost? +#AM_CPPFLAGS += $(BOOST_INCLUDES) +AM_CXXFLAGS = $(B10_CXXFLAGS) + +pyexec_LTLIBRARIES = dns.la +dns_la_SOURCES = dns.cc +dns_la_CPPFLAGS = $(AM_CPPFLAGS) $(PYTHON_INCLUDES) +dns_la_LDFLAGS = $(PYTHON_LDFLAGS) +# Note: PYTHON_CXXFLAGS may have some -Wno... workaround, which must be +# placed after -Wextra defined in AM_CXXFLAGS +acl_la_CXXFLAGS = $(AM_CXXFLAGS) $(PYTHON_CXXFLAGS) + +# Python prefers .so, while some OSes (specifically MacOS) use a different +# suffix for dynamic objects. -module is necessary to work this around. +dns_la_LDFLAGS += -module +dns_la_LIBADD = $(top_builddir)/src/lib/acl/libacl.la +dns_la_LIBADD += $(PYTHON_LIB) diff --git a/src/lib/python/isc/acl/__init__.py b/src/lib/python/isc/acl/__init__.py new file mode 100644 index 0000000000..4b61e6a849 --- /dev/null +++ b/src/lib/python/isc/acl/__init__.py @@ -0,0 +1,3 @@ +""" +Here are function and classes for manipulating access control lists. +""" diff --git a/src/lib/python/isc/acl/dns.cc b/src/lib/python/isc/acl/dns.cc new file mode 100644 index 0000000000..d0c0f60da2 --- /dev/null +++ b/src/lib/python/isc/acl/dns.cc @@ -0,0 +1,38 @@ +// Copyright (C) 2011 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 { +PyModuleDef dnsacl = { + { PyObject_HEAD_INIT(NULL) NULL, 0, NULL}, + "acl", + "This module provides Python bindings for the C++ classes in the " + "isc::acl::dns namespace. Specifically, it defines Python interfaces of " + "handling access control lists (ACLs) with DNS related contexts.\n\n" + "These bindings are close match to the C++ API, but they are not complete " + "(some parts are not needed) and some are done in more python-like ways.", + -1, + NULL, + NULL, + NULL, + NULL, + NULL +}; +} // end of unnamed namespace + +PyMODINIT_FUNC +PyInit_dns(void) { + return (PyModule_Create(&dnsacl)); +} diff --git a/src/lib/python/isc/acl/dns.py b/src/lib/python/isc/acl/dns.py new file mode 100644 index 0000000000..8070559b0a --- /dev/null +++ b/src/lib/python/isc/acl/dns.py @@ -0,0 +1,33 @@ +# Copyright (C) 2011 Internet Systems Consortium. +# +# Permission to use, copy, modify, and 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 INTERNET SYSTEMS CONSORTIUM +# DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL +# INTERNET SYSTEMS CONSORTIUM 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. + +# This file is not installed. The log.so is installed into the right place. +# It is only to find it in the .libs directory when we run as a test or +# from the build directory. +# But as nobody gives us the builddir explicitly (and we can't use generation +# from .in file, as it would put us into the builddir and we wouldn't be found) +# we guess from current directory. Any idea for something better? This should +# be enough for the tests, but would it work for B10_FROM_SOURCE as well? +# Should we look there? Or define something in bind10_config? + +import os +import sys + +for base in sys.path[:]: + bindingdir = os.path.join(base, 'isc/acl/.libs') + if os.path.exists(bindingdir): + sys.path.insert(0, bindingdir) + +from dns import * diff --git a/src/lib/python/isc/acl/tests/Makefile.am b/src/lib/python/isc/acl/tests/Makefile.am new file mode 100644 index 0000000000..1b9e9dfe09 --- /dev/null +++ b/src/lib/python/isc/acl/tests/Makefile.am @@ -0,0 +1,30 @@ +PYCOVERAGE_RUN = @PYCOVERAGE_RUN@ +PYTESTS = dns_test.py + +EXTRA_DIST = $(PYTESTS) + +# If necessary (rare cases), explicitly specify paths to dynamic libraries +# required by loadable python modules. +LIBRARY_PATH_PLACEHOLDER = +if SET_ENV_LIBRARY_PATH +LIBRARY_PATH_PLACEHOLDER += $(ENV_LIBRARY_PATH)=$(abs_top_builddir)/src/lib/acl/.libs:$(abs_top_builddir)/src/lib/cc/.libs:$(abs_top_builddir)/src/lib/config/.libs:$(abs_top_builddir)/src/lib/log/.libs:$(abs_top_builddir)/src/lib/util/.libs:$(abs_top_builddir)/src/lib/exceptions/.libs:$$$(ENV_LIBRARY_PATH) +endif + +# test using command-line arguments, so use check-local target instead of TESTS +check-local: +if ENABLE_PYTHON_COVERAGE + touch $(abs_top_srcdir)/.coverage + rm -f .coverage + ${LN_S} $(abs_top_srcdir)/.coverage .coverage +endif + for pytest in $(PYTESTS) ; do \ + echo Running test: $$pytest ; \ + env PYTHONPATH=$(abs_top_builddir)/src/lib/isc/python/acl/.libs:$(abs_top_srcdir)/src/lib/python:$(abs_top_builddir)/src/lib/python \ + $(LIBRARY_PATH_PLACEHOLDER) \ + $(PYCOVERAGE_RUN) $(abs_srcdir)/$$pytest || exit ; \ + done + +CLEANDIRS = __pycache__ + +clean-local: + rm -rf $(CLEANDIRS) diff --git a/src/lib/python/isc/acl/tests/dns_test.py b/src/lib/python/isc/acl/tests/dns_test.py new file mode 100644 index 0000000000..2954a610d7 --- /dev/null +++ b/src/lib/python/isc/acl/tests/dns_test.py @@ -0,0 +1,25 @@ +# Copyright (C) 2011 Internet Systems Consortium. +# +# Permission to use, copy, modify, and 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 INTERNET SYSTEMS CONSORTIUM +# DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL +# INTERNET SYSTEMS CONSORTIUM 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. + +import unittest +from isc.acl.dns import * + +class DNSACLTest(unittest.TestCase): + + def test_placeholder(self): + pass + +if __name__ == '__main__': + unittest.main()