Ejemplo n.º 1
0
    def locks(self, machine_type=None):
        uri = urljoin(base_url, '/nodes/?up=True')
        if machine_type:
            uri += '&machine_type=%s' % machine_type

        resp = requests.get(uri, timeout=60)
        if resp.status_code == 502:
            redirect('/errors?status_code={status}&message={msg}'.format(
                status=200, msg='502 gateway error :('),
                     internal=True)
        elif resp.status_code == 400:
            error('/errors/invalid/', msg=resp.text)

        nodes = resp.json()
        users = dict()
        for node in nodes:
            if node.get('locked', False):
                owner = node.get('locked_by')
            else:
                owner = '(free)'
            mtype = node.get('machine_type')
            type_dict = users.get(owner, dict())
            type_dict[mtype] = type_dict.get(mtype, 0) + 1
            users[owner] = type_dict

        title = "Machine usage for up {mtype}nodes".format(
            mtype=machine_type + ' ' if machine_type else '', )
        return dict(
            title=title,
            users=users,
        )
Ejemplo n.º 2
0
    def index(self, machine_type=None):
        uri = '{base}/nodes/'.format(
            base=base_url,
        )
        if machine_type:
            uri += '?machine_type=%s' % machine_type

        resp = requests.get(uri, timeout=60)
        if resp.status_code == 502:
            redirect('/errors?status_code={status}&message={msg}'.format(
                status=200, msg='502 gateway error :('),
                internal=True)
        elif resp.status_code == 400:
            error('/errors/invalid/', msg=resp.text)

        nodes = resp.json()
        for node in nodes:
            set_node_status_class(node)
        nodes.sort(key=lambda n: n['name'])

        title = "{mtype} nodes".format(
            mtype=machine_type if machine_type else 'All',
        )
        return dict(
            title=title,
            nodes=nodes,
        )
Ejemplo n.º 3
0
    def index(self, machine_type=None):
        uri = urljoin(base_url, '/nodes/')
        if machine_type:
            uri += '?machine_type=%s' % machine_type

        resp = requests.get(uri, timeout=60)
        if resp.status_code == 502:
            redirect('/errors?status_code={status}&message={msg}'.format(
                status=200, msg='502 gateway error :('),
                internal=True)
        elif resp.status_code == 400:
            error('/errors/invalid/', msg=resp.text)

        nodes = resp.json()
        for node in nodes:
            set_node_status_class(node)
            # keep only the node name, not the fqdn
            node['fqdn'] = node['name']
            node['name'] = node['fqdn'].split(".")[0]
            desc = node['description']
            if not desc or desc.lower() == "none":
                node['description'] = ""
            elif 'teuthworker' in desc:
                # strip out the path part of the description and
                # leave it with the run_name/job_id
                node['description'] = "/".join(desc.split("/")[-2:])
        nodes.sort(key=lambda n: n['name'])

        title = "{mtype} nodes".format(
            mtype=machine_type if machine_type else 'All',
        )
        return dict(
            title=title,
            nodes=nodes,
        )
Ejemplo n.º 4
0
    def jobs(self, machine_type=None, since_days=14):
        uri = urljoin(base_url,
                      '/nodes/job_stats?since_days={0}'.format(since_days))
        if machine_type:
            uri += '&machine_type=%s' % machine_type

        resp = requests.get(uri, timeout=60)
        if resp.status_code == 502:
            redirect('/errors?status_code={status}&message={msg}'.format(
                status=200, msg='502 gateway error :('),
                     internal=True)
        elif resp.status_code == 400:
            error('/errors/invalid/', msg=resp.text)

        nodes = resp.json()
        statuses = ['pass', 'fail', 'dead', 'unknown', 'running']
        for name in nodes.keys():
            node = nodes[name]
            total = sum(node.values())
            node['total'] = total
            for status in statuses:
                if node.get(status) is None:
                    node[status] = 0
        nodes = OrderedDict(
            sorted(nodes.items(), key=lambda t: t[1]['total'], reverse=True))
        title_templ = "{days}-day stats for {mtype} nodes"
        title = title_templ.format(days=since_days,
                                   mtype=(machine_type or 'all'))
        return dict(
            title=title,
            nodes=nodes,
            count=len(nodes),
        )
Ejemplo n.º 5
0
Archivo: stats.py Proyecto: H3C/pulpito
    def locks(self, machine_type=None):
        uri = '{base}/nodes/?up=True'.format(
            base=base_url,
        )
        if machine_type:
            uri += '&machine_type=%s' % machine_type

        resp = requests.get(uri, timeout=60)
        if resp.status_code == 502:
            redirect('/errors?status_code={status}&message={msg}'.format(
                status=200, msg='502 gateway error :('),
                internal=True)
        elif resp.status_code == 400:
            error('/errors/invalid/', msg=resp.text)

        nodes = resp.json()
        users = dict()
        print nodes
        for node in nodes:
            if node.get('locked', False):
                owner = node.get('locked_by')
            else:
                owner = '(free)'
            mtype = node.get('machine_type')
            type_dict = users.get(owner, dict())
            type_dict[mtype] = type_dict.get(mtype, 0) + 1
            users[owner] = type_dict

        title = "Machine usage for up {mtype}nodes".format(
            mtype=machine_type + ' ' if machine_type else '',
        )
        return dict(
            title=title,
            users=users,
        )
Ejemplo n.º 6
0
    def index(self, machine_type=None):
        uri = urlparse.urljoin(base_url, '/nodes/')
        if machine_type:
            uri += '?machine_type=%s' % machine_type

        resp = requests.get(uri, timeout=60)
        if resp.status_code == 502:
            redirect('/errors?status_code={status}&message={msg}'.format(
                status=200, msg='502 gateway error :('),
                internal=True)
        elif resp.status_code == 400:
            error('/errors/invalid/', msg=resp.text)

        nodes = resp.json()
        for node in nodes:
            set_node_status_class(node)
            # keep only the node name, not the fqdn
            node['fqdn'] = node['name']
            node['name'] = node['fqdn'].split(".")[0]
            desc = node['description']
            if not desc or desc.lower() == "none":
                node['description'] = ""
            elif 'teuthworker' in desc:
                # strip out the path part of the description and
                # leave it with the run_name/job_id
                node['description'] = "/".join(desc.split("/")[-2:])
        nodes.sort(key=lambda n: n['name'])

        title = "{mtype} nodes".format(
            mtype=machine_type if machine_type else 'All',
        )
        return dict(
            title=title,
            nodes=nodes,
        )
Ejemplo n.º 7
0
Archivo: root.py Proyecto: H3C/pulpito
    def date(self, from_date_str, to='', to_date_str=''):
        filters = get_run_filters(date=from_date_str, to_date=to_date_str)
        request.context['filters'] = filters
        if to:
            resp = requests.get(
                '{base}/runs/date/from/{from_}/to/{to}'.format(
                    base=base_url, from_=from_date_str, to=to_date_str))
        else:
            resp = requests.get('{base}/runs/date/{date}/'.format(
                base=base_url, date=from_date_str))

        if resp.status_code == 400:
            error('/errors/invalid/',
                  resp.json().get('message'))
        elif resp.status_code == 404:
            error('/errors/not_found/',
                  resp.json().get('message'))
        else:
            runs = resp.json()

        for run in runs:
            prettify_run(run)
        runs.sort(key=run_sorter)
        return dict(runs=runs,
                    filters=request.context.get('filters', dict()),
                    dates=[from_date_str, to_date_str]
                    )
Ejemplo n.º 8
0
Archivo: stats.py Proyecto: H3C/pulpito
    def jobs(self, machine_type=None, since_days=14):
        uri = '{base}/nodes/job_stats?since_days={days}'.format(
            base=base_url,
            days=since_days)
        if machine_type:
            uri += '&machine_type=%s' % machine_type

        resp = requests.get(uri, timeout=60)
        if resp.status_code == 502:
            redirect('/errors?status_code={status}&message={msg}'.format(
                status=200, msg='502 gateway error :('),
                internal=True)
        elif resp.status_code == 400:
            error('/errors/invalid/', msg=resp.text)

        nodes = resp.json()
        statuses = ['pass', 'fail', 'dead', 'unknown', 'running']
        for name in nodes.keys():
            node = nodes[name]
            total = sum(node.values())
            node['total'] = total
            for status in statuses:
                if node.get(status) is None:
                    node[status] = 0
        nodes = OrderedDict(
            sorted(nodes.items(), key=lambda t: t[1]['total'], reverse=True))
        title_templ = "{days}-day stats for {mtype} nodes"
        title = title_templ.format(days=since_days,
                                   mtype=(machine_type or 'all'))
        return dict(
            title=title,
            nodes=nodes,
            count=len(nodes),
        )
Ejemplo n.º 9
0
    def date(self, from_date_str, to='', to_date_str=''):
        filters = get_run_filters(date=from_date_str, to_date=to_date_str)
        request.context['filters'] = filters
        if to:
            url = urljoin(
                base_url,
                '/runs/date/from/{0}/to/{1}'.format(from_date_str,
                                                    to_date_str))
        else:
            url = urljoin(base_url, '/runs/date/{0}/'.format(from_date_str))
        resp = requests.get(url)

        if resp.status_code == 400:
            error('/errors/invalid/', resp.json().get('message'))
        elif resp.status_code == 404:
            error('/errors/not_found/', resp.json().get('message'))
        else:
            runs = resp.json()

        for run in runs:
            prettify_run(run)
        runs.sort(key=run_sorter)
        return dict(runs=runs,
                    filters=request.context.get('filters', dict()),
                    dates=[from_date_str, to_date_str])
Ejemplo n.º 10
0
    def index(self, suite, branch, since=None, count=3):
        """
        Ask paddles for a list of runs of ``suite`` on ``branch``, then build a
        dict that looks like:
            {'runs': [
                {'name': run_name,
                    'jobs': [
                        job_description: {
                            'job_id': job_id,
                            'status': status }
                    ]}
                ]
             'descriptions': [
                 job_description,
                ]
            }
        """
        url = urlparse.urljoin(
            base_url,
            '/runs/branch/{branch}/suite/{suite}/?count={count}'.format(
                branch=branch, suite=suite, count=str(count)))
        if since:
            url += '&since=' + since

        runs = requests.get(url).json()
        full_info = dict(
            branch=branch,
            suite=suite,
            since=since,
            runs=list(),
        )
        descriptions = set()
        for run in runs:
            run_info = dict()
            url = urlparse.urljoin(
                base_url,
                '/runs/{0}/jobs/?fields=job_id,description,status,log_href,failure_reason'
                .format(  # noqa
                    run['name']))
            resp = requests.get(url)

            if resp.status_code == 404:
                error('/errors/not_found/')
            else:
                jobs = resp.json()

            run_info['name'] = run['name']
            run_info['scheduled'] = run['scheduled']
            run_info['jobs'] = dict()
            for job in jobs:
                description = job.pop('description')
                prettify_job(job)
                descriptions.add(description)
                run_info['jobs'][description] = job
            full_info['runs'].append(run_info)
        full_info['runs'].reverse()
        full_info['descriptions'] = sorted(list(descriptions))
        return full_info
Ejemplo n.º 11
0
    def index(self, suite, branch, since=None, count=3):
        """
        Ask paddles for a list of runs of ``suite`` on ``branch``, then build a
        dict that looks like:
            {'runs': [
                {'name': run_name,
                    'jobs': [
                        job_description: {
                            'job_id': job_id,
                            'status': status }
                    ]}
                ]
             'descriptions': [
                 job_description,
                ]
            }
        """
        url = '{base}/runs/branch/{branch}/suite/{suite}/?count={count}'.format(  # noqa
            base=base_url,
            branch=branch,
            suite=suite,
            count=str(count))
        if since:
            url += '&since=' + since

        runs = requests.get(url).json()
        full_info = dict(
            branch=branch,
            suite=suite,
            since=since,
            runs=list(),
        )
        descriptions = set()
        for run in runs:
            run_info = dict()
            resp = requests.get(
                '{base}/runs/{run_name}/jobs/?fields=job_id,description,status,log_href,failure_reason'.format(  # noqa
                    base=base_url,
                    run_name=run['name']))

            if resp.status_code == 404:
                error('/errors/not_found/')
            else:
                jobs = resp.json()

            run_info['name'] = run['name']
            run_info['scheduled'] = run['scheduled']
            run_info['jobs'] = dict()
            for job in jobs:
                description = job.pop('description')
                prettify_job(job)
                descriptions.add(description)
                run_info['jobs'][description] = job
            full_info['runs'].append(run_info)
        full_info['runs'].reverse()
        full_info['descriptions'] = sorted(list(descriptions))
        return full_info
Ejemplo n.º 12
0
    def get_node(self, page=None):
        url = urlparse.urljoin(base_url, '/nodes/{0}/'.format(self.name))
        resp = requests.get(url)
        if resp.status_code == 404:
            error('/errors/not_found/', 'requested node does not exist')
        else:
            node = resp.json()

        set_node_status_class(node)
        self.node = node
        self.get_node_jobs(page=page)
        return self.node
Ejemplo n.º 13
0
 def __init__(self, run_name, job_id):
     self.run_name = run_name
     self.job_id = job_id
     url = urlparse.urljoin(base_url,
                            "/runs/{0}/jobs/{1}/".format(run_name, job_id))
     resp = requests.get(url)
     if resp.status_code == 400:
         error('/errors/invalid/')
     elif resp.status_code == 404:
         error('/errors/not_found/')
     else:
         self.job = resp.json()
         prettify_job(self.job)
Ejemplo n.º 14
0
Archivo: nodes.py Proyecto: H3C/pulpito
    def get_node(self):
        resp = requests.get(
            '{base}/nodes/{name}'.format(base=base_url,
                                         name=self.name))
        if resp.status_code == 404:
            error('/errors/not_found/',
                  'requested node does not exist')
        else:
            node = resp.json()

        set_node_status_class(node)
        self.node = node
        return self.node
Ejemplo n.º 15
0
    def __init__(self, run_name, job_id):
        self.run_name = run_name
        self.job_id = job_id
        resp = requests.get("{base}/runs/{run}/jobs/{job}".format(
            base=base_url, run=run_name, job=job_id))

        if resp.status_code == 400:
            error('/errors/invalid/')
        elif resp.status_code == 404:
            error('/errors/not_found/')
        else:
            self.job = resp.json()
            prettify_job(self.job)
Ejemplo n.º 16
0
    def get_node(self, page=None):
        url = urlparse.urljoin(base_url, '/nodes/{0}/'.format(self.name))
        resp = requests.get(url)
        if resp.status_code == 404:
            error('/errors/not_found/',
                  'requested node does not exist')
        else:
            node = resp.json()

        set_node_status_class(node)
        self.node = node
        self.get_node_jobs(page=page)
        return self.node
Ejemplo n.º 17
0
    def get_run(self):
        url = urljoin(base_url, '/runs/%s/' % self.name)
        resp = requests.get(url)
        if resp.status_code == 404:
            error('/errors/not_found/', 'requested run does not exist')
        else:
            run = resp.json()

        if 'scheduled' in run:
            run['scheduled_day'] = run['scheduled'].split()[0]

        if 'jobs' in run:
            for job in run['jobs']:
                prettify_job(job)

        prettify_run(run)
        self.run = run
        return self.run
Ejemplo n.º 18
0
Archivo: root.py Proyecto: ceph/pulpito
    def get_run(self):
        url = urlparse.urljoin(base_url, '/runs/%s/' % self.name)
        resp = requests.get(url)
        if resp.status_code == 404:
            error('/errors/not_found/',
                  'requested run does not exist')
        else:
            run = resp.json()

        if 'scheduled' in run:
            run['scheduled_day'] = run['scheduled'].split()[0]

        if 'jobs' in run:
            for job in run['jobs']:
                prettify_job(job)

        prettify_run(run)
        self.run = run
        return self.run
Ejemplo n.º 19
0
Archivo: root.py Proyecto: H3C/pulpito
    def get_run(self):
        resp = requests.get(
            '{base}/runs/{name}'.format(base=base_url,
                                        name=self.name))
        if resp.status_code == 404:
            error('/errors/not_found/',
                  'requested run does not exist')
        else:
            run = resp.json()

        if 'scheduled' in run:
            run['scheduled_day'] = run['scheduled'].split()[0]

        if 'jobs' in run:
            for job in run['jobs']:
                prettify_job(job)

        prettify_run(run)
        self.run = run
        return self.run