glance-upgrade revision 5403
0N/A#!/usr/bin/python2.7
5298N/A
0N/A# Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
0N/A#
0N/A# Licensed under the Apache License, Version 2.0 (the "License"); you may
0N/A# not use this file except in compliance with the License. You may obtain
2362N/A# a copy of the License at
0N/A#
2362N/A# http://www.apache.org/licenses/LICENSE-2.0
0N/A#
0N/A# Unless required by applicable law or agreed to in writing, software
0N/A# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
0N/A# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
0N/A# License for the specific language governing permissions and limitations
0N/A# under the License.
0N/A
0N/Aimport glob
0N/Aimport os
0N/Afrom subprocess import check_call, Popen, PIPE
0N/Aimport sys
2362N/Aimport traceback
2362N/A
2362N/Aimport iniparse
0N/Aimport smf_include
0N/Aimport sqlalchemy
0N/A
0N/Afrom openstack_common import alter_mysql_tables, create_backups, modify_conf
0N/A
0N/A
0N/AGLANCE_API_MAPPINGS = {
0N/A # Deprecated group/name
0N/A ('DEFAULT', 'container_formats'): ('image_format', 'container_formats'),
0N/A ('DEFAULT', 'disk_formats'): ('image_format', 'disk_formats'),
0N/A ('DEFAULT', 'matchmaker_ringfile'): ('matchmaker_ring', 'ringfile'),
0N/A ('DEFAULT', 'rabbit_durable_queues'): ('oslo_messaging_qpid',
0N/A 'amqp_durable_queues'),
0N/A ('DEFAULT', 'qpid_hostname'): ('oslo_messaging_qpid', 'qpid_hostname'),
0N/A ('DEFAULT', 'qpid_port'): ('oslo_messaging_qpid', 'qpid_port'),
0N/A ('DEFAULT', 'qpid_username'): ('oslo_messaging_qpid', 'qpid_username'),
5298N/A ('DEFAULT', 'qpid_password'): ('oslo_messaging_qpid', 'qpid_password'),
0N/A ('DEFAULT', 'qpid_sasl_mechanisms'): ('oslo_messaging_qpid',
0N/A 'qpid_sasl_mechanisms'),
0N/A ('DEFAULT', 'qpid_heartbeat'): ('oslo_messaging_qpid', 'qpid_heartbeat'),
0N/A ('DEFAULT', 'qpid_protocol'): ('oslo_messaging_qpid', 'qpid_protocol'),
0N/A ('DEFAULT', 'qpid_tcp_nodelay'): ('oslo_messaging_qpid',
0N/A 'qpid_tcp_nodelay'),
0N/A ('DEFAULT', 'rabbit_host'): ('oslo_messaging_rabbit', 'rabbit_host'),
0N/A ('DEFAULT', 'rabbit_port'): ('oslo_messaging_rabbit', 'rabbit_port'),
0N/A ('DEFAULT', 'rabbit_use_ssl'): ('oslo_messaging_rabbit', 'rabbit_use_ssl'),
0N/A ('DEFAULT', 'rabbit_userid'): ('oslo_messaging_rabbit', 'rabbit_userid'),
0N/A ('DEFAULT', 'rabbit_password'): ('oslo_messaging_rabbit',
0N/A 'rabbit_password'),
0N/A ('DEFAULT', 'rabbit_virtual_host'): ('oslo_messaging_rabbit',
0N/A 'rabbit_virtual_host'),
0N/A ('task', 'eventlet_executor_pool_size'):
0N/A ('taskflow_executor', 'max_workers'),
0N/A ('DEFAULT', 'log-format'): (None, None),
5298N/A ('DEFAULT', 'log_format'): (None, None),
5298N/A ('DEFAULT', 'use-syslog'): (None, None),
5298N/A ('glance_store', 'vmware_datacenter_path'): (None, None),
5298N/A ('glance_store', 'vmware_datastore_name'): (None, None),
5298N/A}
5298N/A
0N/AGLANCE_API_EXCEPTIONS = [
0N/A ('DEFAULT', 'bind_host'),
0N/A ('DEFAULT', 'bind_port'),
0N/A ('DEFAULT', 'log_file'),
0N/A ('DEFAULT', 'backlog'),
0N/A ('DEFAULT', 'workers'),
0N/A ('DEFAULT', 'registry_host'),
0N/A ('DEFAULT', 'registry_port'),
0N/A ('DEFAULT', 'registry_client_protocol'),
0N/A ('DEFAULT', 'delayed_delete'),
0N/A ('DEFAULT', 'scrub_time'),
0N/A ('DEFAULT', 'scrubber_datadir'),
0N/A ('DEFAULT', 'image_cache_dir'),
0N/A ('database', 'connection'),
0N/A ('paste_deploy', 'flavor'),
0N/A ('keystone_authtoken', 'auth_uri'),
0N/A ('keystone_authtoken', 'identity_uri'),
0N/A ('keystone_authtoken', 'admin_tenant_name'),
0N/A ('keystone_authtoken', 'admin_user'),
0N/A ('keystone_authtoken', 'admin_password'),
0N/A ('keystone_authtoken', 'revocation_cache_time'),
0N/A ('glance_store', 'filesystem_store_datadir'),
0N/A ('glance_store', 'swift_store_auth_version'),
0N/A ('glance_store', 'swift_store_auth_address'),
0N/A ('glance_store', 'swift_store_user'),
0N/A ('glance_store', 'swift_store_key'),
0N/A ('glance_store', 'swift_store_container'),
5298N/A ('glance_store', 'swift_store_create_container_on_put'),
5298N/A ('glance_store', 'swift_store_large_object_size'),
5298N/A ('glance_store', 'swift_store_large_object_chunk_size'),
5298N/A ('glance_store', 's3_store_host'),
0N/A ('glance_store', 's3_store_create_bucket_on_put'),
0N/A ('glance_store', 'sheepdog_store_address'),
5298N/A ('glance_store', 'sheepdog_store_port'),
5298N/A ('glance_store', 'sheepdog_store_chunk_size'),
5298N/A ('oslo_messaging_rabbit', 'rabbit_host'),
5298N/A ('oslo_messaging_rabbit', 'rabbit_port'),
5298N/A ('oslo_messaging_rabbit', 'rabbit_use_ssl'),
5298N/A ('oslo_messaging_rabbit', 'rabbit_userid'),
5298N/A ('oslo_messaging_rabbit', 'rabbit_password'),
5298N/A ('oslo_messaging_rabbit', 'rabbit_virtual_host'),
5298N/A ('oslo_messaging_rabbit', 'rabbit_notification_exchange'),
5298N/A ('oslo_messaging_rabbit', 'rabbit_notification_topic'),
5298N/A ('oslo_messaging_rabbit', 'rabbit_durable_queues'),
5298N/A ('oslo_messaging_qpid', 'qpid_notification_exchange'),
5298N/A ('oslo_messaging_qpid', 'qpid_notification_topic'),
0N/A ('oslo_messaging_qpid', 'qpid_hostname'),
5298N/A ('oslo_messaging_qpid', 'qpid_port'),
5298N/A ('oslo_messaging_qpid', 'qpid_usernamd'),
5298N/A ('oslo_messaging_qpid', 'qpid_password'),
5298N/A ('oslo_messaging_qpid', 'qpid_sasl_mechanisms'),
0N/A ('oslo_messaging_qpid', 'qpid_reconnect_timeout'),
5298N/A ('oslo_messaging_qpid', 'qpid_reconnect_limit'),
5298N/A ('oslo_messaging_qpid', 'qpid_reconnect_interval_min'),
5298N/A ('oslo_messaging_qpid', 'qpid_reconnect_interval_max'),
5298N/A ('oslo_messaging_qpid', 'qpid_reconnect_interval'),
5298N/A ('oslo_messaging_qpid', 'qpid_heartbeat'),
5298N/A ('oslo_messaging_qpid', 'qpid_protocol'),
5298N/A ('oslo_messaging_qpid', 'qpid_tcp_nodelay'),
5298N/A]
5298N/A
5298N/AGLANCE_CACHE_EXCEPTIONS = [
5298N/A ('DEFAULT', 'log_file'),
5298N/A ('DEFAULT', 'image_cache_dir'),
0N/A ('DEFAULT', 'image_cache_stall_time'),
5298N/A ('DEFAULT', 'image_cache_max_size'),
0N/A ('DEFAULT', 'registry_host'),
0N/A ('DEFAULT', 'registry_port'),
0N/A ('DEFAULT', 'auth_url'),
0N/A ('DEFAULT', 'admin_tenant_name'),
0N/A ('DEFAULT', 'admin_user'),
0N/A ('DEFAULT', 'admin_password'),
0N/A ('DEFAULT', 'filesystem_store_datadir'),
0N/A]
0N/A
0N/AGLANCE_REGISTRY_MAPPINGS = {
0N/A # Deprecate group/name
0N/A ('DEFAULT', 'rabbit_durable_queues'): ('oslo_messaging_qpid',
0N/A 'rabbit_durable_queues'),
0N/A ('DEFAULT', 'qpid_hostname'): ('oslo_messaging_qpid', 'qpid_hostname'),
0N/A ('DEFAULT', 'qpid_port'): ('oslo_messaging_qpid', 'qpid_port'),
0N/A ('DEFAULT', 'qpid_username'): ('oslo_messaging_qpid', 'qpid_username'),
0N/A ('DEFAULT', 'qpid_password'): ('oslo_messaging_qpid', 'qpid_password'),
0N/A ('DEFAULT', 'qpid_sasl_mechanisms'): ('oslo_messaging_qpid',
0N/A 'qpid_sasl_mechanisms'),
0N/A ('DEFAULT', 'qpid_heartbeat'): ('oslo_messaging_qpid', 'qpid_heartbeat'),
0N/A ('DEFAULT', 'qpid_protocol'): ('oslo_messaging_qpid', 'qpid_protocol'),
0N/A ('DEFAULT', 'qpid_tcp_nodelay'): ('oslo_messaging_qpid',
0N/A 'qpid_tcp_nodelay'),
0N/A ('DEFAULT', 'rabbit_host'): ('oslo_messaging_rabbit', 'rabbit_host'),
0N/A ('DEFAULT', 'rabbit_port'): ('oslo_messaging_rabbit', 'rabbit_port'),
0N/A ('DEFAULT', 'rabbit_use_ssl'): ('oslo_messaging_rabbit', 'rabbit_use_ssl'),
0N/A ('DEFAULT', 'rabbit_userid'): ('oslo_messaging_rabbit', 'rabbit_userid'),
0N/A ('DEFAULT', 'rabbit_password'): ('oslo_messaging_rabbit',
0N/A 'rabbit_password'),
0N/A ('DEFAULT', 'rabbit_virtual_host'): ('oslo_messaging_rabbit',
0N/A 'rabbit_virtual_host'),
0N/A}
0N/A
0N/AGLANCE_REGISTRY_EXCEPTIONS = [
0N/A ('DEFAULT', 'bind_host'),
0N/A ('DEFAULT', 'bind_port'),
0N/A ('DEFAULT', 'log_file'),
0N/A ('DEFAULT', 'backlog'),
0N/A ('DEFAULT', 'workers'),
0N/A ('DEFAULT', 'limit_param_default'),
0N/A ('database', 'connection'),
0N/A ('keystone_authtoken', 'auth_uri'),
0N/A ('keystone_authtoken', 'identity_uri'),
0N/A ('keystone_authtoken', 'admin_tenant_name'),
0N/A ('keystone_authtoken', 'admin_user'),
0N/A ('keystone_authtoken', 'admin_password'),
0N/A ('keystone_authtoken', 'signing_dir'),
0N/A ('oslo_messaging_rabbit', 'rabbit_host'),
0N/A ('oslo_messaging_rabbit', 'rabbit_port'),
0N/A ('oslo_messaging_rabbit', 'rabbit_use_ssl'),
0N/A ('oslo_messaging_rabbit', 'rabbit_userid'),
0N/A ('oslo_messaging_rabbit', 'rabbit_password'),
0N/A ('oslo_messaging_rabbit', 'rabbit_virtual_host'),
0N/A ('oslo_messaging_rabbit', 'rabbit_notification_exchange'),
0N/A ('oslo_messaging_rabbit', 'rabbit_notification_topic'),
0N/A ('oslo_messaging_rabbit', 'rabbit_durable_queues'),
0N/A ('oslo_messaging_qpid', 'qpid_notification_exchange'),
0N/A ('oslo_messaging_qpid', 'qpid_notification_topic'),
0N/A ('oslo_messaging_qpid', 'qpid_hostname'),
0N/A ('oslo_messaging_qpid', 'qpid_port'),
0N/A ('oslo_messaging_qpid', 'qpid_usernamd'),
0N/A ('oslo_messaging_qpid', 'qpid_password'),
0N/A ('oslo_messaging_qpid', 'qpid_sasl_mechanisms'),
0N/A ('oslo_messaging_qpid', 'qpid_reconnect_timeout'),
0N/A ('oslo_messaging_qpid', 'qpid_reconnect_limit'),
0N/A ('oslo_messaging_qpid', 'qpid_reconnect_interval_min'),
0N/A ('oslo_messaging_qpid', 'qpid_reconnect_interval_max'),
0N/A ('oslo_messaging_qpid', 'qpid_reconnect_interval'),
0N/A ('oslo_messaging_qpid', 'qpid_heartbeat'),
0N/A ('oslo_messaging_qpid', 'qpid_protocol'),
0N/A ('oslo_messaging_qpid', 'qpid_tcp_nodelay'),
0N/A ('paste_deploy', 'flavor'),
0N/A]
0N/A
0N/A# TODO: Add mappings?
0N/A# GLANCE_SCRUBBER_MAPPINGS
0N/A
0N/AGLANCE_SCRUBBER_EXCEPTIONS = [
0N/A ('DEFAULT', 'log_file'),
0N/A ('DEFAULT', 'wakeup_time'),
0N/A ('DEFAULT', 'scrubber_datadir'),
0N/A ('DEFAULT', 'cleanup_scrubber'),
0N/A ('DEFAULT', 'cleanup_scrubber_time'),
0N/A ('DEFAULT', 'registry_host'),
0N/A ('DEFAULT', 'registry_port'),
0N/A ('DEFAULT', 'auth_url'),
0N/A ('DEFAULT', 'admin_tenant_name'),
0N/A ('DEFAULT', 'admin_user'),
0N/A ('DEFAULT', 'admin_password'),
0N/A ('database', 'connection'),
0N/A]
0N/A
0N/A
0N/Adef start():
0N/A # pull out the current version of config/upgrade-id
0N/A p = Popen(['/usr/bin/svcprop', '-p', 'config/upgrade-id',
0N/A os.environ['SMF_FMRI']], stdout=PIPE, stderr=PIPE)
0N/A curr_ver, _err = p.communicate()
0N/A curr_ver = curr_ver.strip()
0N/A
0N/A # extract the openstack-upgrade-id from the pkg
0N/A p = Popen(['/usr/bin/pkg', 'contents', '-H', '-t', 'set', '-o', 'value',
0N/A '-a', 'name=openstack.upgrade-id',
0N/A 'pkg:/cloud/openstack/glance'], stdout=PIPE, stderr=PIPE)
0N/A pkg_ver, _err = p.communicate()
0N/A pkg_ver = pkg_ver.strip()
0N/A
0N/A if curr_ver == pkg_ver:
0N/A # No need to upgrade
0N/A sys.exit(smf_include.SMF_EXIT_OK)
0N/A
0N/A # look for any .new files
0N/A if glob.glob('/etc/glance/*.new'):
0N/A # the versions are different, so perform an upgrade
0N/A # modify the configuration files
0N/A
0N/A # backup all the old configuration files
0N/A create_backups('/etc/glance')
0N/A
0N/A modify_conf('/etc/glance/glance-api.conf', GLANCE_API_MAPPINGS,
0N/A GLANCE_API_EXCEPTIONS)
0N/A modify_conf('/etc/glance/glance-api-paste.ini')
0N/A modify_conf('/etc/glance/glance-cache.conf',
0N/A exception_list=GLANCE_CACHE_EXCEPTIONS)
0N/A modify_conf('/etc/glance/glance-registry.conf',
0N/A GLANCE_REGISTRY_MAPPINGS,
0N/A exception_list=GLANCE_REGISTRY_EXCEPTIONS)
0N/A modify_conf('/etc/glance/glance-registry-paste.ini')
0N/A modify_conf('/etc/glance/glance-scrubber.conf',
0N/A exception_list=GLANCE_SCRUBBER_EXCEPTIONS)
0N/A
0N/A config = iniparse.RawConfigParser()
0N/A config.read('/etc/glance/glance-api.conf')
0N/A # In certain cases the database section does not exist and the
0N/A # default database chosen is sqlite.
0N/A if config.has_section('database'):
3002N/A db_connection = config.get('database', 'connection')
3002N/A
0N/A if db_connection.startswith('mysql'):
0N/A engine = sqlalchemy.create_engine(db_connection)
0N/A if engine.url.username != '%SERVICE_USER%':
0N/A alter_mysql_tables(engine)
0N/A print "altered character set to utf8 in glance tables"
0N/A
0N/A # update the current version
0N/A check_call(['/usr/sbin/svccfg', '-s', os.environ['SMF_FMRI'], 'setprop',
0N/A 'config/upgrade-id', '=', pkg_ver])
0N/A check_call(['/usr/sbin/svccfg', '-s', os.environ['SMF_FMRI'], 'refresh'])
0N/A
0N/A sys.exit(smf_include.SMF_EXIT_OK)
0N/A
0N/A
0N/Aif __name__ == '__main__':
0N/A os.putenv('LC_ALL', 'C')
0N/A try:
0N/A smf_include.smf_main()
0N/A except RuntimeError:
0N/A sys.exit(smf_include.SMF_EXIT_ERR_FATAL)
0N/A except Exception as err:
0N/A print 'Unknown error: %s' % err
0N/A print
0N/A traceback.print_exc(file=sys.stdout)
0N/A sys.exit(smf_include.SMF_EXIT_ERR_FATAL)
0N/A