Added: checks for import subprocess module and python version in 8.0
This commit is contained in:
parent
66990e579d
commit
e03ba93186
9
conf.py
9
conf.py
@ -3,11 +3,14 @@ import logging
|
||||
import sys
|
||||
from nodefilter import NodeFilter
|
||||
|
||||
|
||||
class Conf(object):
|
||||
"""Configuration parameters"""
|
||||
hard_filter = None
|
||||
soft_filter = NodeFilter()
|
||||
ssh = {'opts': '-oConnectTimeout=2 -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -oLogLevel=error -lroot -oBatchMode=yes',
|
||||
ssh = {'opts': '''-oConnectTimeout=2 -oStrictHostKeyChecking=no
|
||||
-oUserKnownHostsFile=/dev/null -oLogLevel=error
|
||||
-lroot -oBatchMode=yes''',
|
||||
'vars': 'OPENRC=/root/openrc IPTABLES_STR="iptables -nvL"'}
|
||||
cluster = None
|
||||
fuelip = 'localhost'
|
||||
@ -27,7 +30,7 @@ class Conf(object):
|
||||
self.hard_filter = NodeFilter(**entries['hard_filter'])
|
||||
if 'soft_filter' in entries:
|
||||
self.soft_filter = NodeFilter(**entries['soft_filter'])
|
||||
|
||||
|
||||
@staticmethod
|
||||
def load_conf(filename):
|
||||
try:
|
||||
@ -40,7 +43,7 @@ class Conf(object):
|
||||
logging.error("Could not convert data")
|
||||
sys.exit(1)
|
||||
except yaml.parser.ParserError as e:
|
||||
logging.error("Could not parse %s:\n%s" %(filename, str(e)))
|
||||
logging.error("Could not parse %s:\n%s" % (filename, str(e)))
|
||||
sys.exit(1)
|
||||
except:
|
||||
logging.error("Unexpected error: %s" % sys.exc_info()[0])
|
||||
|
@ -1,9 +1,9 @@
|
||||
class NodeFilter(object):
|
||||
|
||||
status = ['ready', 'discover']
|
||||
online = True
|
||||
roles = []
|
||||
node_ids = []
|
||||
def __init__(self, **entries):
|
||||
self.__dict__.update(entries)
|
||||
status = ['ready', 'discover']
|
||||
online = True
|
||||
roles = []
|
||||
node_ids = []
|
||||
|
||||
def __init__(self, **entries):
|
||||
self.__dict__.update(entries)
|
||||
|
2
timmy.py
2
timmy.py
@ -22,6 +22,7 @@ import sys
|
||||
import os
|
||||
from conf import Conf
|
||||
import flock
|
||||
from tools import import_subprocess
|
||||
|
||||
def main(argv=None):
|
||||
if argv is None:
|
||||
@ -61,6 +62,7 @@ def main(argv=None):
|
||||
loglevel = logging.INFO
|
||||
logging.basicConfig(level=loglevel,
|
||||
format='%(asctime)s %(levelname)s %(message)s')
|
||||
import_subprocess()
|
||||
config = Conf.load_conf(args.config)
|
||||
n = nodes.Nodes(conf=config,
|
||||
extended=args.extended,
|
||||
|
67
tools.py
67
tools.py
@ -21,9 +21,27 @@ tools module
|
||||
|
||||
import os
|
||||
import logging
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
def import_subprocess():
|
||||
if 'subprocess' not in globals():
|
||||
global subprocess
|
||||
try:
|
||||
import subprocess32 as subprocess
|
||||
logging.info("using improved subprocess32 module\n")
|
||||
except:
|
||||
import subprocess
|
||||
logging.warning(("Please upgrade the module 'subprocess' to the latest version: "
|
||||
"https://pypi.python.org/pypi/subprocess32/"))
|
||||
### set not_ok python
|
||||
global ok_python
|
||||
ok_python = True
|
||||
if sys.version > (2,7,0):
|
||||
ok_python = False
|
||||
logging.warning('this subprocess module does not support timeouts')
|
||||
else:
|
||||
logging.info('subprocess is already loaded')
|
||||
|
||||
|
||||
def get_dir_structure(rootdir):
|
||||
"""
|
||||
@ -60,13 +78,22 @@ def launch_cmd(command, timeout):
|
||||
shell=True,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
try:
|
||||
outs, errs = p.communicate(timeout=timeout+1)
|
||||
except subprocess.TimeoutExpired:
|
||||
p.kill()
|
||||
outs, errs = p.communicate()
|
||||
logging.error("command: %s err: %s, returned: %s" %
|
||||
(command, errs, p.returncode))
|
||||
if ok_python:
|
||||
try:
|
||||
outs, errs = p.communicate(timeout=timeout+1)
|
||||
except subprocess.TimeoutExpired:
|
||||
p.kill()
|
||||
outs, errs = p.communicate()
|
||||
logging.error("command: %s err: %s, returned: %s" %
|
||||
(command, errs, p.returncode))
|
||||
else:
|
||||
try:
|
||||
outs, errs = p.communicate()
|
||||
except:
|
||||
p.kill()
|
||||
outs, errs = p.communicate()
|
||||
logging.error("command: %s err: %s, returned: %s" %
|
||||
(command, errs, p.returncode))
|
||||
logging.debug("ssh return: err:%s\nouts:%s\ncode:%s" %
|
||||
(errs, outs, p.returncode))
|
||||
logging.info("ssh return: err:%s\ncode:%s" %
|
||||
@ -117,13 +144,23 @@ def get_files_rsync(ip, data, sshopts, dpath, timeout=15):
|
||||
stdin=subprocess.PIPE,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
try:
|
||||
outs, errs = p.communicate(input=data, timeout=timeout+1)
|
||||
except subprocess.TimeoutExpired:
|
||||
p.kill()
|
||||
outs, errs = p.communicate()
|
||||
logging.error("ip: %s, command: %s err: %s, returned: %s" %
|
||||
(ip, cmd, errs, p.returncode))
|
||||
if ok_python:
|
||||
try:
|
||||
outs, errs = p.communicate(input=data, timeout=timeout+1)
|
||||
except subprocess.TimeoutExpired:
|
||||
p.kill()
|
||||
outs, errs = p.communicate()
|
||||
logging.error("ip: %s, command: %s err: %s, returned: %s" %
|
||||
(ip, cmd, errs, p.returncode))
|
||||
else:
|
||||
try:
|
||||
outs, errs = p.communicate(input=data)
|
||||
except:
|
||||
p.kill()
|
||||
outs, errs = p.communicate()
|
||||
logging.error("ip: %s, command: %s err: %s, returned: %s" %
|
||||
(ip, cmd, errs, p.returncode))
|
||||
|
||||
logging.debug("ip: %s, ssh return: err:%s\nouts:%s\ncode:%s" %
|
||||
(ip, errs, outs, p.returncode))
|
||||
logging.info("ip: %s, ssh return: err:%s\ncode:%s" %
|
||||
|
Loading…
x
Reference in New Issue
Block a user