Fix fence_ssh python script

Import module atexit explicitly. Since a lot of packages were updated
during migration to CentOS7 this script no more works without that.
Probably it was imported implicitly, which is wrong anyway.

Fix command line options changes according to updated fencing.py

Remove test if needed shutdown slave because in any case all
that we do is just restart the slave. Always.

Blueprint: master-on-centos7

Compatible with CentOS6 & CentOS7 master node

Change-Id: I0437a71ac59a46eac58714bb28d78882987e5938
This commit is contained in:
Dmitry Teselkin 2015-11-23 18:55:10 +03:00 committed by Aleksandr Mogylchenko
parent 032c707ec8
commit eb2d15ceaf
3 changed files with 147 additions and 14 deletions

View File

@ -1,8 +1,19 @@
#!/usr/bin/python
import sys, re, pexpect, exceptions
import atexit
import exceptions
import pexpect
import sys
import time
sys.path.append("/usr/share/fence")
from fencing import *
from fencing import all_opt
from fencing import atexit_handler
from fencing import check_input
from fencing import fence_action
from fencing import fence_login
from fencing import process_input
from fencing import show_docs
# BEGIN_VERSION_GENERATION
RELEASE_VERSION = "0.1.0"
@ -15,26 +26,28 @@ def get_power_status(conn, options):
try:
conn.sendline("/bin/echo 1")
conn.log_expect(options, options["-c"], int(options["-Y"]))
except:
except Exception:
return "off"
return "on"
def set_power_status(conn, options):
if options["-o"] == "off":
try:
conn.sendline("/sbin/reboot")
conn.log_expect(options, options["-c"], int(options["-g"]))
time.sleep(2)
except:
except Exception:
pass
def main():
device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug",
device_opt = ["help", "version", "agent", "quiet", "verbose", "debug",
"action", "ipaddr", "login", "passwd", "passwd_script",
"secure", "identity_file", "test", "port", "separator",
"inet4_only", "inet6_only", "ipport",
"power_timeout", "shell_timeout",
"login_timeout", "power_wait" ]
"login_timeout", "power_wait"]
atexit.register(atexit_handler)
@ -53,10 +66,14 @@ def main():
options["-c"] = "\[EXPECT\]#\ "
# this string will be appended to the end of ssh command
options["ssh_options"] = "-t -o 'StrictHostKeyChecking=no' '/bin/bash -c \"PS1=%s /bin/bash --noprofile --norc\"'" % options["-c"]
options["-X"] = "-t -o 'StrictHostKeyChecking=no' '/bin/bash -c \"PS1=%s /bin/bash --noprofile --norc\"'" % options["-c"]
strict = "-t -o 'StrictHostKeyChecking=no'"
bash = "/bin/bash --noprofile --norc"
options["ssh_options"] = "%s '/bin/bash -c \"PS1=%s %s\"'" % \
(strict, options["-c"], bash)
options["-X"] = "%s '/bin/bash -c \"PS1=%s %s\"'" % \
(strict, options["-c"], bash)
docs = { }
docs = {}
docs["shortdesc"] = "Fence agent that can just reboot node via ssh"
docs["longdesc"] = "fence_ssh is an I/O Fencing agent \
which can be used to reboot nodes via ssh."

View File

@ -0,0 +1,102 @@
#!/usr/bin/python
import atexit
import exceptions
import pexpect
import sys
import time
sys.path.append("/usr/share/fence")
from fencing import all_opt
from fencing import atexit_handler
from fencing import check_input
from fencing import fence_action
from fencing import fence_login
from fencing import process_input
from fencing import show_docs
# BEGIN_VERSION_GENERATION
RELEASE_VERSION = "0.1.0"
BUILD_DATE = "(built Wed Oct 31 11:20:18 UTC 2012)"
MIRANTIS_COPYRIGHT = "Copyright (C) Mirantis, Inc. 2012 All rights reserved."
# END_VERSION_GENERATION
def get_power_status(conn, options):
try:
conn.sendline("/bin/echo 1")
conn.log_expect(options, options["--command-prompt"],
int(options["--shell-timeout"]))
except Exception:
return "off"
return "on"
def set_power_status(conn, options):
if options["--action"] == "off":
try:
conn.sendline("/sbin/reboot")
conn.log_expect(options, options["--command-prompt"],
int(options["--power-timeout"]))
time.sleep(2)
except Exception:
pass
def main():
device_opt = ["help", "version", "agent", "verbose", "debug",
"action", "ipaddr", "login", "passwd", "passwd_script",
"secure", "identity_file", "port", "separator",
"inet4_only", "inet6_only", "ipport",
"power_timeout", "shell_timeout",
"login_timeout", "power_wait"]
atexit.register(atexit_handler)
all_opt["login_timeout"]["default"] = 60
pinput = process_input(device_opt)
# use ssh to manipulate node
pinput["--ssh"] = 1
pinput["--command-prompt"] = ".*"
options = check_input(device_opt, pinput)
if options["--action"] != "off":
sys.exit(0)
options["-c"] = "\[EXPECT\]#\ "
# this string will be appended to the end of ssh command
options["ssh_options"] = "-t -o 'StrictHostKeyChecking=no' " \
"'/bin/bash -c \"PS1=%s /bin/bash " \
"--noprofile --norc\"'" % options["-c"]
options["-X"] = "-t -o 'StrictHostKeyChecking=no' " \
"'/bin/bash -c \"PS1=%s /bin/bash " \
"--noprofile --norc\"'" % options["-c"]
docs = {}
docs["shortdesc"] = "Fence agent that can just reboot node via ssh"
docs["longdesc"] = "fence_ssh is an I/O Fencing agent " \
"which can be used to reboot nodes via ssh."
show_docs(options, docs)
# Operate the fencing device
# this method will actually launch ssh command
conn = fence_login(options)
result = fence_action(conn, options, set_power_status,
get_power_status, None)
try:
conn.close()
except exceptions.OSError:
pass
except pexpect.ExceptionPexpect:
pass
sys.exit(result)
if __name__ == "__main__":
main()

View File

@ -46,6 +46,20 @@ class nailgun::cobbler(
default => 'bootstrap',
}
if $::osfamily == 'RedHat' {
case $operatingsystemmajrelease {
'6': {
$fence_ssh_source = 'puppet:///modules/nailgun/cobbler/fence_ssh.centos6.py'
}
'7': {
$fence_ssh_source = 'puppet:///modules/nailgun/cobbler/fence_ssh.centos7.py'
}
default: {
$fence_ssh_source = 'puppet:///modules/nailgun/cobbler/fence_ssh.centos6.py'
}
}
}
class { '::cobbler':
server => $server,
production => $production,
@ -88,7 +102,7 @@ class nailgun::cobbler(
}
file { '/usr/sbin/fence_ssh':
content => template('nailgun/cobbler/fence_ssh.erb'),
source => $fence_ssh_source,
owner => 'root',
group => 'root',
mode => '0755',