Refactor config file generation/modification

This replaces the python script to update swift config files by set
of raw commands or functions in bash.

This also removes the hard-coded storlet-proxy-server.conf and
replaces it by the common internal-client.conf .

Change-Id: I45e92e9323d144230d5850274692c5cbf6aa0014
This commit is contained in:
Takashi Kajinami 2024-01-28 21:53:12 +09:00
parent 1a096cdad6
commit 513f6f777d
5 changed files with 58 additions and 303 deletions

View File

@ -44,6 +44,8 @@ SWIFT_DEFAULT_USER_PWD=testing
SWIFT_MEMBER_USER=tester_member
SWIFT_MEMBER_USER_PWD=member
SWIFT_CONF_DIR=${SWIFT_CONF_DIR:-/etc/swift}
# Storlets install tunables
STORLETS_DEFAULT_USER_DOMAIN_ID=${STORLETS_DEFAULT_USER_DOMAIN_ID:-default}
STORLETS_DEFAULT_PROJECT_DOMAIN_ID=${STORLETS_DEFAULT_PROJECT_DOMAIN_ID:-default}
@ -54,7 +56,6 @@ STORLETS_DOCKER_SWIFT_GROUP_ID=${STORLETS_DOCKER_SWIFT_GROUP_ID:-1003}
STORLETS_DOCKER_SWIFT_USER_ID=${STORLETS_DOCKER_SWIFT_USER_ID:-1003}
STORLETS_SWIFT_RUNTIME_USER=${STORLETS_SWIFT_RUNTIME_USER:-$USER}
STORLETS_SWIFT_RUNTIME_GROUP=${STORLETS_SWIFT_RUNTIME_GROUP:-$USER}
STORLETS_MIDDLEWARE_NAME=storlet_handler
STORLETS_STORLET_CONTAINER_NAME=${STORLETS_STORLET_CONTAINER_NAME:-storlet}
STORLETS_DEPENDENCY_CONTAINER_NAME=${STORLETS_DEPENDENCY_CONTAINER_NAME:-dependency}
STORLETS_LOG_CONTAIER_NAME=${STORLETS_LOG_CONTAIER_NAME:-log}
@ -122,13 +123,8 @@ function configure_swift_and_keystone_for_storlets {
fi
# Modify relevant Swift configuration files
_generate_swift_middleware_conf
_generate_storlet-docker-gateway
sudo python3 devstack/swift_config.py install /tmp/swift_middleware_conf $STORLETS_SWIFT_RUNTIME_USER
rm /tmp/swift_middleware_conf
rm /tmp/storlet-docker-gateway.conf
_modify_swift_conf
_generate_gateway_conf
# Create storlet related containers and set ACLs
start_swift
@ -263,38 +259,57 @@ function install_storlets_code {
cd -
}
function _generate_swift_middleware_conf {
cat <<EOF > /tmp/swift_middleware_conf
[proxy-confs]
proxy_server_conf_file = ${SWIFT_CONF_DIR}/proxy-server.conf
storlet_proxy_server_conf_file = ${SWIFT_CONF_DIR}/storlet-proxy-server.conf
function _modify_swift_conf {
local swift_proxy_config
swift_proxy_config=${SWIFT_CONF_DIR}/proxy-server.conf
iniset ${swift_proxy_config} "filter:storlet_handler" use "egg:storlets#storlet_handler"
iniset ${swift_proxy_config} "filter:storlet_handler" execution_server proxy
iniset ${swift_proxy_config} "filter:storlet_handler" storlet_container $STORLETS_STORLET_CONTAINER_NAME
iniset ${swift_proxy_config} "filter:storlet_handler" storlet_dependency $STORLETS_DEPENDENCY_CONTAINER_NAME
iniset ${swift_proxy_config} "filter:storlet_handler" storlet_log $STORLETS_LOG_CONTAIER_NAME
iniset ${swift_proxy_config} "filter:storlet_handler" storlet_gateway_module $STORLETS_GATEWAY_MODULE
iniset ${swift_proxy_config} "filter:storlet_handler" storlet_gateway_conf $STORLETS_GATEWAY_CONF_FILE
iniset ${swift_proxy_config} "filter:storlet_handler" storlet_execute_on_proxy_only $STORLETS_PROXY_EXECUTION_ONLY
[object-confs]
object_server_conf_files = ${SWIFT_CONF_DIR}/object-server/1.conf
local proxy_pipeline
proxy_pipeline=$(iniget ${swift_proxy_config} "pipeline:main" pipeline)
if ! [[ "${proxy_pipeline}" =~ " storlet_handler copy " ]]; then
proxy_pipeline=$(echo "${proxy_pipeline}" | sed "s/ copy / storlet_handler copy /")
iniset ${swift_proxy_config} "pipeline:main" pipeline "${proxy_pipeline}"
fi
[common-confs]
storlet_middleware = $STORLETS_MIDDLEWARE_NAME
storlet_container = $STORLETS_STORLET_CONTAINER_NAME
storlet_dependency = $STORLETS_DEPENDENCY_CONTAINER_NAME
#storlet_log = $STORLETS_LOG_CONTAIER_NAME
storlet_gateway_module = $STORLETS_GATEWAY_MODULE
storlet_gateway_conf = $STORLETS_GATEWAY_CONF_FILE
storlet_proxy_execution = $STORLETS_PROXY_EXECUTION_ONLY
EOF
local node_number
for node_number in ${SWIFT_REPLICAS_SEQ}; do
local swift_obj_config
local obj_pipeline
swift_obj_config=${SWIFT_CONF_DIR}/object-server/${node_number}.conf
obj_pipeline=$(iniget ${swift_obj_config} "pipeline:main" pipeline)
if ! [[ "${obj_pipeline}" =~ " storlet_handler object-server$" ]]; then
obj_pipeline=$(echo "${obj_pipeline}" | sed "s/ object-server$/ storlet_handler object-server/")
iniset ${swift_obj_config} "pipeline:main" pipeline "${obj_pipeline}"
fi
iniset ${swift_obj_config} "filter:storlet_handler" use "egg:storlets#storlet_handler"
iniset ${swift_obj_config} "filter:storlet_handler" execution_server object
iniset ${swift_obj_config} "filter:storlet_handler" storlet_container $STORLETS_STORLET_CONTAINER_NAME
iniset ${swift_obj_config} "filter:storlet_handler" storlet_dependency $STORLETS_DEPENDENCY_CONTAINER_NAME
iniset ${swift_obj_config} "filter:storlet_handler" storlet_log $STORLETS_LOG_CONTAIER_NAME
iniset ${swift_obj_config} "filter:storlet_handler" storlet_gateway_module $STORLETS_GATEWAY_MODULE
iniset ${swift_obj_config} "filter:storlet_handler" storlet_gateway_conf $STORLETS_GATEWAY_CONF_FILE
iniset ${swift_obj_config} "filter:storlet_handler" storlet_execute_on_proxy_only $STORLETS_PROXY_EXECUTION_ONLY
done
}
function _generate_storlet-docker-gateway {
cat <<EOF > /tmp/storlet-docker-gateway.conf
[DEFAULT]
storlet_logcontainer = $STORLETS_LOG_CONTAIER_NAME
cache_dir = $STORLETS_CACHE_DIR
log_dir = $STORLETS_LOGS_DIR
script_dir = $STORLETS_SCRIPTS_DIR
storlets_dir = $STORLETS_STORLETS_DIR
pipes_dir = $STORLETS_PIPES_DIR
restart_linux_container_timeout = $STORLETS_RESTART_CONTAINER_TIMEOUT
storlet_timeout = $STORLETS_RUNTIME_TIMEOUT
EOF
function _generate_gateway_conf {
iniset ${STORLETS_GATEWAY_CONF_FILE} DEFAULT storlet_logcontainer $STORLETS_LOG_CONTAIER_NAME
iniset ${STORLETS_GATEWAY_CONF_FILE} DEFAULT cache_dir $STORLETS_CACHE_DIR
iniset ${STORLETS_GATEWAY_CONF_FILE} DEFAULT log_dir $STORLETS_LOGS_DIR
iniset ${STORLETS_GATEWAY_CONF_FILE} DEFAULT script_dir $STORLETS_SCRIPTS_DIR
iniset ${STORLETS_GATEWAY_CONF_FILE} DEFAULT storlets_dir $STORLETS_STORLETS_DIR
iniset ${STORLETS_GATEWAY_CONF_FILE} DEFAULT pipes_dir $STORLETS_PIPES_DIR
iniset ${STORLETS_GATEWAY_CONF_FILE} DEFAULT restart_linux_container_timeout $STORLETS_RESTART_CONTAINER_TIMEOUT
iniset ${STORLETS_GATEWAY_CONF_FILE} DEFAULT storlet_timeout $STORLETS_RUNTIME_TIMEOUT
}
function _generate_default_tenant_dockerfile {
@ -355,6 +370,8 @@ function uninstall_storlets {
echo "Cleaning all storlets runtime stuff..."
sudo rm -fr ${STORLETS_DOCKER_DEVICE}
# TODO(tkajinam): Remove config options
# TODO(tkajinam): Remove docker containers/images
}
# Restore xtrace

View File

@ -1,250 +0,0 @@
# Copyright IBM Corp. 2015, 2015 All Rights Reserved
# Copyright (c) 2010-2016 OpenStack Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import configparser
import fileinput
import os
import pwd
import shutil
import sys
swift_run_time_user = None
def _chown_to_swift(path):
global swift_run_time_user
uc = pwd.getpwnam(swift_run_time_user)
os.chown(path, uc.pw_uid, uc.pw_gid)
def _unpatch_pipeline_line(orig_line, storlet_middleware):
mds = list()
for md in orig_line.split():
if md == 'pipeline' or md == '=':
continue
mds.append(md)
if storlet_middleware in mds:
mds.remove(storlet_middleware)
new_line = 'pipeline ='
for md in mds:
new_line += ' ' + md
return new_line + '\n'
def _patch_proxy_pipeline_line(orig_line, storlet_middleware):
mds = list()
for md in orig_line.split():
if md == 'pipeline' or md == '=':
continue
mds.append(md)
if storlet_middleware in mds:
return orig_line
# If there is 'copy' middleware, storlet_hander is placed
# in the left of 'copy' middleware.
try:
copy_index = mds.index('copy')
except Exception:
copy_index = -1
if copy_index != -1:
mds.insert(copy_index, storlet_middleware)
else:
# If there is slo middleware, storlet_hander is placed
# in the left of slo middleware.
try:
slo_index = mds.index('slo')
except Exception:
slo_index = -1
if slo_index != -1:
mds.insert(slo_index, storlet_middleware)
else:
# Otherwise, storlet_hander is placed in the left of proxy-sever.
proxy_index = mds.index('proxy-server')
mds.insert(proxy_index, storlet_middleware)
new_line = 'pipeline ='
for md in mds:
new_line += ' ' + md
return new_line + '\n'
def _patch_object_pipeline_line(orig_line, storlet_middleware):
mds = list()
for md in orig_line.split():
if md == 'pipeline' or md == '=':
continue
mds.append(md)
if storlet_middleware in mds:
return orig_line
object_index = mds.index('object-server')
mds.insert(object_index, storlet_middleware)
new_line = 'pipeline ='
for md in mds:
new_line += ' ' + md
return new_line + '\n'
def unpatch_swift_config_file(conf, conf_file):
storlet_middleware = conf.get('common-confs', 'storlet_middleware')
for line in fileinput.input(conf_file, inplace=1):
if line.startswith('pipeline'):
new_line = _unpatch_pipeline_line(line, storlet_middleware)
line = new_line
sys.stdout.write(line)
_chown_to_swift(conf_file)
def patch_swift_config_file(conf, conf_file, service):
storlet_middleware = conf.get('common-confs', 'storlet_middleware')
filter_block_first_line = '[filter:%s]\n' % storlet_middleware
filter_in_file = False
for line in fileinput.input(conf_file, inplace=1):
if line.startswith('pipeline'):
if service == 'proxy':
new_line = _patch_proxy_pipeline_line(line, storlet_middleware)
else:
new_line = _patch_object_pipeline_line(line,
storlet_middleware)
line = new_line
if filter_block_first_line in line:
filter_in_file = True
sys.stdout.write(line)
if filter_in_file is False:
with open(conf_file, 'a') as f:
f.write('\n')
f.write(filter_block_first_line)
f.write('use = egg:storlets#%s\n' % storlet_middleware)
f.write('storlet_container = %s\n' %
conf.get('common-confs', 'storlet_container'))
f.write('storlet_dependency = %s\n' %
conf.get('common-confs', 'storlet_dependency'))
f.write('storlet_gateway_module = %s\n' %
conf.get('common-confs', 'storlet_gateway_module'))
f.write('storlet_gateway_conf = %s\n' %
conf.get('common-confs', 'storlet_gateway_conf'))
f.write('storlet_execute_on_proxy_only = %s\n' % conf.get(
'common-confs', 'storlet_proxy_execution'))
f.write('execution_server = %s\n' % service)
_chown_to_swift(conf_file)
def unpatch_swift_storlet_proxy_file(conf):
storlet_proxy_server_conf_file = conf.get('proxy-confs',
'storlet_proxy_server_conf_file')
if os.path.exists(storlet_proxy_server_conf_file):
os.remove(storlet_proxy_server_conf_file)
def patch_swift_storlet_proxy_file(conf):
storlet_proxy_server_conf_file = conf.get('proxy-confs',
'storlet_proxy_server_conf_file')
proxy_server_conf_file = conf.get('proxy-confs', 'proxy_server_conf_file')
source_file = proxy_server_conf_file
target_file = storlet_proxy_server_conf_file
shutil.copyfile(source_file, target_file)
for line in fileinput.input(storlet_proxy_server_conf_file, inplace=1):
if line.startswith('pipeline'):
# If there is no proxy-logging in the configuration file, we don't
# want to add it to the pipeline. This may cause invalid internal
# client configuration (we encountered this problem in a fuel swift
# cluster).
if 'proxy-logging' in line:
line = ('pipeline = proxy-logging cache storlet_handler slo '
'proxy-logging proxy-server\n')
else:
line = 'pipeline = cache storlet_handler slo proxy-server\n'
sys.stdout.write(line)
_chown_to_swift(storlet_proxy_server_conf_file)
def remove_gateway_conf_file(conf):
gateway_conf_file = conf.get('common-confs', 'storlet_gateway_conf')
if os.path.exists(gateway_conf_file):
os.remove(gateway_conf_file)
def remove(conf):
object_server_conf_files = conf.get('object-confs',
'object_server_conf_files').split(',')
for f in object_server_conf_files:
if os.path.exists(f):
unpatch_swift_config_file(conf, f)
proxy_server_conf_file = conf.get('proxy-confs', 'proxy_server_conf_file')
unpatch_swift_config_file(conf, proxy_server_conf_file)
unpatch_swift_storlet_proxy_file(conf)
remove_gateway_conf_file(conf)
def install(conf):
object_server_conf_files = conf.get('object-confs',
'object_server_conf_files').split(',')
for f in object_server_conf_files:
if os.path.exists(f):
patch_swift_config_file(conf, f, 'object')
proxy_server_conf_file = conf.get('proxy-confs', 'proxy_server_conf_file')
patch_swift_config_file(conf, proxy_server_conf_file, 'proxy')
patch_swift_storlet_proxy_file(conf)
def usage(argv):
print("Usage: %s %s %s" % (argv[0],
"install/remove conf_file",
"swift_run_time_user"))
def main(argv):
if len(argv) != 4:
usage(argv)
exit(-1)
conf = configparser.ConfigParser()
conf.read(argv[2])
global swift_run_time_user
swift_run_time_user = argv[3]
if argv[1] == 'install':
install(conf)
elif argv[1] == 'remove':
remove(conf)
else:
usage(argv)
if __name__ == "__main__":
main(sys.argv)

View File

@ -306,20 +306,7 @@ with the following content:
docker_repo =
restart_linux_container_timeout = 3
Step 4:
Create and edit the file /etc/swift/storlet-proxy-server.conf:
::
cp /etc/swift/proxy-server.conf /etc/swift/storlet-proxy-server.conf
Change the pipeline in /etc/swift/storlet-proxy-server.conf to be:
::
pipeline = proxy-logging cache slo proxy-logging proxy-server
Step 5: restart swift
Step 4: restart swift
::

View File

@ -205,7 +205,8 @@ class StorletBaseHandler(object):
self.storlet_container = containers['storlet']
self.storlet_dependency = containers['dependency']
self.log_container = containers['log']
self.client_conf_file = '/etc/swift/storlet-proxy-server.conf'
self.ic_conf_path = conf.get('internal_client_conf_path',
'/etc/swift/internal-client.conf')
def _setup_gateway(self):
"""
@ -480,7 +481,7 @@ class StorletBaseHandler(object):
options['file_manager'] = \
SwiftFileManager(self.account, self.storlet_container,
self.storlet_dependency, self.log_container,
self.client_conf_file, self.logger)
self.ic_conf_path, self.logger)
return options

View File

@ -228,7 +228,7 @@ class TestStorletDockerGateway(unittest.TestCase):
# TODO(kota_): should be 'storlet-internal-client.conf' actually
ic_conf_path = os.path.join(self.tempdir,
'storlet-proxy-server.conf')
'internal-client.conf')
with open(ic_conf_path, 'wb') as f:
f.write(b"""
[DEFAULT]