[PATCH] Fix debug report - NEED TESTS

In Fedora 20, the sosreport tool saves the report file in /var/tmp, which crashes kimchi. The --tmp-dir options should be the right approach but it is crashing in Fedora 20 (RHEL works). While waiting sosreport fix, this patch feache the file path and name from sosreport output. This code works on Fedora 20. Need more tests in Ubuntu(s), RHEL and older Fedora. Rodrigo Trujillo (1): Fix host debug report for Fedora 20 src/kimchi/model/debugreports.py | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) -- 1.8.5.3

The tool sosreport does not save the report file in /tmp in F20, which causes a error in Kimchi, which has /tmp hardcoded. This patch fetches the report file location from the output. 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. Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo@linux.vnet.ibm.com> --- src/kimchi/model/debugreports.py | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/src/kimchi/model/debugreports.py b/src/kimchi/model/debugreports.py index a1cb19c..0db9f85 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,36 +64,29 @@ 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('Command terminated with signal') elif retcode > 0: raise OperationFailed('Command failed: rc = %i' % retcode) - pattern = '/tmp/sosreport-%s-*' % name - for reportFile in glob.glob(pattern): - if not fnmatch.fnmatch(reportFile, '*.md5'): - output = reportFile - 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('Can not find generated debug report ' - 'named by %s' % pattern) - ext = output.split('.', 1)[1] + + # SOSREPORT outputs the name of the file in the text block + # The right way should be passing the tar.xz file directory though + # the parameter '--tmp-dir', but this is failing in Fedora 20 + rep_f = [line for line in output.split() + if line.endswith('tar.xz')][0] + rep_name = os.path.basename(rep_f) 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) - cb('OK', True) + target = os.path.join(path, rep_name) + msg = 'Moving debug report file "%s" to "%s"' % (rep_f, target) + kimchi_log.info(msg) + shutil.move(rep_f, target) + os.remove('%s.md5' % rep_f) + cb('OK', True) return except OSError: -- 1.8.5.3

On Wed, 2014-02-05 at 15:21 -0200, Rodrigo Trujillo wrote:
The tool sosreport does not save the report file in /tmp in F20, which causes a error in Kimchi, which has /tmp hardcoded. This patch fetches the report file location from the output. 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.
Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo@linux.vnet.ibm.com> --- src/kimchi/model/debugreports.py | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-)
diff --git a/src/kimchi/model/debugreports.py b/src/kimchi/model/debugreports.py index a1cb19c..0db9f85 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,36 +64,29 @@ 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('Command terminated with signal') elif retcode > 0: raise OperationFailed('Command failed: rc = %i' % retcode) - pattern = '/tmp/sosreport-%s-*' % name - for reportFile in glob.glob(pattern): - if not fnmatch.fnmatch(reportFile, '*.md5'): - output = reportFile - 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('Can not find generated debug report ' - 'named by %s' % pattern) - ext = output.split('.', 1)[1] + + # SOSREPORT outputs the name of the file in the text block + # The right way should be passing the tar.xz file directory though + # the parameter '--tmp-dir', but this is failing in Fedora 20 + rep_f = [line for line in output.split() + if line.endswith('tar.xz')][0] + rep_name = os.path.basename(rep_f) 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) - cb('OK', True) + target = os.path.join(path, rep_name)
+ msg = 'Moving debug report file "%s" to "%s"' % (rep_f, target) + kimchi_log.info(msg) + shutil.move(rep_f, target) + os.remove('%s.md5' % rep_f) Can we log the md5 before we remove it? I've rarely had to use this, but did once. + cb('OK', True) return
except OSError:

On 02/05/2014 05:14 PM, Christy Perez wrote:
On Wed, 2014-02-05 at 15:21 -0200, Rodrigo Trujillo wrote:
The tool sosreport does not save the report file in /tmp in F20, which causes a error in Kimchi, which has /tmp hardcoded. This patch fetches the report file location from the output. 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.
Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo@linux.vnet.ibm.com> --- src/kimchi/model/debugreports.py | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-)
diff --git a/src/kimchi/model/debugreports.py b/src/kimchi/model/debugreports.py index a1cb19c..0db9f85 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,36 +64,29 @@ 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('Command terminated with signal') elif retcode > 0: raise OperationFailed('Command failed: rc = %i' % retcode) - pattern = '/tmp/sosreport-%s-*' % name - for reportFile in glob.glob(pattern): - if not fnmatch.fnmatch(reportFile, '*.md5'): - output = reportFile - 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('Can not find generated debug report ' - 'named by %s' % pattern) - ext = output.split('.', 1)[1] + + # SOSREPORT outputs the name of the file in the text block + # The right way should be passing the tar.xz file directory though + # the parameter '--tmp-dir', but this is failing in Fedora 20 + rep_f = [line for line in output.split() + if line.endswith('tar.xz')][0] + rep_name = os.path.basename(rep_f) 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) - cb('OK', True) + target = os.path.join(path, rep_name)
+ msg = 'Moving debug report file "%s" to "%s"' % (rep_f, target) + kimchi_log.info(msg) + shutil.move(rep_f, target) + os.remove('%s.md5' % rep_f) Can we log the md5 before we remove it? I've rarely had to use this, but did once.
Done in V2. Thanks
+ cb('OK', True) return
except OSError:
_______________________________________________ Kimchi-devel mailing list Kimchi-devel@ovirt.org http://lists.ovirt.org/mailman/listinfo/kimchi-devel

On 02/05/2014 03:21 PM, Rodrigo Trujillo wrote:
The tool sosreport does not save the report file in /tmp in F20, which causes a error in Kimchi, which has /tmp hardcoded. This patch fetches the report file location from the output. 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.
I don't like the idea to parse the output to know where the file was saved. Isn't there a config file or other way to get the directory used by sosreport?
Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo@linux.vnet.ibm.com> --- src/kimchi/model/debugreports.py | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-)
diff --git a/src/kimchi/model/debugreports.py b/src/kimchi/model/debugreports.py index a1cb19c..0db9f85 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,36 +64,29 @@ 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('Command terminated with signal') elif retcode > 0: raise OperationFailed('Command failed: rc = %i' % retcode) - pattern = '/tmp/sosreport-%s-*' % name - for reportFile in glob.glob(pattern): - if not fnmatch.fnmatch(reportFile, '*.md5'): - output = reportFile - 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('Can not find generated debug report ' - 'named by %s' % pattern) - ext = output.split('.', 1)[1] + + # SOSREPORT outputs the name of the file in the text block + # The right way should be passing the tar.xz file directory though + # the parameter '--tmp-dir', but this is failing in Fedora 20 + rep_f = [line for line in output.split() + if line.endswith('tar.xz')][0] + rep_name = os.path.basename(rep_f) 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) - cb('OK', True) + target = os.path.join(path, rep_name)
+ msg = 'Moving debug report file "%s" to "%s"' % (rep_f, target) + kimchi_log.info(msg) + shutil.move(rep_f, target) + os.remove('%s.md5' % rep_f) + cb('OK', True) return
except OSError:

On 02/05/2014 05:40 PM, Aline Manera wrote:
On 02/05/2014 03:21 PM, Rodrigo Trujillo wrote:
The tool sosreport does not save the report file in /tmp in F20, which causes a error in Kimchi, which has /tmp hardcoded. This patch fetches the report file location from the output. 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.
I don't like the idea to parse the output to know where the file was saved. Isn't there a config file or other way to get the directory used by sosreport? No, according to my tests. I am sending V2 with a new approach. Let me know what you think. Thanks
Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo@linux.vnet.ibm.com> --- src/kimchi/model/debugreports.py | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-)
diff --git a/src/kimchi/model/debugreports.py b/src/kimchi/model/debugreports.py index a1cb19c..0db9f85 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,36 +64,29 @@ 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('Command terminated with signal') elif retcode > 0: raise OperationFailed('Command failed: rc = %i' % retcode) - pattern = '/tmp/sosreport-%s-*' % name - for reportFile in glob.glob(pattern): - if not fnmatch.fnmatch(reportFile, '*.md5'): - output = reportFile - 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('Can not find generated debug report ' - 'named by %s' % pattern) - ext = output.split('.', 1)[1] + + # SOSREPORT outputs the name of the file in the text block + # The right way should be passing the tar.xz file directory though + # the parameter '--tmp-dir', but this is failing in Fedora 20 + rep_f = [line for line in output.split() + if line.endswith('tar.xz')][0] + rep_name = os.path.basename(rep_f) 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) - cb('OK', True) + target = os.path.join(path, rep_name)
+ msg = 'Moving debug report file "%s" to "%s"' % (rep_f, target) + kimchi_log.info(msg) + shutil.move(rep_f, target) + os.remove('%s.md5' % rep_f) + cb('OK', True) return
except OSError:
_______________________________________________ Kimchi-devel mailing list Kimchi-devel@ovirt.org http://lists.ovirt.org/mailman/listinfo/kimchi-devel
participants (3)
-
Aline Manera
-
Christy Perez
-
Rodrigo Trujillo