swift-upgrade revision 4312
2ronwalf#!/usr/bin/python2.6
2ronwalf
2ronwalf# Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
2ronwalf#
2ronwalf# Licensed under the Apache License, Version 2.0 (the "License"); you may
2ronwalf# not use this file except in compliance with the License. You may obtain
2ronwalf# a copy of the License at
2ronwalf#
2ronwalf# http://www.apache.org/licenses/LICENSE-2.0
2ronwalf#
2ronwalf# Unless required by applicable law or agreed to in writing, software
2ronwalf# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
2ronwalf# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
2ronwalf# License for the specific language governing permissions and limitations
2ronwalf# under the License.
2ronwalf
2ronwalfimport glob
2ronwalfimport os
2ronwalffrom subprocess import check_call, Popen, PIPE
2ronwalfimport sys
2ronwalfimport traceback
2ronwalf
2ronwalfimport smf_include
2ronwalf
2ronwalffrom openstack_common import create_backups, modify_conf
2ronwalf
2ronwalf
2ronwalfACCOUNT_SERVER_EXCEPTIONS = [
2ronwalf ('DEFAULT', 'bind_port'),
2ronwalf ('DEFAULT', 'workers'),
2ronwalf]
2ronwalf
2ronwalfCONTAINER_SERVER_EXCEPTIONS = [
2ronwalf ('DEFAULT', 'bind_port'),
2ronwalf ('DEFAULT', 'workers'),
2ronwalf]
2ronwalf
2ronwalfDISPERSION_CONF_EXCEPTIONS = [
2ronwalf ('dispersion', 'auth_url'),
2ronwalf ('dispersion', 'auth_user'),
2ronwalf ('dispersion', 'auth_key'),
2ronwalf]
2ronwalf
2ronwalfOBJECT_SERVER_EXCEPTIONS = [
2ronwalf ('DEFAULT', 'bind_port'),
2ronwalf ('DEFAULT', 'workers'),
2ronwalf]
2ronwalf
2ronwalfPROXY_SERVER_EXCEPTIONS = [
2ronwalf ('DEFAULT', 'bind_port'),
2ronwalf ('filter:authtoken', 'auth_uri'),
2ronwalf ('filter:authtoken', 'identity_uri'),
2ronwalf ('filter:authtoken', 'admin_tenant_name'),
2ronwalf ('filter:authtoken', 'admin_user'),
2ronwalf ('filter:authtoken', 'admin_password'),
2ronwalf ('filter:authtoken', 'delay_auth_decision'),
11daenzerorama ('filter:authtoken', 'cache'),
2ronwalf ('filter:authtoken', 'include_service_catalog'),
2ronwalf ('filter:authtoken', 'signing_dir'),
2ronwalf]
2ronwalf
2ronwalfSWIFT_CONF_EXCEPTIONS = [
2ronwalf ('swift-hash', 'swift_hash_path_suffix'),
2ronwalf ('swift-hash', 'swift_hash_path_prefix'),
2ronwalf ('storage-policy:0', 'name'),
2ronwalf ('storage-policy:0', 'default'),
2ronwalf]
2ronwalf
2ronwalf
2ronwalfdef start():
2ronwalf # pull out the current version of config/upgrade-id
2ronwalf p = Popen(['/usr/bin/svcprop', '-p', 'config/upgrade-id',
2ronwalf os.environ['SMF_FMRI']], stdout=PIPE, stderr=PIPE)
2ronwalf curr_ver, _err = p.communicate()
2ronwalf curr_ver = curr_ver.strip()
2ronwalf
2ronwalf # extract the openstack-upgrade-id from the pkg
2ronwalf p = Popen(['/usr/bin/pkg', 'contents', '-H', '-t', 'set', '-o', 'value',
2ronwalf '-a', 'name=openstack.upgrade-id',
2ronwalf 'pkg:/cloud/openstack/swift'], stdout=PIPE, stderr=PIPE)
2ronwalf pkg_ver, _err = p.communicate()
2ronwalf pkg_ver = pkg_ver.strip()
2ronwalf
2ronwalf if curr_ver == pkg_ver:
2ronwalf # No need to upgrade
2ronwalf sys.exit(smf_include.SMF_EXIT_OK)
2ronwalf
2ronwalf # look for any .new files
2ronwalf if glob.glob('/etc/swift/*.new'):
2ronwalf # the versions are different, so perform an upgrade
2ronwalf # modify the configuration files
2ronwalf
2ronwalf # backup all the old configuration files
2ronwalf create_backups('/etc/swift')
2ronwalf
2ronwalf modify_conf('/etc/swift/account-server.conf', None,
2ronwalf ACCOUNT_SERVER_EXCEPTIONS)
2ronwalf modify_conf('/etc/swift/container-reconciler.conf')
2ronwalf modify_conf('/etc/swift/container-server.conf', None,
2ronwalf CONTAINER_SERVER_EXCEPTIONS)
2ronwalf modify_conf('/etc/swift/container-sync-realms.conf')
2ronwalf modify_conf('/etc/swift/dispersion.conf', None,
2ronwalf DISPERSION_CONF_EXCEPTIONS)
2ronwalf modify_conf('/etc/swift/memcache.conf')
2ronwalf modify_conf('/etc/swift/object-expirer.conf')
2ronwalf modify_conf('/etc/swift/object-server.conf', None,
2ronwalf OBJECT_SERVER_EXCEPTIONS)
2ronwalf modify_conf('/etc/swift/proxy-server.conf', None,
2ronwalf PROXY_SERVER_EXCEPTIONS)
2ronwalf modify_conf('/etc/swift/swift.conf', None, SWIFT_CONF_EXCEPTIONS)
2ronwalf
2ronwalf # update the current version
2ronwalf check_call(['/usr/sbin/svccfg', '-s', os.environ['SMF_FMRI'], 'setprop',
2ronwalf 'config/upgrade-id', '=', pkg_ver])
2ronwalf check_call(['/usr/sbin/svccfg', '-s', os.environ['SMF_FMRI'], 'refresh'])
2ronwalf
2ronwalf sys.exit(smf_include.SMF_EXIT_OK)
2ronwalf
2ronwalf
2ronwalfif __name__ == '__main__':
2ronwalf os.putenv('LC_ALL', 'C')
2ronwalf try:
2ronwalf smf_include.smf_main()
2ronwalf except RuntimeError:
2ronwalf sys.exit(smf_include.SMF_EXIT_ERR_FATAL)
2ronwalf except Exception as err:
2ronwalf print 'Unknown error: %s' % err
2ronwalf print
2ronwalf traceback.print_exc(file=sys.stdout)
2ronwalf sys.exit(smf_include.SMF_EXIT_ERR_FATAL)
2ronwalf