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
3998N/A
3998N/AGLANCE_API_MAPPINGS = {
6850N/A # Deprecated from Kilo to Mitaka
5403N/A ('DEFAULT', 'log_format'): (None, None),
5403N/A ('DEFAULT', 'use-syslog'): (None, None),
6850N/A ('DEFAULT', 'rpc_thread_pool_size'):
6850N/A ('DEFAULT', 'executor_thread_pool_size'),
6850N/A ('DEFAULT', 'notification_driver'):
6850N/A ('oslo_messaging_notifications', 'driver'),
6850N/A ('DEFAULT', 'notification_topics'):
6850N/A ('oslo_messaging_notifications', 'topics'),
6850N/A ('glance_store', 'os_region_name'):
6850N/A ('glance_store', 'cinder_os_region_name'),
6850N/A ('keystone_authtoken', 'auth_plugin'):
6850N/A ('keystone_authtoken', 'auth_type'),
6850N/A ('DEFAULT', 'scrubber_datadir'): (None, None),
6850N/A ('DEFAULT', 'cleanup_scrubber'): (None, None),
6850N/A ('DEFAULT', 'cleanup_scrubber_time'): (None, None),
6850N/A ('DEFAULT', 'use_syslog_rfc_format'): (None, None),
6850N/A ('DEFAULT', 'rpc_zmq_port'): (None, None),
6850N/A ('DEFAULT', 'matchmaker_heartbeat_freq'): (None, None),
6850N/A ('DEFAULT', 'matchmaker_heartbeat_ttl'): (None, None),
6850N/A ('glance_store', 'mongodb_store_uri'): (None, None),
6850N/A ('glance_store', 'mongodb_store_db'): (None, None),
3998N/A}
3998N/A
4285N/AGLANCE_API_EXCEPTIONS = [
5717N/A ('DEFAULT', 'admin_tenant_name'),
5717N/A ('DEFAULT', 'admin_user'),
5717N/A ('DEFAULT', 'admin_password'),
4285N/A ('DEFAULT', 'bind_host'),
4285N/A ('DEFAULT', 'bind_port'),
4285N/A ('DEFAULT', 'log_file'),
4285N/A ('DEFAULT', 'backlog'),
4285N/A ('DEFAULT', 'workers'),
4285N/A ('DEFAULT', 'registry_host'),
4285N/A ('DEFAULT', 'registry_port'),
4285N/A ('DEFAULT', 'registry_client_protocol'),
4285N/A ('DEFAULT', 'delayed_delete'),
4285N/A ('DEFAULT', 'scrub_time'),
4285N/A ('DEFAULT', 'scrubber_datadir'),
4285N/A ('DEFAULT', 'image_cache_dir'),
4285N/A ('database', 'connection'),
5403N/A ('paste_deploy', 'flavor'),
4285N/A ('keystone_authtoken', 'auth_uri'),
4285N/A ('keystone_authtoken', 'identity_uri'),
4285N/A ('keystone_authtoken', 'admin_tenant_name'),
4285N/A ('keystone_authtoken', 'admin_user'),
4285N/A ('keystone_authtoken', 'admin_password'),
4285N/A ('keystone_authtoken', 'revocation_cache_time'),
4285N/A ('glance_store', 'filesystem_store_datadir'),
4285N/A ('glance_store', 'swift_store_auth_version'),
4285N/A ('glance_store', 'swift_store_auth_address'),
4285N/A ('glance_store', 'swift_store_user'),
4285N/A ('glance_store', 'swift_store_key'),
4285N/A ('glance_store', 'swift_store_container'),
4285N/A ('glance_store', 'swift_store_create_container_on_put'),
4285N/A ('glance_store', 'swift_store_large_object_size'),
4285N/A ('glance_store', 'swift_store_large_object_chunk_size'),
4285N/A ('glance_store', 's3_store_host'),
4285N/A ('glance_store', 's3_store_create_bucket_on_put'),
4285N/A ('glance_store', 'sheepdog_store_address'),
4285N/A ('glance_store', 'sheepdog_store_port'),
4285N/A ('glance_store', 'sheepdog_store_chunk_size'),
5403N/A ('oslo_messaging_rabbit', 'rabbit_host'),
5403N/A ('oslo_messaging_rabbit', 'rabbit_port'),
5403N/A ('oslo_messaging_rabbit', 'rabbit_use_ssl'),
5403N/A ('oslo_messaging_rabbit', 'rabbit_userid'),
5403N/A ('oslo_messaging_rabbit', 'rabbit_password'),
5403N/A ('oslo_messaging_rabbit', 'rabbit_virtual_host'),
5403N/A ('oslo_messaging_rabbit', 'rabbit_notification_exchange'),
5403N/A ('oslo_messaging_rabbit', 'rabbit_notification_topic'),
5403N/A ('oslo_messaging_rabbit', 'rabbit_durable_queues'),
5403N/A ('oslo_messaging_qpid', 'qpid_notification_exchange'),
5403N/A ('oslo_messaging_qpid', 'qpid_notification_topic'),
5403N/A ('oslo_messaging_qpid', 'qpid_hostname'),
5403N/A ('oslo_messaging_qpid', 'qpid_port'),
5403N/A ('oslo_messaging_qpid', 'qpid_usernamd'),
5403N/A ('oslo_messaging_qpid', 'qpid_password'),
5403N/A ('oslo_messaging_qpid', 'qpid_sasl_mechanisms'),
5403N/A ('oslo_messaging_qpid', 'qpid_reconnect_timeout'),
5403N/A ('oslo_messaging_qpid', 'qpid_reconnect_limit'),
5403N/A ('oslo_messaging_qpid', 'qpid_reconnect_interval_min'),
5403N/A ('oslo_messaging_qpid', 'qpid_reconnect_interval_max'),
5403N/A ('oslo_messaging_qpid', 'qpid_reconnect_interval'),
5403N/A ('oslo_messaging_qpid', 'qpid_heartbeat'),
5403N/A ('oslo_messaging_qpid', 'qpid_protocol'),
5403N/A ('oslo_messaging_qpid', 'qpid_tcp_nodelay'),
4285N/A]
4285N/A
6850N/AGLANCE_CACHE_MAPPINGS = {
6850N/A # Deprecated group/name
6850N/A ('DEFAULT', 'log_format'): (None, None),
6850N/A ('DEFAULT', 'use-syslog'): (None, None),
6850N/A ('DEFAULT', 'use_syslog_rfc_format'): (None, None),
6850N/A}
6850N/A
4285N/AGLANCE_CACHE_EXCEPTIONS = [
4285N/A ('DEFAULT', 'log_file'),
4285N/A ('DEFAULT', 'image_cache_dir'),
4285N/A ('DEFAULT', 'image_cache_stall_time'),
4285N/A ('DEFAULT', 'image_cache_max_size'),
4285N/A ('DEFAULT', 'registry_host'),
4285N/A ('DEFAULT', 'registry_port'),
4285N/A ('DEFAULT', 'auth_url'),
4285N/A ('DEFAULT', 'admin_tenant_name'),
4285N/A ('DEFAULT', 'admin_user'),
4285N/A ('DEFAULT', 'admin_password'),
4285N/A ('DEFAULT', 'filesystem_store_datadir'),
4285N/A]
4285N/A
3998N/AGLANCE_REGISTRY_MAPPINGS = {
6850N/A # Deprecated group/name
6850N/A ('DEFAULT', 'log_format'): (None, None),
6850N/A ('DEFAULT', 'use-syslog'): (None, None),
6850N/A ('DEFAULT', 'rpc_zmq_port'): (None, None),
6850N/A ('DEFAULT', 'matchmaker_heartbeat_freq'): (None, None),
6850N/A ('DEFAULT', 'matchmaker_heartbeat_ttl'): (None, None),
6850N/A ('DEFAULT', 'rpc_thread_pool_size'):
6850N/A ('DEFAULT', 'executor_thread_pool_size'),
6850N/A ('DEFAULT', 'notification_driver'):
6850N/A ('oslo_messaging_notifications', 'driver'),
6850N/A ('DEFAULT', 'notification_topics'):
6850N/A ('oslo_messaging_notifications', 'topics'),
6850N/A ('glance_store', 'mongodb_store_uri'): (None, None),
6850N/A ('glance_store', 'mongodb_store_db'): (None, None),
6850N/A ('glance_store', 'os_region_name'):
6850N/A ('glance_store', 'cinder_os_region_name'),
6850N/A ('keystone_authtoken', 'auth_plugin'):
6850N/A ('keystone_authtoken', 'auth_type'),
3998N/A}
3998N/A
4285N/AGLANCE_REGISTRY_EXCEPTIONS = [
4285N/A ('DEFAULT', 'bind_host'),
5403N/A ('DEFAULT', 'bind_port'),
4285N/A ('DEFAULT', 'log_file'),
4285N/A ('DEFAULT', 'backlog'),
4285N/A ('DEFAULT', 'workers'),
4285N/A ('DEFAULT', 'limit_param_default'),
4285N/A ('database', 'connection'),
4285N/A ('keystone_authtoken', 'auth_uri'),
4285N/A ('keystone_authtoken', 'identity_uri'),
4285N/A ('keystone_authtoken', 'admin_tenant_name'),
4285N/A ('keystone_authtoken', 'admin_user'),
4285N/A ('keystone_authtoken', 'admin_password'),
4285N/A ('keystone_authtoken', 'signing_dir'),
5403N/A ('oslo_messaging_rabbit', 'rabbit_host'),
5403N/A ('oslo_messaging_rabbit', 'rabbit_port'),
5403N/A ('oslo_messaging_rabbit', 'rabbit_use_ssl'),
5403N/A ('oslo_messaging_rabbit', 'rabbit_userid'),
5403N/A ('oslo_messaging_rabbit', 'rabbit_password'),
5403N/A ('oslo_messaging_rabbit', 'rabbit_virtual_host'),
5403N/A ('oslo_messaging_rabbit', 'rabbit_notification_exchange'),
5403N/A ('oslo_messaging_rabbit', 'rabbit_notification_topic'),
5403N/A ('oslo_messaging_rabbit', 'rabbit_durable_queues'),
5403N/A ('oslo_messaging_qpid', 'qpid_notification_exchange'),
5403N/A ('oslo_messaging_qpid', 'qpid_notification_topic'),
5403N/A ('oslo_messaging_qpid', 'qpid_hostname'),
5403N/A ('oslo_messaging_qpid', 'qpid_port'),
5403N/A ('oslo_messaging_qpid', 'qpid_usernamd'),
5403N/A ('oslo_messaging_qpid', 'qpid_password'),
5403N/A ('oslo_messaging_qpid', 'qpid_sasl_mechanisms'),
5403N/A ('oslo_messaging_qpid', 'qpid_reconnect_timeout'),
5403N/A ('oslo_messaging_qpid', 'qpid_reconnect_limit'),
5403N/A ('oslo_messaging_qpid', 'qpid_reconnect_interval_min'),
5403N/A ('oslo_messaging_qpid', 'qpid_reconnect_interval_max'),
5403N/A ('oslo_messaging_qpid', 'qpid_reconnect_interval'),
5403N/A ('oslo_messaging_qpid', 'qpid_heartbeat'),
5403N/A ('oslo_messaging_qpid', 'qpid_protocol'),
5403N/A ('oslo_messaging_qpid', 'qpid_tcp_nodelay'),
4285N/A ('paste_deploy', 'flavor'),
4285N/A]
3998N/A
6850N/AGLANCE_SCRUBBER_MAPPINGS = {
6850N/A # Deprecated group/name
6850N/A ('DEFAULT', 'log_format'): (None, None),
6850N/A ('DEFAULT', 'use_syslog_rfc_format'): (None, None),
6850N/A}
3998N/A
4285N/AGLANCE_SCRUBBER_EXCEPTIONS = [
4285N/A ('DEFAULT', 'log_file'),
4285N/A ('DEFAULT', 'wakeup_time'),
4285N/A ('DEFAULT', 'scrubber_datadir'),
4285N/A ('DEFAULT', 'cleanup_scrubber'),
4285N/A ('DEFAULT', 'cleanup_scrubber_time'),
4285N/A ('DEFAULT', 'registry_host'),
4285N/A ('DEFAULT', 'registry_port'),
4285N/A ('DEFAULT', 'auth_url'),
4285N/A ('DEFAULT', 'admin_tenant_name'),
4285N/A ('DEFAULT', 'admin_user'),
4285N/A ('DEFAULT', 'admin_password'),
4285N/A ('database', 'connection'),
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/glance'], 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/glance/*.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/glance')
4285N/A
4285N/A modify_conf('/etc/glance/glance-api.conf', GLANCE_API_MAPPINGS,
4285N/A GLANCE_API_EXCEPTIONS)
3998N/A modify_conf('/etc/glance/glance-api-paste.ini')
6850N/A modify_conf('/etc/glance/glance-cache.conf', GLANCE_CACHE_MAPPINGS,
6850N/A GLANCE_CACHE_EXCEPTIONS)
3998N/A modify_conf('/etc/glance/glance-registry.conf',
4285N/A GLANCE_REGISTRY_MAPPINGS,
5403N/A exception_list=GLANCE_REGISTRY_EXCEPTIONS)
3998N/A modify_conf('/etc/glance/glance-registry-paste.ini')
4285N/A modify_conf('/etc/glance/glance-scrubber.conf',
6850N/A GLANCE_SCRUBBER_MAPPINGS, GLANCE_SCRUBBER_EXCEPTIONS)
3998N/A
3998N/A config = iniparse.RawConfigParser()
3998N/A config.read('/etc/glance/glance-api.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 glance 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'])
4285N/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)