components/openstack/swift/files/swift-upgrade
author Drew Fisher <drew.fisher@oracle.com>
Tue, 19 May 2015 13:51:17 -0700
branchs11-update
changeset 4314 96c1b7e2e45c
parent 4207 787ed839f409
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 21085479 An openstack-common package should be added to Userland

#!/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 smf_include

from openstack_common import create_backups, modify_conf


ACCOUNT_SERVER_EXCEPTIONS = [
    ('DEFAULT', 'bind_port'),
    ('DEFAULT', 'workers'),
]

CONTAINER_SERVER_EXCEPTIONS = [
    ('DEFAULT', 'bind_port'),
    ('DEFAULT', 'workers'),
]

DISPERSION_CONF_EXCEPTIONS = [
    ('dispersion', 'auth_url'),
    ('dispersion', 'auth_user'),
    ('dispersion', 'auth_key'),
]

OBJECT_SERVER_EXCEPTIONS = [
    ('DEFAULT', 'bind_port'),
    ('DEFAULT', 'workers'),
]

PROXY_SERVER_EXCEPTIONS = [
    ('DEFAULT', 'bind_port'),
    ('filter:authtoken', 'auth_uri'),
    ('filter:authtoken', 'identity_uri'),
    ('filter:authtoken', 'admin_tenant_name'),
    ('filter:authtoken', 'admin_user'),
    ('filter:authtoken', 'admin_password'),
    ('filter:authtoken', 'delay_auth_decision'),
    ('filter:authtoken', 'cache'),
    ('filter:authtoken', 'include_service_catalog'),
    ('filter:authtoken', 'signing_dir'),
]

SWIFT_CONF_EXCEPTIONS = [
    ('swift-hash', 'swift_hash_path_suffix'),
    ('swift-hash', 'swift_hash_path_prefix'),
    ('storage-policy:0', 'name'),
    ('storage-policy:0', 'default'),
]


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/swift'], 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/swift/*.new'):
        # the versions are different, so perform an upgrade
        # modify the configuration files

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

        modify_conf('/etc/swift/account-server.conf', None,
                    ACCOUNT_SERVER_EXCEPTIONS)
        modify_conf('/etc/swift/container-reconciler.conf')
        modify_conf('/etc/swift/container-server.conf', None,
                    CONTAINER_SERVER_EXCEPTIONS)
        modify_conf('/etc/swift/container-sync-realms.conf')
        modify_conf('/etc/swift/dispersion.conf', None,
                    DISPERSION_CONF_EXCEPTIONS)
        modify_conf('/etc/swift/memcache.conf')
        modify_conf('/etc/swift/object-expirer.conf')
        modify_conf('/etc/swift/object-server.conf', None,
                    OBJECT_SERVER_EXCEPTIONS)
        modify_conf('/etc/swift/proxy-server.conf', None,
                    PROXY_SERVER_EXCEPTIONS)
        modify_conf('/etc/swift/swift.conf', None, SWIFT_CONF_EXCEPTIONS)

    # 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)