implement gerrit pagination in simplequery

gerrit defaults to a limit of 500 changes returned. Nova regularly has
more than 500 open reviews. This means that some operations aren't
seeing all the open reviews, and causing some oddness (like merge
check).

Implement implicit paging.

In looking at this code I also believe I found a double -1 slicing
error which would mean that we would miss some reviews being listed.

Change-Id: I00d47c05e4a740b61c690510593fd29eaef49679
This commit is contained in:
Sean Dague 2014-11-13 11:29:10 -05:00
parent 1f4f8e136e
commit eae3f421be
2 changed files with 28 additions and 16 deletions

View File

@ -145,21 +145,33 @@ class Gerrit(object):
return data
def simpleQuery(self, query):
args = '--current-patch-set'
cmd = 'gerrit query --format json %s %s' % (
args, query)
out, err = self._ssh(cmd)
if not out:
return False
lines = out.split('\n')
if not lines:
return False
data = [json.loads(line) for line in lines[:-1]]
if not data:
return False
self.log.debug("Received data from Gerrit query: \n%s" %
(pprint.pformat(data)))
return data
def _query_chunk(query):
args = '--current-patch-set'
cmd = 'gerrit query --format json %s %s' % (
args, query)
out, err = self._ssh(cmd)
if not out:
return False
lines = out.split('\n')
if not lines:
return False
data = [json.loads(line) for line in lines[:-1]]
if not data:
return False
self.log.debug("Received data from Gerrit query: \n%s" %
(pprint.pformat(data)))
return data
# gerrit returns 500 results by default, so implement paging
# for large projects like nova
alldata = []
chunk = _query_chunk(query)
while(chunk):
alldata.extend(chunk)
sortkey = "resume_sortkey:'%s'" % chunk[-1]["sortKey"]
chunk = _query_chunk("%s %s" % (query, sortkey))
return alldata
def _open(self):
client = paramiko.SSHClient()

View File

@ -330,7 +330,7 @@ class Gerrit(object):
self.log.debug("Running query %s to get project open changes" % (query,))
data = self.gerrit.simpleQuery(query)
changes = []
for record in data[:-1]:
for record in data:
try:
changes.append(self._getChange(record['number'],
record['currentPatchSet']['number']))