#!/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
GLANCE_API_MAPPINGS = {
# Deprecated group/name
('DEFAULT', 'container_formats'): ('image_format', 'container_formats'),
('DEFAULT', 'disk_formats'): ('image_format', 'disk_formats'),
('DEFAULT', 'matchmaker_ringfile'): ('matchmaker_ring', 'ringfile'),
('DEFAULT', 'rabbit_durable_queues'): ('oslo_messaging_qpid',
'amqp_durable_queues'),
('DEFAULT', 'qpid_hostname'): ('oslo_messaging_qpid', 'qpid_hostname'),
('DEFAULT', 'qpid_port'): ('oslo_messaging_qpid', 'qpid_port'),
('DEFAULT', 'qpid_username'): ('oslo_messaging_qpid', 'qpid_username'),
('DEFAULT', 'qpid_password'): ('oslo_messaging_qpid', 'qpid_password'),
('DEFAULT', 'qpid_sasl_mechanisms'): ('oslo_messaging_qpid',
'qpid_sasl_mechanisms'),
('DEFAULT', 'qpid_heartbeat'): ('oslo_messaging_qpid', 'qpid_heartbeat'),
('DEFAULT', 'qpid_protocol'): ('oslo_messaging_qpid', 'qpid_protocol'),
('DEFAULT', 'qpid_tcp_nodelay'): ('oslo_messaging_qpid',
'qpid_tcp_nodelay'),
('DEFAULT', 'rabbit_host'): ('oslo_messaging_rabbit', 'rabbit_host'),
('DEFAULT', 'rabbit_port'): ('oslo_messaging_rabbit', 'rabbit_port'),
('DEFAULT', 'rabbit_use_ssl'): ('oslo_messaging_rabbit', 'rabbit_use_ssl'),
('DEFAULT', 'rabbit_userid'): ('oslo_messaging_rabbit', 'rabbit_userid'),
('DEFAULT', 'rabbit_password'): ('oslo_messaging_rabbit',
'rabbit_password'),
('DEFAULT', 'rabbit_virtual_host'): ('oslo_messaging_rabbit',
'rabbit_virtual_host'),
('task', 'eventlet_executor_pool_size'):
('taskflow_executor', 'max_workers'),
('DEFAULT', 'log-format'): (None, None),
('DEFAULT', 'log_format'): (None, None),
('DEFAULT', 'use-syslog'): (None, None),
('glance_store', 'vmware_datacenter_path'): (None, None),
('glance_store', 'vmware_datastore_name'): (None, None),
}
GLANCE_API_EXCEPTIONS = [
('DEFAULT', 'admin_tenant_name'),
('DEFAULT', 'admin_user'),
('DEFAULT', 'admin_password'),
('DEFAULT', 'bind_host'),
('DEFAULT', 'bind_port'),
('DEFAULT', 'log_file'),
('DEFAULT', 'backlog'),
('DEFAULT', 'workers'),
('DEFAULT', 'registry_host'),
('DEFAULT', 'registry_port'),
('DEFAULT', 'registry_client_protocol'),
('DEFAULT', 'delayed_delete'),
('DEFAULT', 'scrub_time'),
('DEFAULT', 'scrubber_datadir'),
('DEFAULT', 'image_cache_dir'),
('database', 'connection'),
('paste_deploy', 'flavor'),
('keystone_authtoken', 'auth_uri'),
('keystone_authtoken', 'identity_uri'),
('keystone_authtoken', 'admin_tenant_name'),
('keystone_authtoken', 'admin_user'),
('keystone_authtoken', 'admin_password'),
('keystone_authtoken', 'revocation_cache_time'),
('glance_store', 'filesystem_store_datadir'),
('glance_store', 'swift_store_auth_version'),
('glance_store', 'swift_store_auth_address'),
('glance_store', 'swift_store_user'),
('glance_store', 'swift_store_key'),
('glance_store', 'swift_store_container'),
('glance_store', 'swift_store_create_container_on_put'),
('glance_store', 'swift_store_large_object_size'),
('glance_store', 'swift_store_large_object_chunk_size'),
('glance_store', 's3_store_host'),
('glance_store', 's3_store_create_bucket_on_put'),
('glance_store', 'sheepdog_store_address'),
('glance_store', 'sheepdog_store_port'),
('glance_store', 'sheepdog_store_chunk_size'),
('oslo_messaging_rabbit', 'rabbit_host'),
('oslo_messaging_rabbit', 'rabbit_port'),
('oslo_messaging_rabbit', 'rabbit_use_ssl'),
('oslo_messaging_rabbit', 'rabbit_userid'),
('oslo_messaging_rabbit', 'rabbit_password'),
('oslo_messaging_rabbit', 'rabbit_virtual_host'),
('oslo_messaging_rabbit', 'rabbit_notification_exchange'),
('oslo_messaging_rabbit', 'rabbit_notification_topic'),
('oslo_messaging_rabbit', 'rabbit_durable_queues'),
('oslo_messaging_qpid', 'qpid_notification_exchange'),
('oslo_messaging_qpid', 'qpid_notification_topic'),
('oslo_messaging_qpid', 'qpid_hostname'),
('oslo_messaging_qpid', 'qpid_port'),
('oslo_messaging_qpid', 'qpid_usernamd'),
('oslo_messaging_qpid', 'qpid_password'),
('oslo_messaging_qpid', 'qpid_sasl_mechanisms'),
('oslo_messaging_qpid', 'qpid_reconnect_timeout'),
('oslo_messaging_qpid', 'qpid_reconnect_limit'),
('oslo_messaging_qpid', 'qpid_reconnect_interval_min'),
('oslo_messaging_qpid', 'qpid_reconnect_interval_max'),
('oslo_messaging_qpid', 'qpid_reconnect_interval'),
('oslo_messaging_qpid', 'qpid_heartbeat'),
('oslo_messaging_qpid', 'qpid_protocol'),
('oslo_messaging_qpid', 'qpid_tcp_nodelay'),
]
GLANCE_CACHE_EXCEPTIONS = [
('DEFAULT', 'log_file'),
('DEFAULT', 'image_cache_dir'),
('DEFAULT', 'image_cache_stall_time'),
('DEFAULT', 'image_cache_max_size'),
('DEFAULT', 'registry_host'),
('DEFAULT', 'registry_port'),
('DEFAULT', 'auth_url'),
('DEFAULT', 'admin_tenant_name'),
('DEFAULT', 'admin_user'),
('DEFAULT', 'admin_password'),
('DEFAULT', 'filesystem_store_datadir'),
]
GLANCE_REGISTRY_MAPPINGS = {
# Deprecate group/name
('DEFAULT', 'rabbit_durable_queues'): ('oslo_messaging_qpid',
'rabbit_durable_queues'),
('DEFAULT', 'qpid_hostname'): ('oslo_messaging_qpid', 'qpid_hostname'),
('DEFAULT', 'qpid_port'): ('oslo_messaging_qpid', 'qpid_port'),
('DEFAULT', 'qpid_username'): ('oslo_messaging_qpid', 'qpid_username'),
('DEFAULT', 'qpid_password'): ('oslo_messaging_qpid', 'qpid_password'),
('DEFAULT', 'qpid_sasl_mechanisms'): ('oslo_messaging_qpid',
'qpid_sasl_mechanisms'),
('DEFAULT', 'qpid_heartbeat'): ('oslo_messaging_qpid', 'qpid_heartbeat'),
('DEFAULT', 'qpid_protocol'): ('oslo_messaging_qpid', 'qpid_protocol'),
('DEFAULT', 'qpid_tcp_nodelay'): ('oslo_messaging_qpid',
'qpid_tcp_nodelay'),
('DEFAULT', 'rabbit_host'): ('oslo_messaging_rabbit', 'rabbit_host'),
('DEFAULT', 'rabbit_port'): ('oslo_messaging_rabbit', 'rabbit_port'),
('DEFAULT', 'rabbit_use_ssl'): ('oslo_messaging_rabbit', 'rabbit_use_ssl'),
('DEFAULT', 'rabbit_userid'): ('oslo_messaging_rabbit', 'rabbit_userid'),
('DEFAULT', 'rabbit_password'): ('oslo_messaging_rabbit',
'rabbit_password'),
('DEFAULT', 'rabbit_virtual_host'): ('oslo_messaging_rabbit',
'rabbit_virtual_host'),
}
GLANCE_REGISTRY_EXCEPTIONS = [
('DEFAULT', 'bind_host'),
('DEFAULT', 'bind_port'),
('DEFAULT', 'log_file'),
('DEFAULT', 'backlog'),
('DEFAULT', 'workers'),
('DEFAULT', 'limit_param_default'),
('database', 'connection'),
('keystone_authtoken', 'auth_uri'),
('keystone_authtoken', 'identity_uri'),
('keystone_authtoken', 'admin_tenant_name'),
('keystone_authtoken', 'admin_user'),
('keystone_authtoken', 'admin_password'),
('keystone_authtoken', 'signing_dir'),
('oslo_messaging_rabbit', 'rabbit_host'),
('oslo_messaging_rabbit', 'rabbit_port'),
('oslo_messaging_rabbit', 'rabbit_use_ssl'),
('oslo_messaging_rabbit', 'rabbit_userid'),
('oslo_messaging_rabbit', 'rabbit_password'),
('oslo_messaging_rabbit', 'rabbit_virtual_host'),
('oslo_messaging_rabbit', 'rabbit_notification_exchange'),
('oslo_messaging_rabbit', 'rabbit_notification_topic'),
('oslo_messaging_rabbit', 'rabbit_durable_queues'),
('oslo_messaging_qpid', 'qpid_notification_exchange'),
('oslo_messaging_qpid', 'qpid_notification_topic'),
('oslo_messaging_qpid', 'qpid_hostname'),
('oslo_messaging_qpid', 'qpid_port'),
('oslo_messaging_qpid', 'qpid_usernamd'),
('oslo_messaging_qpid', 'qpid_password'),
('oslo_messaging_qpid', 'qpid_sasl_mechanisms'),
('oslo_messaging_qpid', 'qpid_reconnect_timeout'),
('oslo_messaging_qpid', 'qpid_reconnect_limit'),
('oslo_messaging_qpid', 'qpid_reconnect_interval_min'),
('oslo_messaging_qpid', 'qpid_reconnect_interval_max'),
('oslo_messaging_qpid', 'qpid_reconnect_interval'),
('oslo_messaging_qpid', 'qpid_heartbeat'),
('oslo_messaging_qpid', 'qpid_protocol'),
('oslo_messaging_qpid', 'qpid_tcp_nodelay'),
('paste_deploy', 'flavor'),
]
# TODO: Add mappings?
# GLANCE_SCRUBBER_MAPPINGS
GLANCE_SCRUBBER_EXCEPTIONS = [
('DEFAULT', 'log_file'),
('DEFAULT', 'wakeup_time'),
('DEFAULT', 'scrubber_datadir'),
('DEFAULT', 'cleanup_scrubber'),
('DEFAULT', 'cleanup_scrubber_time'),
('DEFAULT', 'registry_host'),
('DEFAULT', 'registry_port'),
('DEFAULT', 'auth_url'),
('DEFAULT', 'admin_tenant_name'),
('DEFAULT', 'admin_user'),
('DEFAULT', 'admin_password'),
('database', 'connection'),
]
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/glance'], 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/glance/*.new'):
# the versions are different, so perform an upgrade
# modify the configuration files
# backup all the old configuration files
create_backups('/etc/glance')
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)