When I first started creating custom Mistral actions for TripleO, I quickly found the need to debug them interactively. I wasn’t satisfied with dumping out information to logs and searching through them. I started with creating scripts that used the same code so I could run them directly, but I soon found that approach inadequate. I needed to be able to debug an action that used something internal to Mistral (e.g. mistral.context) or when an action is passing a unit test but fails within a workflow execution. I found myself wanting a solution where you could create a Mistral execution and on any error have it open a pdb session in the shell.
To solve this problem, a coworker suggested remote debugging with pdb. A quick search led to the Remote PDB package. It turned out to be quick and simple to use and it worked immediately without a ton of effort. To use remote-pdb on the undercloud, you need to perform the following steps:
# https://pypi.python.org/pypi/remote-pdb pip install remote-pdb # open port for remote-pdb access on undercloud sudo iptables -A INPUT -p tcp -m multiport --dports 4445 -m comment --comment "remote pdb" -m state --state NEW -j ACCEPT # add two lines to any action you want to debug from remote_pdb import RemotePdb RemotePdb('127.0.0.1', 4445).set_trace() # run action or create exececution mistral run-action tripleo.get_capabilities '{"container": "overcloud"}' # open netcat in another terminal on undercloud nc -C 127.0.0.1 4445