fix: replace unix paths with os independent functions
This commit is contained in:
parent
f212c18c9a
commit
cfe63a5e83
@ -23,6 +23,7 @@ import os
|
||||
from timmy.conf import load_conf
|
||||
from timmy import flock
|
||||
from timmy.tools import interrupt_wrapper
|
||||
from tempfile import gettempdir
|
||||
|
||||
|
||||
@interrupt_wrapper
|
||||
@ -123,7 +124,7 @@ def main(argv=None):
|
||||
main_arc,
|
||||
60)
|
||||
if args.only_logs or args.getlogs:
|
||||
lf = '/tmp/timmy-logs.lock'
|
||||
lf = os.path.join(gettempdir(),'timmy-logs.lock')
|
||||
lock = flock.FLock(lf)
|
||||
if lock.lock():
|
||||
size = nm.calculate_log_size(args.maxthreads)
|
||||
|
@ -1,4 +1,6 @@
|
||||
from tools import load_yaml_file, choose_path
|
||||
from tools import load_yaml_file
|
||||
from tempfile import gettempdir
|
||||
import os
|
||||
|
||||
|
||||
def load_conf(filename):
|
||||
@ -11,12 +13,20 @@ def load_conf(filename):
|
||||
'-lroot', '-oBatchMode=yes']
|
||||
conf['env_vars'] = ['OPENRC=/root/openrc', 'IPTABLES_STR="iptables -nvL"']
|
||||
conf['fuelip'] = 'localhost'
|
||||
conf['outdir'] = '/tmp/timmy/info'
|
||||
conf['outdir'] = os.path.join(gettempdir(), 'timmy', 'info')
|
||||
conf['timeout'] = 15
|
||||
conf['rqdir'] = choose_path('/usr/share/timmy/rq')
|
||||
conf['rqfile'] = choose_path('/usr/share/timmy/configs/rq.yaml')
|
||||
rqlabel = 'rq'
|
||||
dtm = os.path.join(os.path.abspath(os.sep), 'usr', 'share', 'timmy')
|
||||
if os.path.isdir(os.path.join(dtm, rqlabel)):
|
||||
conf['rqdir'] = os.path.join(dtm, rqlabel)
|
||||
else:
|
||||
conf['rqdir'] = rqlabel
|
||||
if os.path.isfile(os.path.join(dtm, 'configs', 'rq.yaml')):
|
||||
conf['rqfile'] = os.path.join(dtm, 'configs', 'rq.yaml')
|
||||
else:
|
||||
conf['rqfile'] = 'rq.yaml'
|
||||
conf['compress_timeout'] = 3600
|
||||
conf['archives'] = '/tmp/timmy/archives'
|
||||
conf['archives'] = os.path.join(gettempdir(), 'timmy', 'archives')
|
||||
conf['cmds_archive'] = ''
|
||||
conf['logs'] = {'path': '/var/log',
|
||||
'exclude': '[-_]\d{8}$|atop[-_]|\.gz$'}
|
||||
|
@ -26,6 +26,7 @@ import logging
|
||||
import sys
|
||||
import re
|
||||
import tools
|
||||
from tempfile import gettempdir
|
||||
from tools import w_list
|
||||
from copy import deepcopy
|
||||
|
||||
@ -522,7 +523,7 @@ class NodeManager(object):
|
||||
|
||||
def run_commands(self, odir='info', timeout=15, fake=False,
|
||||
maxthreads=100):
|
||||
lock = flock.FLock('/tmp/timmy-cmds.lock')
|
||||
lock = flock.FLock(os.path.join(gettempdir(), 'timmy-cmds.lock'))
|
||||
if not lock.lock():
|
||||
logging.warning('Unable to obtain lock, skipping "cmds"-part')
|
||||
return ''
|
||||
@ -623,13 +624,13 @@ class NodeManager(object):
|
||||
try:
|
||||
with open(logslistfile, 'w') as llf:
|
||||
for filename in node.logs_dict():
|
||||
llf.write(filename.lstrip('/')+"\0")
|
||||
llf.write(filename.lstrip(os.path.abspath(os.sep))+"\0")
|
||||
except:
|
||||
logging.error("create_archive_logs: Can't write to file %s" %
|
||||
logslistfile)
|
||||
continue
|
||||
cmd = ("tar --gzip -C / --create --warning=no-file-changed "
|
||||
" --file - --null --files-from -")
|
||||
cmd = ("tar --gzip -C %s --create --warning=no-file-changed "
|
||||
" --file - --null --files-from -" % os.path.abspath(os.sep))
|
||||
if not (node.ip == 'localhost' or node.ip.startswith('127.')):
|
||||
cmd = ' '.join([cmd, "| python -c '%s'" % pythonslowpipe])
|
||||
args = {'cmd': cmd,
|
||||
@ -647,7 +648,7 @@ class NodeManager(object):
|
||||
logging.error("archive_logs: can't delete file %s" % tfile)
|
||||
|
||||
def get_files(self, odir=Node.fkey, timeout=15):
|
||||
lock = flock.FLock('/tmp/timmy-files.lock')
|
||||
lock = flock.FLock(os.path.join(gettempdir(), 'timmy-files.lock'))
|
||||
if not lock.lock():
|
||||
logging.warning('Unable to obtain lock, skipping "files"-part')
|
||||
return ''
|
||||
|
@ -146,21 +146,15 @@ def get_dir_structure(rootdir):
|
||||
return dir
|
||||
|
||||
|
||||
def choose_path(filename):
|
||||
if os.path.exists(filename):
|
||||
return filename
|
||||
elif '/' in filename:
|
||||
return filename.split('/')[-1]
|
||||
|
||||
|
||||
def load_yaml_file(filename):
|
||||
try:
|
||||
with open(choose_path(filename), 'r') as f:
|
||||
with open(filename, 'r') as f:
|
||||
return yaml.load(f)
|
||||
except IOError as e:
|
||||
logging.error("load_conf: I/O error(%s): file: %s; msg: %s" %
|
||||
(e.errno, e.filename, e.strerror))
|
||||
return e
|
||||
sys.exit(1)
|
||||
# return e
|
||||
except ValueError:
|
||||
logging.error("load_conf: Could not convert data")
|
||||
sys.exit(1)
|
||||
|
Loading…
x
Reference in New Issue
Block a user