Gerrymander tips & tricks – viewing comments on a gerrit review without bots

Posted: May 21st, 2014 | Filed under: Coding Tips, Fedora, OpenStack, Virt Tools | Tags: , , , | 1 Comment »

Those who saw my original announcement of gerrymander will know that OpenStack uses the Gerrit tool for code review. One of the efforts made by the Nova (Compute) team during the last release cycle was to increase the automated testing coverage for hypervisors supported by Nova. Previously we only tested Libvirt on KVM, but now there is testing for VMWare, HyperV and XenAPI too. This is great for our code quality, but far less great for the usability of the gerrit web interface. Consider a fairly typical change I needed to look at today, the web UI for gerrit shows many comments. When doing code review of new patch versions though, I mostly don’t care about comments from the “robot” accounts doing automated testing – just the pass / fail status. I’m far more interested in comments made by humans, so I can see whether they’ve been addressed by new patch versions, or whether I agree/disagree with the comments. The gerrit web UI though doesn’t provide any way to separate this info – it just shows a huge list with human & robot comments combined. The ever growing number of robots used by OpenStack for testing mean the human comments are drowned out in the noise

Gerrit comments

This problem is one of the reasons I created the gerrymander tool. The ‘comments’ command has the ability to display all comments on a change, while filtering out those made by known bot accounts. Now there’s a little setup required, by which I mean you must edit $HOME/.gerrymander to list all the bot accounts. For those using OpenStack though, I’ve uploaded a sample config file, which lists all bot accounts, to the wiki. With this config file in effect I can now look at this same change number 87329

# gerrymander comments --color 87329
Change (I06c2d9930e0f36a0d7057b6a0f5c9c591caac43f)

  libvirt: Use os_command_line when kernel_id is set

Patch 1 (c8d1cf4559174777be4b42b68379cf78ccd8f382)

  Jay Pipes: (jaypipes) nova/virt/libvirt/

  You can condense lines 3202-3203 to:   guest.os_cmdline =

  Jay Pipes: (jaypipes)

  Patch Set 1: I would prefer that you didn't merge this  (1 inline comment)
  Suggestion for consolidation inline, otherwise, looks good.

  Vladan Popovic: (vladan)

  Patch Set 1:  Thanks for the review Jay.

Patch 2 (58323a7271e0f09689b94bc8632204c179934add)

  Daniel Berrange: (berrange) /COMMIT_MSG:18

  "AMI images" is a pretty obscure/non-obvious term.  This is about images with
  an explicit boot kernel set, so please say that explicitly and void the term

  Daniel Berrange: (berrange)

  Patch Set 2: I would prefer that you didn't merge this  (1 inline comment)

  Jay Pipes: (jaypipes)

  Patch Set 2:  recheck bug 1307344

Patch 3 (8f3ced280d80eaee69029f4bf2a193bcba749284)

  garyk: (garyk) nova/tests/virt/libvirt/

  please use self.assertIsNone

  Mohammed Naser: (mnaser)

  Patch Set 3: Looks good to me, but someone else must approve

  garyk: (garyk)

  Patch Set 3: I would prefer that you didn't merge this  (1 inline comment)
  code looks good. one minor nit

Patch 4 (5698a6c7c5195bd1d3ecf01af6fb65c19ae8a990)

  No  comments

Patch 5 (a87773776a0d39aa5591fde6caa65b92f5b17a6d)

  Jay Pipes: (jaypipes)

  Patch Set 5: Looks good to me, but someone else must approve  ++, thx Vladlan!

  Mohammed Naser: (mnaser)

  Patch Set 5: Looks good to me, but someone else must approve  recheck bug

  Daniel Berrange: (berrange)

  Patch Set 5: I would prefer that you didn't merge this  Jenkins failures are
  genuine bugs

  Sreeram Yerrapragada: (syerrapragada)

  Patch Set 5:  recheck-vmware

Patch 6 (a1eb12f0c8281c0b01dde00b8225d742b8e832e3)

  garyk: (garyk)

  Patch Set 6: Code-Review+1

The obvious limitation here is that the file comments are not shown inline with the code, but overall I think this is still much more useful than the gerrit web UI display of comments. I can still go look at the web UI if I do need to see the context of certain inline comments. So gerrymander comments report complements the web UI nicely.

Announce: gerrymander 1.0 “A dachshund named Colin” – a client API and command line tool for gerrit

Posted: May 9th, 2014 | Filed under: Coding Tips, Fedora, OpenStack, Virt Tools | Tags: , , , | 3 Comments »

This blog post is to announce the first release of a new project, gerrymander, which I’ve mentioned on IRC in passing a few times. The 32,000 ft summary is that it provides a set of python (2 & 3 compatible) APIs and command line tool for extracting and presenting information from gerrit. You can get it from pypi

 # pip install gerrymander

Or straight from GitHub

 # git clone git://

If you’re the impatient type, then go to the README file which provides a quick start guide to using the tool.

For details on why/how I built gerrymander, read onwards….

Background motivation

The OpenStack project uses Gerrit for review of pretty much all contributions to the project. Not wishing to get into a discussion of the merits of using a Gerrit based workflow, I’ll just say that with large volume of changes going through some sub-projects, such as Nova, the Gerrit web interface really starts to show its limitations. As a result a number of OpenStack contributors have developed cli tools for extracting information from Gerrit and presenting it in more practical formats.

  • gerrit_view – created by Josh Harlow, it provides a general purpose query tool and a interactive TUI for live monitoring of changes.
  • reviewtodo – created by Russell Bryant, it generates reports which attempt to prioritize changes such that the most “important” ones are presented at the top of the todo list.
  • reviewstats – created by Russell Bryant, it generates reports which summarize the reviewing activity of all contributors across the project, and reports which attempt to identify how efficiently reviews are being handled.

I’ve previously contributed to the gerrit_view project and in the second half of the IceHouse dev cycle, I turned off gerrit email alerts and stopped using the gerrit web UI index pages for identifying changes needing review. Instead I exclusively use the qgerrit command line tool to identify changes that affect the libvirt driver which need attention from myself. This had a significant positive impact on my productivity when using gerrit, so I started looking at other gerrit client tools and thinking about what further reports or information I might wish to get from gerrit. It became apparent that the tools people are writing have significant overlap / duplication of code for dealing with basic interaction with gerrit. There are features in some tools (eg caching of gerrit queries in reviewstats) which would be useful to the other tools, but since these are all designed as singe-purpose standalone tools there’s not really much scope for sharing functionality.

Introducing the “gerrymander” project

Clearly what was needed was a new “standard” for building gerrit command line tools, so enter “gerrymander“. The gerrymander project is not simply another command line tool, rather it is intended to provide a collection of python modules / APIs to facilitate the creation of arbitrary gerrit command line reports/tools. With that goal in mind the gerrymander package provides a set of modules, for both Python 2 and Python 3:

  • gerrymander.client – module providing a class for connecting to the gerrit server over SSH, running the ‘gerrit’ tool and passing the results to a callback for processing. As well as the standard “live” client, there is a caching client which stores the results from ‘gerrit’ in local files. This means that expensive queries (eg querying the entire history of all changes ever) won’t inflict repeated denial of service attacks on the server.
  • gerrymander.model – module providing a set of classes that represent the JSON schemas returned by the ‘gerrit’ tool as Python objects. This means you’re not simply blindly accessing untyped dictionary fields. Many of the classes have helper APIs against them to allow their information to be accessed in interesting ways.
  • gerrymander.format – module providing a few helper APIs for formatting data to present to the user. For example, a way to produce coloured text for ANSI capable terminals, or to format time deltas / dates in more user friendly ways (ie “4 days ago” instead of “May 5, 2014”).
  • gerrymander.operation – module providing a class for each operation supported by the ‘gerrit’ tool. This provides a slightly higher level way to utilize to the gerrymander.client module classes. This takes care of obscure oddities such as the need to re-execute ‘gerrit query’ multiple times, since it refuses to return more than 500 results at a time.
  • gerrymander.reports – module providing a set of classes for extracting interesting information from gerrit. Each report class will execute one of more operations against gerrit, post-process the data from the query, and then return an object with the structured results. This is where all the really interesting functionality lives.
  • gerrymander.commands – module providing the command line interface to the reports. It takes the report output and formats it as text, xml or json. A configuration file is used to customize default behaviour, such as which fields are visible, defining command lines, project names, usernames of bots, etc.

The actual “gerrymander” command line tool is designed as a multi-call binary – ie it has a number to sub-commands you can execute, each with their own set of options. I won’t repeat what’s already covered in the README file in this blog post, rather just see the help message for the list of reports/commands I’ve written. So far I’ve targeted the functionality provided by the 3 pre-existing projects I mentioned above:

$ gerrymander --help
usage: gerrymander [-h] [-c CONFIG] [-d] [-q]


Gerrymander client

positional arguments:
watch Watch incoming changes
todo-noones List of changes no one has looked at yet
todo-anyones List of changes anyone has looked at
todo-mine List of changes I've looked at before
todo-others List of changes I've not looked at before
patchreviewstats Statistics on patch review approvals
openreviewstats Statistics on open patch reviews
changes Query project changes
comments Display comments on a change
changes-nova-specs Changes in Nova SPECS

optional arguments:
-h, --help show this help message and exit
-c CONFIG, --config CONFIG
Override config file (default
-d, --debug Display debugging information
-q, --quiet Supress display of warnings

As one example, taking the simplest / most generic ‘changes’ command, lets see all changes that I’ve written but abandoned

$ gerrymander changes --owner berrange --status abandoned

| Status    | URL                                | Owner    | Subject                           | Created  | Updated  | Approvals        |
| ABANDONED |  | berrange | Allow CPU model to be specifie... | 694 days | 688 days | v=-1,1 c=-1      |
| ABANDONED |  | berrange | Fix use of uninitialized varia... | 673 days | 672 days | v=-1 c=1         |
| ABANDONED | | berrange | Revert "Handle InstanceNotFoun... | 641 days | 641 days | v=-1             |
| ABANDONED | | berrange | Merge LibvirtOpenVswitchVirtua... | 490 days | 486 days |                  |
| ABANDONED | | berrange | Merge all VIF classes into one... | 486 days | 463 days | v=1,1 c=1        |
| ABANDONED | | berrange | Make it possible to set nova o... | 485 days | 483 days | v=1 c=1,-1       |
| ABANDONED | | berrange | Make devstack work on Fedora 1... | 353 days | 336 days | v=1 c=-1,1,-1,-1 |
| ABANDONED | | berrange | Increase min required libvirt ... | 164 days | 79 days  | v=-1 c=-1        |
| ABANDONED | | berrange | Fix quoting of username in pol... | 70 days  | 63 days  | v=1 c=-1         |

Some things to note about that are unique in comparison to other gerrit client tools I’ve mentioned above that can do the same kind of query

  • The gerrit query is cached for 5 minutes, so if you re-run to change the display options (eg which fields are shown) it won’t hit the gerrit server again, unless you change the actual args to the query.
  • The default output mode is formatted text, but you can ask for the data in XML or JSON documents, allowing easier parsing by further downstream tools
  • The configuration file lets you set defaults for all of the command line parameters. So you can hide fields you don’t care about, or make fields wider, and more
  • The configuration file lets you define command aliases. So if you have a number of different queries you run, you can define new commands (eg ‘my-abandoned-changes’) which record all the query parameters for the ‘changes’ command. This avoids the need to create shell wrapper scripts around the gerrymander command for common queries
  • The command and/or report are accessible via the Python API, so if you want direct access to the raw data you can use the API instead of parsing the text/xml/json outputs.
  • Optional colourization of fields (eg +1’s / +2’s in green, -1’s / -2’s in red)

If any of this sounds interesting to you, pip install the package and try it out. If you want to contribute patches for more interesting reports, then the code is all up on github at the URL mentioned earlier.

One final important point is that this tool is written such that it has zero knowledge about OpenStack. It is intended to be useful to any project which is using Gerrit for their code review. As such all the projects specific knowledge, such as list of project names, team members, bot accounts, is isolated in the configuration file. So one thing I need to do to ease first time users is to upload a sample configuration file for OpenStack that includes all the different projects / teams / bots OpenStack has.

EDIT: Use this config file with OpenStack

Getting started hacking on OpenStack Nova

Posted: March 9th, 2012 | Filed under: Fedora, libvirt, OpenStack, Virt Tools | Tags: , , , | 5 Comments »

In recent months I have spent more of my time working on projects immediately above/related to the core libvirt library, such as libvirt-glib, libosinfo and virt-sandbox. To that list I have now added OpenStack, where my goal is to ensure that the libvirt driver is following all the best practices and start to take advantage of libosinfo for optimizing virtual hardware configuration. I’m familiar with hacking on python so that’s no big issue, but what is new about OpenStack is dealing with Gerrit.  For the sake of reference, here were the steps I went through on Fedora 16 for my first patch (a tweak to the tools/ file)

  1. Get the initial Nova GIT checkout
    $ mkdir $HOME/src/cloud
    $ cd $HOME/src/cloud
    $ git clone git://
    $ cd nova
  2. Install some basic pre-reqs, and ensure python-distutils-extra is not present since that conflicts with part of the openstack build system
    $ sudo yum install gcc python-pep8 python-virtualenv m2crypto libvirt libvirt-python libxslt-devel libxml2-devel
    $ sudo yum remove python-distutils-extra
  3. Visit the OpenStack Gerrit Website, and follow ‘Sign In’ link which redirects to LaunchPad for authentication
  4. Back on Gerrit site, now signed in, follow ‘Settings’ link, select ‘SSH Public Keys’ page, and paste your SSH public key (eg contents of $HOME/.ssh/
  5. Test SSH connectivity from the CLI
    $ ssh -p 29418
    The authenticity of host '[]:29418 ([]:29418)' can't be established.
    RSA key fingerprint is ee:2f:ac:1b:f8:25:d0:39:be:55:02:c7:76:5e:39:53.
    Are you sure you want to continue connecting (yes/no)? yes
    Warning: Permanently added '[]:29418,[]:29418' (RSA) to the list of known hosts.
    **** Welcome to Gerrit Code Review ****
    Hi Daniel Berrange, you have successfully connected over SSH.
    Unfortunately, interactive shells are disabled.
    To clone a hosted Git repository, use:
    git clone ssh://
    Connection to closed.
  6. Install commit hook to ensure ‘ChangeId’ fields get added to your commits
    $ scp -p -P 29418 .git/hooks/
  7. Add the gerrit remote to GIT config
    $ git remote add gerrit ssh://
  8. Start a new branch for your work
    $ git checkout -b venv-install-fixes
  9. Make whatever code changes you need todo
    $ vi tools/
    $ git add -u
    (Don't forget to add yourself to Authors if this is your first change)
  10. Commit the changes, checking the commit message gets a ‘Change-Id’ line added just prior to the signed-off-by line
    $ git commit -s
    $ git show
    commit fd682a28fb4591c65f20129d4bfb4eccf1232cb8
    Author: Daniel P. Berrange <>
    Date: Thu Jan 5 13:15:15 2012 +0000
    Tell users what is about to be installed via sudo
    Rather than just giving users the sudo password prompt immediately,
    actually tell them what is about to be installed, so they know what
    privileged action is being attempted.
    Change-Id: Ic0c1de812be119384753895531a008075b13494e
    Signed-off-by: Daniel P. Berrange <>

    If the commit is fixing a OpenStack bug, then the commit message should include a line “BugXXXX” where XXXX is the bug number. Gerrit uses this to link to the bug tracker

  11. Run the unit test suite, and the python pep8 syntax test suite; Be prepared to wait a long time
    $ ./
    $ ./ --pep8
  12. Send the changes to Gerrit for review
    $ git push gerrit HEAD:refs/for/master
  13. Wait for email notifications of review, or watch the OpenStack Gerrit Website.
  14. If problems are found by reviewers, or the automated smoke stack tests. Repeat steps 9->l;12, but use ‘git commit –amend’ to ensure you preserve the original “Change-Id” line in the commit message. This lets gerrit track followup patches.
  15. If everything passes review & testing, it will be automatically merged into master.

There is also a GIT plugin  “git review” available in the git-review RPM, which can provide syntactic sugar for step 12, but personally I don’t find it adds significant value to be worth my while using.

I can see the attraction of Gerrit, but I personally still prefer the practice of using git send-email for reviewing on mailing lists. My problems with Gerrit are

  • The email notifications sent out for new patches are almost worse than useless as an information source
  • While very pretty, the web UI for browsing the diffs is really quite cumbersome to use
  • Poor support for reviewing large patch series
  • Use of merge commits makes navigating GIT history cumbersome, forcing the use of the graphical gitk viewer tool