Ejemplo n.º 1
0
    def __iter__(self):
        if self.auth is None:
            self.auth = JbacAuthentication.get()

        def failures_generator():
            url = self.__build_url()

            self.logger.info('Querying JBAC: ' + url)
            text = self.urlutils.read(url, self.auth.login, self.auth.password)
            self.logger.info('Got a reply.')

            try:
                root = self.xml.parse_string(text)
                for error in root.findall('.//failedTests/testResult'):
                    class_name = error.attrib['className']
                    method_name = error.attrib['methodName']
                    plan_name = self.__extract_plan_name(
                        error.find('.//message').text)
                    if plan_name:
                        yield (plan_name, class_name + '.' + method_name)
            except ParseError:
                self.logger.error('Could not parse JBAC reply.')
                self.logger.debug('\n' + text)

        return failures_generator()
Ejemplo n.º 2
0
    def get_build_name(self, logger, args, branchDiscovery, urlutils=UrlUtils(), xml=XmlUtils()):
        if branchDiscovery.branch == 'master':
            return self.__fulljobname(args.type)
        else:
            # translate the branch into bamboo branch name:
            bamboo_branch_name = branchDiscovery.branch.replace('/', '-')
            logger.info('Trying to find bamboo branch "%s"...' % bamboo_branch_name)

            auth = JbacAuthentication.get()
            url = '%s/rest/api/latest/plan/%s?expand=branches&max-results=10000' % (Jbac.url, CIInvestigate.planname[args.type])
            logger.info('Querying JBAC: ' + url)
            text = self.urlutils.read(url, auth.login, auth.password)

            try:
                root = self.xml.parse_string(text)
                for branchElement in root.findall('.//branches/branch'):
                    branch_key = branchElement.attrib['key']
                    branch_name = branchElement.attrib['shortName']
                    if branch_name == bamboo_branch_name:
                        logger.debug('Bamboo branch plan key is: "%s".' % branch_key)
                        return '-'.join([branch_key, CIInvestigate.jobname[args.type]])
            except ParseError:
                logger.debug('\n' + text)
                logger.error('Could not parse JBAC reply.')

            logger.warn('Could not find the Bamboo branch for branch: "%s". Will inspect master instead.' % bamboo_branch_name)
            return self.__fulljobname(args.type)
Ejemplo n.º 3
0
    def get_hits_for_build(self, log: Logger, target_dir: str,
                           build_number: str):
        job, bn = self.bamboo_utils.decode_build_number(build_number)
        url = '%s/browse/%s/artifact/%s/eh-metrics-hits.tgz/eh-metrics-hits.tgz' % (
            Jbac.url, bn, job)
        local_file = os.sep.join([target_dir, 'eh-metrics-hits-%s.tgz' % bn])
        if not self.fs.file_exists(local_file):
            log.info(
                'Missing metrics hits for build %s (file not exists: %s)' %
                (build_number, local_file))
            log.info('You can download them from %s' % url)
            log.info(
                'Or, I can do that for you (you may CTRL-C out of here at any time and do this manually).'
            )
            auth = JbacAuthentication.get()
            if not self.url.download(url, auth.login, auth.password,
                                     local_file):
                log.error(
                    'Failed to download the detailed metrics file from JBAC')
                return Callable.failure
        else:
            log.debug('Metrics hits for build %s exists, cool' % build_number)

        # unpack to temporary directory
        temp_dir = os.sep.join([target_dir, 'eh-metrics-hits-temp'])
        if self.fs.dir_exists(temp_dir):
            log.debug('Removing temp dir: %s' % temp_dir)
            self.fs.remove_dir(temp_dir)

        log.debug('unpacking %s to %s...' % (local_file, temp_dir))
        try:
            self.tar_utils.unpack_file(local_file, temp_dir)
        except Exception as e:
            log.error('Failed to unpack tar file %s. Error: %s' %
                      (local_file, e))
            return Callable.failure, None

        # move to proper directory
        commit_file = os.sep.join([temp_dir, '.commit'])
        if not self.fs.file_exists(commit_file):
            log.error(
                'Commit file does not exists! Is the metrics hits package corrupted? '
                'Expected file not found: %s' % commit_file)
        commit_hash = self.fs.read_lines(commit_file)[0]
        hits_dir = os.sep.join(
            [target_dir,
             'eh-metrics-hits-%s-%s' % (commit_hash, bn)])
        if self.fs.dir_exists(hits_dir):
            log.debug('Removing destination dir: %s' % hits_dir)
            self.fs.remove_dir(hits_dir)
        self.fs.rename(temp_dir, hits_dir)
        return Callable.success, hits_dir
Ejemplo n.º 4
0
    def get_hits_for_build(self, log: Logger, target_dir: str, build_number: str):
        job, bn = self.bamboo_utils.decode_build_number(build_number)
        url = '%s/browse/%s/artifact/%s/eh-metrics-hits.tgz/eh-metrics-hits.tgz' % (Jbac.url, bn, job)
        local_file = os.sep.join([target_dir, 'eh-metrics-hits-%s.tgz' % bn])
        if not self.fs.file_exists(local_file):
            log.info('Missing metrics hits for build %s (file not exists: %s)' % (build_number, local_file))
            log.info('You can download them from %s' % url)
            log.info('Or, I can do that for you (you may CTRL-C out of here at any time and do this manually).')
            auth = JbacAuthentication.get()
            if not self.url.download(url, auth.login, auth.password, local_file):
                log.error('Failed to download the detailed metrics file from JBAC')
                return Callable.failure
        else:
            log.debug('Metrics hits for build %s exists, cool' % build_number)

        # unpack to temporary directory
        temp_dir = os.sep.join([target_dir, 'eh-metrics-hits-temp'])
        if self.fs.dir_exists(temp_dir):
            log.debug('Removing temp dir: %s' % temp_dir)
            self.fs.remove_dir(temp_dir)

        log.debug('unpacking %s to %s...' % (local_file, temp_dir))
        try:
            self.tar_utils.unpack_file(local_file, temp_dir)
        except Exception as e:
            log.error('Failed to unpack tar file %s. Error: %s' % (local_file, e))
            return Callable.failure, None

        # move to proper directory
        commit_file = os.sep.join([temp_dir, '.commit'])
        if not self.fs.file_exists(commit_file):
            log.error('Commit file does not exists! Is the metrics hits package corrupted? '
                      'Expected file not found: %s' % commit_file)
        commit_hash = self.fs.read_lines(commit_file)[0]
        hits_dir = os.sep.join([target_dir, 'eh-metrics-hits-%s-%s' % (commit_hash, bn)])
        if self.fs.dir_exists(hits_dir):
            log.debug('Removing destination dir: %s' % hits_dir)
            self.fs.remove_dir(hits_dir)
        self.fs.rename(temp_dir, hits_dir)
        return Callable.success, hits_dir
Ejemplo n.º 5
0
    def get_build_name(self,
                       logger,
                       args,
                       branchDiscovery,
                       urlutils=UrlUtils(),
                       xml=XmlUtils()):
        if branchDiscovery.branch == 'master':
            return self.__fulljobname(args.type)
        else:
            # translate the branch into bamboo branch name:
            bamboo_branch_name = branchDiscovery.branch.replace('/', '-')
            logger.info('Trying to find bamboo branch "%s"...' %
                        bamboo_branch_name)

            auth = JbacAuthentication.get()
            url = '%s/rest/api/latest/plan/%s?expand=branches&max-results=10000' % (
                Jbac.url, CIInvestigate.planname[args.type])
            logger.info('Querying JBAC: ' + url)
            text = self.urlutils.read(url, auth.login, auth.password)

            try:
                root = self.xml.parse_string(text)
                for branchElement in root.findall('.//branches/branch'):
                    branch_key = branchElement.attrib['key']
                    branch_name = branchElement.attrib['shortName']
                    if branch_name == bamboo_branch_name:
                        logger.debug('Bamboo branch plan key is: "%s".' %
                                     branch_key)
                        return '-'.join(
                            [branch_key, CIInvestigate.jobname[args.type]])
            except ParseError:
                logger.debug('\n' + text)
                logger.error('Could not parse JBAC reply.')

            logger.warn(
                'Could not find the Bamboo branch for branch: "%s". Will inspect master instead.'
                % bamboo_branch_name)
            return self.__fulljobname(args.type)
Ejemplo n.º 6
0
    def __iter__(self):
        if self.auth is None:
            self.auth = JbacAuthentication.get()
        def failures_generator():
            url = self.__build_url()

            self.logger.info('Querying JBAC: ' + url)
            text = self.urlutils.read(url, self.auth.login, self.auth.password)
            self.logger.info('Got a reply.')

            try:
                root = self.xml.parse_string(text)
                for error in root.findall('.//failedTests/testResult'):
                    class_name = error.attrib['className']
                    method_name = error.attrib['methodName']
                    plan_name = self.__extract_plan_name(error.find('.//message').text)
                    if plan_name:
                        yield (plan_name, class_name + '.' + method_name)
            except ParseError:
                self.logger.error('Could not parse JBAC reply.')
                self.logger.debug('\n' + text)

        return failures_generator()
Ejemplo n.º 7
0
 def __init__(self, plan_name: str, urlutils=UrlUtils()):
     self.auth = JbacAuthentication.get()
     self.plan_name = plan_name
     self.urlutils = urlutils
Ejemplo n.º 8
0
 def __init__(self, plan_name: str, urlutils=UrlUtils()):
     self.auth = JbacAuthentication.get()
     self.plan_name = plan_name
     self.urlutils = urlutils