Set file size limit to 50M in the python rumtime image
The original file size limit is too small and not suitable for common user case. This patch changes the file size limit to 50M but it could be configurable in future. Change-Id: Ie48c9374f8eb2b6a15416fb5ec775f6a444063c3 Story: 2002967 Task: 22973
This commit is contained in:
parent
bcdbfb61be
commit
4a4a18f2ec
|
@ -22,7 +22,7 @@ QINLING_CONF_FILE=${QINLING_CONF_DIR}/qinling.conf
|
||||||
QINLING_POLICY_FILE=${QINLING_CONF_DIR}/policy.json
|
QINLING_POLICY_FILE=${QINLING_CONF_DIR}/policy.json
|
||||||
QINLING_AUTH_CACHE_DIR=${QINLING_AUTH_CACHE_DIR:-/var/cache/qinling}
|
QINLING_AUTH_CACHE_DIR=${QINLING_AUTH_CACHE_DIR:-/var/cache/qinling}
|
||||||
QINLING_FUNCTION_STORAGE_DIR=${QINLING_FUNCTION_STORAGE_DIR:-/opt/qinling/function/packages}
|
QINLING_FUNCTION_STORAGE_DIR=${QINLING_FUNCTION_STORAGE_DIR:-/opt/qinling/function/packages}
|
||||||
QINLING_PYTHON_RUNTIME_IMAGE=${QINLING_PYTHON_RUNTIME_IMAGE:-openstackqinling/python-runtime:0.0.4}
|
QINLING_PYTHON_RUNTIME_IMAGE=${QINLING_PYTHON_RUNTIME_IMAGE:-openstackqinling/python-runtime:0.0.5}
|
||||||
QINLING_NODEJS_RUNTIME_IMAGE=${QINLING_NODEJS_RUNTIME_IMAGE:-openstackqinling/nodejs-runtime:0.0.1}
|
QINLING_NODEJS_RUNTIME_IMAGE=${QINLING_NODEJS_RUNTIME_IMAGE:-openstackqinling/nodejs-runtime:0.0.1}
|
||||||
QINLING_SIDECAR_IMAGE=${QINLING_SIDECAR_IMAGE:-openstackqinling/sidecar:0.0.2}
|
QINLING_SIDECAR_IMAGE=${QINLING_SIDECAR_IMAGE:-openstackqinling/sidecar:0.0.2}
|
||||||
|
|
||||||
|
|
|
@ -17,45 +17,53 @@ import os
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
import swiftclient
|
import swiftclient
|
||||||
|
from swiftclient.exceptions import ClientException
|
||||||
|
|
||||||
|
|
||||||
def resize_image(image_path, resized_path):
|
def resize_image(image_path, resized_path):
|
||||||
with Image.open(image_path) as image:
|
with Image.open(image_path) as image:
|
||||||
image.thumbnail((75, 75))
|
image.thumbnail(tuple(x / 4 for x in image.size))
|
||||||
image.save(resized_path)
|
image.save(resized_path)
|
||||||
|
|
||||||
|
|
||||||
def main(context, container, object):
|
def main(context, container_name, object_name):
|
||||||
conn = swiftclient.Connection(
|
conn = swiftclient.Connection(
|
||||||
session=context['os_session'],
|
session=context['os_session'],
|
||||||
os_options={'region_name': 'RegionOne'},
|
os_options={'region_name': 'RegionOne'},
|
||||||
)
|
)
|
||||||
|
|
||||||
new_container = '%s_thumb' % container
|
# Download original image
|
||||||
|
image_path = os.path.abspath('./%s' % object_name)
|
||||||
# Download original photo
|
_, obj_contents = conn.get_object(container_name, object_name)
|
||||||
image_path = '/%s' % object
|
|
||||||
_, obj_contents = conn.get_object(container, object)
|
|
||||||
with open(image_path, 'w') as local:
|
with open(image_path, 'w') as local:
|
||||||
local.write(obj_contents)
|
local.write(obj_contents)
|
||||||
|
|
||||||
print('Downloaded object %s from container %s' % (object, container))
|
print('Downloaded object %s from container %s' %
|
||||||
|
(object_name, container_name))
|
||||||
|
|
||||||
thumb_path = '/thumb_%s' % object
|
thumb_path = os.path.abspath('./%s_resized.png' % object_name)
|
||||||
resize_image(image_path, thumb_path)
|
resize_image(image_path, thumb_path)
|
||||||
|
|
||||||
print('Resized.')
|
print('Resized.')
|
||||||
|
|
||||||
# Upload thumb photo
|
# Create new container if needed
|
||||||
|
new_container_name = '%s_resized' % container_name
|
||||||
|
try:
|
||||||
|
conn.head_container(new_container_name)
|
||||||
|
except ClientException:
|
||||||
|
conn.put_container(new_container_name)
|
||||||
|
print("New container %s created." % new_container_name)
|
||||||
|
|
||||||
|
# Upload resized image
|
||||||
with open(thumb_path, 'r') as new_local:
|
with open(thumb_path, 'r') as new_local:
|
||||||
conn.put_object(
|
conn.put_object(
|
||||||
new_container,
|
new_container_name,
|
||||||
object,
|
object_name,
|
||||||
contents=new_local,
|
contents=new_local,
|
||||||
content_type='text/plain'
|
content_type='text/plain'
|
||||||
)
|
)
|
||||||
|
|
||||||
os.remove(image_path)
|
os.remove(image_path)
|
||||||
os.remove(thumb_path)
|
os.remove(thumb_path)
|
||||||
|
|
||||||
print('Uploaded object %s to container %s' % (object, new_container))
|
print('Uploaded object %s to container %s' %
|
||||||
|
(object_name, new_container_name))
|
||||||
|
|
|
@ -40,7 +40,7 @@ QinlingGroup = [
|
||||||
'publicURL', 'adminURL', 'internalURL'],
|
'publicURL', 'adminURL', 'internalURL'],
|
||||||
help="The endpoint type to use for the qinling service."),
|
help="The endpoint type to use for the qinling service."),
|
||||||
cfg.StrOpt("python_runtime_image",
|
cfg.StrOpt("python_runtime_image",
|
||||||
default="openstackqinling/python-runtime:0.0.4",
|
default="openstackqinling/python-runtime:0.0.5",
|
||||||
help="The Python runtime being used in the tests."),
|
help="The Python runtime being used in the tests."),
|
||||||
cfg.StrOpt("nodejs_runtime_image",
|
cfg.StrOpt("nodejs_runtime_image",
|
||||||
default="openstackqinling/nodejs-runtime:0.0.1",
|
default="openstackqinling/nodejs-runtime:0.0.1",
|
||||||
|
|
|
@ -50,7 +50,8 @@ def _set_ulimit():
|
||||||
customized_limits = {
|
customized_limits = {
|
||||||
resource.RLIMIT_NOFILE: 1024,
|
resource.RLIMIT_NOFILE: 1024,
|
||||||
resource.RLIMIT_NPROC: 128,
|
resource.RLIMIT_NPROC: 128,
|
||||||
resource.RLIMIT_FSIZE: 61440
|
# TODO(lxkong): 50M by default, need to be configurable in future.
|
||||||
|
resource.RLIMIT_FSIZE: 524288000
|
||||||
}
|
}
|
||||||
for t, soft in customized_limits.items():
|
for t, soft in customized_limits.items():
|
||||||
_, hard = resource.getrlimit(t)
|
_, hard = resource.getrlimit(t)
|
||||||
|
|
Loading…
Reference in New Issue