When I was much younger and foolish (last month), I tried to debug neutron network creation, by inserting ‘import pdb; pdb.set_trace()’ to  /usr/lib/python2.7/site-packages/neutron/db/db_base_plugin_v2.py and simply create network, waiting for pdb to take action. But that didn’t happen. I had to guess it will not work since neutron-server starts as a daemon, and not owned by the terminal. So using the pdb.set_trace() had no effect.

The right way would be to start neutron-server directly and not by starting the service. Don’t worry, we’ll do it together. step by step.

Stop neutron-server

I’m assuming you are debugging live environment. In my case I debugged environment installed with packstack.

So before running neutron-server directly, we need to ensure the current process is not active. Do it with the following comamnd:

Make sure it really stopped using one of the following commands:

You should inactive/dead if using systemctl. Using the ps command, you should see nothing.

Add pdb.set_trace()

Quick note: this step could be the first one. The order here is not important.

In order to debug network creation, we need to add the pdb in the desired code block.

The network creation resides in /usr/lib/python2.7/site-packages/neutron/db/db_base_plugin_v2.py, in the function:  def create_network(self, context, network).

Let’s add there ‘import pdb; pdb.set_trace()”:

Don’t forget to save the file =)

Run neutron-server

pdb is in place, all that left now is to run neutron-server directly so all the server output spilled right to our terminal.

Check what command used to to run the server. If you are using distribution with systemd, you should check in ‘/usr/lib/systemd/system/neutron-server.service’. If your system is not using systemd, it’s probably in /etc/init.d/neutron-server.

You should find something similar to the following command:

Run it from your terminal. You should see a lot of output starting to get spilled.

Let the debugging begin!

You are ready to go! Open anther terminal and connect the same server in which you started neutrons-server directly.

Now create new network:

Hop in to the second terminal. You should see the output flood stopped and pdb is waiting for you to debug this code 🙂

Back to origins

You’ve completed the debugging and you would like to revert changes and run server in normal state.

All you have to do is to stop the running of neutron-server, remove pdb from source code and run neutron-server with: