Skip to content

Commit

Permalink
Merge pull request #90 from kshtsk/wip-filter-sha1
Browse files Browse the repository at this point in the history
Add support for filter runs by sha1
  • Loading branch information
David Galloway authored Sep 28, 2020
2 parents 25f9d1b + 5957122 commit 0015bd1
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
30 changes: 30 additions & 0 deletions paddles/controllers/runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ def get_lookup_controller(self, field):
return DatesController()
if field == 'machine_type':
return MachineTypesController()
if field == 'sha1':
return Sha1sController()
if field == 'status':
return StatusesController()
if field == 'suite':
Expand Down Expand Up @@ -272,6 +274,32 @@ def index(self):
.group_by(Run).order_by(Run.scheduled)
return query.all()

class Sha1sController(RunFilterIndexController):
def get_subquery(self, query):
return query.values(Job.sha1)

def get_lookup_controller(self):
return Sha1Controller


class Sha1Controller(RunFilterController):
def get_subquery(self, query):
return query.join(Job).filter(Job.sha1.startswith(self.value))\
.group_by(Run)

def get_lookup_controller(self, field):
if field == 'branch':
return BranchesController()
if field == 'date':
return DatesController()
if field == 'machine_type':
return MachineTypesController()
if field == 'status':
return StatusesController()
if field == 'suite':
return SuitesController()



class RunsController(object):
@expose(generic=True, template='json')
Expand Down Expand Up @@ -307,6 +335,8 @@ def index_post(self):

queued = QueuedRunsController()

sha1 = Sha1sController()

@expose('json')
def _lookup(self, name, *remainder):
return RunController(name), remainder
5 changes: 4 additions & 1 deletion paddles/models/runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ def __json__(self):
branch=self.branch,
suite=self.suite,
machine_type=self.machine_type,
sha1=results['sha1'],
)

@classmethod
Expand Down Expand Up @@ -220,6 +221,7 @@ def get_results(self):
dead = jobs_status.count('dead')
unknown = jobs_status.count(None) + jobs_status.count('unknown')
total = len(jobs_status)
sha1 = next(self.jobs.values(Job.sha1), ['none'])[0]
return {
'queued': queued,
'pass': passing,
Expand All @@ -228,7 +230,8 @@ def get_results(self):
'fail': fail,
'dead': dead,
'unknown': unknown,
'total': total
'total': total,
'sha1': sha1,
}

def set_status(self, results=None):
Expand Down
4 changes: 2 additions & 2 deletions paddles/tests/models/test_runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,10 @@ def test_run_machine_type(self):
def test_run_results(self):
run_name = 'teuthology-2014-03-27_00:00:00-x-x-x-x-x'
new_run = Run(run_name)
stats_in = {'pass': 9, 'fail': 1, 'dead': 6, 'running': 5,
stats_in = {'pass': 9, 'fail': 1, 'dead': 6, 'running': 5, 'sha1': None,
'waiting': 1, 'unknown': 1, 'queued': 1}
statuses = stats_in.keys()
stats_in['total'] = sum(stats_in.values())
stats_in['total'] = sum(_ for _ in stats_in.values() if _)
stats_out = {}
for i in range(stats_in['total']):
for status in statuses:
Expand Down

0 comments on commit 0015bd1

Please sign in to comment.