components/openstack/keystone/files/keystone-upgrade
author Drew Fisher <drew.fisher@oracle.com>
Wed, 27 May 2015 15:21:04 -0600
branchs11u2-sru
changeset 4380 2ac4d1fcad4a
parent 4217 631d20122b9c
child 4625 18adb92d4193
permissions -rw-r--r--
PSARC/2015/233 OpenStack Common Package 20866995 glance.images table is corrupted/missing on upgrade from 69 to 71 20984895 Upgrade still fails when the mappings change section to 'None' 20984926 nova-upgrade has multiple deprecation mappings for DEFAULT.sql_connection 20990795 OpenStack upgrade methods should preserve some values from the previous release 20992699 Restore OpenStack upgrade services once upgrade bugs are fixed in s12/s11.3 21085479 An openstack-common package should be added to Userland 21150246 MySQL needs more time to come online

#!/usr/bin/python2.6

# Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
#
#    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 glob
import os
from subprocess import check_call, Popen, PIPE
import sys
import traceback

import iniparse
import smf_include
import sqlalchemy

from openstack_common import alter_mysql_tables, create_backups, modify_conf


KEYSTONE_CONF_MAPPINGS = {
    # Deprecated group/name
    ('DEFAULT', 'rabbit_durable_queues'): ('DEFAULT', 'amqp_durable_queues'),
    ('rpc_notifier2', 'topics'): ('DEFAULT', 'notification_topics'),
    ('DEFAULT', 'log_config'): ('DEFAULT', 'log_config_append'),
    ('DEFAULT', 'logfile'): ('DEFAULT', 'log_file'),
    ('DEFAULT', 'logdir'): ('DEFAULT', 'log_dir'),
    ('DEFAULT', 'db_backend'): ('database', 'backend'),
    ('DEFAULT', 'sql_connection'): ('database', 'connection'),
    ('DATABASE', 'sql_connection'): ('database', 'connection'),
    ('sql', 'connection'): ('database', 'connection'),
    ('DEFAULT', 'sql_idle_timeout'): ('database', 'idle_timeout'),
    ('DATABASE', 'sql_idle_timeout'): ('database', 'idle_timeout'),
    ('sql', 'idle_timeout'): ('database', 'idle_timeout'),
    ('DEFAULT', 'sql_min_pool_size'): ('database', 'min_pool_size'),
    ('DATABASE', 'sql_min_pool_size'): ('database', 'min_pool_size'),
    ('DEFAULT', 'sql_max_pool_size'): ('database', 'max_pool_size'),
    ('DATABASE', 'sql_max_pool_size'): ('database', 'max_pool_size'),
    ('DEFAULT', 'sql_max_retries'): ('database', 'max_retries'),
    ('DATABASE', 'sql_max_retries'): ('database', 'max_retries'),
    ('DEFAULT', 'sql_retry_interval'): ('database', 'retry_interval'),
    ('DATABASE', 'reconnect_interval'): ('database', 'retry_interval'),
    ('DEFAULT', 'sql_max_overflow'): ('database', 'max_overflow'),
    ('DATABASE', 'sqlalchemy_max_overflow'): ('database', 'max_overflow'),
    ('DEFAULT', 'sql_connection_debug'): ('database', 'connection_debug'),
    ('DEFAULT', 'sql_connection_trace'): ('database', 'connection_trace'),
    ('DATABASE', 'sqlalchemy_pool_timeout'): ('database', 'pool_timeout'),
    ('ldap', 'tenant_tree_dn'): ('ldap', 'project_tree_dn'),
    ('ldap', 'tenant_filter'): ('ldap', 'project_filter'),
    ('ldap', 'tenant_objectclass'): ('ldap', 'project_objectclass'),
    ('ldap', 'tenant_id_attribute'): ('ldap', 'project_id_attribute'),
    ('ldap', 'tenant_member_attribute'): ('ldap', 'project_member_attribute'),
    ('ldap', 'tenant_name_attribute'): ('ldap', 'project_name_attribute'),
    ('ldap', 'tenant_desc_attribute'): ('ldap', 'project_desc_attribute'),
    ('ldap', 'tenant_enabled_attribute'):
        ('ldap', 'project_enabled_attribute'),
    ('ldap', 'tenant_domain_id_attribute'):
        ('ldap', 'project_domain_id_attribute'),
    ('ldap', 'tenant_attribute_ignore'): ('ldap', 'project_attribute_ignore'),
    ('ldap', 'tenant_allow_create'): ('ldap', 'project_allow_create'),
    ('ldap', 'tenant_allow_update'): ('ldap', 'project_allow_update'),
    ('ldap', 'tenant_allow_delete'): ('ldap', 'project_allow_delete'),
    ('ldap', 'tenant_enabled_emulation'):
        ('ldap', 'project_enabled_emulation'),
    ('ldap', 'tenant_enabled_emulation_dn'):
        ('ldap', 'project_enabled_emulation_dn'),
    ('ldap', 'tenant_additional_attribute_mapping'):
        ('ldap', 'project_additional_attribute_mapping'),
    ('DEFAULT', 'matchmaker_ringfile'): ('matchmaker_ring', 'ringfile'),
}

KEYSTONE_CONF_EXCEPTIONS = [
    ('DEFAULT', 'public_workers'),
    ('DEFAULT', 'admin_workers'),
    ('database', 'connection'),
]


def start():
    # pull out the current version of config/upgrade-id
    p = Popen(['/usr/bin/svcprop', '-p', 'config/upgrade-id',
               os.environ['SMF_FMRI']], stdout=PIPE, stderr=PIPE)
    curr_ver, _err = p.communicate()
    curr_ver = curr_ver.strip()

    # extract the openstack-upgrade-id from the pkg
    p = Popen(['/usr/bin/pkg', 'contents', '-H', '-t', 'set', '-o', 'value',
               '-a', 'name=openstack.upgrade-id',
               'pkg:/cloud/openstack/keystone'], stdout=PIPE, stderr=PIPE)
    pkg_ver, _err = p.communicate()
    pkg_ver = pkg_ver.strip()

    if curr_ver == pkg_ver:
        # No need to upgrade
        sys.exit(smf_include.SMF_EXIT_OK)

    # look for any .new files
    if glob.glob('/etc/keystone/*.new'):
        # the versions are different, so perform an upgrade
        # modify the configuration files

        # backup all the old configuration files
        create_backups('/etc/keystone')

        modify_conf('/etc/keystone/keystone.conf', KEYSTONE_CONF_MAPPINGS,
                    KEYSTONE_CONF_EXCEPTIONS)
        modify_conf('/etc/keystone/keystone-paste.ini')
        modify_conf('/etc/keystone/logging.conf')

    config = iniparse.RawConfigParser()
    config.read('/etc/keystone/keystone.conf')
    # In certain cases the database section does not exist and the
    # default database chosen is sqlite.
    if config.has_section('database'):
        db_connection = config.get('database', 'connection')

        if db_connection.startswith('mysql'):
            engine = sqlalchemy.create_engine(db_connection)
            if engine.url.username != '%SERVICE_USER%':
                alter_mysql_tables(engine)
                print "altered character set to utf8 in keystone tables"

    # update the current version
    check_call(['/usr/sbin/svccfg', '-s', os.environ['SMF_FMRI'], 'setprop',
               'config/upgrade-id', '=', pkg_ver])
    check_call(['/usr/sbin/svccfg', '-s', os.environ['SMF_FMRI'], 'refresh'])

    sys.exit(smf_include.SMF_EXIT_OK)


if __name__ == '__main__':
    os.putenv('LC_ALL', 'C')
    try:
        smf_include.smf_main()
    except RuntimeError:
        sys.exit(smf_include.SMF_EXIT_ERR_FATAL)
    except Exception as err:
        print 'Unknown error:  %s' % err
        print
        traceback.print_exc(file=sys.stdout)
        sys.exit(smf_include.SMF_EXIT_ERR_FATAL)