Le jeu. 10 nov. 2022 à 14:47, Gk Gk <ygk.kmr@gmail.com> a écrit :


---------- Forwarded message ---------
From: Gk Gk <ygk.kmr@gmail.com>
Date: Thu, Nov 10, 2022 at 7:01 PM
Subject: Re: Need assistance
To: <neil@shrug.pw>


The file which is being picked by uwsgi is '../../nova-20.2.1/lib/python3.6/site-packages/nova/api/openstack/compute/wsgi.py' . But I dont see how this file is being called. Which program loads this file ?
Can someone help me here ?

Disregard the abive message.  This is the file I believe is being called "/openstack/venvs//nova-20.2.1/lib/python3.6/site-packages/nova/api/openstack/wsgi.py" .  So how is it being called or which program is calling it ? I want to know the first file which  uwsgi loads after being launched.


You're basically asking how we run our WSGI application in Nova.
As explained below by Neil, we have an entrypoint defined by [1] that helps uwsgi (the WSGI server) to know the WSGI application to run above it.

The source of the entrypoint can be found in [2]. As you can read, it calls the init_application function of the nova.api.openstack.wsgi_app module which itself calls Paste [3] (a library for URL dispatching and WSGI pipelining with middlewares/filters [4]) for deploying the WSGI middlewares and application based on paste.ini config file [5]

As you see, we eventually create the routes using the osapi_compute_app_v21 factory which is defined by nova.api.openstack.compute:APIRouterV21.factory
That's then how the plumbing is made so that when you call the Nova API for an openstack server list, it calls the API with the URL /nova/servers which is routed by the factory, using the routes module [6] (to expose the routes) to the index method in the ServerController [7].

[1] https://github.com/openstack/nova/blob/c97507dfcd57cce9d76670d3b0d48538900c00e9/setup.cfg#L92
[2] https://github.com/openstack/nova/blob/c97507dfcd57cce9d76670d3b0d48538900c00e9/nova/api/openstack/compute/wsgi.py
[3] https://github.com/openstack/nova/blob/c97507dfcd57cce9d76670d3b0d48538900c00e9/nova/api/openstack/wsgi_app.py#L138
[4] https://pythonpaste.readthedocs.io/en/latest/
[5] https://github.com/openstack/nova/blob/c97507dfcd57cce9d76670d3b0d48538900c00e9/etc/nova/api-paste.ini#L33
[6] https://github.com/openstack/nova/blob/c97507dfcd57cce9d76670d3b0d48538900c00e9/nova/api/openstack/compute/routes.py#L743
[7] https://github.com/openstack/nova/blob/c97507dfcd57cce9d76670d3b0d48538900c00e9/nova/api/openstack/compute/servers.py#L122

HTH
-S
 


On Wed, Nov 9, 2022 at 5:28 PM Neil Hanlon <neil@shrug.pw> wrote:


On Wed, Nov 9, 2022, 05:51 Gk Gk <ygk.kmr@gmail.com> wrote:
Thanks Melanie for the reply. I am able to use pdb successfully for the trace. But I am observing a strange behaviour with the python source files. Whenever I make any changes to the source files
, for example, insert a pdb statement in servers.py, it is taking a minute or more for the changes to take effect. For example, after the change, if I run the uwsgi command at the terminal manually with --honour-stdin option,  then immediately if I fire the nova list command, it is not taking effect. Only after a minute or so of making the change, it is taking effect. Somewhat strange.

My next question is, inside the nova-api container, I am trying to trace how nova-api service starts. The systemd file has this content:
---
ExecStart = /openstack/venvs/uwsgi-20.2.1-python3/bin/uwsgi --autoload --ini /etc/uwsgi/nova-api-os-compute.ini
----
So I have checked the file /etc/uwsgi/nova-api-os-compute.ini , which has the below content:
---
wsgi-file = /openstack/venvs/nova-20.2.1/bin/nova-api-wsgi
--

Is the above file '/openstack/venvs/nova-20.2.1/bin/nova-api-wsgi' the one from which the nova-api service starts at all ?

That is correct. The nova-api-wsgi and nova-metadata-wsgi entry points read nova.conf and api-paste.ini to generate the required WSGI application.

Those scripts are just python entry points so you should be able to follow along there, barring some setuptools magic invoked.


Thanks
Kumar

On Wed, Nov 9, 2022 at 5:39 AM melanie witt <melwittt@gmail.com> wrote:
On Tue Nov 08 2022 03:03:18 GMT-0800 (Pacific Standard Time), Gk Gk
<ygk.kmr@gmail.com> wrote:
> Hi All,
>
> I have a OSA setup. I am trying to trace the control flow of nova-api
> using pdb in the file
> "/openstack/venvs/nova-20.2.1/lib/python3.6/site-packages/nova/objects/instance.py".
>
> My goal is to trace the flow for "nova list --all" command. I am
> launching the nova-api service  manually from the command line as follows:
>
> #/openstack/venvs/uwsgi-20.2.1-python3/bin/uwsgi --ini
> /etc/uwsgi/nova-api-os-compute.ini   --workers 1
>
> I am executing "nova list --all" command in another terminal.  I have
> inserted pdb in instance.py as follows:
>
> ----
>      @base.remotable_classmethod
>      def get_all(cls, context, expected_attrs=None):
>          import pdb; pdb.set_trace()
>          """Returns all instances on all nodes."""
>          db_instances = db.instance_get_all(
>                  context, columns_to_join=_expected_cols(expected_attrs))
>          return _make_instance_list(context, cls(), db_instances,
>                                     expected_attrs)
> ---
>
> But when I fire the nova list --all command, I see no pdb prompt being
> shown in the nova-api window. Can anyone help me how to use the pdb to
> trace the flow of control  for "nova list --all" command ?

It looks like running nova-api that way is still running as a background
process:

https://stackoverflow.com/questions/34914704/bdbquit-raised-when-debugging-python-with-pdb

I got that result ^ when I tried it locally.

I was however able to get success with remote pdb:

https://docs.openstack.org/devstack/latest/systemd.html#using-remote-pdb

so maybe give that a try. Note that the code where you set the trace in
nova/objects/instance.py is not actually hit when doing a server list.
You may have instead meant:

https://github.com/openstack/nova/blob/c97507dfcd57cce9d76670d3b0d48538900c00e9/nova/compute/api.py#L2991

Also note that as a community we're trying to get away from using the
legacy 'nova' command and recommend using the openstackclient instead:

https://docs.openstack.org/python-openstackclient/latest/cli/command-objects/server.html#server-list

The 'nova' CLI is no longer being maintained and we're adding to the
novaclient python bindings only when necessary.

HTH,
-melwitt