Add Gerrit DB query method to gerritlib.
Sometimes you need to query the Gerrit DB directly instead of using the Gerrit query abstraction layer. Add api method to communicate directly to the DB. Change-Id: I3ef3173cbe62741bb9d37f49abda1cf0eacbceff
This commit is contained in:
parent
900136ec1e
commit
38749dfb1e
@ -137,6 +137,22 @@ class Gerrit(object):
|
||||
pprint.pformat(data)))
|
||||
return data
|
||||
|
||||
def dbQuery(self, query):
|
||||
cmd = 'gerrit gsql --format JSON -c "%s"' % query
|
||||
out, err = self._ssh(cmd)
|
||||
if not out:
|
||||
return False
|
||||
lines = out.strip().split('\n')
|
||||
if not lines:
|
||||
return False
|
||||
data = map(json.loads, lines)
|
||||
if not data:
|
||||
return False
|
||||
self.log.debug("Received %s rows from Gerrit DB query: \n%s" % (
|
||||
# Subtract one for query states line.
|
||||
(len(data) - 1), query))
|
||||
return data
|
||||
|
||||
def _ssh(self, command):
|
||||
client = paramiko.SSHClient()
|
||||
client.load_system_host_keys()
|
||||
|
Loading…
x
Reference in New Issue
Block a user