Exemplo n.º 1
0
    def sosreport_generate(cb, name):
        try:
            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})

            # 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:
                kimchi_log.error('Debug report file not found. See sosreport '
                                 'output for detail:\n%s', output)
                fname = (patterns[0] % name).split('/')[-1]
                raise OperationFailed('KCHDR0004E', {'name': fname})

            md5_report_file = reportFile + '.md5'
            report_file_extension = '.' + reportFile.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)
            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:
            raise

        except Exception, e:
            # No need to call cb to update the task status here.
            # The task object will catch the exception rasied here
            # and update the task status there
            log = logging.getLogger('Model')
            log.warning('Exception in generating debug file: %s', e)
            raise OperationFailed("KCHDR0005E", {'name': name, 'err': e})
Exemplo n.º 2
0
    def get_list(self):
        path = config.get_debugreports_path()
        file_pattern = os.path.join(path, '*.*')
        file_lists = glob.glob(file_pattern)
        file_lists = [os.path.split(file)[1] for file in file_lists]
        name_lists = [file.split('.', 1)[0] for file in file_lists]

        return name_lists
Exemplo n.º 3
0
    def get_list(self):
        path = config.get_debugreports_path()
        file_pattern = os.path.join(path, '*.*')
        file_lists = glob.glob(file_pattern)
        file_lists = [os.path.split(file)[1] for file in file_lists]
        name_lists = [file.split('.', 1)[0] for file in file_lists]

        return name_lists
Exemplo n.º 4
0
    def debugreport_delete(self, name):
        path = config.get_debugreports_path()
        file_pattern = os.path.join(path, name + '.txt')
        try:
            file_target = glob.glob(file_pattern)[0]
        except IndexError:
            raise NotFoundError('no such report')

        os.remove(file_target)
Exemplo n.º 5
0
    def delete(self, name):
        path = config.get_debugreports_path()
        file_pattern = os.path.join(path, name + '.*')
        try:
            file_target = glob.glob(file_pattern)[0]
        except IndexError:
            raise NotFoundError("KCHDR0001E", {'name': name})

        os.remove(file_target)
Exemplo n.º 6
0
    def delete(self, name):
        path = config.get_debugreports_path()
        file_pattern = os.path.join(path, name + '.*')
        try:
            file_target = glob.glob(file_pattern)[0]
        except IndexError:
            raise NotFoundError("KCHDR0001E", {'name': name})

        os.remove(file_target)
Exemplo n.º 7
0
 def _create_log(self, cb, name):
     path = config.get_debugreports_path()
     tmpf = os.path.join(path, name + '.tmp')
     realf = os.path.join(path, name + '.txt')
     length = random.randint(1000, 10000)
     with open(tmpf, 'w') as fd:
         while length:
             fd.write('I am logged')
             length = length - 1
     os.rename(tmpf, realf)
     cb("OK", True)
Exemplo n.º 8
0
 def _create_log(self, cb, name):
     path = config.get_debugreports_path()
     tmpf = os.path.join(path, name + '.tmp')
     realf = os.path.join(path, name + '.txt')
     length = random.randint(1000, 10000)
     with open(tmpf, 'w') as fd:
         while length:
             fd.write('I am logged')
             length = length - 1
     os.rename(tmpf, realf)
     cb("OK", True)
Exemplo n.º 9
0
    def debugreport_lookup(self, name):
        path = config.get_debugreports_path()
        file_pattern = os.path.join(path, name + '.txt')
        try:
            file_target = glob.glob(file_pattern)[0]
        except IndexError:
            raise NotFoundError("KCHDR0001E", {'name': name})

        ctime = os.stat(file_target).st_ctime
        ctime = time.strftime("%Y-%m-%d-%H:%M:%S", time.localtime(ctime))
        file_target = os.path.split(file_target)[-1]
        file_target = os.path.join("/data/debugreports", file_target)
        return {'uri': file_target, 'ctime': ctime}
Exemplo n.º 10
0
    def debugreport_lookup(self, name):
        path = config.get_debugreports_path()
        file_pattern = os.path.join(path, name + '.txt')
        try:
            file_target = glob.glob(file_pattern)[0]
        except IndexError:
            raise NotFoundError("KCHDR0001E", {'name': name})

        ctime = os.stat(file_target).st_ctime
        ctime = time.strftime("%Y-%m-%d-%H:%M:%S", time.localtime(ctime))
        file_target = os.path.split(file_target)[-1]
        file_target = os.path.join("/data/debugreports", file_target)
        return {'uri': file_target,
                'ctime': ctime}
Exemplo n.º 11
0
    def update(self, name, params):
        path = config.get_debugreports_path()
        file_pattern = os.path.join(path, name + '.*')
        try:
            file_source = glob.glob(file_pattern)[0]
        except IndexError:
            raise NotFoundError("KCHDR0001E", {'name': name})

        file_target = file_source.replace(name, params['name'])
        if os.path.isfile(file_target):
            raise InvalidParameter('KCHDR0008E', {'name': params['name']})

        shutil.move(file_source, file_target)
        kimchi_log.info('%s renamed to %s' % (file_source, file_target))
        return params['name']
Exemplo n.º 12
0
    def update(self, name, params):
        path = config.get_debugreports_path()
        file_pattern = os.path.join(path, name + '.*')
        try:
            file_source = glob.glob(file_pattern)[0]
        except IndexError:
            raise NotFoundError("KCHDR0001E", {'name': name})

        file_target = file_source.replace(name, params['name'])
        if os.path.isfile(file_target):
            raise InvalidParameter('KCHDR0008E', {'name': params['name']})

        shutil.move(file_source, file_target)
        kimchi_log.info('%s renamed to %s' % (file_source, file_target))
        return params['name']
Exemplo n.º 13
0
    def lookup(self, name):
        path = config.get_debugreports_path()
        file_pattern = os.path.join(path, name)
        file_pattern = file_pattern + '.*'
        try:
            file_target = glob.glob(file_pattern)[0]
        except IndexError:
            raise NotFoundError('no such report')

        ctime = os.stat(file_target).st_ctime
        ctime = time.strftime("%Y-%m-%d-%H:%M:%S", time.localtime(ctime))
        file_target = os.path.split(file_target)[-1]
        file_target = os.path.join("/data/debugreports", file_target)
        return {'file': file_target,
                'ctime': ctime}
Exemplo n.º 14
0
    def sosreport_generate(cb, name):
        command = 'sosreport --batch --name "%s"' % name
        try:
            retcode = subprocess.call(command, shell=True,
                                      stdout=subprocess.PIPE)
            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
                    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]
            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)

            return

        except OSError:
            raise

        except Exception, e:
            # No need to call cb to update the task status here.
            # The task object will catch the exception rasied here
            # and update the task status there
            log = logging.getLogger('Model')
            log.warning('Exception in generating debug file: %s', e)
            raise OperationFailed("KCHDR0005E", {'name': name, 'err': e})
Exemplo n.º 15
0
    def __init__(self, options):
        # Launch reverse proxy
        start_proxy(options)

        make_dirs = [
            os.path.dirname(os.path.abspath(options.access_log)),
            os.path.dirname(os.path.abspath(options.error_log)),
            os.path.dirname(os.path.abspath(config.get_object_store())),
            os.path.abspath(config.get_screenshot_path()),
            os.path.abspath(config.get_debugreports_path()),
            os.path.abspath(config.get_distros_store())
        ]
        for directory in make_dirs:
            if not os.path.isdir(directory):
                os.makedirs(directory)

        self.configObj = KimchiConfig()
        cherrypy.tools.nocache = cherrypy.Tool('on_end_resource', set_no_cache)
        cherrypy.tools.kimchiauth = cherrypy.Tool('before_handler',
                                                  auth.kimchiauth)
        # Setting host to 127.0.0.1. This makes kimchi runs
        # as a localhost app, inaccessible to the outside
        # directly. You must go through the proxy.
        cherrypy.server.socket_host = '127.0.0.1'
        cherrypy.server.socket_port = options.cherrypy_port
        cherrypy.config.nginx_port = options.port

        cherrypy.log.screen = True
        cherrypy.log.access_file = options.access_log
        cherrypy.log.error_file = options.error_log

        logLevel = LOGGING_LEVEL.get(options.log_level, logging.DEBUG)
        dev_env = options.environment != 'production'

        # Create handler to rotate access log file
        h = logging.handlers.RotatingFileHandler(options.access_log, 'a',
                                                 10000000, 1000)
        h.setLevel(logLevel)
        h.setFormatter(cherrypy._cplogging.logfmt)

        # Add access log file to cherrypy configuration
        cherrypy.log.access_log.addHandler(h)

        # Create handler to rotate error log file
        h = logging.handlers.RotatingFileHandler(options.error_log, 'a',
                                                 10000000, 1000)
        h.setLevel(logLevel)
        h.setFormatter(cherrypy._cplogging.logfmt)

        # Add rotating log file to cherrypy configuration
        cherrypy.log.error_log.addHandler(h)

        # Handling running mode
        if not dev_env:
            cherrypy.config.update({'environment': 'production'})

        if hasattr(options, 'model'):
            model_instance = options.model
        elif options.test:
            model_instance = mockmodel.get_mock_environment()
        else:
            model_instance = model.Model()

        if isinstance(model_instance, model.Model):
            vnc_ws_proxy = vnc.new_ws_proxy()
            cherrypy.engine.subscribe('exit', vnc_ws_proxy.kill)

        for ident, node in sub_nodes.items():
            if node.url_auth:
                cfg = self.configObj
                ident = "/%s" % ident
                cfg[ident] = {'tools.kimchiauth.on': True}
                if node.admin_methods:
                    cfg[ident][
                        'tools.kimchiauth.admin_methods'] = node.admin_methods

        self.app = cherrypy.tree.mount(KimchiRoot(model_instance, dev_env),
                                       config=self.configObj)
        self._load_plugins()

        # Terminate proxy when cherrypy server is terminated
        cherrypy.engine.subscribe('exit', terminate_proxy)

        cherrypy.lib.sessions.init()
Exemplo n.º 16
0
    def sosreport_generate(cb, name):
        try:
            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
                })

            # 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:
                kimchi_log.error(
                    'Debug report file not found. See sosreport '
                    'output for detail:\n%s', output)
                fname = (patterns[0] % name).split('/')[-1]
                raise OperationFailed('KCHDR0004E', {'name': fname})

            md5_report_file = reportFile + '.md5'
            report_file_extension = '.' + reportFile.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)
            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:
            raise

        except Exception, e:
            # No need to call cb to update the task status here.
            # The task object will catch the exception rasied here
            # and update the task status there
            log = logging.getLogger('Model')
            log.warning('Exception in generating debug file: %s', e)
            raise OperationFailed("KCHDR0005E", {'name': name, 'err': e})
Exemplo n.º 17
0
    def __init__(self, options):
        # Launch reverse proxy
        start_proxy(options)

        make_dirs = [
            os.path.dirname(os.path.abspath(options.access_log)),
            os.path.dirname(os.path.abspath(options.error_log)),
            os.path.dirname(os.path.abspath(config.get_object_store())),
            os.path.abspath(config.get_screenshot_path()),
            os.path.abspath(config.get_debugreports_path()),
            os.path.abspath(config.get_distros_store())
        ]
        for directory in make_dirs:
            if not os.path.isdir(directory):
                os.makedirs(directory)

        self.configObj = KimchiConfig()
        cherrypy.tools.nocache = cherrypy.Tool('on_end_resource', set_no_cache)
        cherrypy.tools.kimchiauth = cherrypy.Tool('before_handler',
                                                  auth.kimchiauth)
        # Setting host to 127.0.0.1. This makes kimchi runs
        # as a localhost app, inaccessible to the outside
        # directly. You must go through the proxy.
        cherrypy.server.socket_host = '127.0.0.1'
        cherrypy.server.socket_port = options.cherrypy_port
        cherrypy.config.nginx_port = options.port

        cherrypy.log.screen = True
        cherrypy.log.access_file = options.access_log
        cherrypy.log.error_file = options.error_log

        logLevel = LOGGING_LEVEL.get(options.log_level, logging.DEBUG)
        dev_env = options.environment != 'production'

        # Create handler to rotate access log file
        h = logging.handlers.RotatingFileHandler(options.access_log, 'a',
                                                 10000000, 1000)
        h.setLevel(logLevel)
        h.setFormatter(cherrypy._cplogging.logfmt)

        # Add access log file to cherrypy configuration
        cherrypy.log.access_log.addHandler(h)

        # Create handler to rotate error log file
        h = logging.handlers.RotatingFileHandler(options.error_log, 'a',
                                                 10000000, 1000)
        h.setLevel(logLevel)
        h.setFormatter(cherrypy._cplogging.logfmt)

        # Add rotating log file to cherrypy configuration
        cherrypy.log.error_log.addHandler(h)

        # Handling running mode
        if not dev_env:
            cherrypy.config.update({'environment': 'production'})

        if hasattr(options, 'model'):
            model_instance = options.model
        elif options.test:
            model_instance = mockmodel.get_mock_environment()
        else:
            model_instance = model.Model()

        if isinstance(model_instance, model.Model):
            vnc_ws_proxy = vnc.new_ws_proxy()
            cherrypy.engine.subscribe('exit', vnc_ws_proxy.kill)

        for ident, node in sub_nodes.items():
            if node.url_auth:
                cfg = self.configObj
                ident = "/%s" % ident
                cfg[ident] = {'tools.kimchiauth.on': True}
                if node.admin_methods:
                    cfg[ident][
                        'tools.kimchiauth.admin_methods'] = node.admin_methods

        self.app = cherrypy.tree.mount(KimchiRoot(model_instance, dev_env),
                                       config=self.configObj)
        self._load_plugins()

        # Terminate proxy when cherrypy server is terminated
        cherrypy.engine.subscribe('exit', terminate_proxy)

        cherrypy.lib.sessions.init()
Exemplo n.º 18
0
    def __init__(self, options):
        make_dirs = [
            os.path.dirname(os.path.abspath(options.access_log)),
            os.path.dirname(os.path.abspath(options.error_log)),
            os.path.dirname(os.path.abspath(config.get_object_store())),
            os.path.abspath(config.get_screenshot_path()),
            os.path.abspath(config.get_session_path()),
            os.path.abspath(config.get_debugreports_path()),
            os.path.abspath(config.get_distros_store())
        ]
        for directory in make_dirs:
            if not os.path.isdir(directory):
                os.makedirs(directory)

        cherrypy.tools.nocache = cherrypy.Tool('on_end_resource', set_no_cache)
        cherrypy.tools.kimchiauth = cherrypy.Tool('before_handler',
                                                  auth.kimchiauth)
        cherrypy.server.socket_host = options.host
        cherrypy.server.socket_port = options.port

        # SSL Server
        try:
            if options.ssl_port and options.ssl_port > 0:
                self._init_ssl(options)
        except AttributeError:
            pass

        cherrypy.log.screen = True
        cherrypy.log.access_file = options.access_log
        cherrypy.log.error_file = options.error_log

        logLevel = LOGGING_LEVEL.get(options.log_level, logging.DEBUG)
        dev_env = options.environment != 'production'

        # Create handler to rotate access log file
        h = logging.handlers.RotatingFileHandler(options.access_log, 'a',
                                                 10000000, 1000)
        h.setLevel(logLevel)
        h.setFormatter(cherrypy._cplogging.logfmt)

        # Add access log file to cherrypy configuration
        cherrypy.log.access_log.addHandler(h)

        # Create handler to rotate error log file
        h = logging.handlers.RotatingFileHandler(options.error_log, 'a',
                                                 10000000, 1000)
        h.setLevel(logLevel)
        h.setFormatter(cherrypy._cplogging.logfmt)

        # Add rotating log file to cherrypy configuration
        cherrypy.log.error_log.addHandler(h)

        # Handling running mode
        if not dev_env:
            cherrypy.config.update({'environment': 'production'})

        if hasattr(options, 'model'):
            model_instance = options.model
        elif options.test:
            model_instance = mockmodel.get_mock_environment()
        else:
            model_instance = model.Model()

        if isinstance(model_instance, model.Model):
            vnc_ws_proxy = vnc.new_ws_proxy()
            cherrypy.engine.subscribe('exit', vnc_ws_proxy.kill)

        for ident, node in sub_nodes.items():
            if node.url_auth:
                self.configObj["/%s" % ident] = {'tools.kimchiauth.on': True}

        self.app = cherrypy.tree.mount(KimchiRoot(model_instance, dev_env),
                                       config=self.configObj)
        self._load_plugins()

        cherrypy.lib.sessions.init()