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.
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.
- checkout Glance from git
- 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:
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:
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:
In the bottom pane of pycharm you should now see the text:
Starting debug server at port 5678 Waiting for connection...
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:
- cd <python installation that will run glance>/lib/python2.7/site-packages
- 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.
Run keystone-all from the command line with the following two options:
- –pydev-debug-host localhost
- –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
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.