keystone-upgrade revision 5403
4049N/A#!/usr/bin/python2.7
3998N/A
5403N/A# Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
3998N/A#
3998N/A# Licensed under the Apache License, Version 2.0 (the "License"); you may
3998N/A# not use this file except in compliance with the License. You may obtain
3998N/A# a copy of the License at
3998N/A#
3998N/A# http://www.apache.org/licenses/LICENSE-2.0
3998N/A#
3998N/A# Unless required by applicable law or agreed to in writing, software
3998N/A# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
3998N/A# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
3998N/A# License for the specific language governing permissions and limitations
3998N/A# under the License.
3998N/A
3998N/Aimport glob
3998N/Aimport os
3998N/Afrom subprocess import check_call, Popen, PIPE
3998N/Aimport sys
3998N/Aimport traceback
3998N/A
3998N/Aimport iniparse
3998N/Aimport smf_include
3998N/Aimport sqlalchemy
3998N/A
4285N/Afrom openstack_common import alter_mysql_tables, create_backups, modify_conf
4285N/A
3998N/A
3998N/AKEYSTONE_CONF_MAPPINGS = {
3998N/A # Deprecated group/name
5403N/A ('DEFAULT', 'admin_bind_host'): ('eventlet_server', 'admin_bind_host'),
5403N/A ('DEFAULT', 'admin_workers'): ('eventlet_server', 'admin_workers'),
5403N/A ('DEFAULT', 'admin_port'): ('eventlet_server', 'admin_port'),
5403N/A ('DEFAULT', 'tcp_keepidle'): ('eventlet_server', 'tcp_keepidle'),
5403N/A ('ssl', 'cert_required'): ('eventlet_server_ssl', 'cert_required'),
5403N/A ('DEFAULT', 'public_port'): ('eventlet_server', 'public_port'),
5403N/A ('DEFAULT', 'public_bind_host'): ('eventlet_server', 'public_bind_host'),
5403N/A ('DEFAULT', 'tcp_keepalive'): ('eventlet_server', 'tcp_keepalive'),
5403N/A ('DEFAULT', 'public_workers'): ('eventlet_server', 'public_workers'),
5403N/A ('ssl', 'keyfile'): ('eventlet_server_ssl', 'keyfile'),
5403N/A ('ssl', 'ca_certs'): ('eventlet_server_ssl', 'ca_certs'),
5403N/A ('ssl', 'enable'): ('eventlet_server_ssl', 'enable'),
5403N/A ('ssl', 'certfile'): ('eventlet_server_ssl', 'certfile'),
5403N/A ('DEFAULT', 'max_request_body_size'):
5403N/A ('oslo_middleware', 'max_request_body_size'),
5403N/A ('assignment', 'list_limit'): ('resource', 'list_limit'),
5403N/A ('assignment', 'caching'): ('resource', 'caching'),
5403N/A ('assignment', 'cache_time'): ('resource', 'cache_time'),
5403N/A ('token', 'revocation_cache_time'): ('revoke', 'cache_time'),
5403N/A ('DEFAULT', 'log-format'): (None, None),
5403N/A ('DEFAULT', 'use-syslog'): (None, None),
3998N/A}
3998N/A
4285N/AKEYSTONE_CONF_EXCEPTIONS = [
5403N/A ('eventlet_server', 'public_workers'),
5403N/A ('eventlet_server', 'admin_workers'),
4285N/A ('database', 'connection'),
4285N/A]
3998N/A
3998N/A
3998N/Adef start():
3998N/A # pull out the current version of config/upgrade-id
3998N/A p = Popen(['/usr/bin/svcprop', '-p', 'config/upgrade-id',
3998N/A os.environ['SMF_FMRI']], stdout=PIPE, stderr=PIPE)
3998N/A curr_ver, _err = p.communicate()
3998N/A curr_ver = curr_ver.strip()
3998N/A
3998N/A # extract the openstack-upgrade-id from the pkg
3998N/A p = Popen(['/usr/bin/pkg', 'contents', '-H', '-t', 'set', '-o', 'value',
3998N/A '-a', 'name=openstack.upgrade-id',
3998N/A 'pkg:/cloud/openstack/keystone'], stdout=PIPE, stderr=PIPE)
3998N/A pkg_ver, _err = p.communicate()
3998N/A pkg_ver = pkg_ver.strip()
3998N/A
3998N/A if curr_ver == pkg_ver:
3998N/A # No need to upgrade
3998N/A sys.exit(smf_include.SMF_EXIT_OK)
3998N/A
3998N/A # look for any .new files
3998N/A if glob.glob('/etc/keystone/*.new'):
3998N/A # the versions are different, so perform an upgrade
3998N/A # modify the configuration files
4285N/A
4285N/A # backup all the old configuration files
4285N/A create_backups('/etc/keystone')
4285N/A
4285N/A modify_conf('/etc/keystone/keystone.conf', KEYSTONE_CONF_MAPPINGS,
4285N/A KEYSTONE_CONF_EXCEPTIONS)
3998N/A modify_conf('/etc/keystone/keystone-paste.ini')
3998N/A modify_conf('/etc/keystone/logging.conf')
3998N/A
3998N/A config = iniparse.RawConfigParser()
3998N/A config.read('/etc/keystone/keystone.conf')
3998N/A # In certain cases the database section does not exist and the
3998N/A # default database chosen is sqlite.
3998N/A if config.has_section('database'):
3998N/A db_connection = config.get('database', 'connection')
3998N/A
3998N/A if db_connection.startswith('mysql'):
3998N/A engine = sqlalchemy.create_engine(db_connection)
3998N/A if engine.url.username != '%SERVICE_USER%':
3998N/A alter_mysql_tables(engine)
3998N/A print "altered character set to utf8 in keystone tables"
3998N/A
3998N/A # update the current version
3998N/A check_call(['/usr/sbin/svccfg', '-s', os.environ['SMF_FMRI'], 'setprop',
3998N/A 'config/upgrade-id', '=', pkg_ver])
3998N/A check_call(['/usr/sbin/svccfg', '-s', os.environ['SMF_FMRI'], 'refresh'])
3998N/A
3998N/A sys.exit(smf_include.SMF_EXIT_OK)
3998N/A
3998N/A
3998N/Aif __name__ == '__main__':
3998N/A os.putenv('LC_ALL', 'C')
3998N/A try:
3998N/A smf_include.smf_main()
4285N/A except RuntimeError:
4285N/A sys.exit(smf_include.SMF_EXIT_ERR_FATAL)
3998N/A except Exception as err:
3998N/A print 'Unknown error: %s' % err
3998N/A print
3998N/A traceback.print_exc(file=sys.stdout)
3998N/A sys.exit(smf_include.SMF_EXIT_ERR_FATAL)