From 783fa72f481d68962509e708585fea4c163d5bf4 Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Tue, 21 Jul 2020 16:25:40 -0700 Subject: [PATCH] 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 --- .zuul.yaml | 7 +++++++ glance/async_/flows/plugins/image_conversion.py | 2 ++ glance/common/config.py | 9 +++++++++ 3 files changed, 18 insertions(+) diff --git a/.zuul.yaml b/.zuul.yaml index cbbe37896b..9e1a61f0bb 100644 --- a/.zuul.yaml +++ b/.zuul.yaml @@ -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: diff --git a/glance/async_/flows/plugins/image_conversion.py b/glance/async_/flows/plugins/image_conversion.py index 3bfbc4a42e..a5165b0abf 100644 --- a/glance/async_/flows/plugins/image_conversion.py +++ b/glance/async_/flows/plugins/image_conversion.py @@ -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(): diff --git a/glance/common/config.py b/glance/common/config.py index cc5e45ef94..2093117ad6 100644 --- a/glance/common/config.py +++ b/glance/common/config.py @@ -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.""")), ]