Merge "Change default value for [wsgi]/python_interpreter"

This commit is contained in:
Zuul 2022-03-02 01:03:52 +00:00 committed by Gerrit Code Review
commit ca6c0681cf
3 changed files with 27 additions and 7 deletions
glance
async_/flows/plugins
common
tests/unit/async_/flows/plugins

@ -15,6 +15,7 @@
import json import json
import os import os
import sys
from oslo_concurrency import processutils as putils from oslo_concurrency import processutils as putils
from oslo_config import cfg from oslo_config import cfg
@ -69,7 +70,7 @@ class _ConvertImage(task.Task):
self.action_wrapper = action_wrapper self.action_wrapper = action_wrapper
self.image_id = action_wrapper.image_id self.image_id = action_wrapper.image_id
self.dest_path = "" self.dest_path = ""
self.python = CONF.wsgi.python_interpreter self.python = CONF.wsgi.python_interpreter or sys.executable
super(_ConvertImage, self).__init__( super(_ConvertImage, self).__init__(
name='%s-Convert_Image-%s' % (task_type, task_id)) name='%s-Convert_Image-%s' % (task_type, task_id))

@ -19,7 +19,6 @@ Routines for configuring Glance
import logging import logging
import os import os
import sys
from oslo_config import cfg from oslo_config import cfg
from oslo_middleware import cors from oslo_middleware import cors
@ -641,13 +640,13 @@ may overwhelm other system resources such as disk or outbound network
bandwidth. If this is too small, image import requests will have to wait bandwidth. If this is too small, image import requests will have to wait
until a thread becomes available to begin processing.""")), until a thread becomes available to begin processing.""")),
cfg.StrOpt('python_interpreter', cfg.StrOpt('python_interpreter',
default=sys.executable, default=None,
help=_(""" help=_("""
Path to the python interpreter to use when spawning external Path to the python interpreter to use when spawning external
processes. By default this is sys.executable, which should be the processes. If left unspecified, this will be sys.executable, which should
same interpreter running Glance itself. However, in some situations be the same interpreter running Glance itself. However, in some situations
(i.e. uwsgi) this may not actually point to a python interpreter (for example, uwsgi) sys.executable may not actually point to a python
itself.""")), interpreter and an alternative value must be set.""")),
] ]

@ -15,6 +15,7 @@
import json import json
import os import os
import sys
from unittest import mock from unittest import mock
import glance_store import glance_store
@ -264,3 +265,22 @@ class TestConvertImageTask(test_utils.BaseTestCase):
os_exists_mock.return_value = True os_exists_mock.return_value = True
image_convert.revert(result=mock.MagicMock()) image_convert.revert(result=mock.MagicMock())
self.assertEqual(1, mock_os_remove.call_count) self.assertEqual(1, mock_os_remove.call_count)
def test_image_convert_interpreter_resolution(self):
# By default, wsgi.python_interpreter is None, which we should
# translate to sys.executable at runtime.
convert = image_conversion._ConvertImage(self.context,
self.task.task_id,
self.task_type,
self.wrapper)
self.assertEqual(sys.executable, convert.python)
# If overridden, we should take the interpreter from config.
fake_interpreter = '/usr/bin/python2.7'
self.config(python_interpreter=fake_interpreter,
group='wsgi')
convert = image_conversion._ConvertImage(self.context,
self.task.task_id,
self.task_type,
self.wrapper)
self.assertEqual(fake_interpreter, convert.python)