added: ok_codes for commands
replacement: general archive uses gzip fix: flake8 warnings fix: typo from copy/paste functions fix: cmds and files have the same names in dirs fix: tar uses '-C /' option and ok_codes
This commit is contained in:
parent
1a76e7a6b7
commit
6808eace18
@ -1 +1 @@
|
||||
../../cmds/dmesg
|
||||
../../cmds/.dmesg-centos
|
@ -1 +1 @@
|
||||
../../cmds/dmesg-t
|
||||
../../cmds/.dmesg-t-ubuntu
|
@ -1,3 +0,0 @@
|
||||
/etc/yum.d/
|
||||
/etc/yum
|
||||
/etc/yum.conf
|
1
rq/files/by-os/centos/yum
Symbolic link
1
rq/files/by-os/centos/yum
Symbolic link
@ -0,0 +1 @@
|
||||
../../../files/files/yum
|
@ -1 +0,0 @@
|
||||
/etc/apt
|
1
rq/files/by-os/ubuntu/etc-apt
Symbolic link
1
rq/files/by-os/ubuntu/etc-apt
Symbolic link
@ -0,0 +1 @@
|
||||
../../../files/files/etc-apt
|
1
rq/files/files/etc-apt
Normal file
1
rq/files/files/etc-apt
Normal file
@ -0,0 +1 @@
|
||||
/etc/apt
|
3
rq/files/files/yum
Normal file
3
rq/files/files/yum
Normal file
@ -0,0 +1,3 @@
|
||||
/etc/yum.d/
|
||||
/etc/yum
|
||||
/etc/yum.conf
|
@ -74,13 +74,13 @@ def main(argv=None):
|
||||
config = Conf()
|
||||
if args.config:
|
||||
config = Conf.load_conf(args.config)
|
||||
main_arc = os.path.join(config.archives, 'general.tar.bz2')
|
||||
main_arc = os.path.join(config.archives, 'general.tar.gz')
|
||||
if args.dest_file:
|
||||
main_arc = args.dest_file
|
||||
nm = NodeManager(conf=config,
|
||||
extended=args.extended,
|
||||
cluster=args.cluster,
|
||||
)
|
||||
extended=args.extended,
|
||||
cluster=args.cluster,
|
||||
)
|
||||
if not args.only_logs:
|
||||
nm.get_node_file_list()
|
||||
nm.launch_ssh(config.outdir, args.maxthreads)
|
||||
|
@ -1,8 +1,7 @@
|
||||
import logging
|
||||
import sys
|
||||
from nodefilter import NodeFilter
|
||||
from tools import load_yaml_file
|
||||
|
||||
|
||||
class Conf(object):
|
||||
"""Configuration parameters"""
|
||||
hard_filter = None
|
||||
@ -20,8 +19,8 @@ class Conf(object):
|
||||
compress_timeout = 3600
|
||||
archives = '/tmp/timmy/archives'
|
||||
cmds_archive = ''
|
||||
logs = { 'path': '/var/log',
|
||||
'exclude': '[-_]\d{8}$|atop[-_]|\.gz$'}
|
||||
logs = {'path': '/var/log',
|
||||
'exclude': '[-_]\d{8}$|atop[-_]|\.gz$'}
|
||||
|
||||
def __init__(self, **entries):
|
||||
self.__dict__.update(entries)
|
||||
@ -37,5 +36,6 @@ class Conf(object):
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import yaml
|
||||
conf = Conf.load_conf('config.yaml')
|
||||
print(yaml.dump(conf))
|
||||
|
@ -108,7 +108,6 @@ class Node(object):
|
||||
def set_files_from_yaml(self, dirname, key, ds, version):
|
||||
files = []
|
||||
dfs = 'default'
|
||||
print(ds)
|
||||
for role in self.roles:
|
||||
if 'by-role' in ds[key] and role in ds[key]['by-role']:
|
||||
for f in ds[key]['by-role'][role]:
|
||||
@ -187,7 +186,8 @@ class Node(object):
|
||||
logging.error("exec_cmd: can't write to file %s" % dfile)
|
||||
return self
|
||||
|
||||
def exec_simple_cmd(self, cmd, infile, outfile, timeout=15, fake=False):
|
||||
def exec_simple_cmd(self, cmd, infile, outfile, timeout=15,
|
||||
fake=False, ok_codes=[0, ]):
|
||||
logging.info('node:%s(%s), exec: %s' % (self.node_id, self.ip, cmd))
|
||||
if not fake:
|
||||
outs, errs, code = tools.ssh_node(ip=self.ip,
|
||||
@ -197,7 +197,7 @@ class Node(object):
|
||||
timeout=timeout,
|
||||
outputfile=outfile,
|
||||
inputfile=infile)
|
||||
if code != 0:
|
||||
if code not in ok_codes:
|
||||
logging.warning("node: %s, ip: %s, cmdfile: %s,"
|
||||
" code: %s, error message: %s" %
|
||||
(self.node_id, self.ip, cmd, code, errs))
|
||||
@ -264,7 +264,7 @@ class Node(object):
|
||||
if '\t' in line:
|
||||
size, f = line.split('\t')
|
||||
if filter_by_re(item, f):
|
||||
item['files'][filename] = int(size)
|
||||
item['files'][f] = int(size)
|
||||
logging.debug('logs_populate: logs: %s' % (item['files']))
|
||||
return self
|
||||
|
||||
@ -305,7 +305,6 @@ class NodeManager(object):
|
||||
if (not os.path.exists(self.dirname)):
|
||||
logging.error("directory %s doesn't exist" % (self.dirname))
|
||||
sys.exit(1)
|
||||
dn = os.path.basename(self.dirname)
|
||||
self.files = tools.load_yaml_file(conf.rqfile)
|
||||
if (conf.fuelip is None) or (conf.fuelip == ""):
|
||||
logging.error('looks like fuelip is not set(%s)' % conf.fuelip)
|
||||
@ -462,7 +461,10 @@ class NodeManager(object):
|
||||
# ### case
|
||||
roles = []
|
||||
for node in self.nodes.values():
|
||||
node.set_files_from_yaml(self.dirname, key, self.files, self.version)
|
||||
node.set_files_from_yaml(self.dirname,
|
||||
key,
|
||||
self.files,
|
||||
self.version)
|
||||
# once-by-role functionality
|
||||
if self.extended and key == ckey and node.online:
|
||||
for role in node.roles:
|
||||
@ -550,7 +552,7 @@ class NodeManager(object):
|
||||
return True
|
||||
|
||||
def create_archive_general(self, directory, outfile, timeout):
|
||||
cmd = "tar jcf '%s' -C %s %s" % (outfile, directory, ".")
|
||||
cmd = "tar zcf '%s' -C %s %s" % (outfile, directory, ".")
|
||||
tools.mdir(self.conf.archives)
|
||||
logging.debug("create_archive_general: cmd: %s" % cmd)
|
||||
outs, errs, code = tools.launch_cmd(command=cmd,
|
||||
@ -598,19 +600,20 @@ class NodeManager(object):
|
||||
try:
|
||||
with open(logslistfile, 'w') as llf:
|
||||
for filename in node.logs_dict():
|
||||
llf.write(filename+"\0")
|
||||
llf.write(filename.lstrip('/')+"\0")
|
||||
except:
|
||||
logging.error("create_archive_logs: Can't write to file %s" %
|
||||
logslistfile)
|
||||
continue
|
||||
cmd = ("tar --gzip --create --warning=no-file-changed "
|
||||
cmd = ("tar --gzip -C / --create --warning=no-file-changed "
|
||||
" --file - --null --files-from -")
|
||||
if not (node.ip == 'localhost' or node.ip.startswith('127.')):
|
||||
cmd = ' '.join([cmd, "| python -c '%s'" % pythonslowpipe])
|
||||
args = {'cmd': cmd,
|
||||
'infile': logslistfile,
|
||||
'outfile': node.archivelogsfile,
|
||||
'timeout': timeout}
|
||||
'timeout': timeout,
|
||||
'ok_codes': [0, 1]}
|
||||
run_items.append(tools.RunItem(target=node.exec_simple_cmd,
|
||||
args=args))
|
||||
tools.run_batch(run_items, maxthreads)
|
||||
|
Loading…
x
Reference in New Issue
Block a user