Preparing My First Patch for OpenStack

I joined DreamHost about four weeks ago on Feb 6. and am on the
team building a cloud hosting service based on the open source project
OpenStack. I spent the first couple of weeks at the new job doing
the usual sorts of new-hire activities: reading a lot of documentation
and learning my way around the development environment and tool
chain. I’ve done a little bit of work on some internal code already,
and I recently had a good opportunity to start working on OpenStack
itself.

The OpenStack project team was running a coordinated “Global
Hack-In
” on March 1st to work on bugs for the upcoming Essex
release. Several members of the OpenStack Atlanta meetup, sponsored
by DreamHost, met to participate in the hack-in as a group. Since we
don’t have official offices in Atlanta, yet, we gathered over at
Duncan McGreggor’s house
. Brent Scotten has already posted a quick
recap of the day on the OpenStack blog, but I wanted to go into a
little more detail about my experiences preparing my first patch for
the project because for me this was a new code base on a new project
using new version control and code review tools.

Becoming an OpenStack Contributor

The process for signing up to be a contributor to OpenStack isn’t
terribly complicated, but there are a lot of steps and the
instructions are spread out over a couple of different documents. I
took care of subscribing to the required mailing lists and signing the
contributor agreement a couple of weeks ago, but I am including those
steps here along with the technical stuff I did yesterday, to provide
an end-to-end view of the process.

Community

The first set of instructions, in the wiki under HowToContribute,
explains how to join the OpenStack community. I registered an account
on Launchpad, the code hosting service managed by Canonical and
used by Ubuntu and other open source projects. Then I joined all of
the OpenStack projects (Nova, Swift, Glance, and Keystone). Joining
the individual teams under the OpenStack umbrella gave me access to
the project mailing lists, so I can eventually participate in
conversations about designs and implementation details.

Contributor Agreement

Please refer to this wiki page for the current process for signing
the CLA.

Development Environment

I am familiar with source control and virtualization, but not the
specific flavors used for this project. My next step was to set up a
development environment where I could work on the Nova project
documentation, which meant setting up an virtual machine where I could
build the project.

Virtualbox

My desktop system is running Mac OS X 10.7.3 (Lion), and OpenStack is
intended to run on Linux (primarily Ubuntu). To set up an Ubuntu
system for the build, I used virtualbox and vagrant. Duncan and
Mark had already found a Vagrantfile that would set up an Oneiric
image and then use DevStack to deploy all of the parts of OpenStack
into the new VM using these chef cookbooks.

I saved the Vagrantfile to an empty directory and started a VM using
vagrant up. After a short wait while devstack downloaded and
installed all of the dependencies, the VM was ready and running a copy
of OpenStack based on the git repositories created by the devstack
script. The local repositories are created in /opt/stack within
the VM, but I wanted to work in a copy that was mounted via NFS from
the host OS so I could edit under OS X and build in the VM.

I was going to work on Nova, so I cloned its git repository from
github and modified the Vagrantfile to have more RAM and so it
would mount the directory where my source code was checked out using
NFS to /home/vagrant/Devel.

# -*- mode: ruby -*-

Vagrant::Config.run do |config|
  sshdir = "#{ENV['HOME']}/.ssh/"
  cachedir = (ENV['CACHEDIR'] or "/Users/dhellmann/Documents/Devel/openstack-vm/cache")
  checkout = (ENV['COOKBOOKS'] or "/Users/dhellmann/Documents/Devel/openstack-vm/openstack-cookbooks")

  # Make /vagrant an NFS mount instead of using the default setting
  #config.vm.share_folder("v-root", "/vagrant", ".", :nfs => true)

  ip_prefix = (ENV['IP_PREFIX'] or "10.0.5.")
  mac_prefix = (ENV['MAC_PREFIX'] or "080027027")
  suffix = "100"
  ip = "#{ip_prefix}#{suffix}"
  config.vm.box = "oneiric"
  config.vm.box_url = "http://images.ansolabs.com/vagrant/oneiric64.box"
  config.vm.customize ['modifyvm', :id, '--memory', '2048']
  config.vm.network :hostonly, ip, :mac => "#{mac_prefix}#{suffix}"

  config.vm.share_folder("v-cache", "/home/vagrant/cache", cachedir, :nfs => true)
  config.vm.share_folder("v-ssh", "/home/vagrant/.host-ssh", sshdir)
  config.vm.share_folder("v-dev", "/home/vagrant/Devel", "/Users/dhellmann/Documents/Devel/nova-docs",
                         :nfs => true)

  config.vm.forward_port 80, 8080
  config.vm.provision :chef_solo do |chef|
    chef.cookbooks_path = "#{checkout}/cookbooks"
    chef.roles_path = "#{checkout}/roles"
    chef.log_level = :debug
    chef.run_list = [
      "recipe[anso::cache]",
      "recipe[nova::hostname]",
      "recipe[nova::source]",
      #"recipe[anso::settings]", # vim / screen / git settings for testing
    ]
    chef.json.merge!({
      :nova => {
        :source => {
          :mysql_password => "secrete",
          :rabbit_password => "secrete",
          :admin_password => "secrete",
          :service_token => "secrete",
          :flat_interface => "eth1",
          :public_interface => "eth1",
          :floating_range => (ENV['FLOATING'] or "#{ip_prefix}128/28"),
          :host_ip => ip,
        }
      },
    })
  end
end

After restarting the VM (vagrant halt && vagrant up) I was able to
login and switch Nova to use the git repository I had just checked
out:

$ vagrant ssh
$ cd Devel/nova
$ sudo python setup.py develop

I encountered some I/O issues using vagrant ssh to connect to the
VM, so in the end I switched to using ssh directly via the port that
was forwarded using the instructions in the Vagrantfile above and the
key vagrant used when setting up the VM.

$ ssh -i ~/.vagrant.d/insecure_private_key -p 2222 vagrant@127.0.0.1

Building the Documentation

The documentation (and test) build for Nova use a local virtualenv
created within the source tree. The instructions for creating the
virtualenv
are part of the Nova Developer Guide. We all had
issues with timeouts and installation failures of one sort or another
setting up the virtualenv within a virtualbox VM, and I eventually
resorted to installing the dependencies into the virtualenv by hand
using:

$ cd Devel/nova
$ source .venv/bin/activate
(.venv)$ pip install -r tools/pip-requires
(.venv)$ pip install -r tools/test-requires

Sphinx and the other related tools needed to build the documentation
are installed into the virtualenv so that, with the environment
active, it is easy to build the HTML documentation using make:

$ cd doc
$ make

Choosing Something to Fix

It takes Sphinx a while to process all of the documentation, and it
produced a lot of warnings and errors along the way. Duncan and Mark
worked on some bugs in the OpenStack code, but I decided that since I
was new to the tools as well as the code-base I would focus on
shepherding a small documentation change all the way through the
process this time around, to make sure I had everything set up
correctly and that I understood the process. Fixing some of the errors
in the reStructuredText formatting within the documentation met my
criteria nicely.

Tracking Changes

OpenStack uses Launchpad for bug reports and task management.
Launchpad’s operating model uses “blueprints” to group related related
bugs and feature tickets. After studying the errors produced by
Sphinx, I decided that there were basically three causes:

  1. Problems in the automatically generated markup used to produce the

    API guide.

  2. Problems in the manually written markup of the manual.

  3. Problems in the manually written reStructuredText within the Nova

    source code, used when the API guide is generated.

I created one blueprint called sphinx-doc-cleanup to track all of
the changes, and then opened three separate bug tickets to address the
different types of problems. After opening the bugs, I went back to
the blueprint page to associate the new tickets with the blueprint.

I decided to tackle the changes in the order they are listed above,
because the fix for the first one was just a few lines and it would
eliminate several error messages.

Crafting the Fix

When Sphinx runs to build the Nova documentation, the first thing it
does is generate skeleton files for some of the API documentation
using a script called nova/doc/generate_autodoc_index.sh. For each
module that needs to be documented and for which no documentation
exists, a reStructuredText file is emitted containing a header such
as:

The :mod:`nova.wsgi` Module
===========================
.. automodule:: nova.wsgi
   :members:
   :undoc-members:
   :show-inheritance:

The result is that even if there is no special local documentation for
the module, the doc-strings from the code will be processed and
included in the final output.

The bug I found was with the way generate_autodoc_index.sh
calculated the length of the underline to create the reStructuredText
heading. The original version of the script used a single long line of
=, but some of the module names were longer than the line. Rather
than just extend it, I changed the script to calculate the proper
length.

Because this was my first patch, I also added myself to the
Authors file at the top of the Nova source tree so I would be
listed among the project contributors. I committed the change to my
local repository, including the blueprint and bug id in the git commit
message. At that point I was ready to submit the patch for review.

Review Tools and Process

OpenStack uses github to host its code, but the project does not
accept
pull requests in the usual way. Instead, it uses a copy of
Gerrit tied to Launchpad and Jenkins so that changes can be reviewed
by other developers and then run through the test suite before being
merged into the main repository automatically.

The instructions for setting up git to be able to submit change
requests to Gerrit are in the GerritWorkflow page of the OpenStack
wiki. After installing the git-review plug-in described there, I
ran into some trouble authenticating with Gerrit. I finally figured
out that I needed to upload the public half of my my ssh key to the
Gerrit server. I don’t know if it was missing because I did not have
it installed on Launchpad when I authenticated the first time, or if I
would have had to take the extra step anyway. Installing the key
allowed me to complete the setup, though, and then submit my change
for review
with git review.

While I was looking for instructions about how to make sure someone
saw that the change was ready for review, Vish Ishaya reviewed the
change (email notification of reviews are sent to a review mailing
list populated, I assume, from people who have signed up for the
OpenStack Gerrit instance). I ended up needing to modify the git
metadata for my change to use my DreamHost email address instead of my
personal account, but after a bit of back-and-forth on IRC to ask for
another review, Vish approved the change. A little while later the
Jenkins build completed and the change was merged into the main
repository. My first commit was merged!

Final Thoughts

So far I have found the OpenStack community helpful and welcoming. I
especially want to thank Anne Gentle, who assisted me with finding
some of the development setup documentation I needed. I should also
thank Vish Ishaya and Brian Waldon for jumping right on the code
review as soon as I submitted the patch, which made it possible to
achieve my personal goal for the day. As I mentioned above, the
OpenStack developers are using several tools I hadn’t used extensively
before. The tools integrate well, especially those like gerrit that
can use Launchpad for authentication. I am confident that I have
everything I need set up now, which means I can start making more
significant contributions.