I use devstack and eclipse pydev to debug openstack services using the remote debugging feature of pydev. I first install openstack using devstack. Then create a new project in eclipse pydev using the code available at /opt/stack/.
Once that is done, all openstack code is available in eclipse pydev.
All openstack services are available as screens and can be checked using the command screen -r
Now let us understand how to debug nova API service.
First check the location of for the directory "pysrc". Generally it is available in /opt/eclipse/plugins/org.python.pydev_2.7.4.2013051601/pysrc
Add this to the python path. This can be done by modifing /nova/nova/cmd/__init__.py
search for the line import sys and then the following line below it
sys.path.append("path to pysrc on your machine")
Next search for line
eventlet.monkey_patch(os=False)
Comment this line and add the following line
eventlet.patcher.monkey_patch(all=False, socket=True, time=True, thread=False)
Once this is done, modify the python file which you want to debug and add the following line where you want the breakpoint
import pydevd;pydevd.settrace('localhost', port=5678, stdoutToServer=True, stderrToServer=True,suspend=True)
Open the debug perspective in eclipse pydev and start the debug server. Check the port on which debug server started. If the port is not 5678, replace the port in the above line of code with the port number on which debug server started
Now you need to restart the nova api service from screen. Enter screen -r
and then goto to nova-api screen (which is screen 5) by entering CTRL+A
followed by 5
.
Once you are in nova-api screen, kill the nova-api service(CTRL+C) and the restart it by pressing "up" arrow and enter.
Once nova-api service is started, try to execute an api which will call the code which has the debug point, and the debug point will be hit.
I tried to debug the nova api stop instance by adding the debug code in the /nova/compute/api.py, definition stop as shown below
def stop(self, context, instance, do_cast=True):
"""Stop an instance."""
LOG.debug(_("Going to try to stop instance"), instance=instance)
import pydevd;pydevd.settrace('localhost', port=5678, stdoutToServer=True, stderrToServer=True,suspend=True)
When I tried to stop an instance, I could get the debug point.
Hope this helps and answer your question.
I have not tried local debugging, Ie starting nova-api service from eclipse. I find remote debuging more easy as all services are already started by devstack.