Posted by: John Bresnahan | January 24, 2013

Debugging OpenStack with pycharm and pydevd

Introduction

For years I was a strict vi user who peered warily at clickety-clack IDEs. I wrote mostly C code and happily used gdb for debugging.  Then I got involved with a large Java project and working on it with anything other than IDEA was an avalanche of lost productivity.  From there I decided to try out pycharm for my python work and I really liked it.  I now look back on my arrogant stance against IDEs and wonder how much more I could have accomplished were I to use tools outside of the Luddite code.  The main feature of interest for me is its integrated debugger.

OpenStack recently accepted two patches to Glance and Keystone which allow for remote debugging via pydevd.   You can run a pycharm debugger on one machine and Glance/Keystone (and hopefully more to come) services on another.  When the service starts up it will connect back to the pycharm debugger providing all the joys of local integrated debugging on a remotely running service.

That said, in this post I will only address the case where the debugger and the service run on the same machine (or at least on machines that share the same file system).  I will address any questions about a real remote setup in comments or a later post.

Pycharm Setup

Much of this is explained in this post, however I will summarize it here with what worked for me.  The first thing to do is create a pycharm project.

  1. checkout Glance from git
  2. start pycharm (install it first ;-) ) and create the glance project
    • File->Open Directory->Select your directory

Next set up a remote debugger for the project.  Bring up the debug configurations window by clicking on Run -> Edit Configurations.  You should now see something like that is below:

ren_debug_window

Click on the “+” in the upper left corner and select Python Remote Debugging.  Make sure Local host name: is set to “localhost” and Port: is set to 5678.  Set the name at the top to Remote.  It should look like the following:

remote_debug_setup

Click OK. Finally start up the debugger with Run -> Debug Remote, or by clicking on the icon in the top center that looks like the following:

debug_arrow

In the bottom pane of pycharm you should now see the text:

Starting debug server at port 5678
Waiting for connection...

Python Setup

The pydev libraries must be installed into the python environment which will run the OpenStack services.  Find the file pycharm-debug.egg under the directory where you installed pycharm.  It should be in the top-level directory.  Now do the following:

  1. cd <python installation that will run glance>/lib/python2.7/site-packages
  2. unzip <installation of pycharm>/pycharm-debug.egg

pydev should now be installed.

OpenStack Service Setup

In two earlier posts I explained how to manually setup Glance and Keystone development environments.  Have that setup (or whatever works for you) and make sure that you have code that includes the needed patches reviewed here and here.

Keystone Configuration

Run keystone-all from the command line with the following two options:

  1. –pydev-debug-host localhost
  2. –pydev-debug-port 5678
keystone-all --pydev-debug-host localhost  --pydev-debug-port 5678

Once it starts up the debug console in pycharm should show some messages notifying you that

Glance Configuration

With Glance you can set up debugging for either the glance-api server or the glance-registry server.

To set up glance-api debugging open up the glance-api.conf file and make sure the following are set:

pydev_worker_debug_host = localhost
workers = 1

The workers line is important because glance can use many worker processes, however the debugger can only handle one connection.

To set up debugging for glance-registry open glance-registry.conf and make sure the following is set:

pydev_worker_debug_host = localhost

Note: you can only debug one of the services at a time, so do not set the pydev_worker_debug_host option in both files at the same time.

Run the service (either glance-api or glance-registry) and notice how it connects back to pycharm for debugging.

About these ads

Responses

  1. komobo and dbpg also can do it..:)

    • Yep! I am sure there are lots of good ways.

  2. […] debugger (hey jetbrains, wanna hook a bruddah up with a free open source license?).  In a previous blog I talked about how to get that running.  I will review and expand on that a bit […]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: