ctdb-tests: Fix remaining common.sh ShellCheck hits
[vlendec/samba-autobuild/.git] / ctdb / wscript
index c762106ccc055a0f3aa94b28dd0f74b84680af02..c2f1956a916ad83f8e39c2bc9fde183ef58db4aa 100644 (file)
@@ -2,20 +2,21 @@
 
 APPNAME = 'ctdb'
 
-blddir = 'bin'
-
 import sys, os
 
 # find the buildtools directory
-srcdir = '.'
-while not os.path.exists(srcdir+'/buildtools') and len(srcdir.split('/')) < 5:
-    srcdir = srcdir + '/..'
-sys.path.insert(0, srcdir + '/buildtools/wafsamba')
+top = '.'
+while not os.path.exists(top+'/buildtools') and len(top.split('/')) < 5:
+    top = top + '/..'
+sys.path.insert(0, top + '/buildtools/wafsamba')
+
+out = 'bin'
 
-import wafsamba, samba_dist, Options, Logs, Utils
-import samba_utils, samba_version
+from waflib import Options, Logs, Errors, Context
+import wafsamba
+from wafsamba import samba_dist, samba_utils
+from samba_utils import MODE_644, MODE_744, MODE_755, MODE_777
 
-env = samba_utils.LOAD_ENVIRONMENT()
 if os.path.isfile('./VERSION'):
     vdir = '.'
 elif os.path.isfile('../VERSION'):
@@ -23,9 +24,6 @@ elif os.path.isfile('../VERSION'):
 else:
     Logs.error("VERSION file not found")
 
-version = samba_version.samba_version_file('%s/VERSION' % vdir, vdir, env)
-VERSION = version.STRING.replace('-', '.')
-
 default_prefix = Options.default_prefix = '/usr/local'
 
 samba_dist.DIST_DIRS('''ctdb:. lib/replace:lib/replace lib/talloc:lib/talloc
@@ -64,8 +62,22 @@ manpages_ceph = [
     'ctdb_mutex_ceph_rados_helper.7',
 ]
 
+VERSION = ''
+
+def get_version():
+    import samba_version
+    env = samba_utils.LOAD_ENVIRONMENT()
+
+    return samba_version.samba_version_file('%s/VERSION' % vdir, vdir, env)
 
-def set_options(opt):
+def get_version_string():
+    if Context.g_module.VERSION:
+        return Context.g_module.VERSION
+    version = get_version()
+    Context.g_module.VERSION = version.STRING.replace('-', '.')
+    return Context.g_module.VERSION
+
+def options(opt):
     opt.PRIVATE_EXTENSION_DEFAULT('ctdb')
 
     opt.RECURSE('lib/replace')
@@ -85,6 +97,10 @@ def set_options(opt):
     opt.add_option('--enable-etcd-reclock',
                    help=("Enable etcd recovery lock helper (default=no)"),
                    action="store_true", dest='ctdb_etcd_reclock', default=False)
+
+    opt.add_option('--with-libcephfs',
+                   help=("Directory under which libcephfs is installed"),
+                   action="store", dest='libcephfs_dir', default=None)
     opt.add_option('--enable-ceph-reclock',
                    help=("Enable Ceph CTDB recovery lock helper (default=no)"),
                    action="store_true", dest='ctdb_ceph_reclock', default=False)
@@ -98,7 +114,6 @@ def set_options(opt):
 
 
 def configure(conf):
-
     # No need to build python bindings for talloc/tevent/tdb
     if conf.IN_LAUNCH_DIR():
         conf.env.standalone_ctdb = True
@@ -135,7 +150,7 @@ def configure(conf):
             conf.env.SOCKET_WRAPPER_SO_PATH = conf.CONFIG_GET('LIBSOCKET_WRAPPER_SO_PATH')
     else:
         if not conf.CHECK_POPT():
-            raise Utils.WafError('popt development packages have not been found\nIf third_party is installed, check that it is in the proper place.')
+            raise Errors.WafError('popt development packages have not been found\nIf third_party is installed, check that it is in the proper place.')
         else:
             conf.define('USING_SYSTEM_POPT', 1)
         conf.env.SOCKET_WRAPPER_SO_PATH = ''
@@ -143,7 +158,7 @@ def configure(conf):
 
         if conf.env.standalone_ctdb or conf.CONFIG_GET('ENABLE_SELFTEST'):
             if not conf.CHECK_SOCKET_WRAPPER():
-                raise Utils.WafError('socket_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
+                raise Errors.WafError('socket_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
             else:
                 conf.define('USING_SYSTEM_SOCKET_WRAPPER', 1)
                 conf.env.SOCKET_WRAPPER_SO_PATH = conf.CONFIG_GET('LIBSOCKET_WRAPPER_SO_PATH')
@@ -237,8 +252,16 @@ def configure(conf):
     conf.env.etcd_reclock = have_etcd_reclock
 
     if Options.options.ctdb_ceph_reclock:
+        # Use custom libcephfs library path if provided. XXX The top level build
+        # explicitly sets LIBPATH_CEPH-COMMON when libcephfs_dir isn't provided.
+        if Options.options.libcephfs_dir:
+            conf.env['CPPPATH_RADOS'] = Options.options.libcephfs_dir + '/include'
+            conf.env['LIBPATH_RADOS'] = Options.options.libcephfs_dir + '/lib'
+            conf.env['LIBPATH_CEPH-COMMON'] = conf.env['LIBPATH_RADOS'] + '/ceph'
+
         if (conf.CHECK_HEADERS('rados/librados.h', False, False, 'rados') and
                                        conf.CHECK_LIB('rados', shlib=True)):
+            conf.CHECK_LIB('ceph-common', shlib=True)
             Logs.info('Building with Ceph librados recovery lock support')
             conf.define('HAVE_LIBRADOS', 1)
         else:
@@ -246,6 +269,7 @@ def configure(conf):
             sys.exit(1)
 
     conf.env.CTDB_BINDIR = os.path.join(conf.env.EXEC_PREFIX, 'bin')
+    conf.env.CTDB_DATADIR = os.path.join(conf.env.EXEC_PREFIX, 'share/ctdb')
     conf.env.CTDB_ETCDIR = os.path.join(conf.env.SYSCONFDIR, 'ctdb')
     conf.env.CTDB_VARDIR = os.path.join(conf.env.LOCALSTATEDIR, 'lib/ctdb')
     conf.env.CTDB_RUNDIR = os.path.join(conf.env.LOCALSTATEDIR, 'run/ctdb')
@@ -265,17 +289,18 @@ def configure(conf):
 
     conf.ADD_CFLAGS('''-DCTDB_HELPER_BINDIR=\"%s\"
                        -DLOGDIR=\"%s\"
+                       -DCTDB_DATADIR=\"%s\"
                        -DCTDB_ETCDIR=\"%s\"
                        -DCTDB_VARDIR=\"%s\"
                        -DCTDB_RUNDIR=\"%s\"''' % (
                     conf.env.CTDB_HELPER_BINDIR,
                     conf.env.CTDB_LOGDIR,
+                    conf.env.CTDB_DATADIR,
                     conf.env.CTDB_ETCDIR,
                     conf.env.CTDB_VARDIR,
                     conf.env.CTDB_RUNDIR))
 
-    conf.env.CTDB_TEST_DATADIR = os.path.join(conf.env.EXEC_PREFIX,
-                                              'share/ctdb/tests')
+    conf.env.CTDB_TEST_DATADIR = os.path.join(conf.env.CTDB_DATADIR, 'tests')
     conf.env.CTDB_TEST_LIBEXECDIR = os.path.join(conf.env.LIBEXECDIR, 'ctdb/tests')
 
     # Allow unified compilation and separate compilation of utilities
@@ -283,7 +308,7 @@ def configure(conf):
     if not conf.env.standalone_ctdb:
         conf.ADD_EXTRA_INCLUDES('#include/public #ctdb/include #ctdb')
     else:
-        if srcdir == '.':
+        if Context.g_module.top == '.':
             # Building from tarball
             conf.ADD_EXTRA_INCLUDES('#include')
         else:
@@ -316,11 +341,11 @@ def configure(conf):
                 Logs.info("  %s: no" % (m))
 
 def gen_ctdb_version(task):
-    fp = file(task.outputs[0].bldpath(task.env), 'w')
+    fp = open(task.outputs[0].bldpath(task.env), 'w')
     fp.write('/* This file is auto-generated from waf */\n')
     fp.write('#include "version.h"\n')
     fp.write('\n')
-    fp.write('#define CTDB_VERSION_STRING "%s"\n' % VERSION)
+    fp.write('#define CTDB_VERSION_STRING "%s"\n' % get_version_string())
     fp.close()
 
 
@@ -336,7 +361,7 @@ def build(bld):
                             target='include/ctdb_version.h',
                             rule=gen_ctdb_version,
                             dep_vars=['VERSION'])
-    t.env.VERSION = VERSION
+    t.env.VERSION = get_version_string()
 
     bld.env.PKGCONFIGDIR = '${LIBDIR}/pkgconfig'
 
@@ -400,9 +425,10 @@ def build(bld):
                                              pkt_read.c pkt_write.c comm.c
                                              logging.c rb_tree.c tunable.c
                                              pidfile.c run_proc.c
-                                             hash_count.c run_event.c
+                                             hash_count.c
+                                             run_event.c event_script.c
                                              sock_client.c version.c
-                                             cmdline.c path.c conf.c
+                                             cmdline.c path.c conf.c line.c
                                           '''),
                         deps='''samba-util sys_rw tevent-util
                                 replace talloc tevent tdb popt''')
@@ -426,14 +452,13 @@ def build(bld):
                                              protocol_tunnel.c
                                              protocol_client.c
                                              protocol_debug.c
-                                             protocol_event.c
                                              protocol_sock.c'''),
                         includes='include',
                         deps='ctdb-protocol-basic replace talloc tdb')
 
     bld.SAMBA_SUBSYSTEM('ctdb-protocol-util',
                         source='protocol/protocol_util.c',
-                        deps='replace talloc tdb')
+                        deps='ctdb-util replace talloc tdb')
 
     bld.SAMBA_SUBSYSTEM('ctdb-client',
                         source=bld.SUBDIR('client',
@@ -442,7 +467,7 @@ def build(bld):
                                              client_message_sync.c
                                              client_control_sync.c
                                              client_db.c client_util.c
-                                             client_event.c client_tunnel.c
+                                             client_tunnel.c
                                           '''),
                         includes='include',
                         deps='replace talloc tevent tdb tdb-wrap')
@@ -482,6 +507,10 @@ def build(bld):
                         source='event/event_conf.c',
                         deps='ctdb-util')
 
+    bld.SAMBA_SUBSYSTEM('ctdb-failover-conf',
+                        source='failover/failover_conf.c',
+                        deps='ctdb-util')
+
     bld.SAMBA_SUBSYSTEM('ctdb-legacy-conf',
                         source='server/legacy_conf.c',
                         deps='ctdb-util')
@@ -493,10 +522,44 @@ def build(bld):
                              ctdb-event-conf
                              ctdb-cluster-conf
                              ctdb-database-conf
+                             ctdb-failover-conf
                              ctdb-legacy-conf
                              ctdb-util samba-util talloc replace popt''',
                      install_path='${CTDB_HELPER_BINDIR}')
 
+    bld.SAMBA_SUBSYSTEM('ctdb-event-protocol',
+                        source=bld.SUBDIR('event',
+                                          '''event_protocol.c
+                                             event_protocol_util.c
+                                          '''),
+                        deps='ctdb-protocol-basic')
+
+    bld.SAMBA_LIBRARY('ctdb-event-client',
+                      source='event/event_client.c',
+                      deps='ctdb-event-protocol ctdb-util tevent talloc',
+                      private_library=True)
+
+    bld.SAMBA_BINARY('ctdb-eventd',
+                     source=bld.SUBDIR('event',
+                                       '''event_cmd.c
+                                          event_config.c
+                                          event_context.c
+                                          event_daemon.c
+                                          event_request.c
+                                          '''),
+                     deps='''ctdb-event-protocol
+                             ctdb-event-conf ctdb-logging-conf
+                             ctdb-server-util samba-util ctdb-util
+                             talloc tevent replace popt''',
+                     install_path='${CTDB_HELPER_BINDIR}')
+
+    bld.SAMBA_BINARY('ctdb-event',
+                        source='event/event_tool.c',
+                        cflags='-DCTDB_EVENT_TOOL',
+                        deps='''ctdb-event-client ctdb-event-protocol
+                                ctdb-util samba-util talloc replace''',
+                        install_path='${CTDB_HELPER_BINDIR}')
+
     bld.SAMBA_BINARY('ctdbd',
                      source='server/ctdbd.c ' +
                                bld.SUBDIR('server',
@@ -525,7 +588,9 @@ def build(bld):
                              ctdb-cluster-conf
                              ctdb-database-conf
                              ctdb-event-conf
+                             ctdb-failover-conf
                              ctdb-legacy-conf
+                             ctdb-event-protocol
                              talloc tevent tdb-wrap tdb talloc_report''' +
                           ib_deps,
                      install_path='${SBINDIR}',
@@ -544,12 +609,6 @@ def build(bld):
                              samba-util replace''',
                      install_path='${CTDB_HELPER_BINDIR}')
 
-    bld.SAMBA_BINARY('ctdb_event',
-                     source='tools/ctdb_event.c',
-                     deps='''ctdb-client ctdb-protocol ctdb-protocol-util
-                             ctdb-util ctdb-system samba-util replace''',
-                     install_path='${CTDB_HELPER_BINDIR}')
-
     bld.SAMBA_BINARY('ltdbtool',
                      source='tools/ltdbtool.c',
                      includes='include',
@@ -557,12 +616,6 @@ def build(bld):
                      install_path='${BINDIR}',
                      manpages='ltdbtool.1')
 
-    bld.SAMBA_BINARY('ctdb_eventd',
-                     source='server/ctdb_eventd.c',
-                     deps='''ctdb-server-util ctdb-protocol ctdb-protocol-util
-                             ctdb-util samba-util replace popt''',
-                     install_path='${CTDB_HELPER_BINDIR}')
-
     bld.SAMBA_BINARY('ctdb_lock_helper',
                      source='server/ctdb_lock_helper.c',
                      deps='''samba-util sys_rw ctdb-system tevent-util
@@ -641,7 +694,7 @@ def build(bld):
     if bld.env.HAVE_LIBRADOS:
         bld.SAMBA_BINARY('ctdb_mutex_ceph_rados_helper',
                          source='utils/ceph/ctdb_mutex_ceph_rados_helper.c',
-                        deps='talloc tevent rados',
+                        deps='talloc tevent rados ceph-common',
                         includes='include',
                         install_path='${CTDB_HELPER_BINDIR}')
 
@@ -652,9 +705,10 @@ def build(bld):
     sed_expr5 = 's|/usr/local/sbin|%s|g'          % (bld.env.SBINDIR)
     sed_expr6 = 's|/usr/local/libexec/ctdb|%s|g'  % (bld.env.CTDB_HELPER_BINDIR)
     sed_expr7 = 's|/usr/local/bin|%s|g'           % (bld.env.BINDIR)
-    sed_cmdline = '-e "%s" -e "%s" -e "%s" -e "%s" -e "%s" -e "%s" -e "%s"' % \
+    sed_expr8 = 's|/usr/local/share/ctdb|%s|g'    % (bld.env.CTDB_DATADIR)
+    sed_cmdline = '-e "%s" ' * 8 % \
                        (sed_expr1, sed_expr2, sed_expr3, sed_expr4, sed_expr5,
-                        sed_expr6, sed_expr7)
+                        sed_expr6, sed_expr7, sed_expr8)
 
     manpages_extra = manpages_misc
     if bld.env.etcd_reclock:
@@ -683,14 +737,14 @@ def build(bld):
                         target='onnode',
                         rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
     bld.INSTALL_FILES('${BINDIR}', 'onnode',
-                      destname='onnode', chmod=0755)
+                      destname='onnode', chmod=MODE_755)
 
     bld.SAMBA_GENERATOR('ctdb-diagnostics',
                         source='tools/ctdb_diagnostics',
                         target='ctdb_diagnostics',
                         rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
     bld.INSTALL_FILES('${BINDIR}', 'ctdb_diagnostics',
-                      destname='ctdb_diagnostics', chmod=0755)
+                      destname='ctdb_diagnostics', chmod=MODE_755)
 
     if bld.env.etcd_reclock:
         bld.SAMBA_GENERATOR('ctdb-etcd-lock',
@@ -698,46 +752,50 @@ def build(bld):
                             target='ctdb_etcd_lock',
                             rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
         bld.INSTALL_FILES('${CTDB_HELPER_BINDIR}', 'ctdb_etcd_lock',
-                          destname='ctdb_etcd_lock', chmod=0744)
+                          destname='ctdb_etcd_lock', chmod=MODE_744)
 
     bld.SAMBA_GENERATOR('ctdb-natgw',
                         source='tools/ctdb_natgw',
                         target='ctdb_natgw',
                         rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
     bld.INSTALL_FILES('${CTDB_HELPER_BINDIR}', 'ctdb_natgw',
-                      destname='ctdb_natgw', chmod=0755)
+                      destname='ctdb_natgw', chmod=MODE_755)
 
     bld.SAMBA_GENERATOR('ctdb-lvs',
                         source='tools/ctdb_lvs',
                         target='ctdb_lvs',
                         rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
     bld.INSTALL_FILES('${CTDB_HELPER_BINDIR}', 'ctdb_lvs',
-                      destname='ctdb_lvs', chmod=0755)
+                      destname='ctdb_lvs', chmod=MODE_755)
 
     bld.SAMBA_GENERATOR('ctdbd-wrapper',
                         source='config/ctdbd_wrapper',
                         target='ctdbd_wrapper',
                         rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
     bld.INSTALL_FILES('${SBINDIR}', 'ctdbd_wrapper',
-                      destname='ctdbd_wrapper', chmod=0755)
+                      destname='ctdbd_wrapper', chmod=MODE_755)
 
     def SUBDIR_MODE_callback(arg, dirname, fnames):
         for f in fnames:
             fl = os.path.join(dirname, f)
             if os.path.isdir(fl) or os.path.islink(fl):
                 continue
-            mode = os.lstat(fl).st_mode & 0777
+            mode = os.lstat(fl).st_mode & MODE_777
             if arg['trim_path']:
                 fl = samba_utils.os_path_relpath(fl, arg['trim_path'])
             arg['file_list'].append([fl, mode])
 
     def SUBDIR_MODE(path, trim_path=None):
         pd = {'trim_path': trim_path, 'file_list': []}
-        os.path.walk(path, SUBDIR_MODE_callback, pd)
+        for dirname, _subdirs, fnames in os.walk(path):
+            SUBDIR_MODE_callback(pd, dirname, fnames)
         return pd['file_list']
 
-    etc_subdirs = [
+    event_script_subdirs = [
         'events/legacy',
+    ]
+
+    etc_subdirs = [
         'nfs-checks.d'
     ]
 
@@ -746,12 +804,38 @@ def build(bld):
     else:
         configdir = 'ctdb/config'
 
+    for t in event_script_subdirs:
+        bld.INSTALL_DIR(os.path.join(bld.env.CTDB_ETCDIR, t))
+        files = SUBDIR_MODE('%s/%s' % (configdir, t), trim_path=configdir)
+        for fmode in files:
+            bld.INSTALL_FILES(bld.env.CTDB_DATADIR, 'config/%s' % fmode[0],
+                              destname=fmode[0], chmod=fmode[1])
+
     for t in etc_subdirs:
         files = SUBDIR_MODE('%s/%s' % (configdir, t), trim_path=configdir)
         for fmode in files:
             bld.INSTALL_FILES(bld.env.CTDB_ETCDIR, 'config/%s' % fmode[0],
                               destname=fmode[0], chmod=fmode[1])
 
+    # If this is a direct install and there are no event scripts
+    # linked/enabled then enable some standard ones
+    if os.environ.get('DESTDIR') is None:
+        fmt = 'events/legacy/%s.script'
+        required_script = '00.ctdb'
+        required_path = os.path.join(bld.env.CTDB_ETCDIR,
+                                     fmt % (required_script))
+        if not os.path.islink(required_path) and \
+           not os.path.exists(required_path):
+            default_scripts = [ required_script,
+                                '01.reclock',
+                                '05.system',
+                                '10.interface',
+                              ]
+            for t in default_scripts:
+                tgt = os.path.join(bld.env.CTDB_DATADIR, fmt % (t))
+                name = os.path.join(bld.env.CTDB_ETCDIR, fmt % (t))
+                bld.symlink_as(name, tgt)
+
     bld.SAMBA_GENERATOR('ctdb-functions',
                         source='config/functions',
                         target='functions',
@@ -769,7 +853,7 @@ def build(bld):
 
     for t in etc_scripts:
         bld.INSTALL_FILES(bld.env.CTDB_ETCDIR, 'config/%s' % t,
-                          destname=t, chmod=0755)
+                          destname=t, chmod=MODE_755)
 
     bld.SAMBA_GENERATOR('ctdb-sudoers',
                         source='config/ctdb.sudoers',
@@ -782,12 +866,22 @@ def build(bld):
                       'config/notification.README',
                       destname='README')
 
-    bld.install_dir(bld.env.CTDB_LOGDIR)
-    bld.install_dir(bld.env.CTDB_RUNDIR)
-    bld.install_dir(bld.env.CTDB_VARDIR)
+    bld.INSTALL_DIR(bld.env.CTDB_LOGDIR)
+    bld.INSTALL_DIR(bld.env.CTDB_RUNDIR)
+    bld.INSTALL_DIR(bld.env.CTDB_VARDIR)
 
     for d in ['volatile', 'persistent', 'state']:
-        bld.install_dir(os.path.join(bld.env.CTDB_VARDIR, d))
+        bld.INSTALL_DIR(os.path.join(bld.env.CTDB_VARDIR, d))
+
+    bld.SAMBA_BINARY('errcode',
+                     source='tests/src/errcode.c',
+                     deps='replace',
+                     install_path='${CTDB_TEST_LIBEXECDIR}')
+
+    bld.SAMBA_BINARY('sigcode',
+                     source='tests/src/sigcode.c',
+                     deps='replace',
+                     install_path='${CTDB_TEST_LIBEXECDIR}')
 
     # Unit tests
     ctdb_unit_tests = [
@@ -805,6 +899,8 @@ def build(bld):
         'run_event_test',
         'cmdline_test',
         'conf_test',
+        'line_test',
+        'event_script_test',
     ]
 
     for target in ctdb_unit_tests:
@@ -831,6 +927,11 @@ def build(bld):
                      deps='talloc tevent tdb ctdb-protocol',
                      install_path='${CTDB_TEST_LIBEXECDIR}')
 
+    bld.SAMBA_BINARY('system_socket_test',
+                     source='tests/src/system_socket_test.c',
+                     deps='talloc ctdb-protocol-util pcap',
+                     install_path='${CTDB_TEST_LIBEXECDIR}')
+
     bld.SAMBA_BINARY('porting_tests',
                      source='tests/src/porting_tests.c',
                      deps='samba-util ctdb-system popt',
@@ -842,6 +943,12 @@ def build(bld):
                              LIBASYNC_REQ samba-util sys_rw''',
                      install_path='${CTDB_TEST_LIBEXECDIR}')
 
+    bld.SAMBA_BINARY('ctdb_io_test',
+                     source='tests/src/ctdb_io_test.c',
+                     deps='''talloc tevent tdb samba-util sys_rw''',
+                     install_path='${CTDB_TEST_LIBEXECDIR}')
+
+
     bld.SAMBA_SUBSYSTEM('ctdb-protocol-tests-basic',
                         source=bld.SUBDIR('tests/src',
                                           'protocol_common_basic.c'),
@@ -851,7 +958,6 @@ def build(bld):
                         source=bld.SUBDIR('tests/src',
                                           '''protocol_common.c
                                              protocol_common_ctdb.c
-                                             protocol_common_event.c
                                           '''),
                         includes='include',
                         deps='ctdb-protocol-tests-basic replace talloc tdb')
@@ -864,7 +970,6 @@ def build(bld):
     ctdb_protocol_tests = [
             'protocol_types_test',
             'protocol_ctdb_test',
-            'protocol_event_test',
             'protocol_util_test',
             'protocol_types_compat_test',
             'protocol_ctdb_compat_test',
@@ -876,9 +981,15 @@ def build(bld):
         bld.SAMBA_BINARY(target,
                          source=src,
                          deps='''ctdb-protocol-tests-common
-                                 samba-util talloc tdb''',
+                                 samba-util ctdb-util talloc tdb''',
                          install_path='${CTDB_TEST_LIBEXECDIR}')
 
+    bld.SAMBA_BINARY('event_protocol_test',
+                     source='event/event_protocol_test.c',
+                     deps='''ctdb-protocol-tests-basic
+                             ctdb-protocol-basic talloc''',
+                     install_path='${CTDB_TEST_LIBEXECDIR}')
+
     bld.SAMBA_SUBSYSTEM('ctdb-tests-common',
                         source=bld.SUBDIR('tests/src',
                                           'cluster_wait.c test_options.c'),
@@ -946,7 +1057,9 @@ def build(bld):
 
     test_subdirs = [
         'complex',
+        'ctdb_eventd',
         'cunit',
+        'etc-ctdb',
         'eventd',
         'eventscripts',
         'onnode',
@@ -987,7 +1100,7 @@ def build(bld):
                         target='test_wrap',
                         rule='sed -e "%s" ${SRC} > ${TGT}' % sed_expr)
     bld.INSTALL_FILES(bld.env.CTDB_TEST_DATADIR+"/scripts", 'test_wrap',
-                      destname='test_wrap', chmod=0755)
+                      destname='test_wrap', chmod=MODE_755)
 
     bld.SAMBA_GENERATOR('ctdb-test-script-install-paths',
                         source='tests/scripts/script_install_paths.sh',
@@ -995,11 +1108,10 @@ def build(bld):
                         rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
     bld.INSTALL_FILES(bld.env.CTDB_TEST_DATADIR+"/scripts",
                       'script_install_paths.sh',
-                      destname='script_install_paths.sh', chmod=0644)
+                      destname='script_install_paths.sh', chmod=MODE_644)
 
-    sed_expr1 = 's@^\(export %s\)=.*@\\1=%s\\nexport %s=\"%s\"@''' % (
-                    'CTDB_TEST_DIR', bld.env.CTDB_TEST_DATADIR,
-                    'TEST_BIN_DIR', bld.env.CTDB_TEST_LIBEXECDIR)
+    sed_expr1 = 's@^\(export %s\)=.*@\\1=%s@' % (
+                    'CTDB_TEST_DIR', bld.env.CTDB_TEST_DATADIR)
     sed_expr2 = 's@^\(export CTDB_TESTS_ARE_INSTALLED\)=false@\\1=true@'
     bld.SAMBA_GENERATOR('ctdb-test-runner',
                         source='tests/run_tests.sh',
@@ -1007,10 +1119,18 @@ def build(bld):
                         rule='sed -e "%s" -e "%s" ${SRC} > ${TGT}' % (
                              sed_expr1, sed_expr2))
     bld.INSTALL_FILES('${BINDIR}', 'ctdb_run_tests.sh',
-                      destname='ctdb_run_tests', chmod=0755)
+                      destname='ctdb_run_tests', chmod=MODE_755)
     bld.symlink_as(os.path.join(bld.env.BINDIR, 'ctdb_run_cluster_tests'),
                    'ctdb_run_tests')
 
+    bld.SAMBA_GENERATOR('ctdb-local-daemons',
+                        source='tests/local_daemons.sh',
+                        target='ctdb_local_daemons.sh',
+                        rule='sed -e "%s" -e "%s" ${SRC} > ${TGT}' % (
+                             sed_expr1, sed_expr2))
+    bld.INSTALL_FILES('${BINDIR}', 'ctdb_local_daemons.sh',
+                      destname='ctdb_local_daemons', chmod=MODE_755)
+
 
 def testonly(ctx):
     cmd = 'tests/run_tests.sh -V tests/var'
@@ -1021,9 +1141,8 @@ def testonly(ctx):
 
 
 def test(ctx):
-    import Scripting
-    Scripting.commands.append('build')
-    Scripting.commands.append('testonly')
+    Options.commands.append('build')
+    Options.commands.append('testonly')
 
 
 def autotest(ctx):
@@ -1036,7 +1155,7 @@ def autotest(ctx):
 
 
 def show_version(ctx):
-    print VERSION
+    print(get_version_string())
 
 
 def manpages(ctx):
@@ -1062,14 +1181,16 @@ def manpages(ctx):
 def distonly(ctx):
     samba_dist.DIST_FILES('VERSION:VERSION', extend=True)
 
-    distfile = file('.distversion', 'w')
+    version = get_version()
+
+    distfile = open('.distversion', 'w')
     for field in version.vcs_fields:
         distfile.write('%s=%s\n' % (field, str(version.vcs_fields[field])))
     distfile.close()
     samba_dist.DIST_FILES('ctdb/.distversion:.distversion', extend=True)
 
     t = 'ctdb.spec'
-    sed_expr1 = 's/@VERSION@/%s/g' % VERSION
+    sed_expr1 = 's/@VERSION@/%s/g' % get_version_string()
     sed_expr2 = 's/@RELEASE@/%s/g' % '1'
     cmd = 'sed -e "%s" -e "%s" packaging/RPM/ctdb.spec.in > %s' % (
         sed_expr1, sed_expr2, t)
@@ -1089,14 +1210,14 @@ def distonly(ctx):
 
 
 def dist():
-    import Scripting
-    Scripting.commands.append('manpages')
-    Scripting.commands.append('distonly')
+    Options.commands.append('manpages')
+    Options.commands.append('distonly')
 
 
 def rpmonly(ctx):
     opts = os.getenv('RPM_OPTIONS') or ''
-    cmd = 'rpmbuild -ta --clean --rmsource %s ctdb-%s.tar.gz' % (opts, VERSION)
+    cmd = 'rpmbuild -ta --clean --rmsource %s ctdb-%s.tar.gz' % \
+          (opts, get_version_string())
     ret = samba_utils.RUN_COMMAND(cmd)
     if ret != 0:
         print('rpmbuild exited with exit status %d' % ret)
@@ -1104,16 +1225,14 @@ def rpmonly(ctx):
 
 
 def rpm(ctx):
-    import Scripting
-    Scripting.commands.append('manpages')
-    Scripting.commands.append('distonly')
-    Scripting.commands.append('rpmonly')
+    Options.commands.append('manpages')
+    Options.commands.append('distonly')
+    Options.commands.append('rpmonly')
 
 
 def ctags(ctx):
     "build 'tags' file using ctags"
-    import Utils
-    source_root = os.path.dirname(Utils.g_module.root_path)
+    source_root = os.path.dirname(Context.g_module.root_path)
     cmd = 'ctags $(find %s -name "*.[ch]")' % source_root
     print("Running: %s" % cmd)
     ret = samba_utils.RUN_COMMAND(cmd)