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