4623N/A#!/usr/bin/python2.7
4070N/A
6033N/A# Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
4070N/A#
4070N/A# Licensed under the Apache License, Version 2.0 (the "License"); you may
4070N/A# not use this file except in compliance with the License. You may obtain
4070N/A# a copy of the License at
4070N/A#
4070N/A# http://www.apache.org/licenses/LICENSE-2.0
4070N/A#
4070N/A# Unless required by applicable law or agreed to in writing, software
4070N/A# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
4070N/A# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
4070N/A# License for the specific language governing permissions and limitations
4070N/A# under the License.
4070N/A
4070N/Aimport glob
4070N/Aimport os
4070N/Afrom subprocess import check_call, Popen, PIPE
4070N/Aimport sys
4070N/Aimport traceback
4070N/A
4070N/Aimport iniparse
4070N/Aimport smf_include
4070N/Aimport sqlalchemy
4070N/A
4312N/Afrom openstack_common import alter_mysql_tables, create_backups, modify_conf, \
4312N/A move_conf
4312N/A
4070N/A
4070N/ACINDER_CONF_MAPPINGS = {
4070N/A # Deprecated group/name
6033N/A ('DEFAULT', 'eqlx_chap_password'): ('DEFAULT', 'chap_password'),
6033N/A ('DEFAULT', 'eqlx_use_chap'): ('DEFAULT', 'use_chap_auth'),
6033N/A ('DEFAULT', 'eqlx_chap_login'): ('DEFAULT', 'chap_username'),
6033N/A ('DEFAULT', 'host'): ('DEFAULT', 'backend_host'),
4070N/A ('DEFAULT', 'db_backend'): ('database', 'backend'),
6033N/A ('DEFAULT', 'qpid_hostname'):
6033N/A ('oslo_messaging_qpid', 'qpid_hostname'),
6033N/A ('DEFAULT', 'qpid_port'):
6033N/A ('oslo_messaging_qpid', 'qpid_port'),
6033N/A ('DEFAULT', 'qpid_hosts'):
6033N/A ('oslo_messaging_qpid', 'qpid_hosts'),
6033N/A ('DEFAULT', 'qpid_username'):
6033N/A ('oslo_messaging_qpid', 'qpid_username'),
6033N/A ('DEFAULT', 'qpid_password'):
6033N/A ('oslo_messaging_qpid', 'qpid_password'),
6033N/A ('DEFAULT', 'qpid_sasl_mechanisms'):
6033N/A ('oslo_messaging_qpid', 'qpid_sasl_mechanisms'),
6033N/A ('DEFAULT', 'qpid_heartbeat'):
6033N/A ('oslo_messaging_qpid', 'qpid_heartbeat'),
6033N/A ('DEFAULT', 'qpid_protocol'):
6033N/A ('oslo_messaging_qpid', 'qpid_protocol'),
6033N/A ('DEFAULT', 'qpid_tcp_nodelay'):
6033N/A ('oslo_messaging_qpid', 'qpid_tcp_nodelay'),
6033N/A ('DEFAULT', 'qpid_receiver_capacity'):
6033N/A ('oslo_messaging_qpid', 'qpid_receiver_capacity'),
6033N/A ('DEFAULT', 'qpid_topology_version'):
6033N/A ('oslo_messaging_qpid', 'qpid_topology_version'),
6033N/A ('DEFAULT', 'amqp_durable_queues'):
6033N/A ('oslo_messaging_rabbit', 'amqp_durable_queues'),
6033N/A ('DEFAULT', 'amqp_auto_delete'):
6033N/A ('oslo_messaging_rabbit', 'amqp_auto_delete'),
6033N/A ('DEFAULT', 'rpc_conn_pool_size'):
6033N/A ('oslo_messaging_rabbit', 'rpc_conn_pool_size'),
6033N/A ('DEFAULT', 'kombu_ssl_version'):
6033N/A ('oslo_messaging_rabbit', 'kombu_ssl_version'),
6033N/A ('DEFAULT', 'kombu_ssl_keyfile'):
6033N/A ('oslo_messaging_rabbit', 'kombu_ssl_keyfile'),
6033N/A ('DEFAULT', 'kombu_ssl_certfile'):
6033N/A ('oslo_messaging_rabbit', 'kombu_ssl_certfile'),
6033N/A ('DEFAULT', 'kombu_ssl_ca_certs'):
6033N/A ('oslo_messaging_rabbit', 'kombu_ssl_ca_certs'),
6033N/A ('DEFAULT', 'kombu_reconnect_delay'):
6033N/A ('oslo_messaging_rabbit', 'kombu_reconnect_delay'),
6033N/A ('DEFAULT', 'rabbit_host'):
6033N/A ('oslo_messaging_rabbit', 'rabbit_host'),
6033N/A ('DEFAULT', 'rabbit_port'):
6033N/A ('oslo_messaging_rabbit', 'rabbit_port'),
6033N/A ('DEFAULT', 'rabbit_hosts'):
6033N/A ('oslo_messaging_rabbit', 'rabbit_hosts'),
6033N/A ('DEFAULT', 'rabbit_use_ssl'):
6033N/A ('oslo_messaging_rabbit', 'rabbit_use_ssl'),
6033N/A ('DEFAULT', 'rabbit_userid'):
6033N/A ('oslo_messaging_rabbit', 'rabbit_userid'),
6033N/A ('DEFAULT', 'rabbit_password'):
6033N/A ('oslo_messaging_rabbit', 'rabbit_password'),
6033N/A ('DEFAULT', 'rabbit_login_method'):
6033N/A ('oslo_messaging_rabbit', 'rabbit_login_method'),
6033N/A ('DEFAULT', 'rabbit_virtual_host'):
6033N/A ('oslo_messaging_rabbit', 'rabbit_virtual_host'),
6033N/A ('DEFAULT', 'rabbit_retry_interval'):
6033N/A ('oslo_messaging_rabbit', 'rabbit_retry_interval'),
6033N/A ('DEFAULT', 'rabbit_retry_backoff'):
6033N/A ('oslo_messaging_rabbit', 'rabbit_retry_backoff'),
6033N/A ('DEFAULT', 'rabbit_max_retries'):
6033N/A ('oslo_messaging_rabbit', 'rabbit_max_retries'),
6033N/A ('DEFAULT', 'rabbit_ha_queues'):
6033N/A ('oslo_messaging_rabbit', 'rabbit_ha_queues'),
6033N/A ('DEFAULT', 'fake_rabbit'):
6033N/A ('oslo_messaging_rabbit', 'fake_rabbit'),
6033N/A ('DEFAULT', 'osapi_max_request_body_size'):
6033N/A ('oslo_middleware', 'max_request_body_size'),
6033N/A ('DEFAULT', 'log-format'): (None, None),
6033N/A ('DEFAULT', 'use-syslog'): (None, None),
6033N/A ('DEFAULT', 'datera_api_token'): (None, None),
6033N/A ('DEFAULT', 'enable_v1_api'): (None, None),
6033N/A ('DEFAULT', 'log_format'): (None, None),
4070N/A}
4070N/A
4312N/ACINDER_CONF_EXCEPTIONS = [
4312N/A ('DEFAULT', 'osapi_volume_workers'),
4312N/A ('DEFAULT', 'auth_strategy'),
4312N/A ('DEFAULT', 'san_is_local'),
4312N/A ('DEFAULT', 'volume_driver'),
4312N/A ('database', 'connection'),
4312N/A ('keystone_authtoken', 'auth_uri'),
4312N/A ('keystone_authtoken', 'identity_uri'),
4312N/A ('keystone_authtoken', 'admin_user'),
4312N/A ('keystone_authtoken', 'admin_password'),
4312N/A ('keystone_authtoken', 'admin_tenant_name'),
4312N/A ('keystone_authtoken', 'signing_dir'),
4312N/A]
4070N/A
4070N/A
4070N/Adef start():
4070N/A # pull out the current version of config/upgrade-id
4070N/A p = Popen(['/usr/bin/svcprop', '-p', 'config/upgrade-id',
4070N/A os.environ['SMF_FMRI']], stdout=PIPE, stderr=PIPE)
4070N/A curr_ver, _err = p.communicate()
4070N/A curr_ver = curr_ver.strip()
4070N/A
4070N/A # extract the openstack-upgrade-id from the pkg
4070N/A p = Popen(['/usr/bin/pkg', 'contents', '-H', '-t', 'set', '-o', 'value',
4070N/A '-a', 'name=openstack.upgrade-id',
4070N/A 'pkg:/cloud/openstack/cinder'], stdout=PIPE, stderr=PIPE)
4070N/A pkg_ver, _err = p.communicate()
4070N/A pkg_ver = pkg_ver.strip()
4070N/A
4070N/A if curr_ver == pkg_ver:
4070N/A # No need to upgrade
4070N/A sys.exit(smf_include.SMF_EXIT_OK)
4070N/A
4070N/A # look for any .new files
4070N/A if glob.glob('/etc/cinder/*.new'):
4070N/A # the versions are different, so perform an upgrade
4070N/A # modify the configuration files
4312N/A
4312N/A # backup all the old configuration files
4312N/A create_backups('/etc/cinder')
4312N/A
4070N/A modify_conf('/etc/cinder/api-paste.ini')
4312N/A
4312N/A modify_conf('/etc/cinder/cinder.conf', CINDER_CONF_MAPPINGS,
4312N/A CINDER_CONF_EXCEPTIONS)
4070N/A
4070N/A config = iniparse.RawConfigParser()
4070N/A config.read('/etc/cinder/cinder.conf')
4070N/A # In certain cases the database section does not exist and the
4070N/A # default database chosen is sqlite.
4070N/A if config.has_section('database'):
4070N/A db_connection = config.get('database', 'connection')
4070N/A
4070N/A if db_connection.startswith('mysql'):
4070N/A engine = sqlalchemy.create_engine(db_connection)
4070N/A if engine.url.username != '%SERVICE_USER%':
4070N/A alter_mysql_tables(engine)
4070N/A print "altered character set to utf8 in cinder tables"
4070N/A
4070N/A # update the current version
4070N/A check_call(['/usr/sbin/svccfg', '-s', os.environ['SMF_FMRI'], 'setprop',
4070N/A 'config/upgrade-id', '=', pkg_ver])
4070N/A check_call(['/usr/sbin/svccfg', '-s', os.environ['SMF_FMRI'], 'refresh'])
4070N/A
4070N/A sys.exit(smf_include.SMF_EXIT_OK)
4070N/A
4070N/A
4070N/Aif __name__ == '__main__':
4070N/A os.putenv('LC_ALL', 'C')
4070N/A try:
4070N/A smf_include.smf_main()
4312N/A except RuntimeError:
4312N/A sys.exit(smf_include.SMF_EXIT_ERR_FATAL)
4070N/A except Exception as err:
4070N/A print 'Unknown error: %s' % err
4070N/A print
4070N/A traceback.print_exc(file=sys.stdout)
4070N/A sys.exit(smf_include.SMF_EXIT_ERR_FATAL)