[PATCH V2] #748 Sosreport generation.

From: Megha Smriti <mesmriti@linux.vnet.ibm.com> The reveiw comments have been taken care of and changes were made to keep a separate sosreport method and the path where the sosreport will be generated will be specified in the sosreport command. Ex: path_sosreport = '/var/tmp/' command = ['sosreport', '--batch', '--name=%s' % name, '--tmp-dir=%s' % path_sosreport] Megha Smriti (1): model/debugreports.py Rodrigo Trujillo (1): Allow listStorageVolumes ajax call be synchronized src/wok/plugins/gingerbase/model/debugreports.py | 103 ++++++++++++--------- src/wok/plugins/kimchi/ui/js/src/kimchi.api.js | 7 +- .../ui/js/src/kimchi.guest_storage_add.main.js | 2 +- .../kimchi/ui/js/src/kimchi.storage_main.js | 2 +- 4 files changed, 67 insertions(+), 47 deletions(-) -- 2.4.3

From: Rodrigo Trujillo <rodrigo.trujillo@linux.vnet.ibm.com> This patch changes kimchi.listStorageVolumes function to receive a new parameter 'sync' in order to set it as synchronous call. Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo@linux.vnet.ibm.com> --- src/wok/plugins/kimchi/ui/js/src/kimchi.api.js | 7 ++++--- src/wok/plugins/kimchi/ui/js/src/kimchi.guest_storage_add.main.js | 2 +- src/wok/plugins/kimchi/ui/js/src/kimchi.storage_main.js | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/wok/plugins/kimchi/ui/js/src/kimchi.api.js b/src/wok/plugins/kimchi/ui/js/src/kimchi.api.js index d01bed4..ff0c172 100644 --- a/src/wok/plugins/kimchi/ui/js/src/kimchi.api.js +++ b/src/wok/plugins/kimchi/ui/js/src/kimchi.api.js @@ -393,12 +393,13 @@ var kimchi = { }); }, - listStorageVolumes : function(poolName, suc, err) { + listStorageVolumes : function(poolName, suc, err, sync) { $.ajax({ url : 'plugins/kimchi/storagepools/' + encodeURIComponent(poolName) + '/storagevolumes', type : 'GET', contentType : 'application/json', dataType : 'json', + async : !sync, success : suc, error : err }); @@ -452,7 +453,7 @@ var kimchi = { return; } suc(isos, true); - }, err); + }, err, false); } else if (status === "running") { if (deepScanHandler.stop) { return; @@ -463,7 +464,7 @@ var kimchi = { } suc(isos, false); setTimeout(monitorTask, 2000); - }, err); + }, err, false); } else if (status === "failed") { if (deepScanHandler.stop) { return; diff --git a/src/wok/plugins/kimchi/ui/js/src/kimchi.guest_storage_add.main.js b/src/wok/plugins/kimchi/ui/js/src/kimchi.guest_storage_add.main.js index ec07cf0..d6606ee 100644 --- a/src/wok/plugins/kimchi/ui/js/src/kimchi.guest_storage_add.main.js +++ b/src/wok/plugins/kimchi/ui/js/src/kimchi.guest_storage_add.main.js @@ -94,7 +94,7 @@ kimchi.guest_storage_add_main = function() { } } $('#guest-disk').selectMenu("setData", options); - }); + }, null, false); }); diff --git a/src/wok/plugins/kimchi/ui/js/src/kimchi.storage_main.js b/src/wok/plugins/kimchi/ui/js/src/kimchi.storage_main.js index 567aba3..8ed896c 100644 --- a/src/wok/plugins/kimchi/ui/js/src/kimchi.storage_main.js +++ b/src/wok/plugins/kimchi/ui/js/src/kimchi.storage_main.js @@ -313,7 +313,7 @@ kimchi.doListVolumes = function(poolObj) { slide.slideDown('slow'); }, function(err) { wok.message.error(err.responseJSON.reason); - }); + }, false); } kimchi.initLogicalPoolExtend = function() { -- 2.4.3

From: Megha Smriti <mesmriti@linux.vnet.ibm.com> --- src/wok/plugins/gingerbase/model/debugreports.py | 103 ++++++++++++++--------- 1 file changed, 61 insertions(+), 42 deletions(-) diff --git a/src/wok/plugins/gingerbase/model/debugreports.py b/src/wok/plugins/gingerbase/model/debugreports.py index 94ab7fe..9c325ef 100644 --- a/src/wok/plugins/gingerbase/model/debugreports.py +++ b/src/wok/plugins/gingerbase/model/debugreports.py @@ -19,13 +19,13 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -import fnmatch import glob import logging import os import shutil import subprocess import time +import re from wok.exception import InvalidParameter, NotFoundError, OperationFailed from wok.exception import WokException @@ -75,50 +75,19 @@ class DebugReportsModel(object): def log_error(e): log = logging.getLogger('Model') log.warning('Exception in generating debug file: %s', e) - try: - command = ['sosreport', '--batch', '--name=%s' % name] - output, error, retcode = run_command(command) - - if retcode != 0: - raise OperationFailed("GGBDR0003E", {'name': name, - 'err': retcode}) - - # 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 - # Some error in sosreport happened - if reportFile is None: - wok_log.error('Debug report file not found. See sosreport ' - 'output for detail:\n%s', output) - fname = (patterns[0] % name).split('/')[-1] - raise OperationFailed('GGBDR0004E', {'name': fname}) - - md5_report_file = reportFile + '.md5' - report_file_extension = '.' + reportFile.split('.', 1)[1] + # Sosreport collection + sosreport_file = sosreport_collection(name) + md5_report_file = sosreport_file + '.md5' + report_file_extension = '.' + sosreport_file.split('.', 1)[1] path = config.get_debugreports_path() - target = os.path.join(path, name + report_file_extension) - # Moving report - msg = 'Moving debug report file "%s" to "%s"' % (reportFile, - target) - wok_log.info(msg) - shutil.move(reportFile, target) - # Deleting md5 - msg = 'Deleting report md5 file: "%s"' % (md5_report_file) + sosreport_target = os.path.join(path, + name + report_file_extension) + msg = 'Moving debug report file "%s" to "%s"' \ + % (sosreport_file, sosreport_target) wok_log.info(msg) - with open(md5_report_file) as f: - md5 = f.read().strip() - wok_log.info('Md5 file content: "%s"', md5) - os.remove(md5_report_file) + shutil.move(sosreport_file, sosreport_target) + delete_the_sosreport_md5_file(md5_report_file) cb('OK', True) return @@ -213,3 +182,53 @@ class DebugReportContentModel(object): def lookup(self, name): return self._debugreport.lookup(name) + + +def delete_the_sosreport_md5_file(md5_file): + """ + Deleting md5 file and displaying the contents of the same. + """ + msg = 'Deleting report md5 file: "%s"' % md5_file + wok_log.info(msg) + with open(md5_file) as f: + md5 = f.read().strip() + wok_log.info('Md5 file content: "%s"', md5) + os.remove(md5_file) + + +def sosreport_collection(name): + """ + Code for the collection of sosreport n the path + /var/tmp as specified in the command. + """ + path_sosreport = '/var/tmp/' + command = ['sosreport', '--batch', '--name=%s' % name, + '--tmp-dir=%s' % path_sosreport] + output, error, retcode = run_command(command) + if retcode != 0: + raise OperationFailed("GGBDR0003E", {'name': name, + 'err': retcode}) + + # 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 + sosreport_name = name.replace('_', '') + sosreport_name_regex = '(\s+)(' + path_sosreport + \ + ')(sosreport-' +\ + sosreport_name + '-\d+.tar.xz)' + sosreport_file = None + output = output.splitlines() + for line in output: + if line: + matched_name = re.match(sosreport_name_regex, line) + if matched_name: + path = matched_name.groups()[1] + fname = matched_name.groups()[2] + sosreport_file = path + fname + break + # Some error in sosreport happened + if sosreport_file is None: + wok_log.error('Debug report file not found. See sosreport ' + 'output for detail:\n%s', output) + raise OperationFailed('GGBDR0004E', {'name': name}) + return sosreport_file -- 2.4.3

On 17/11/2015 11:54, mesmriti@linux.vnet.ibm.com wrote:
From: Megha Smriti <mesmriti@linux.vnet.ibm.com>
Please, add an appropriated commit message explaining what this patch is for.
--- src/wok/plugins/gingerbase/model/debugreports.py | 103 ++++++++++++++--------- 1 file changed, 61 insertions(+), 42 deletions(-)
diff --git a/src/wok/plugins/gingerbase/model/debugreports.py b/src/wok/plugins/gingerbase/model/debugreports.py index 94ab7fe..9c325ef 100644 --- a/src/wok/plugins/gingerbase/model/debugreports.py +++ b/src/wok/plugins/gingerbase/model/debugreports.py @@ -19,13 +19,13 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-import fnmatch import glob import logging import os import shutil import subprocess import time +import re
from wok.exception import InvalidParameter, NotFoundError, OperationFailed from wok.exception import WokException @@ -75,50 +75,19 @@ class DebugReportsModel(object): def log_error(e): log = logging.getLogger('Model') log.warning('Exception in generating debug file: %s', e) - try: - command = ['sosreport', '--batch', '--name=%s' % name] - output, error, retcode = run_command(command) - - if retcode != 0: - raise OperationFailed("GGBDR0003E", {'name': name, - 'err': retcode}) - - # 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 - # Some error in sosreport happened - if reportFile is None: - wok_log.error('Debug report file not found. See sosreport ' - 'output for detail:\n%s', output) - fname = (patterns[0] % name).split('/')[-1] - raise OperationFailed('GGBDR0004E', {'name': fname}) - - md5_report_file = reportFile + '.md5' - report_file_extension = '.' + reportFile.split('.', 1)[1] + # Sosreport collection + sosreport_file = sosreport_collection(name) + md5_report_file = sosreport_file + '.md5'
+ report_file_extension = '.' + sosreport_file.split('.', 1)[1] path = config.get_debugreports_path() - target = os.path.join(path, name + report_file_extension) - # Moving report - msg = 'Moving debug report file "%s" to "%s"' % (reportFile, - target) - wok_log.info(msg) - shutil.move(reportFile, target) - # Deleting md5 - msg = 'Deleting report md5 file: "%s"' % (md5_report_file) + sosreport_target = os.path.join(path, + name + report_file_extension) + msg = 'Moving debug report file "%s" to "%s"' \ + % (sosreport_file, sosreport_target)
Why do you need to move the file if you use the --tmp-dir to collect and save the sosreport in the right location?
wok_log.info(msg) - with open(md5_report_file) as f: - md5 = f.read().strip() - wok_log.info('Md5 file content: "%s"', md5) - os.remove(md5_report_file)
+ shutil.move(sosreport_file, sosreport_target)
This is not needed anymore, right? As we are using the --tmp-dir from now on.
+ delete_the_sosreport_md5_file(md5_report_file) cb('OK', True) return
@@ -213,3 +182,53 @@ class DebugReportContentModel(object):
def lookup(self, name): return self._debugreport.lookup(name) + + +def delete_the_sosreport_md5_file(md5_file): + """ + Deleting md5 file and displaying the contents of the same. + """ + msg = 'Deleting report md5 file: "%s"' % md5_file + wok_log.info(msg) + with open(md5_file) as f: + md5 = f.read().strip() + wok_log.info('Md5 file content: "%s"', md5) + os.remove(md5_file) + + +def sosreport_collection(name):
+ """ + Code for the collection of sosreport n the path + /var/tmp as specified in the command. + """
This comment is not up to date
+ path_sosreport = '/var/tmp/' + command = ['sosreport', '--batch', '--name=%s' % name, + '--tmp-dir=%s' % path_sosreport] + output, error, retcode = run_command(command) + if retcode != 0: + raise OperationFailed("GGBDR0003E", {'name': name, + 'err': retcode}) +
+ # 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
You can remove this comment.
+ sosreport_name = name.replace('_', '')
Do not change the user input without letting the user know about it. As I said before, we should not allow user to enter underscore in the debug report name.
+ sosreport_name_regex = '(\s+)(' + path_sosreport + \ + ')(sosreport-' +\ + sosreport_name + '-\d+.tar.xz)' + sosreport_file = None + output = output.splitlines() + for line in output: + if line: + matched_name = re.match(sosreport_name_regex, line) + if matched_name: + path = matched_name.groups()[1] + fname = matched_name.groups()[2] + sosreport_file = path + fname + break
You don't need that code anymore while using --tmp-dir The file will be <tmp-dir>/sosreport-<name>.tar.gz
+ # Some error in sosreport happened + if sosreport_file is None: + wok_log.error('Debug report file not found. See sosreport ' + 'output for detail:\n%s', output) + raise OperationFailed('GGBDR0004E', {'name': name}) + return sosreport_file
participants (2)
-
Aline Manera
-
mesmriti@linux.vnet.ibm.com