Skip to content

Commit

Permalink
Revert "vstart_runner: rotate logs between testcases"
Browse files Browse the repository at this point in the history
Fixes: https://tracker.ceph.com/issues/47032
Signed-off-by: Ernesto Puerta <epuertat@redhat.com>
  • Loading branch information
epuertat committed Aug 19, 2020
1 parent 4d0b57d commit 64ec111
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 116 deletions.
84 changes: 12 additions & 72 deletions qa/tasks/vstart_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -1200,22 +1200,11 @@ def __del__(self):
if test_path:
shutil.rmtree(test_path)


class LogRotate():
def __init__(self):
self.conf_file_path = os.path.join(os.getcwd(), 'logrotate.conf')
self.state_file_path = os.path.join(os.getcwd(), 'logrotate.state')

def run_logrotate(self):
remote.run(args=['logrotate', '-f', self.conf_file_path, '-s',
self.state_file_path, '--verbose'])

def teardown_cluster():
log.info('\ntearing down the cluster...')
remote.run(args=[os.path.join(SRC_PREFIX, "stop.sh")], timeout=60)
remote.run(args=['rm', '-rf', './dev', './out'])


def clear_old_log():
from os import stat

Expand All @@ -1232,7 +1221,6 @@ def clear_old_log():
init_log()
log.info('logging in a fresh file now...')


def exec_test():
# Parse arguments
opt_interactive_on_error = False
Expand All @@ -1247,7 +1235,6 @@ def exec_test():
opt_use_ns = False
opt_brxnet= None
opt_verbose = True
opt_rotate_log = True

args = sys.argv[1:]
flags = [a for a in args if a.startswith("-")]
Expand Down Expand Up @@ -1285,8 +1272,6 @@ def exec_test():
sys.exit(-1)
elif '--no-verbose' == f:
opt_verbose = False
elif f == '--dont-rotate':
opt_rotate_log = False
else:
log.error("Unknown option '{0}'".format(f))
sys.exit(-1)
Expand Down Expand Up @@ -1396,39 +1381,19 @@ class LogStream(object):
def __init__(self):
self.buffer = ""

def _del_result_lines(self):
"""
Don't let unittest.TextTestRunner print "Ran X tests in Ys",
vstart_runner.py will do it for itself since it runs tests in a
testsuite one by one.
"""
self.buffer = re.sub('\n\n'+'-'*70+'\nran [0-9]* test in [0-9.]*s\n\n',
'', self.buffer, flags=re.I)

self.buffer = self.buffer.replace('OK\n', '')

def write(self, data):
self.buffer += data
if self.buffer.count("\n") > 5:
self._write()

def _write(self):
self._del_result_lines()
if self.buffer == '':
return

lines = self.buffer.split("\n")
for line in lines:
# sys.stderr.write(line + "\n")
log.info(line)
self.buffer = ''
if "\n" in self.buffer:
lines = self.buffer.split("\n")
for line in lines[:-1]:
pass
# sys.stderr.write(line + "\n")
log.info(line)
self.buffer = lines[-1]

def flush(self):
pass

def __del__(self):
self._write()

decorating_loader = DecoratingLoader({
"ctx": ctx,
"mounts": mounts,
Expand Down Expand Up @@ -1517,37 +1482,12 @@ def addSkip(self, test, reason):
else:
super(LoggingResult, self).addSkip(test, reason)


# Execute!
overall_suite = load_tests(modules, loader.TestLoader())
no_of_tests_execed = 0
if opt_rotate_log:
logrotate = LogRotate()
started_at = datetime.datetime.utcnow()
for suite_, case in enumerate_methods(overall_suite):
# don't run logrotate beforehand since some ceph daemons might be
# down and pre/post-rotate scripts in logrotate.conf might fail.
if opt_rotate_log:
logrotate.run_logrotate()

result = unittest.TextTestRunner(stream=LogStream(),
resultclass=LoggingResult,
verbosity=2, failfast=True).run(case)

if not result.wasSuccessful():
break

no_of_tests_execed += 1

time_elapsed = (datetime.datetime.utcnow() - started_at).total_seconds()

if result.wasSuccessful():
log.info('')
log.info('-'*70)
log.info('Ran {} tests in {}s'.format(no_of_tests_execed,
time_elapsed))
log.info('')
log.info('OK')
result = unittest.TextTestRunner(
stream=LogStream(),
resultclass=LoggingResult,
verbosity=2,
failfast=True).run(overall_suite)

CephFSMount.cleanup_stale_netnses_and_bridge(remote)

Expand Down
44 changes: 0 additions & 44 deletions src/vstart.sh
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,9 @@ inc_osd_num=0

msgr="21"

rotate_logs=1

usage="usage: $0 [option]... \nex: MON=3 OSD=1 MDS=1 MGR=1 RGW=1 NFS=1 $0 -n -d\n"
usage=$usage"options:\n"
usage=$usage"\t-d, --debug\n"
usage=$usage"\t--dont-rotate: don't rotate the logs\n"
usage=$usage"\t-s, --standby_mds: Generate standby-replay MDS for each active\n"
usage=$usage"\t-l, --localhost: use localhost instead of hostname\n"
usage=$usage"\t-i <ip>: bind to specific ip\n"
Expand Down Expand Up @@ -246,9 +243,6 @@ case $1 in
-d | --debug )
debug=1
;;
--dont-rotate)
rotate_logs=0
;;
-s | --standby_mds)
standby=1
;;
Expand Down Expand Up @@ -725,40 +719,6 @@ $extra_conf
EOF
}

write_logrotate_conf() {
out_dir=$(pwd)"/out/*.log"

cat << EOF
$out_dir
{
rotate 5
size 1G
copytruncate
compress
notifempty
missingok
sharedscripts
postrotate
# NOTE: assuring that the absence of one of the following processes
# won't abort the logrotate command.
killall -u $USER -q -1 ceph-mon ceph-mgr ceph-mds ceph-osd ceph-fuse radosgw rbd-mirror || echo ""
endscript
}
EOF
}

init_logrotate() {
logrotate_conf_path=$(pwd)"/logrotate.conf"
logrotate_state_path=$(pwd)"/logrotate.state"

if ! test -a $logrotate_conf_path; then
if test -a $logrotate_state_path; then
rm -f $logrotate_state_path
fi
write_logrotate_conf > $logrotate_conf_path
fi
}

start_mon() {
local MONS=""
local count=0
Expand Down Expand Up @@ -1597,7 +1557,3 @@ if [ -f "$STRAY_CONF_PATH" -a -n "$conf_fn" -a ! "$conf_fn" -ef "$STRAY_CONF_PAT
echo "NOTE:"
echo " Remember to restart cluster after removing $STRAY_CONF_PATH"
fi

if [ $rotate_logs -ne 0 ]; then
init_logrotate
fi

0 comments on commit 64ec111

Please sign in to comment.