ctdb-daemon: Add an environment variable to set version
authorMartin Schwenke <martin@meltin.net>
Wed, 6 Feb 2019 02:57:00 +0000 (13:57 +1100)
committerAmitay Isaacs <amitay@samba.org>
Fri, 15 Mar 2019 05:17:14 +0000 (05:17 +0000)
This can be used to test the version checking logic.  Cache the
version to avoid re-checking the environment variable each time.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@samba.org>
ctdb/server/ctdb_keepalive.c
ctdb/tests/README

index a4569ec..b4c9d37 100644 (file)
 
 static uint32_t keepalive_version(void)
 {
-       return (SAMBA_VERSION_MAJOR << 16) | SAMBA_VERSION_MINOR;
+       static uint32_t version = 0;
+
+       if (version == 0) {
+               const char *t;
+
+               version = (SAMBA_VERSION_MAJOR << 16) | SAMBA_VERSION_MINOR;
+
+               t = getenv("CTDB_TEST_SAMBA_VERSION");
+               if (t != NULL) {
+                       int v;
+
+                       v = atoi(t);
+                       if (v <= 0) {
+                               DBG_WARNING("Failed to parse env var: %s\n", t);
+                       } else {
+                               version = v;
+                       }
+               }
+       }
+
+       return version;
 }
 
 static uint32_t keepalive_uptime(struct ctdb_context *ctdb)
index c911dd8..bbda331 100644 (file)
@@ -162,6 +162,17 @@ Test and debugging variable options
 
           Default is no.
 
+       CTDB_TEST_SAMBA_VERSION=VERSION
+
+           VERSION is a 32-bit number containg the Samba major
+           version in the most significant 16 bits and the minor
+           version in the least significant 16 bits.  This can be
+           used to test CTDB's checking of incompatible versions
+           without installing an incompatible version.  This is
+           probably best set like this:
+
+               export CTDB_TEST_SAMBA_VERSION=$(( (4 << 16) | 12 ))
+
        CTDB_VARDIR=DIRECTORY
           DIRECTORY containing CTDB files that are modified at runtime.