Skip to content

How to debug pfcon, pman, and pfioh in containers using pudb

Arnav Nidumolu edited this page Sep 1, 2020 · 5 revisions

Debugging pfcon, pman, and pfioh Containerized Services with pudb

Abstract

This page documents the steps required to set up a python debugger within pfcon, pfioh, and pman docker containers.

Introduction

In order to debug pfcon, pfioh, and pman, changes have to be made to the docker-compose.yml and the source code of a particular service also has to be modified.

Preconditions

Assuming that we want to debug pman, its source code has to be modified first. Then the docker-compose.yml should be updated accordingly. Let's assume that the pman has been cloned at the same directory level as pfcon.

Add Python Debugger within the Source Code of pman

Let's add a debugger within the processPOST method of Listener class in pman/pman.py.

pman/pman.py

from pudb import set_trace; set_trace()

Enable input stream and Interaction with the container

In the pfcon directory, modify the docker-compose.yml file. Add these two lines just above the labels: section of the pman_service:

stdin_open: true
tty: true

In the same file, add the following line to the volumes: section in pman_service:

- ../pman/pman/pman.py:/usr/local/lib/python3.8/dist-packages/pman/pman.py

In summary, the pman_service section of docker-compose.yml should look something similar to this:

  pman_service:
    environment:
      - STOREBASE
    image:  ${PMANREPO}/pman${TAG}
    command: ["--rawmode", "1", "--http", "--port", "5010", "--listeners", "12", "--verbosity", "1"]
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ./FS/remote:/hostFS/storeBase
      - ../pman/pman/pman.py:/usr/local/lib/python3.8/dist-packages/pman/pman.py
    ports:
      - "5010:5010"
    stdin_open: true
    tty: true
    labels:
      name: "pman"
      role: "pman service"

Debug setup

The simplest way to debug is to open two terminals. In one container, the make script would be executed. In the other container, the pman_service can be debugged.

Stop services and restart in interactive mode

Terminal 1 Terminal 2
./unmake.sh ; # ( Wait for the final pfcon container to start )
sudo rm -fr FS ; docker attach pfcon_pman_service_1
rm -fr FS ;
./make.sh

Run a Sample Pfcon Hello Command

Create a HOST_IP Variable

export HOST_IP=$(ip route | grep -v docker | awk '{if(NF==11) print $9}' | head -n 1)

pfurl Hello Command

Execute the hello command on pfcon which would then execute pfioh and pman hello and return the response.

pfurl --verb POST --raw --http ${HOST_IP}:5005/api/v1/cmd   \
        --httpResponseBodyParse --jsonwrapper 'payload' --msg \
'{  "action": "hello",
    "meta": {
                "askAbout":     "sysinfo",
                "echoBack":      "Hi there!",
                "service":       "host"
            }
}'

Conclusion

Assuming satisfied preconditions, a PuDB console should open in Terminal 2, where docker attach was executed.