heat-upgrade revision 4312
15N/A#!/usr/bin/python2.6
15N/A
15N/A# Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
15N/A#
15N/A# Licensed under the Apache License, Version 2.0 (the "License"); you may
15N/A# not use this file except in compliance with the License. You may obtain
15N/A# a copy of the License at
15N/A#
15N/A# http://www.apache.org/licenses/LICENSE-2.0
15N/A#
15N/A# Unless required by applicable law or agreed to in writing, software
15N/A# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15N/A# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15N/A# License for the specific language governing permissions and limitations
15N/A# under the License.
15N/A
15N/Aimport glob
15N/Aimport os
15N/Afrom subprocess import check_call, Popen, PIPE
15N/Aimport sys
15N/Aimport traceback
15N/A
3293N/Aimport iniparse
15N/Aimport smf_include
15N/Aimport sqlalchemy
15N/A
15N/Afrom openstack_common import alter_mysql_tables, create_backups, modify_conf, \
1578N/A move_conf
15N/A
15N/A
15N/AHEAT_CONF_MAPPINGS = {
1578N/A # Deprecated group/name
221N/A ('DEFAULT', 'stack_user_domain'): ('DEFAULT', 'stack_user_domain_id'),
241N/A ('DEFAULT', 'rabbit_durable_queues'): ('DEFAULT', 'amqp_durable_queues'),
221N/A ('rpc_notifier2', 'topics'): ('DEFAULT', 'notification_topics'),
15N/A ('DEFAULT', 'log_config'): ('DEFAULT', 'log_config_append'),
15N/A ('DEFAULT', 'logfile'): ('DEFAULT', 'log_file'),
138N/A ('DEFAULT', 'logdir'): ('DEFAULT', 'log_dir'),
1578N/A ('DEFAULT', 'db_backend'): ('database', 'backend'),
15N/A ('DEFAULT', 'sql_connection'): ('database', 'connection'),
1578N/A ('DATABASE', 'sql_connection'): ('database', 'connection'),
3293N/A ('sql', 'connection'): ('database', 'connection'),
3293N/A ('DEFAULT', 'sql_idle_timeout'): ('database', 'idle_timeout'),
3293N/A ('DATABASE', 'sql_idle_timeout'): ('database', 'idle_timeout'),
15N/A ('sql', 'idle_timeout'): ('database', 'idle_timeout'),
15N/A ('DEFAULT', 'sql_min_pool_size'): ('database', 'min_pool_size'),
15N/A ('DATABASE', 'sql_min_pool_size'): ('database', 'min_pool_size'),
1578N/A ('DEFAULT', 'sql_max_pool_size'): ('database', 'max_pool_size'),
15N/A ('DATABASE', 'sql_max_pool_size'): ('database', 'max_pool_size'),
1195N/A ('DEFAULT', 'sql_max_retries'): ('database', 'max_retries'),
1195N/A ('DATABASE', 'sql_max_retries'): ('database', 'max_retries'),
1578N/A ('DEFAULT', 'sql_retry_interval'): ('database', 'retry_interval'),
1195N/A ('DATABASE', 'reconnect_interval'): ('database', 'retry_interval'),
3293N/A ('DEFAULT', 'sql_max_overflow'): ('database', 'max_overflow'),
3293N/A ('DATABASE', 'sqlalchemy_max_overflow'): ('database', 'max_overflow'),
3293N/A ('DEFAULT', 'sql_connection_debug'): ('database', 'connection_debug'),
3293N/A ('DEFAULT', 'sql_connection_trace'): ('database', 'connection_trace'),
3293N/A ('DATABASE', 'sqlalchemy_pool_timeout'): ('database', 'pool_timeout'),
453N/A ('DEFAULT', 'memcache_servers'):
15N/A ('keystone_authtoken', 'memcached_servers'),
1578N/A ('DEFAULT', 'matchmaker_ringfile'): ('matchmaker_ring', 'ringfile'),
453N/A # No longer referenced by the service or causes a DeprecationWarning
453N/A ('DEFAULT', 'instance_user'): (None, None),
1578N/A ('DEFAULT', 'onready'): (None, None),
1578N/A ('DEFAULT', 'list_notifier_drivers'): (None, None),
1578N/A}
1578N/A
3293N/AHEAT_CONF_EXCEPTIONS = [
('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'),
]
HEAT_MOVE_CONFIG = {
('filter:authtoken', 'auth_uri'): ('keystone_authtoken', 'auth_uri'),
('filter:authtoken', 'identity_uri'):
('keystone_authtoken', 'identity_uri'),
('filter:authtoken', 'admin_tenant_name'):
('keystone_authtoken', 'admin_tenant_name'),
('filter:authtoken', 'admin_user'): ('keystone_authtoken', 'admin_user'),
('filter:authtoken', 'admin_password'):
('keystone_authtoken', 'admin_password'),
}
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/heat'], 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/heat/*.new'):
# the versions are different, so perform an upgrade
# modify the configuration files
# backup all the old configuration files
create_backups('/etc/heat')
modify_conf('/etc/heat/api-paste.ini')
# before modifying heat.conf, move the [filter:authtoken] entries from
# the updated api-paste.ini to the old heat.conf
move_conf('/etc/heat/api-paste.ini', '/etc/heat/heat.conf',
HEAT_MOVE_CONFIG)
modify_conf('/etc/heat/heat.conf', HEAT_CONF_MAPPINGS,
HEAT_CONF_EXCEPTIONS)
config = iniparse.RawConfigParser()
config.read('/etc/heat/heat.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 heat 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)