|
|
ed0026 |
commit c8136d5f0abe785223f4ea809073d6566aa36b58
|
|
|
ed0026 |
Author: David Vossel <dvossel@redhat.com>
|
|
|
ed0026 |
Date: Wed Sep 25 18:14:13 2013 -0400
|
|
|
ed0026 |
|
|
|
ed0026 |
RemoteLXC port
|
|
|
ed0026 |
|
|
|
ed0026 |
diff --git a/configure.ac b/configure.ac
|
|
|
ed0026 |
index 6c80891..cfc1b1f 100644
|
|
|
ed0026 |
--- a/configure.ac
|
|
|
ed0026 |
+++ b/configure.ac
|
|
|
ed0026 |
@@ -1084,6 +1084,10 @@ CRM_CONFIG_DIR="${localstatedir}/lib/pacemaker/cib"
|
|
|
ed0026 |
AC_DEFINE_UNQUOTED(CRM_CONFIG_DIR,"$CRM_CONFIG_DIR", Where to keep configuration files)
|
|
|
ed0026 |
AC_SUBST(CRM_CONFIG_DIR)
|
|
|
ed0026 |
|
|
|
ed0026 |
+CRM_CONFIG_CTS="${localstatedir}/lib/pacemaker/cts"
|
|
|
ed0026 |
+AC_DEFINE_UNQUOTED(CRM_CONFIG_CTS,"$CRM_CONFIG_CTS", Where to keep cts stateful data)
|
|
|
ed0026 |
+AC_SUBST(CRM_CONFIG_CTS)
|
|
|
ed0026 |
+
|
|
|
ed0026 |
CRM_LEGACY_CONFIG_DIR="${localstatedir}/lib/heartbeat/crm"
|
|
|
ed0026 |
AC_DEFINE_UNQUOTED(CRM_LEGACY_CONFIG_DIR,"$CRM_LEGACY_CONFIG_DIR", Where Pacemaker used to keep configuration files)
|
|
|
ed0026 |
AC_SUBST(CRM_LEGACY_CONFIG_DIR)
|
|
|
ed0026 |
@@ -1790,7 +1794,8 @@ cts/Makefile \
|
|
|
ed0026 |
cts/CTSvars.py \
|
|
|
ed0026 |
cts/LSBDummy \
|
|
|
ed0026 |
cts/benchmark/Makefile \
|
|
|
ed0026 |
- cts/benchmark/clubench \
|
|
|
ed0026 |
+ cts/benchmark/clubench \
|
|
|
ed0026 |
+ cts/lxc_autogen.sh \
|
|
|
ed0026 |
cib/Makefile \
|
|
|
ed0026 |
crmd/Makefile \
|
|
|
ed0026 |
pengine/Makefile \
|
|
|
ed0026 |
diff --git a/cts/CTSlab.py b/cts/CTSlab.py
|
|
|
ed0026 |
index 58506c3..f7e183c 100755
|
|
|
ed0026 |
--- a/cts/CTSlab.py
|
|
|
ed0026 |
+++ b/cts/CTSlab.py
|
|
|
ed0026 |
@@ -95,6 +95,7 @@ class LabEnvironment(CtsLab):
|
|
|
ed0026 |
#self["valgrind-opts"] = """--trace-children=no --num-callers=25 --gen-suppressions=all --suppressions="""+CTSvars.CTS_home+"""/cts.supp"""
|
|
|
ed0026 |
|
|
|
ed0026 |
self["experimental-tests"] = 0
|
|
|
ed0026 |
+ self["container-tests"] = 0
|
|
|
ed0026 |
self["valgrind-tests"] = 0
|
|
|
ed0026 |
self["unsafe-tests"] = 1
|
|
|
ed0026 |
self["loop-tests"] = 1
|
|
|
ed0026 |
@@ -148,6 +149,7 @@ def usage(arg, status=1):
|
|
|
ed0026 |
print "\t [--no-unsafe-tests] dont run tests that are unsafe for use with ocfs2/drbd"
|
|
|
ed0026 |
print "\t [--valgrind-tests] include tests using valgrind"
|
|
|
ed0026 |
print "\t [--experimental-tests] include experimental tests"
|
|
|
ed0026 |
+ print "\t [--container-tests] include pacemaker_remote tests that run in lxc container resources"
|
|
|
ed0026 |
print "\t [--oprofile 'node list'] list of cluster nodes to run oprofile on]"
|
|
|
ed0026 |
print "\t [--qarsh] use the QARSH backdoor to access nodes instead of SSH"
|
|
|
ed0026 |
print "\t [--seed random_seed]"
|
|
|
ed0026 |
@@ -427,6 +429,9 @@ if __name__ == '__main__':
|
|
|
ed0026 |
elif args[i] == "--experimental-tests":
|
|
|
ed0026 |
Environment["experimental-tests"] = 1
|
|
|
ed0026 |
|
|
|
ed0026 |
+ elif args[i] == "--container-tests":
|
|
|
ed0026 |
+ Environment["container-tests"] = 1
|
|
|
ed0026 |
+
|
|
|
ed0026 |
elif args[i] == "--set":
|
|
|
ed0026 |
skipthis=1
|
|
|
ed0026 |
(name, value) = args[i+1].split('=')
|
|
|
ed0026 |
diff --git a/cts/CTStests.py b/cts/CTStests.py
|
|
|
ed0026 |
index b5dd69a..19f6ef4 100644
|
|
|
ed0026 |
--- a/cts/CTStests.py
|
|
|
ed0026 |
+++ b/cts/CTStests.py
|
|
|
ed0026 |
@@ -73,6 +73,7 @@ class CTSTest:
|
|
|
ed0026 |
self.is_loop = 0
|
|
|
ed0026 |
self.is_unsafe = 0
|
|
|
ed0026 |
self.is_experimental = 0
|
|
|
ed0026 |
+ self.is_container = 0
|
|
|
ed0026 |
self.is_valgrind = 0
|
|
|
ed0026 |
self.benchmark = 0 # which tests to benchmark
|
|
|
ed0026 |
self.timer = {} # timers
|
|
|
ed0026 |
@@ -205,6 +206,8 @@ class CTSTest:
|
|
|
ed0026 |
return 0
|
|
|
ed0026 |
elif self.is_experimental and not self.CM.Env["experimental-tests"]:
|
|
|
ed0026 |
return 0
|
|
|
ed0026 |
+ elif self.is_container and not self.CM.Env["container-tests"]:
|
|
|
ed0026 |
+ return 0
|
|
|
ed0026 |
elif self.CM.Env["benchmark"] and self.benchmark == 0:
|
|
|
ed0026 |
return 0
|
|
|
ed0026 |
|
|
|
ed0026 |
@@ -2473,4 +2476,118 @@ def TestList(cm, audits):
|
|
|
ed0026 |
result.append(bound_test)
|
|
|
ed0026 |
return result
|
|
|
ed0026 |
|
|
|
ed0026 |
+###################################################################
|
|
|
ed0026 |
+class RemoteLXC(CTSTest):
|
|
|
ed0026 |
+###################################################################
|
|
|
ed0026 |
+ def __init__(self, cm):
|
|
|
ed0026 |
+ CTSTest.__init__(self,cm)
|
|
|
ed0026 |
+ self.name="RemoteLXC"
|
|
|
ed0026 |
+ self.start = StartTest(cm)
|
|
|
ed0026 |
+ self.startall = SimulStartLite(cm)
|
|
|
ed0026 |
+ self.num_containers = 2
|
|
|
ed0026 |
+ self.is_container = 1
|
|
|
ed0026 |
+ self.failed = 0
|
|
|
ed0026 |
+ self.fail_string = ""
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+ def start_lxc_simple(self, node):
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+ rc = self.CM.rsh(node, "/usr/share/pacemaker/tests/cts/lxc_autogen.sh -v &>/dev/null")
|
|
|
ed0026 |
+ if rc == 1:
|
|
|
ed0026 |
+ return self.skipped()
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+ # restore any artifacts laying around from a previous test.
|
|
|
ed0026 |
+ self.CM.rsh(node, "/usr/share/pacemaker/tests/cts/lxc_autogen.sh -R &>/dev/null")
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+ # generate the containers, put them in the config, add some resources to them
|
|
|
ed0026 |
+ pats = [ ]
|
|
|
ed0026 |
+ watch = self.create_watch(pats, 120)
|
|
|
ed0026 |
+ watch.setwatch()
|
|
|
ed0026 |
+ pats.append("process_lrm_event: LRM operation lxc1_start_0.*confirmed.*ok")
|
|
|
ed0026 |
+ pats.append("process_lrm_event: LRM operation lxc2_start_0.*confirmed.*ok")
|
|
|
ed0026 |
+ pats.append("process_lrm_event: LRM operation lxc-ms_start_0.*confirmed.*ok")
|
|
|
ed0026 |
+ pats.append("process_lrm_event: LRM operation lxc-ms_promote_0.*confirmed.*ok")
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+ self.CM.rsh(node, "/usr/share/pacemaker/tests/cts/lxc_autogen.sh -g -a -m -s -c %d &>/dev/null" % self.num_containers)
|
|
|
ed0026 |
+ self.set_timer("remoteSimpleInit")
|
|
|
ed0026 |
+ watch.lookforall()
|
|
|
ed0026 |
+ self.log_timer("remoteSimpleInit")
|
|
|
ed0026 |
+ if watch.unmatched:
|
|
|
ed0026 |
+ self.fail_string = "Unmatched patterns: %s" % (repr(watch.unmatched))
|
|
|
ed0026 |
+ self.failed = 1
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+ def cleanup_lxc_simple(self, node):
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+ pats = [ ]
|
|
|
ed0026 |
+ # if the test failed, attempt to clean up the cib and libvirt environment
|
|
|
ed0026 |
+ # as best as possible
|
|
|
ed0026 |
+ if self.failed == 1:
|
|
|
ed0026 |
+ # restore libvirt and cib
|
|
|
ed0026 |
+ self.CM.rsh(node, "/usr/share/pacemaker/tests/cts/lxc_autogen.sh -R &>/dev/null")
|
|
|
ed0026 |
+ self.CM.rsh(node, "crm_resource -C -r container1 &>/dev/null")
|
|
|
ed0026 |
+ self.CM.rsh(node, "crm_resource -C -r container2 &>/dev/null")
|
|
|
ed0026 |
+ self.CM.rsh(node, "crm_resource -C -r lxc1 &>/dev/null")
|
|
|
ed0026 |
+ self.CM.rsh(node, "crm_resource -C -r lxc2 &>/dev/null")
|
|
|
ed0026 |
+ self.CM.rsh(node, "crm_resource -C -r lxc-ms &>/dev/null")
|
|
|
ed0026 |
+ time.sleep(20)
|
|
|
ed0026 |
+ return
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+ watch = self.create_watch(pats, 120)
|
|
|
ed0026 |
+ watch.setwatch()
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+ pats.append("process_lrm_event: LRM operation container1_stop_0.*confirmed.*ok")
|
|
|
ed0026 |
+ pats.append("process_lrm_event: LRM operation container2_stop_0.*confirmed.*ok")
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+ self.CM.rsh(node, "/usr/share/pacemaker/tests/cts/lxc_autogen.sh -p &>/dev/null")
|
|
|
ed0026 |
+ self.set_timer("remoteSimpleCleanup")
|
|
|
ed0026 |
+ watch.lookforall()
|
|
|
ed0026 |
+ self.log_timer("remoteSimpleCleanup")
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+ if watch.unmatched:
|
|
|
ed0026 |
+ self.fail_string = "Unmatched patterns: %s" % (repr(watch.unmatched))
|
|
|
ed0026 |
+ self.failed = 1
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+ # cleanup libvirt
|
|
|
ed0026 |
+ self.CM.rsh(node, "/usr/share/pacemaker/tests/cts/lxc_autogen.sh -R &>/dev/null")
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+ def __call__(self, node):
|
|
|
ed0026 |
+ '''Perform the 'RemoteLXC' test. '''
|
|
|
ed0026 |
+ self.incr("calls")
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+ ret = self.startall(None)
|
|
|
ed0026 |
+ if not ret:
|
|
|
ed0026 |
+ return self.failure("Setup failed, start all nodes failed.")
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+ self.start_lxc_simple(node)
|
|
|
ed0026 |
+ self.cleanup_lxc_simple(node)
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+ self.CM.debug("Waiting for the cluster to recover")
|
|
|
ed0026 |
+ self.CM.cluster_stable()
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+ if self.failed == 1:
|
|
|
ed0026 |
+ return self.failure(self.fail_string)
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+ return self.success()
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+ def errorstoignore(self):
|
|
|
ed0026 |
+ '''Return list of errors which should be ignored'''
|
|
|
ed0026 |
+ return [ """Updating failcount for ping""",
|
|
|
ed0026 |
+ """LogActions: Recover ping""",
|
|
|
ed0026 |
+ """LogActions: Recover lxc-ms""",
|
|
|
ed0026 |
+ """LogActions: Recover container""",
|
|
|
ed0026 |
+ # The orphaned lxc-ms resource causes an expected transition error
|
|
|
ed0026 |
+ # that is a result of the pengine not having knowledge that the
|
|
|
ed0026 |
+ # ms resource used to be a clone. As a result it looks like that
|
|
|
ed0026 |
+ # resource is running in multiple locations when it shouldn't... But in
|
|
|
ed0026 |
+ # this instance we know why this error is occurring and that it is expected.
|
|
|
ed0026 |
+ """Calculated Transition .* /var/lib/pacemaker/pengine/pe-error""",
|
|
|
ed0026 |
+ """Resource lxc-ms .* is active on 2 nodes attempting recovery""",
|
|
|
ed0026 |
+ """Unknown operation: fail""",
|
|
|
ed0026 |
+ """notice: operation_finished: ping-""",
|
|
|
ed0026 |
+ """notice: operation_finished: container""",
|
|
|
ed0026 |
+ """notice: operation_finished: .*_monitor_0:.*:stderr""",
|
|
|
ed0026 |
+ """(ERROR|error): sending stonithRA op to stonithd failed.""",
|
|
|
ed0026 |
+ ]
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+AllTestClasses.append(RemoteLXC)
|
|
|
ed0026 |
+
|
|
|
ed0026 |
# vim:ts=4:sw=4:et:
|
|
|
ed0026 |
diff --git a/cts/Makefile.am b/cts/Makefile.am
|
|
|
ed0026 |
index e01ac10..cb86db8 100644
|
|
|
ed0026 |
--- a/cts/Makefile.am
|
|
|
ed0026 |
+++ b/cts/Makefile.am
|
|
|
ed0026 |
@@ -40,6 +40,7 @@ cts_DATA = README cts.supp
|
|
|
ed0026 |
|
|
|
ed0026 |
cts_SCRIPTS = cluster_test \
|
|
|
ed0026 |
CTSlab.py \
|
|
|
ed0026 |
+ lxc_autogen.sh \
|
|
|
ed0026 |
LSBDummy \
|
|
|
ed0026 |
$(top_srcdir)/fencing/fence_dummy
|
|
|
ed0026 |
|
|
|
ed0026 |
diff --git a/cts/lxc_autogen.sh.in b/cts/lxc_autogen.sh.in
|
|
|
ed0026 |
new file mode 100644
|
|
|
ed0026 |
index 0000000..1d334c4
|
|
|
ed0026 |
--- /dev/null
|
|
|
ed0026 |
+++ b/cts/lxc_autogen.sh.in
|
|
|
ed0026 |
@@ -0,0 +1,362 @@
|
|
|
ed0026 |
+#!/bin/bash
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+containers="2"
|
|
|
ed0026 |
+download=0
|
|
|
ed0026 |
+share_configs=0
|
|
|
ed0026 |
+# different than default libvirt network in case this is run nested in a KVM instance
|
|
|
ed0026 |
+addr="192.168.123.1"
|
|
|
ed0026 |
+restore=0
|
|
|
ed0026 |
+restore_pcmk=0
|
|
|
ed0026 |
+restore_all=0
|
|
|
ed0026 |
+generate=0
|
|
|
ed0026 |
+key_gen=0
|
|
|
ed0026 |
+cib=0
|
|
|
ed0026 |
+add_master=0
|
|
|
ed0026 |
+verify=0
|
|
|
ed0026 |
+working_dir="@CRM_CONFIG_CTS@/lxc"
|
|
|
ed0026 |
+curdir=$(pwd)
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+function helptext() {
|
|
|
ed0026 |
+ echo "lxc_autogen.sh - A tool for generating libvirt lxc containers for testing purposes."
|
|
|
ed0026 |
+ echo ""
|
|
|
ed0026 |
+ echo "Usage: lxc-autogen [options]"
|
|
|
ed0026 |
+ echo ""
|
|
|
ed0026 |
+ echo "Options:"
|
|
|
ed0026 |
+ echo "-g, --generate Generate libvirt lxc environment in the directory this script is run from."
|
|
|
ed0026 |
+ echo "-k, --key-gen Generate local pacemaker remote key only."
|
|
|
ed0026 |
+ echo "-r, --restore-libvirt Restore the default network, and libvirt config to before this script ran."
|
|
|
ed0026 |
+ echo "-p, --restore-cib Remove cib entries this script generated."
|
|
|
ed0026 |
+ echo "-R, --restore-all Restore both libvirt and cib plus clean working directory. This will leave libvirt xml files though so rsc can be stopped properly."
|
|
|
ed0026 |
+ echo ""
|
|
|
ed0026 |
+ echo "-a, --add-cib Add remote-node entries for each lxc instance into the cib"
|
|
|
ed0026 |
+ echo "-m, --add-master Add master resource shared between remote-nodes"
|
|
|
ed0026 |
+ echo "-d, --download-agent Download and install the latest VirtualDomain agent."
|
|
|
ed0026 |
+ echo "-s, --share-configs Copy container configs to all other known cluster nodes, (crm_node -l)"
|
|
|
ed0026 |
+ echo "-c, --containers Specify the number of containers to generate, defaults to $containers. Used with -g"
|
|
|
ed0026 |
+ echo "-n, --network What network to override default libvirt network to. Example: -n 192.168.123.1. Used with -g"
|
|
|
ed0026 |
+ echo "-v, --verify Verify environment is capable of running lxc"
|
|
|
ed0026 |
+ echo ""
|
|
|
ed0026 |
+ exit $1
|
|
|
ed0026 |
+}
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+while true ; do
|
|
|
ed0026 |
+ case "$1" in
|
|
|
ed0026 |
+ --help|-h|-\?) helptext 0;;
|
|
|
ed0026 |
+ -c|--containers) containers="$2"; shift; shift;;
|
|
|
ed0026 |
+ -d|--download-agent) download=1; shift;;
|
|
|
ed0026 |
+ -s|--share-configs) share_configs=1; shift;;
|
|
|
ed0026 |
+ -n|--network) addr="$2"; shift; shift;;
|
|
|
ed0026 |
+ -r|--restore-libvirt) restore=1; shift;;
|
|
|
ed0026 |
+ -p|--restore-cib) restore_pcmk=1; shift;;
|
|
|
ed0026 |
+ -R|--restore-all)
|
|
|
ed0026 |
+ restore_all=1
|
|
|
ed0026 |
+ restore=1
|
|
|
ed0026 |
+ restore_pcmk=1
|
|
|
ed0026 |
+ shift;;
|
|
|
ed0026 |
+ -g|--generate) generate=1; shift;;
|
|
|
ed0026 |
+ -k|--key-gen) key_gen=1; shift;;
|
|
|
ed0026 |
+ -a|--add-cib) cib=1; shift;;
|
|
|
ed0026 |
+ -m|--add-master) add_master=1; shift;;
|
|
|
ed0026 |
+ -v|--verify) verify=1; shift;;
|
|
|
ed0026 |
+ "") break;;
|
|
|
ed0026 |
+ *) helptext 1;;
|
|
|
ed0026 |
+ esac
|
|
|
ed0026 |
+done
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+if [ $verify -eq 1 ]; then
|
|
|
ed0026 |
+ # verify virsh tool is available and that
|
|
|
ed0026 |
+ # we can connect to lxc driver.
|
|
|
ed0026 |
+ virsh -c lxc:/// list --all > /dev/null 2>&1
|
|
|
ed0026 |
+ if [ $? -ne 0 ]; then
|
|
|
ed0026 |
+ echo "Could not connect 'virsh -c lxc:///' check that libvirt lxc driver is installed"
|
|
|
ed0026 |
+ exit 1
|
|
|
ed0026 |
+ fi
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+ cat /etc/selinux/config | grep -e "SELINUX.*=.*permissive" -e "SELINUX.*=.*enforcing" > /dev/null 2>&1
|
|
|
ed0026 |
+ if [ $? -ne 0 ]; then
|
|
|
ed0026 |
+ echo "/etc/selinux/config must have SELINUX set to permissive or enforcing mode."
|
|
|
ed0026 |
+ exit 1
|
|
|
ed0026 |
+ fi
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+ ps x > /tmp/lxc-autogen-libvirt-test.txt
|
|
|
ed0026 |
+ grep "libvirtd" /tmp/lxc-autogen-libvirt-test.txt
|
|
|
ed0026 |
+ if [ $? -ne 0 ]; then
|
|
|
ed0026 |
+ rm -f /tmp/lxc-autogen-libvirt-test.txt
|
|
|
ed0026 |
+ echo "libvirtd isn't up."
|
|
|
ed0026 |
+ exit 1
|
|
|
ed0026 |
+ fi
|
|
|
ed0026 |
+ rm -f /tmp/lxc-autogen-libvirt-test.txt
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+ which rsync > /dev/null 2>&1
|
|
|
ed0026 |
+ if [ $? -ne 0 ]; then
|
|
|
ed0026 |
+ echo "rsync is required"
|
|
|
ed0026 |
+ fi
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+fi
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+#strip last digits off addr
|
|
|
ed0026 |
+tmp="s/\.$(echo "$addr" | tr '.' ' ' | awk '{print $4}')$//g"
|
|
|
ed0026 |
+addr=$(echo $addr | sed -e ${tmp})
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+set_network()
|
|
|
ed0026 |
+{
|
|
|
ed0026 |
+ rm -f cur_network.xml
|
|
|
ed0026 |
+ cat << END >> cur_network.xml
|
|
|
ed0026 |
+<network>
|
|
|
ed0026 |
+ <name>default</name>
|
|
|
ed0026 |
+ <uuid>41ebdb84-7134-1111-a136-91f0f1119225</uuid>
|
|
|
ed0026 |
+ <forward mode='nat'/>
|
|
|
ed0026 |
+ <bridge name='virbr0' stp='on' delay='0' />
|
|
|
ed0026 |
+ <mac address='52:54:00:A8:12:35'/>
|
|
|
ed0026 |
+ <ip address='$addr.1' netmask='255.255.255.0'>
|
|
|
ed0026 |
+ <dhcp>
|
|
|
ed0026 |
+ <range start='$addr.2' end='$addr.254' />
|
|
|
ed0026 |
+ </dhcp>
|
|
|
ed0026 |
+ </ip>
|
|
|
ed0026 |
+</network>
|
|
|
ed0026 |
+END
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+ ls restore_default.xml > /dev/null 2>&1
|
|
|
ed0026 |
+ if [ $? -ne 0 ]; then
|
|
|
ed0026 |
+ virsh net-dumpxml default > restore_default.xml
|
|
|
ed0026 |
+ fi
|
|
|
ed0026 |
+ virsh net-destroy default
|
|
|
ed0026 |
+ virsh net-undefine default
|
|
|
ed0026 |
+ virsh net-define cur_network.xml
|
|
|
ed0026 |
+ virsh net-start default
|
|
|
ed0026 |
+}
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+generate_key()
|
|
|
ed0026 |
+{
|
|
|
ed0026 |
+ #generate pacemaker remote key
|
|
|
ed0026 |
+ ls /etc/pacemaker/authkey > /dev/null 2>&1
|
|
|
ed0026 |
+ if [ $? != 0 ]; then
|
|
|
ed0026 |
+ mkdir -p /etc/pacemaker
|
|
|
ed0026 |
+ dd if=/dev/urandom of=/etc/pacemaker/authkey bs=4096 count=1
|
|
|
ed0026 |
+ fi
|
|
|
ed0026 |
+}
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+generate()
|
|
|
ed0026 |
+{
|
|
|
ed0026 |
+ set_network
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+ # Generate libvirt domains in xml
|
|
|
ed0026 |
+ for (( c=1; c <= $containers; c++ ))
|
|
|
ed0026 |
+ do
|
|
|
ed0026 |
+ rm -rf lxc$c-filesystem
|
|
|
ed0026 |
+ mkdir -p lxc$c-filesystem/var/run/
|
|
|
ed0026 |
+ mkdir -p lxc$c-filesystem/usr/var/run
|
|
|
ed0026 |
+ rm -f lxc$c.xml
|
|
|
ed0026 |
+ cat << END >> lxc$c.xml
|
|
|
ed0026 |
+<domain type='lxc'>
|
|
|
ed0026 |
+ <name>lxc$c</name>
|
|
|
ed0026 |
+ <memory>102400</memory>
|
|
|
ed0026 |
+ <os>
|
|
|
ed0026 |
+ <type>exe</type>
|
|
|
ed0026 |
+ <init>$working_dir/lxc$c-filesystem/launch-helper</init>
|
|
|
ed0026 |
+ </os>
|
|
|
ed0026 |
+ <devices>
|
|
|
ed0026 |
+ <console type='pty'/>
|
|
|
ed0026 |
+ <filesystem type='mount'>
|
|
|
ed0026 |
+ <source dir='$working_dir/lxc$c-filesystem/var/run'/>
|
|
|
ed0026 |
+ <target dir='/var/run'/>
|
|
|
ed0026 |
+ </filesystem>
|
|
|
ed0026 |
+ <filesystem type='mount'>
|
|
|
ed0026 |
+ <source dir='$working_dir/lxc$c-filesystem/usr/var/run'/>
|
|
|
ed0026 |
+ <target dir='/usr/var/run'/>
|
|
|
ed0026 |
+ </filesystem>
|
|
|
ed0026 |
+ <interface type='network'>
|
|
|
ed0026 |
+ <mac address='52:54:00:$c$c:$(($RANDOM % 9))$(($RANDOM % 9)):$(($RANDOM % 9))$c'/>
|
|
|
ed0026 |
+ <source network='default'/>
|
|
|
ed0026 |
+ </interface>
|
|
|
ed0026 |
+ </devices>
|
|
|
ed0026 |
+</domain>
|
|
|
ed0026 |
+END
|
|
|
ed0026 |
+ rm -f container$c.cib
|
|
|
ed0026 |
+ cat << END >> container$c.cib
|
|
|
ed0026 |
+ <primitive class="ocf" id="container$c" provider="heartbeat" type="VirtualDomain">
|
|
|
ed0026 |
+ <instance_attributes id="container$c-instance_attributes">
|
|
|
ed0026 |
+ <nvpair id="container$c-instance_attributes-force_stop" name="force_stop" value="true"/>
|
|
|
ed0026 |
+ <nvpair id="container$c-instance_attributes-hypervisor" name="hypervisor" value="lxc:///"/>
|
|
|
ed0026 |
+ <nvpair id="container$c-instance_attributes-config" name="config" value="$working_dir/lxc$c.xml"/>
|
|
|
ed0026 |
+ <nvpair id="container$c-instance_attributes-remote-node" name="remote-node" value="lxc$c"/>
|
|
|
ed0026 |
+ </instance_attributes>
|
|
|
ed0026 |
+ <utilization id="container$c-utilization">
|
|
|
ed0026 |
+ <nvpair id="container$c-utilization-cpu" name="cpu" value="1"/>
|
|
|
ed0026 |
+ <nvpair id="container$c-utilization-hv_memory" name="hv_memory" value="100"/>
|
|
|
ed0026 |
+ </utilization>
|
|
|
ed0026 |
+ <meta_attributes id="container$c-meta_attributes">
|
|
|
ed0026 |
+ <nvpair id="container$c-meta_attributes-remote-node" name="remote-node" value="lxc$c"/>
|
|
|
ed0026 |
+ </meta_attributes>
|
|
|
ed0026 |
+ </primitive>
|
|
|
ed0026 |
+END
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+ rm -f lxc-ms$c.cib
|
|
|
ed0026 |
+ cat << END >> lxc-ms.cib
|
|
|
ed0026 |
+ <master id="lxc-ms-master">
|
|
|
ed0026 |
+ <primitive class="ocf" id="lxc-ms" provider="pacemaker" type="Stateful">
|
|
|
ed0026 |
+ <instance_attributes id="lxc-ms-instance_attributes"/>
|
|
|
ed0026 |
+ <operations>
|
|
|
ed0026 |
+ <op id="lxc-ms-monitor-interval-10s" interval="10s" name="monitor"/>
|
|
|
ed0026 |
+ </operations>
|
|
|
ed0026 |
+ </primitive>
|
|
|
ed0026 |
+ <meta_attributes id="lxc-ms-meta_attributes">
|
|
|
ed0026 |
+ <nvpair id="lxc-ms-meta_attributes-master-max" name="master-max" value="1"/>
|
|
|
ed0026 |
+ <nvpair id="lxc-ms-meta_attributes-clone-max" name="clone-max" value="$containers"/>
|
|
|
ed0026 |
+ </meta_attributes>
|
|
|
ed0026 |
+ </master>
|
|
|
ed0026 |
+END
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+ rm -f lxc$c-filesystem/launch-helper
|
|
|
ed0026 |
+ cat << END >> lxc$c-filesystem/launch-helper
|
|
|
ed0026 |
+#!/bin/bash
|
|
|
ed0026 |
+ifconfig eth0 $addr.10$c
|
|
|
ed0026 |
+route add 0.0.0.0 gw $addr.1 eth0
|
|
|
ed0026 |
+hostname lxc$c
|
|
|
ed0026 |
+/usr/sbin/pacemaker_remoted
|
|
|
ed0026 |
+END
|
|
|
ed0026 |
+ chmod 711 lxc$c-filesystem/launch-helper
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+ cat << END >> /etc/hosts
|
|
|
ed0026 |
+$addr.10$c lxc$c
|
|
|
ed0026 |
+END
|
|
|
ed0026 |
+ done
|
|
|
ed0026 |
+}
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+apply_cib_master()
|
|
|
ed0026 |
+{
|
|
|
ed0026 |
+ cibadmin -Q > cur.cib
|
|
|
ed0026 |
+ export CIB_file=cur.cib
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+ cibadmin -o resources -C -x lxc-ms.cib
|
|
|
ed0026 |
+ for tmp in $(ls lxc*.xml); do
|
|
|
ed0026 |
+ tmp=$(echo $tmp | sed -e 's/\.xml//g')
|
|
|
ed0026 |
+ echo "<rsc_location id=\"lxc-ms-location-${tmp}\" node=\"${tmp}\" rsc=\"lxc-ms\" score=\"INFINITY\"/>" > tmp_constraint
|
|
|
ed0026 |
+ cibadmin -o constraints -C -x tmp_constraint
|
|
|
ed0026 |
+ echo "<rsc_location id=\"lxc-ping-location-${tmp}\" node=\"${tmp}\" rsc=\"ping-1\" score=\"-INFINITY\"/>" > tmp_constraint
|
|
|
ed0026 |
+ cibadmin -o constraints -C -x tmp_constraint > /dev/null 2>&1
|
|
|
ed0026 |
+ rm -f tmp_constraint
|
|
|
ed0026 |
+ done
|
|
|
ed0026 |
+ unset CIB_file
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+ cibadmin --replace --xml-file cur.cib
|
|
|
ed0026 |
+ rm -f cur.cib
|
|
|
ed0026 |
+}
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+apply_cib_entries()
|
|
|
ed0026 |
+{
|
|
|
ed0026 |
+ node=$(crm_node -n)
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+ cibadmin -Q > cur.cib
|
|
|
ed0026 |
+ export CIB_file=cur.cib
|
|
|
ed0026 |
+ for tmp in $(ls container*.cib); do
|
|
|
ed0026 |
+ cibadmin -o resources -C -x $tmp
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+ tmp=$(echo $tmp | sed -e 's/\.cib//g')
|
|
|
ed0026 |
+ crm_resource -M -r $tmp -H $node
|
|
|
ed0026 |
+ done
|
|
|
ed0026 |
+ unset CIB_file
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+ cibadmin --replace --xml-file cur.cib
|
|
|
ed0026 |
+ rm -f cur.cib
|
|
|
ed0026 |
+}
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+restore_cib()
|
|
|
ed0026 |
+{
|
|
|
ed0026 |
+ node=$(crm_node -n)
|
|
|
ed0026 |
+ cibadmin -Q > cur.cib
|
|
|
ed0026 |
+ export CIB_file=cur.cib
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+ for tmp in $(ls lxc*.xml); do
|
|
|
ed0026 |
+ tmp=$(echo $tmp | sed -e 's/\.xml//g')
|
|
|
ed0026 |
+ echo "<rsc_location id=\"lxc-ms-location-${tmp}\" node=\"${tmp}\" rsc=\"lxc-ms\" score=\"INFINITY\"/>" > tmp_constraint
|
|
|
ed0026 |
+ cibadmin -o constraints -D -x tmp_constraint
|
|
|
ed0026 |
+ echo "<rsc_location id=\"lxc-ping-location-${tmp}\" node=\"${tmp}\" rsc=\"ping-1\" score=\"-INFINITY\"/>" > tmp_constraint
|
|
|
ed0026 |
+ cibadmin -o constraints -D -x tmp_constraint
|
|
|
ed0026 |
+ rm -f tmp_constraint
|
|
|
ed0026 |
+ done
|
|
|
ed0026 |
+ cibadmin -o resources -D -x lxc-ms.cib
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+ for tmp in $(ls container*.cib); do
|
|
|
ed0026 |
+ tmp=$(echo $tmp | sed -e 's/\.cib//g')
|
|
|
ed0026 |
+ crm_resource -U -r $tmp -H $node
|
|
|
ed0026 |
+ crm_resource -D -r $tmp -t primitive
|
|
|
ed0026 |
+ done
|
|
|
ed0026 |
+ unset CIB_file
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+ cibadmin --replace --xml-file cur.cib
|
|
|
ed0026 |
+ rm -f cur.cib
|
|
|
ed0026 |
+}
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+restore_libvirt()
|
|
|
ed0026 |
+{
|
|
|
ed0026 |
+ for tmp in $(ls lxc*.xml); do
|
|
|
ed0026 |
+ tmp=$(echo $tmp | sed -e 's/\.xml//g')
|
|
|
ed0026 |
+ virsh -c lxc:/// destroy $tmp > /dev/null 2>&1
|
|
|
ed0026 |
+ virsh -c lxc:/// undefine $tmp > /dev/null 2>&1
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+ sed -i.bak "/...\....\....\..* ${tmp}/d" /etc/hosts
|
|
|
ed0026 |
+ echo "$tmp destroyed"
|
|
|
ed0026 |
+ done
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+ ls restore_default.xml > /dev/null 2>&1
|
|
|
ed0026 |
+ if [ $? -eq 0 ]; then
|
|
|
ed0026 |
+ virsh net-destroy default > /dev/null 2>&1
|
|
|
ed0026 |
+ virsh net-undefine default > /dev/null 2>&1
|
|
|
ed0026 |
+ virsh net-define restore_default.xml
|
|
|
ed0026 |
+ virsh net-start default
|
|
|
ed0026 |
+ if [ $? -eq 0 ]; then
|
|
|
ed0026 |
+ echo "default network restored"
|
|
|
ed0026 |
+ fi
|
|
|
ed0026 |
+ fi
|
|
|
ed0026 |
+ rm -f restore_default.xml > /dev/null 2>&1
|
|
|
ed0026 |
+}
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+distribute_configs()
|
|
|
ed0026 |
+{
|
|
|
ed0026 |
+ local node
|
|
|
ed0026 |
+ local id
|
|
|
ed0026 |
+ while read id node
|
|
|
ed0026 |
+ do
|
|
|
ed0026 |
+ rsync -ave 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' $working_dir/lxc*.xml $node:/$working_dir
|
|
|
ed0026 |
+ rsync -ave 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' $working_dir/lxc*-filesystem $node:/$working_dir
|
|
|
ed0026 |
+ done < <(crm_node -l)
|
|
|
ed0026 |
+}
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+mkdir -p $working_dir
|
|
|
ed0026 |
+cd $working_dir
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+if [ $download -eq 1 ]; then
|
|
|
ed0026 |
+ wget https://raw.github.com/ClusterLabs/resource-agents/master/heartbeat/VirtualDomain
|
|
|
ed0026 |
+ chmod 755 VirtualDomain
|
|
|
ed0026 |
+ mv -f VirtualDomain /usr/lib/ocf/resource.d/heartbeat/VirtualDomain
|
|
|
ed0026 |
+fi
|
|
|
ed0026 |
+if [ $restore_pcmk -eq 1 ]; then
|
|
|
ed0026 |
+ restore_cib
|
|
|
ed0026 |
+fi
|
|
|
ed0026 |
+if [ $restore -eq 1 ]; then
|
|
|
ed0026 |
+ restore_libvirt
|
|
|
ed0026 |
+fi
|
|
|
ed0026 |
+if [ $key_gen -eq 1 ]; then
|
|
|
ed0026 |
+ generate_key
|
|
|
ed0026 |
+fi
|
|
|
ed0026 |
+if [ $generate -eq 1 ]; then
|
|
|
ed0026 |
+ if [ $key_gen -eq 0]; then
|
|
|
ed0026 |
+ generate_key
|
|
|
ed0026 |
+ fi
|
|
|
ed0026 |
+ generate
|
|
|
ed0026 |
+fi
|
|
|
ed0026 |
+if [ $cib -eq 1 ]; then
|
|
|
ed0026 |
+ apply_cib_entries
|
|
|
ed0026 |
+fi
|
|
|
ed0026 |
+if [ $add_master -eq 1 ]; then
|
|
|
ed0026 |
+ apply_cib_master
|
|
|
ed0026 |
+fi
|
|
|
ed0026 |
+if [ $share_configs -eq 1 ]; then
|
|
|
ed0026 |
+ distribute_configs
|
|
|
ed0026 |
+fi
|
|
|
ed0026 |
+if [ $restore_all -eq 1 ]; then
|
|
|
ed0026 |
+ ls | grep -v "lxc.\.xml" | xargs rm -rf
|
|
|
ed0026 |
+fi
|
|
|
ed0026 |
+
|
|
|
ed0026 |
+cd $curdir
|