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