From 253aaec4bbe7190ba34f8470996562ada79abefa Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Tue, 25 Feb 2025 00:30:24 +0900 Subject: [PATCH] Use consistent program name for wsgi scripts and entry points Make sure that the consistent program name is always set,so that the same config sub-directory ( /etc/{project}/{prog}.conf.d ) is used regardless of the way api service is run. Closes-Bug: #2098514 Change-Id: Ib5c6d431176b83eefafddc1b35589015db6dfd04 Signed-off-by: Takashi Kajinami --- nova/api/openstack/wsgi_app.py | 11 +++++++---- nova/config.py | 3 ++- nova/tests/unit/api/openstack/test_wsgi_app.py | 7 ++++--- nova/tests/unit/api/test_wsgi_loader.py | 5 +++-- nova/wsgi/metadata.py | 3 ++- nova/wsgi/osapi_compute.py | 3 ++- releasenotes/notes/bug-2098514-c0adc143c7b70ee8.yaml | 12 ++++++++++++ 7 files changed, 32 insertions(+), 12 deletions(-) create mode 100644 releasenotes/notes/bug-2098514-c0adc143c7b70ee8.yaml diff --git a/nova/api/openstack/wsgi_app.py b/nova/api/openstack/wsgi_app.py index 9e5d911ffe..026a17f74c 100644 --- a/nova/api/openstack/wsgi_app.py +++ b/nova/api/openstack/wsgi_app.py @@ -98,14 +98,17 @@ def error_application(exc, name): @utils.run_once('Global data already initialized, not re-initializing.', LOG.info) -def init_global_data(conf_files, service_name): +def init_global_data(conf_files, service_name, prog): # NOTE(melwitt): parse_args initializes logging and calls global rpc.init() # and db_api.configure(). The db_api.configure() call does not initiate any # connection to the database. # NOTE(gibi): sys.argv is set by the wsgi runner e.g. uwsgi sets it based # on the --pyargv parameter of the uwsgi binary - config.parse_args(sys.argv, default_config_files=conf_files) + config.parse_args( + sys.argv, + default_config_files=conf_files, + prog=prog) logging.setup(CONF, "nova") gmr_opts.set_defaults(CONF) @@ -119,7 +122,7 @@ def init_global_data(conf_files, service_name): @utils.latch_error_on_raise(retryable=(odbe.DBConnectionError,)) -def init_application(name): +def init_application(name, prog): conf_files = _get_config_files() # NOTE(melwitt): The init_application method can be called multiple times @@ -128,7 +131,7 @@ def init_application(name): # apache/mod_wsgi reloads the init_application script. So, we initialize # global data separately and decorate the method to run only once in a # python interpreter instance. - init_global_data(conf_files, name) + init_global_data(conf_files, name, prog) try: _setup_service(CONF.host, name) diff --git a/nova/config.py b/nova/config.py index c0fce224c3..5e8330141d 100644 --- a/nova/config.py +++ b/nova/config.py @@ -79,7 +79,7 @@ def set_log_defaults(): def parse_args(argv, default_config_files=None, configure_db=True, - init_rpc=True): + init_rpc=True, prog=None): log.register_options(CONF) # NOTE(sean-k-mooney): this filter addresses bug #1825584 @@ -94,6 +94,7 @@ def parse_args(argv, default_config_files=None, configure_db=True, CONF(argv[1:], project='nova', + prog=prog, version=version.version_string(), default_config_files=default_config_files) diff --git a/nova/tests/unit/api/openstack/test_wsgi_app.py b/nova/tests/unit/api/openstack/test_wsgi_app.py index b744e4e269..3549b4c39c 100644 --- a/nova/tests/unit/api/openstack/test_wsgi_app.py +++ b/nova/tests/unit/api/openstack/test_wsgi_app.py @@ -82,13 +82,13 @@ document_root = /tmp # Run init_application the first time, simulating an exception being # raised during it. self.assertRaises(test.TestingException, wsgi_app.init_application, - 'nova-api') + 'nova-api', 'nova-api') # reset the latch_error_on_raise decorator wsgi_app.init_application.reset() # Now run init_application a second time, it should succeed since no # exception is being raised (the init of global data should not be # re-attempted). - wsgi_app.init_application('nova-api') + wsgi_app.init_application('nova-api', 'nova-api') self.assertIn('Global data already initialized, not re-initializing.', self.stdlog.logger.output) @@ -106,7 +106,8 @@ document_root = /tmp error, test.TestingException, test.TestingException] for i in range(3): e = self.assertRaises( - excepted_type, wsgi_app.init_application, 'nova-api') + excepted_type, wsgi_app.init_application, 'nova-api', + 'nova-api') self.assertIs(e, error) # since the expction is latched on the first raise mock_get_files # should not be called again on each iteration diff --git a/nova/tests/unit/api/test_wsgi_loader.py b/nova/tests/unit/api/test_wsgi_loader.py index 5d4c6a3c96..7ff3fabf51 100644 --- a/nova/tests/unit/api/test_wsgi_loader.py +++ b/nova/tests/unit/api/test_wsgi_loader.py @@ -31,8 +31,9 @@ class TestInitApplication(test.NoDBTestCase): with utils.temporary_mutation(sys, argv=mock.sentinel.argv): with mock.patch('nova.config.parse_args') as mock_parse_args: - wsgi_app.init_application('test-app') + wsgi_app.init_application('test-app', 'test-app') mock_parse_args.assert_called_once_with( mock.sentinel.argv, default_config_files=[ - '/etc/nova/api-paste.ini', '/etc/nova/nova.conf']) + '/etc/nova/api-paste.ini', '/etc/nova/nova.conf'], + prog='test-app') diff --git a/nova/wsgi/metadata.py b/nova/wsgi/metadata.py index cd7817c2ef..31e88c7103 100644 --- a/nova/wsgi/metadata.py +++ b/nova/wsgi/metadata.py @@ -20,9 +20,10 @@ import threading from nova.api.openstack import wsgi_app NAME = "metadata" +PROG = "nova-api-metadata" application = None lock = threading.Lock() with lock: if application is None: - application = wsgi_app.init_application(NAME) + application = wsgi_app.init_application(NAME, PROG) diff --git a/nova/wsgi/osapi_compute.py b/nova/wsgi/osapi_compute.py index 53c759e42d..b37dbbe46b 100644 --- a/nova/wsgi/osapi_compute.py +++ b/nova/wsgi/osapi_compute.py @@ -20,9 +20,10 @@ import threading from nova.api.openstack import wsgi_app NAME = "osapi_compute" +PROG = "nova-api-os-compute" application = None lock = threading.Lock() with lock: if application is None: - application = wsgi_app.init_application(NAME) + application = wsgi_app.init_application(NAME, PROG) diff --git a/releasenotes/notes/bug-2098514-c0adc143c7b70ee8.yaml b/releasenotes/notes/bug-2098514-c0adc143c7b70ee8.yaml new file mode 100644 index 0000000000..7924ccb8b3 --- /dev/null +++ b/releasenotes/notes/bug-2098514-c0adc143c7b70ee8.yaml @@ -0,0 +1,12 @@ +--- +fixes: + - | + [`bug 2098514 _`] Fixed + the per-service configuration directories for the API wsgi modules + (``nova.wsgi.osapi_compute`` and ``nova.wsgi.metadata``), unexpectedly + affected by the application servers hosting these. Now these modules use + the following per-service configuration directories regardless of + the application server used. + + - ``nova.wsgi.osapi_compute``: ``/etc/nova/nova-api-os-compute.d`` + - ``nova.wsgi.metadata``: ``/etc/nova/nova-api-metadata.d``