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 move_conf
4285N/A
3998N/A
3998N/ACINDER_CONF_MAPPINGS = {
3998N/A # Deprecated group/name
6847N/A ('DEFAULT', 'host'): ('BACKEND', 'backend_host'),
6847N/A ('DEFAULT', 'glusterfs_sparsed_volumes'):
6847N/A ('DEFAULT', 'nas_volume_prov_type'),
6847N/A ('DEFAULT', 'glusterfs_qcow2_volumes'):
6847N/A ('DEFAULT', 'nas_volume_prov_type'),
6847N/A ('DEFAULT', 'rpc_thread_pool_size'):
6847N/A ('DEFAULT', 'executor_thread_pool_size'),
6847N/A ('DEFAULT', 'netapp_volume_list'):
6847N/A ('DEFAULT', 'netapp_pool_name_search_pattern'),
6847N/A ('DEFAULT', 'netapp_storage_pools'):
6847N/A ('DEFAULT', 'netapp_pool_name_search_pattern'),
6847N/A ('DEFAULT', 'netapp_eseries_host_type'):
6847N/A ('DEFAULT', 'netapp_host_type'),
6847N/A ('DEFAULT', 'storage_vnx_pool_name'):
6847N/A ('DEFAULT', 'storage_vnx_pool_names'),
6847N/A ('DEFAULT', 'notification_driver'):
6847N/A ('oslo_messaging_notifications', 'driver'),
6847N/A ('DEFAULT', 'notification_topics'):
6847N/A ('oslo_messaging_notifications', 'topics'),
6847N/A ('DEFAULT', 'hp3par_api_url'): ('DEFAULT', 'hpe3par_api_url'),
6847N/A ('DEFAULT', 'hp3par_cpg'): ('DEFAULT', 'hp3par_cpg'),
6847N/A ('DEFAULT', 'hp3par_cpg_snap'): ('DEFAULT', 'hpe3par_cpg_snap'),
6847N/A ('DEFAULT', 'hp3par_debug'): ('DEFAULT', 'hpe3par_debug'),
6847N/A ('DEFAULT', 'hp3par_iscsi_chap_enabled'):
6847N/A ('DEFAULT', 'hpe3par_iscsi_chap_enabled'),
6847N/A ('DEFAULT', 'hp3par_debug'): ('DEFAULT', 'hpe3par_debug'),
6847N/A ('DEFAULT', 'hp3par_password'): ('DEFAULT', 'hpe3par_password'),
6847N/A ('DEFAULT', 'hp3par_snapshot_expiration'):
6847N/A ('DEFAULT', 'hpe3par_snapshot_expiration'),
6847N/A ('DEFAULT', 'hp3par_snapshot_retention'):
6847N/A ('DEFAULT', 'hpe3par_snapshot_retention'),
6847N/A ('DEFAULT', 'hp3par_username'): ('DEFAULT', 'hpe3par_username'),
6847N/A ('DEFAULT', 'hplefthand_api_url'): ('DEFAULT', 'hpelefthand_api_url'),
6847N/A ('DEFAULT', 'hplefthand_clustername'):
6847N/A ('DEFAULT', ' hpelefthand_clustername'),
6847N/A ('DEFAULT', 'hplefthand_debug'): ('DEFAULT', 'hpelefthand_debug'),
6847N/A ('DEFAULT', 'hplefthand_iscsi_chap_enabled'):
6847N/A ('DEFAULT', ' hpelefthand_iscsi_chap_enabled'),
6847N/A ('DEFAULT', 'hplefthand_password'): ('DEFAULT', 'hpelefthand_password'),
6847N/A ('DEFAULT', 'hplefthand_username'): ('DEFAULT', 'hpelefthand_username'),
6847N/A ('DEFAULT', 'hpxp_async_copy_check_interval'):
6847N/A ('DEFAULT', 'hpexp_async_copy_check_interval'),
6847N/A ('DEFAULT', 'hpxp_compute_target_ports'):
6847N/A ('DEFAULT', 'hpexp_compute_target_ports'),
6847N/A ('DEFAULT', 'hpxp_copy_check_interval'):
6847N/A ('DEFAULT', 'hpexp_copy_check_interval'),
6847N/A ('DEFAULT', 'hpxp_copy_speed'): ('DEFAULT', 'hpexp_copy_speed'),
6847N/A ('DEFAULT', 'hpxp_default_copy_method'):
6847N/A ('DEFAULT', 'hpexp_default_copy_method'),
6847N/A ('DEFAULT', 'hpxp_group_request'): ('DEFAULT', 'hpexp_group_request'),
6847N/A ('DEFAULT', 'hpxp_horcm_add_conf'): ('DEFAULT', 'hpexp_horcm_add_conf'),
6847N/A ('DEFAULT', 'hpxp_horcm_name_only_discovery'):
6847N/A ('DEFAULT', 'hpexp_horcm_name_only_discovery'),
6847N/A ('DEFAULT', 'hpxp_horcm_numbers'): ('DEFAULT', 'hpexp_horcm_numbers'),
6847N/A ('DEFAULT', 'hpxp_horcm_resource_name'):
6847N/A ('DEFAULT', 'hpexp_horcm_resource_name'),
6847N/A ('DEFAULT', 'hpxp_horcm_user'): ('DEFAULT', 'hpexp_horcm_user'),
6847N/A ('DEFAULT', 'hpxp_ldev_range'): ('DEFAULT', 'hpexp_ldev_range'),
6847N/A ('DEFAULT', 'hpxp_pool'): ('DEFAULT', 'hpexp_pool'),
6847N/A ('DEFAULT', 'hpxp_storage_cli'): ('DEFAULT', 'hpexp_storage_cli'),
6847N/A ('DEFAULT', 'hpxp_storage_id'): ('DEFAULT', 'hpexp_storage_id'),
6847N/A ('DEFAULT', 'hpxp_target_ports'): ('DEFAULT', 'hpexp_target_ports'),
6847N/A ('DEFAULT', 'hpxp_thin_pool'): ('DEFAULT', 'hpexp_thin_pool'),
6847N/A ('DEFAULT', 'hpxp_zoning_request'): ('DEFAULT', 'hpexp_zoning_request'),
6847N/A ('profiler', 'profiler_enabled'): ('profiler', 'enabled'),
6847N/A ('DEFAULT', 'enable_v2_api'): (None, None),
6847N/A ('DEFAULT', 'use_syslog_rfc_format'): (None, None),
6847N/A ('DEFAULT', 'use_syslog'): (None, None),
6847N/A ('hyperv', 'force_volumeutils_v1'): (None, None),
6847N/A ('DEFAULT', 'rpc_zmq_port'): (None, None),
6847N/A ('DEFAULT', 'matchmaker_heartbeat_freq'): (None, None),
6847N/A ('DEFAULT', 'matchmaker_heartbeat_ttl'): (None, None),
6847N/A ('DEFAULT', 'request_timeout'): ('DEFAULT', 'violin_request_timeout'),
6847N/A ('DEFAULT', 'gateway_mga'): (None, None),
6847N/A ('DEFAULT', 'gateway_mgb'): (None, None),
6847N/A ('DEFAULT', 'use_igroups'): (None, None),
6847N/A
6847N/A
3998N/A}
3998N/A
4285N/ACINDER_CONF_EXCEPTIONS = [
4285N/A ('DEFAULT', 'osapi_volume_workers'),
4285N/A ('DEFAULT', 'auth_strategy'),
4285N/A ('DEFAULT', 'san_is_local'),
4285N/A ('DEFAULT', 'volume_driver'),
4285N/A ('database', 'connection'),
4285N/A ('keystone_authtoken', 'auth_uri'),
4285N/A ('keystone_authtoken', 'identity_uri'),
4285N/A ('keystone_authtoken', 'admin_user'),
4285N/A ('keystone_authtoken', 'admin_password'),
4285N/A ('keystone_authtoken', 'admin_tenant_name'),
4285N/A ('keystone_authtoken', 'signing_dir'),
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/cinder'], 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/cinder/*.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/cinder')
4285N/A
3998N/A modify_conf('/etc/cinder/api-paste.ini')
4285N/A
4285N/A modify_conf('/etc/cinder/cinder.conf', CINDER_CONF_MAPPINGS,
4285N/A CINDER_CONF_EXCEPTIONS)
3998N/A
3998N/A config = iniparse.RawConfigParser()
3998N/A config.read('/etc/cinder/cinder.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 cinder 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)