Debugging a Custom Mistral Action

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

Reboot, Refresh, Renew

“Think for yourself and let others enjoy the privilege of doing so too.” – Voltaire

 

The last couple of years have been part of a journey that took me away from public writing. My choice of employment at the time came with many constraints that makes sharing your ideas and experiences difficult. My blog had become stale and virtually abandoned. Most of my previous writing was either quickly written or vague. I tried to force myself to write when I really didn’t have the time or wasn’t allowed to write to any level of detail about my projects.

 

Life has changed for me. I recently started working for Red Hat and their company culture based on collaboration, sharing, and open communication is a sharp contrast to the last four years of my career. I love working with a bunch of talented people who are very passionate about what they do.  My work is now in the community; it’s open and available for anyone to see.  It will be exciting to see what unfolds for me in this new phase of my career.

 

I have hopes to write more and to share a voice.  Hopefully the choices of my past haven’t formed bad habits in procrastination too much (I am a developer though).