How do i trace a particular terminal command?
Question: In Openstack, lets say for example, i'm entering the command and i start up an
instance using the image myimage and use flavor 1.

    
    
    nova boot --image myimage --flavor 1 server1 
    

How can i actually trace this command and get details like what functions are
executed since the code is in python, which files it enters while executing
the command etc.,

Sorry i'm a linux noob and i'm trying to find ways to trace few calls. Instead
of doing this by going through all the files and doing this.

Is there a simple way to do this?


Answer: If you want to trace a regular Python program, take a look at the [Python
trace module](http://docs.python.org/2/library/trace.html).

However, I don't think you will find tracing useful to understand what
OpenStack is doing in the example you provided:

    
    
    nova boot --image myimage --flavor 1 server1 
    

OpenStack is not implemented as a single Python program. It is implemented as
a collection of Python programs that run as Linux services in separate
processes, and typically these processes are distributed across multiple
machines.

The `nova` program is just a small client program that makes requests against
an OpenStack endpoint over HTTP. When you do the request above, the following
services are involved. Note that most of the OpenStack "Services" are actually
implemented by multiple Linux "services" (aka daemons). These are the
OpenStack Services and Linux services/daemons involved when you do a `nova
boot`.

  * Identity Service (keystone) 
    * _keystone_
  * Compute Service (nova) 
    * _nova-api_
    * _nova-scheduler_
    * _nova-compute_
    * _nova-network_ (if not using the new Network Service (quantum))
  * Image Service (glance) 
    * _glance-api_
    * _glance-registry_

Note that if the new Network service (quantum) were involved, there would be
even more services involved here.

OpenStack does inter-process communication using two mechanisms:

  * HTTP (using REST API) for communication across OpenStack project boundaries (e.g., communication between the Compute service and the Image service)
  * AMQP-based message queue (typically RabbitMQ, but could be Qpid or ZeroMQ) for communication across services within a single OpenStack project (e.g, communication between _nova-api_ and _nova-compute_)

_The services also share information via a database, but that isn't important
if you're interested in tracing the thread of control_.

For the example you gave with `nova boot`, note all of the interactions that
occur across services:

  1. _nova_ client makes a request over HTTP against the Identity service (keystone), passing username and password and getting a token
  2. _nova_ client makes a request over HTTP against the Compute service (_nova-api_) to [create a new server](http://docs.openstack.org/api/openstack-compute/2/content/CreateServers.html).
  3. _nova-api_ makes a request over the message queue to _nova-scheduler_ to run an instance.
  4. _nova-scheduler_ selects a compute host and makes a request over the message queue to _nova-compute_ on that host to boot a new virtual machine instance.
  5. _nova-compute_ makes a request over the message queue to _nova-network_ to do network configuration for the new instance.
  6. _nova-compute_ makes a request over HTTP against the Image Service (_glance-api_) for the virtual machine image file.
  7. _glance-api_ makes a request over HTTP against _glance-registry_ to retrieve the file from the image backend.

If you wanted to generate a trace that encompasses all of the OpenStack code
involved, you would have to trace each service involved.

I'd recommend just reading the code rather than trying to do automated traces.
You can also look at the log files, since they contain a lot of debug
information. Take a look at the recently released [OpenStack Operations
Guide](http://docs.openstack.org/ops/) for some guidance on how to read the
log files.

