[Kimchi-devel] [PATCH V4] Fix host debug report for Fedora 20
Rodrigo Trujillo
rodrigo.trujillo at linux.vnet.ibm.com
Thu Feb 13 20:28:17 UTC 2014
The tool sosreport does not save the report file in /tmp in F20, this
causes a error in Kimchi, which has /tmp hardcoded. This fixes this
problem searching report files in /var/tmp too.
Notice that is possible to pass --tmp-dir as the directory to save the
report file, but this option is crashing in Fedora 20, so the code is
not using it.
This patch also improves the logging and uses new i18n translation
system for exception error messages.
Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo at linux.vnet.ibm.com>
---
src/kimchi/i18n.py | 2 +-
src/kimchi/model/debugreports.py | 58 +++++++++++++++++++++++++---------------
2 files changed, 37 insertions(+), 23 deletions(-)
diff --git a/src/kimchi/i18n.py b/src/kimchi/i18n.py
index 03d1052..cd06264 100644
--- a/src/kimchi/i18n.py
+++ b/src/kimchi/i18n.py
@@ -164,7 +164,7 @@ messages = {
"KCHDR0001E": _("Debug report %(name)s does not exist"),
"KCHDR0002E": _("Debug report tool not found in system"),
"KCHDR0003E": _("Unable to create debug report %(name)s. Details: %(err)s."),
- "KCHDR0004E": _("Can not find generated debug report named %(name)s"),
+ "KCHDR0004E": _("Can not find any generated debug report matching name %(name)s"),
"KCHDR0005E": _("Unable to generate debug report %(name)s. Details: %(err)s"),
"KCHSR0001E": _("Storage server %(server)s was not used by Kimchi"),
diff --git a/src/kimchi/model/debugreports.py b/src/kimchi/model/debugreports.py
index 2c5b13a..dc27eee 100644
--- a/src/kimchi/model/debugreports.py
+++ b/src/kimchi/model/debugreports.py
@@ -32,6 +32,7 @@ from kimchi import config
from kimchi.exception import NotFoundError, OperationFailed
from kimchi.model.tasks import TaskModel
from kimchi.utils import add_task, kimchi_log
+from kimchi.utils import run_command
class DebugReportsModel(object):
@@ -63,38 +64,51 @@ class DebugReportsModel(object):
@staticmethod
def sosreport_generate(cb, name):
- command = 'sosreport --batch --name "%s"' % name
try:
- retcode = subprocess.call(command, shell=True,
- stdout=subprocess.PIPE)
+ command = ['sosreport', '--batch', '--name=%s' % name]
+ output, error, retcode = run_command(command)
+
if retcode < 0:
raise OperationFailed("KCHDR0003E", {'name': name,
'err': retcode})
elif retcode > 0:
raise OperationFailed("KCHDR0003E", {'name': name,
'err': retcode})
- pattern = '/tmp/sosreport-%s-*' % name
- for reportFile in glob.glob(pattern):
- if not fnmatch.fnmatch(reportFile, '*.md5'):
- output = reportFile
+
+ # SOSREPORT might create file in /tmp or /var/tmp
+ # FIXME: The right way should be passing the tar.xz file directory
+ # though the parameter '--tmp-dir', but it is failing in Fedora 20
+ patterns = ['/tmp/sosreport-%s-*', '/var/tmp/sosreport-%s-*']
+ reports = []
+ reportFile = None
+ for p in patterns:
+ reports = reports + [f for f in glob.glob(p % name)]
+ for f in reports:
+ if not fnmatch.fnmatch(f, '*.md5'):
+ reportFile = f
break
- else:
- # sosreport tends to change the name mangling rule and
- # compression file format between different releases.
- # It's possible to fail to match a report file even sosreport
- # runs successfully. In future we might have a general name
- # mangling function in kimchi to format the name before passing
- # it to sosreport. Then we can delete this exception.
- raise OperationFailed("KCHDR0004E", {'name': pattern})
-
- ext = output.split('.', 1)[1]
+ # Some error in sosreport happened
+ if reportFile is None:
+ kimchi_log.error('Debug report file not found. See sosreport '
+ 'output for detail:\n%s', output)
+ raise OperationFailed('KCHDR0004E',
+ {'name': (patterns[0] % name).split('/')[-1]})
+
+ md5_report_file = reportFile + '.md5'
+ report_file_extension = '.' + reportFile.split('.', 1)[1]
path = config.get_debugreports_path()
- target = os.path.join(path, name)
- target_file = '%s.%s' % (target, ext)
- shutil.move(output, target_file)
- os.remove('%s.md5' % output)
+ target = os.path.join(path, name + report_file_extension)
+ # Moving report
+ msg = 'Moving debug report file "%s" to "%s"' % (reportFile, target)
+ kimchi_log.info(msg)
+ shutil.move(reportFile, target)
+ # Deleting md5
+ msg = 'Deleting report md5 file: "%s"' % (md5_report_file)
+ kimchi_log.info(msg)
+ md5 = open(md5_report_file).read().strip()
+ kimchi_log.info('Md5 file content: "%s"', md5)
+ os.remove(md5_report_file)
cb('OK', True)
-
return
except OSError:
--
1.8.5.3
More information about the Kimchi-devel
mailing list