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
|
import sys
|
||||||
from nodefilter import NodeFilter
|
from nodefilter import NodeFilter
|
||||||
|
|
||||||
|
|
||||||
class Conf(object):
|
class Conf(object):
|
||||||
"""Configuration parameters"""
|
"""Configuration parameters"""
|
||||||
hard_filter = None
|
hard_filter = None
|
||||||
soft_filter = NodeFilter()
|
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"'}
|
'vars': 'OPENRC=/root/openrc IPTABLES_STR="iptables -nvL"'}
|
||||||
cluster = None
|
cluster = None
|
||||||
fuelip = 'localhost'
|
fuelip = 'localhost'
|
||||||
@ -27,7 +30,7 @@ class Conf(object):
|
|||||||
self.hard_filter = NodeFilter(**entries['hard_filter'])
|
self.hard_filter = NodeFilter(**entries['hard_filter'])
|
||||||
if 'soft_filter' in entries:
|
if 'soft_filter' in entries:
|
||||||
self.soft_filter = NodeFilter(**entries['soft_filter'])
|
self.soft_filter = NodeFilter(**entries['soft_filter'])
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def load_conf(filename):
|
def load_conf(filename):
|
||||||
try:
|
try:
|
||||||
@ -40,7 +43,7 @@ class Conf(object):
|
|||||||
logging.error("Could not convert data")
|
logging.error("Could not convert data")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
except yaml.parser.ParserError as e:
|
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)
|
sys.exit(1)
|
||||||
except:
|
except:
|
||||||
logging.error("Unexpected error: %s" % sys.exc_info()[0])
|
logging.error("Unexpected error: %s" % sys.exc_info()[0])
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
class NodeFilter(object):
|
class NodeFilter(object):
|
||||||
|
|
||||||
status = ['ready', 'discover']
|
status = ['ready', 'discover']
|
||||||
online = True
|
online = True
|
||||||
roles = []
|
roles = []
|
||||||
node_ids = []
|
node_ids = []
|
||||||
def __init__(self, **entries):
|
|
||||||
self.__dict__.update(entries)
|
|
||||||
|
|
||||||
|
def __init__(self, **entries):
|
||||||
|
self.__dict__.update(entries)
|
||||||
|
2
timmy.py
2
timmy.py
@ -22,6 +22,7 @@ import sys
|
|||||||
import os
|
import os
|
||||||
from conf import Conf
|
from conf import Conf
|
||||||
import flock
|
import flock
|
||||||
|
from tools import import_subprocess
|
||||||
|
|
||||||
def main(argv=None):
|
def main(argv=None):
|
||||||
if argv is None:
|
if argv is None:
|
||||||
@ -61,6 +62,7 @@ def main(argv=None):
|
|||||||
loglevel = logging.INFO
|
loglevel = logging.INFO
|
||||||
logging.basicConfig(level=loglevel,
|
logging.basicConfig(level=loglevel,
|
||||||
format='%(asctime)s %(levelname)s %(message)s')
|
format='%(asctime)s %(levelname)s %(message)s')
|
||||||
|
import_subprocess()
|
||||||
config = Conf.load_conf(args.config)
|
config = Conf.load_conf(args.config)
|
||||||
n = nodes.Nodes(conf=config,
|
n = nodes.Nodes(conf=config,
|
||||||
extended=args.extended,
|
extended=args.extended,
|
||||||
|
67
tools.py
67
tools.py
@ -21,9 +21,27 @@ tools module
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
import subprocess
|
|
||||||
import sys
|
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):
|
def get_dir_structure(rootdir):
|
||||||
"""
|
"""
|
||||||
@ -60,13 +78,22 @@ def launch_cmd(command, timeout):
|
|||||||
shell=True,
|
shell=True,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE)
|
stderr=subprocess.PIPE)
|
||||||
try:
|
if ok_python:
|
||||||
outs, errs = p.communicate(timeout=timeout+1)
|
try:
|
||||||
except subprocess.TimeoutExpired:
|
outs, errs = p.communicate(timeout=timeout+1)
|
||||||
p.kill()
|
except subprocess.TimeoutExpired:
|
||||||
outs, errs = p.communicate()
|
p.kill()
|
||||||
logging.error("command: %s err: %s, returned: %s" %
|
outs, errs = p.communicate()
|
||||||
(command, errs, p.returncode))
|
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" %
|
logging.debug("ssh return: err:%s\nouts:%s\ncode:%s" %
|
||||||
(errs, outs, p.returncode))
|
(errs, outs, p.returncode))
|
||||||
logging.info("ssh return: err:%s\ncode:%s" %
|
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,
|
stdin=subprocess.PIPE,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE)
|
stderr=subprocess.PIPE)
|
||||||
try:
|
if ok_python:
|
||||||
outs, errs = p.communicate(input=data, timeout=timeout+1)
|
try:
|
||||||
except subprocess.TimeoutExpired:
|
outs, errs = p.communicate(input=data, timeout=timeout+1)
|
||||||
p.kill()
|
except subprocess.TimeoutExpired:
|
||||||
outs, errs = p.communicate()
|
p.kill()
|
||||||
logging.error("ip: %s, command: %s err: %s, returned: %s" %
|
outs, errs = p.communicate()
|
||||||
(ip, cmd, errs, p.returncode))
|
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" %
|
logging.debug("ip: %s, ssh return: err:%s\nouts:%s\ncode:%s" %
|
||||||
(ip, errs, outs, p.returncode))
|
(ip, errs, outs, p.returncode))
|
||||||
logging.info("ip: %s, ssh return: err:%s\ncode:%s" %
|
logging.info("ip: %s, ssh return: err:%s\ncode:%s" %
|
||||||
|
Loading…
x
Reference in New Issue
Block a user