Skip to content

Commit

Permalink
CP-41107: Store bug tool log in status report
Browse files Browse the repository at this point in the history
  • Loading branch information
GeraldEV committed Jul 14, 2023
1 parent f03c045 commit 09ea949
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions xen-bugtool
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ SWTPM_RCA ='/var/lib/swtpm-localca/swtpm-localca-rootca-cert.pem'
SWTPM_CS = '/var/lib/swtpm-localca/certserial'
NRPE_CONF = '/etc/nagios/nrpe.cfg'
NRPE_DIR = '/etc/nrpe.d'
XEN_BUGTOOL_LOG = 'xen-bugtool.log'

#
# External programs
Expand Down Expand Up @@ -352,6 +353,7 @@ CAP_TAPDISK_LOGS = 'tapdisk-logs'
CAP_VTPM = 'vtpm'
CAP_XAPI_DEBUG = 'xapi-debug'
CAP_XAPI_SUBPROCESS = 'xapi-subprocess'
CAP_XEN_BUGTOOL = 'xen-bugtool'
CAP_XENRT = 'xenrt'
CAP_XENSERVER_CONFIG = 'xenserver-config'
CAP_XENSERVER_DOMAINS = 'xenserver-domains'
Expand Down Expand Up @@ -427,6 +429,7 @@ cap(CAP_VTPM, PII_NO, max_size=5*KB)
cap(CAP_XAPI_DEBUG, PII_MAYBE, max_size=10*MB)
cap(CAP_XAPI_SUBPROCESS, PII_NO, max_size=5*KB,
max_time=10)
cap(CAP_XEN_BUGTOOL, PII_NO, min_size=0)
cap(CAP_XENRT, PII_NO, min_size=0, max_size=500*MB,
checked=False, hidden=True)
cap(CAP_XENSERVER_CONFIG, PII_MAYBE, max_size=80*KB,
Expand Down Expand Up @@ -455,6 +458,13 @@ def no_unicode(x):
return x.encode('utf-8')
return x

def log(x, output=True):
if output:
output(x)

with open(XEN_BUGTOOL_LOG, "a") as logFile:
print >>logFile, x

def output(x):
if not SILENT_MODE:
print x
Expand Down Expand Up @@ -497,7 +507,7 @@ def file_output(cap, path_list):
data[p] = {'cap': cap, 'filename': p}
cap_sizes[cap] += s.st_size
else:
output("Omitting %s, size constraint of %s exceeded" % (p, cap))
log("Omitting %s, size constraint of %s exceeded" % (p, cap))
except:
pass

Expand Down Expand Up @@ -542,7 +552,7 @@ def collect_data(subdir, archive):
del v['output']
cap_sizes[cap] += len(s)
else:
output("Omitting %s, size constraint of %s exceeded" % (v['filename'], cap))
log("Omitting %s, size constraint of %s exceeded" % (v['filename'], cap))
except:
pass
elif v.has_key('func'):
Expand All @@ -558,7 +568,7 @@ def collect_data(subdir, archive):
del v['output']
cap_sizes[cap] += len(s)
else:
output("Omitting %s, size constraint of %s exceeded" % (k, cap))
log("Omitting %s, size constraint of %s exceeded" % (k, cap))
elif filename:
try:
archive.addRealFile(name, filename)
Expand Down Expand Up @@ -610,6 +620,15 @@ def main(argv = None):
if argv is None:
argv = sys.argv

# Ensure we have a clean bugtool log file
try:
os.remove(XEN_BUGTOOL_LOG)
except:
pass

log(" ".join(argv), output=False)
log("PATH=%s" % os.environ['PATH'], output=False)

try:
(options, params) = getopt.gnu_getopt(
argv, 'adsuy', ['capabilities', 'silent', 'yestoall', 'entries=',
Expand Down Expand Up @@ -1091,6 +1110,8 @@ exclude those logs from the archive.
cmd_output(CAP_YUM, [RPM, '-qa'])
tree_output(CAP_YUM, SIGNING_KEY_INFO_DIR)

file_output(CAP_XEN_BUGTOOL, [XEN_BUGTOOL_LOG])

# permit the user to filter out data
for k in sorted(data.keys()):
if not ANSWER_YES_TO_ALL and not yes("Include '%s'? [Y/n]: " % k):
Expand Down Expand Up @@ -1135,6 +1156,11 @@ exclude those logs from the archive.

clean_tapdisk_logs()

try:
os.remove(XEN_BUGTOOL_LOG)
except:
pass

if dbg:
print >>sys.stderr, "Category sizes (max, actual):\n"
for c in caps.keys():
Expand Down

0 comments on commit 09ea949

Please sign in to comment.