Add the sp_rand_init and sp_rand_cleanup tools.
These will be used on the worker node to set up a random volume name
prefix for the StorPool volumes and snapshots created during
the OpenStack CI run, and detach and remove them all later.
Change-Id: Ic558e2183db8068545f7454f956dc8bc740959c6
diff --git a/tools/sp-rand/test_functional.sh b/tools/sp-rand/test_functional.sh
new file mode 100755
index 0000000..a03b01d
--- /dev/null
+++ b/tools/sp-rand/test_functional.sh
@@ -0,0 +1,41 @@
+#!/bin/sh
+
+set -e
+set -x
+
+tempd="$(mktemp -d)"
+trap "rm -rf -- '$tempd'" EXIT HUP INT TERM QUIT
+
+conffile="$tempd/sp-ostack-random.conf"
+
+rm -rf -- "$tempd"
+test ! -e "$tempd"
+test ! -h "$tempd"
+
+sp_rand_init -d "$tempd" -N
+sp_rand_init -d "$tempd" -N | grep -Fqxe "$conffile"
+sp_rand_init -d "$tempd" -N | grep -Eqe '^osci-1-date-[0-9]{8}-[0-9]{4}-[0-9]{4}-$'
+
+mkdir -- "$tempd"
+test -d "$tempd"
+test ! -e "$conffile"
+test ! -h "$conffile"
+
+sp_rand_init -d "$tempd" -N
+test ! -e "$conffile"
+test ! -h "$conffile"
+
+sp_rand_init -d "$tempd"
+test -f "$conffile"
+
+cat -- "$conffile"
+grep -Eqe '^SP_OPENSTACK_VOLUME_PREFIX=osci-1-date-[0-9]{8}-[0-9]{4}-[0-9]{4}-$' -- "$conffile"
+
+sp_rand_cleanup -d "$tempd" --skip-api yes -N
+test -f "$conffile"
+
+sp_rand_cleanup -d "$tempd" --skip-api yes
+test ! -e "$conffile"
+test ! -h "$conffile"
+
+rmdir -- "$tempd"