Make image conversion use a proper python interpreter for prlimit

The image conversion plugin does a processutils exec(), which needs
to spawn python for prlimit support. Under uwsgi, sys.executable
points to uwsgi itself, which won't work in this case. This introduces
a [wsgi]/python_interpreter config option (because I don't think
there is any way to get this from uwsgi itself) which we use for
the exec. By default, it's sys.executable, which is what is used
right now so nobody should notice a change unless they need it.

Note: Making this depend on the devstack change to remove the wsgi
import restriction so we can get a test on it.

Partial-Bug: #1888713
Change-Id: I7cb2e135d6ea2cb21de55060df3f7bf40b3e64b6
This commit is contained in:
Dan Smith 2020-07-21 16:25:40 -07:00
parent 16a5431c66
commit 783fa72f48
3 changed files with 18 additions and 0 deletions

View File

@ -242,6 +242,13 @@
$GLANCE_API_CONF:
DEFAULT:
enabled_import_methods: "[\"copy-image\", \"glance-direct\"]"
wsgi:
python_interpreter: /usr/bin/python3
$GLANCE_IMAGE_IMPORT_CONF:
image_import_opts:
image_import_plugins: "['image_conversion']"
image_conversion:
output_format: raw
- project:
templates:

View File

@ -70,6 +70,7 @@ class _ConvertImage(task.Task):
self.image_repo = image_repo
self.image_id = image_id
self.dest_path = ""
self.python = CONF.wsgi.python_interpreter
super(_ConvertImage, self).__init__(
name='%s-Convert_Image-%s' % (task_type, task_id))
@ -88,6 +89,7 @@ class _ConvertImage(task.Task):
"--output=json",
src_path,
prlimit=utils.QEMU_IMG_PROC_LIMITS,
python_exec=self.python,
log_errors=putils.LOG_ALL_ERRORS,)
except OSError as exc:
with excutils.save_and_reraise_exception():

View File

@ -19,6 +19,7 @@ Routines for configuring Glance
import logging
import os
import sys
from oslo_config import cfg
from oslo_middleware import cors
@ -578,6 +579,14 @@ too large, you *may* have increased memory footprint per worker and/or you
may overwhelm other system resources such as disk or outbound network
bandwidth. If this is too small, image import requests will have to wait
until a thread becomes available to begin processing.""")),
cfg.StrOpt('python_interpreter',
default=sys.executable,
help=_("""
Path to the python interpreter to use when spawning external
processes. By default this is sys.executable, which should be the
same interpreter running Glance itself. However, in some situations
(i.e. uwsgi) this may not actually point to a python interpreter
itself.""")),
]