def run_copy(): try: from psshlib import api as pssh except ImportError: crm_script.exit_fail("Command node needs pssh installed") opts = make_opts() has_auth = os.path.isfile(COROSYNC_AUTH) if has_auth: results = pssh.copy(add_nodes, COROSYNC_AUTH, COROSYNC_AUTH, opts) check_results(pssh, results) results = pssh.call( add_nodes, "chown root:root %s;chmod 400 %s" % (COROSYNC_AUTH, COROSYNC_AUTH), opts) check_results(pssh, results) # Add new nodes to corosync.conf before copying for node in add_nodes: rc, _, err = crm_script.call(['crm', 'corosync', 'add-node', node]) if rc != 0: crm_script.exit_fail('Failed to add %s to corosync.conf: %s' % (node, err)) results = pssh.copy(add_nodes, COROSYNC_CONF, COROSYNC_CONF, opts) check_results(pssh, results) # reload corosync config here? rc, _, err = crm_script.call(['crm', 'corosync', 'reload']) if rc != 0: crm_script.exit_fail('Failed to reload corosync configuration: %s' % (err)) crm_script.exit_ok(host)
def run_copy(): try: from psshlib import api as pssh except ImportError: crm_script.exit_fail("Command node needs pssh installed") opts = make_opts() has_auth = os.path.isfile(COROSYNC_AUTH) if has_auth: results = pssh.copy(add_nodes, COROSYNC_AUTH, COROSYNC_AUTH, opts) check_results(pssh, results) results = pssh.call(add_nodes, "chown root:root %s;chmod 400 %s" % (COROSYNC_AUTH, COROSYNC_AUTH), opts) check_results(pssh, results) # Add new nodes to corosync.conf before copying for node in add_nodes: rc, _, err = crm_script.call(['crm', 'corosync', 'add-node', node]) if rc != 0: crm_script.exit_fail('Failed to add %s to corosync.conf: %s' % (node, err)) results = pssh.copy(add_nodes, COROSYNC_CONF, COROSYNC_CONF, opts) check_results(pssh, results) # reload corosync config here? rc, _, err = crm_script.call(['crm', 'corosync', 'reload']) if rc != 0: crm_script.exit_fail('Failed to reload corosync configuration: %s' % (err)) crm_script.exit_ok(host)
def testUptime(self): opts = pssh.Options() opts.default_user = g_user for host, result in pssh.call(g_hosts, "uptime", opts).iteritems(): rc, out, err = result self.assertEqual(rc, 0) self.assert_(out.find("load average") != -1)
def testSimpleCall(self): opts = pssh.Options() opts.default_user = g_user for host, result in pssh.call(g_hosts, "ls -l /", opts).iteritems(): rc, out, err = result self.assertEqual(rc, 0) self.assert_(len(out) > 0)
def run_copy(): try: from psshlib import api as pssh except ImportError: crm_script.exit_fail("Command node needs pssh installed") opts = make_opts() results = pssh.copy(others, COROSYNC_AUTH, COROSYNC_AUTH, opts) check_results(pssh, results) results = pssh.call(others, "chown root:root %s;chmod 400 %s" % (COROSYNC_AUTH, COROSYNC_AUTH), opts) check_results(pssh, results)
def run_copy(): try: from psshlib import api as pssh except ImportError: crm_script.exit_fail("Command node needs pssh installed") opts = make_opts() results = pssh.copy(others, COROSYNC_AUTH, COROSYNC_AUTH, opts) check_results(pssh, results) results = pssh.call( others, "chown root:root %s;chmod 400 %s" % (COROSYNC_AUTH, COROSYNC_AUTH), opts) check_results(pssh, results)
def do_run(self, context, cmd): ''' Execute the given command on all nodes, report outcome ''' try: from psshlib import api as pssh _has_pssh = True except ImportError: _has_pssh = False if not _has_pssh: context.fatal_error("PSSH not found") hosts = utils.list_cluster_nodes() opts = pssh.Options() for host, result in pssh.call(hosts, cmd, opts).iteritems(): if isinstance(result, pssh.Error): err_buf.error("[%s]: %s" % (host, result)) else: if result[0] != 0: err_buf.error("[%s]: rc=%s\n%s\n%s" % (host, result[0], result[1], result[2])) else: err_buf.ok("[%s]\n%s" % (host, result[1]))
def _pssh_call(hosts, cmd, opts): "pssh.call with debug logging" if config.core.debug or options.regression_tests: err_buf.debug("pssh.call(%s, %s)" % (repr(hosts), cmd)) return pssh.call(hosts, cmd, opts)
def testFailingCall(self): opts = pssh.Options() opts.default_user = g_user for host, result in pssh.call(g_hosts, "touch /foofoo/barbar/jfikjfdj", opts).iteritems(): self.assert_(isinstance(result, pssh.Error)) self.assert_(str(result).find('with error code') != -1)