6033N/A#!/usr/bin/python2.7
6033N/A
6033N/A# Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
6033N/A#
6033N/A# Licensed under the Apache License, Version 2.0 (the "License"); you may
6033N/A# not use this file except in compliance with the License. You may obtain
6033N/A# a copy of the License at
6033N/A#
6033N/A# http://www.apache.org/licenses/LICENSE-2.0
6033N/A#
6033N/A# Unless required by applicable law or agreed to in writing, software
6033N/A# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
6033N/A# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
6033N/A# License for the specific language governing permissions and limitations
6033N/A# under the License.
6033N/A
6033N/Aimport glob
6033N/Aimport os
6033N/Afrom subprocess import check_call, Popen, PIPE
6033N/Aimport sys
6033N/Aimport traceback
6033N/A
6033N/Aimport smf_include
6033N/Aimport sqlalchemy
6033N/A
6033N/Afrom openstack_common import alter_mysql_tables, create_backups, modify_conf
6033N/A
6033N/AIRONIC_CONF_MAPPINGS = {
6033N/A # Deprecated group/name
6033N/A ('DEFAULT', 'amqp_durable_queues'):
6033N/A ('oslo_messaging_qpid', 'amqp_durable_queues'),
6033N/A ('DEFAULT', 'amqp_auto_delete'):
6033N/A ('oslo_messaging_qpid', 'amqp_auto_delete'),
6033N/A ('DEFAULT', 'rpc_conn_pool_size'):
6033N/A ('oslo_messaging_qpid', 'rpc_conn_pool_size'),
6033N/A ('DEFAULT', 'qpid_hostname'):
6033N/A ('oslo_messaging_qpid', 'qpid_hostname'),
6033N/A ('DEFAULT', 'qpid_port'):
6033N/A ('oslo_messaging_qpid', 'qpid_port'),
6033N/A ('DEFAULT', 'qpid_hosts'):
6033N/A ('oslo_messaging_qpid', 'qpid_hosts'),
6033N/A ('DEFAULT', 'qpid_username'):
6033N/A ('oslo_messaging_qpid', 'qpid_username'),
6033N/A ('DEFAULT', 'qpid_password'):
6033N/A ('oslo_messaging_qpid', 'qpid_password'),
6033N/A ('DEFAULT', 'qpid_sasl_mechanisms'):
6033N/A ('oslo_messaging_qpid', 'qpid_sasl_mechanisms'),
6033N/A ('DEFAULT', 'qpid_tcp_nodelay'):
6033N/A ('oslo_messaging_qpid', 'qpid_tcp_nodelay'),
6033N/A ('DEFAULT', 'qpid_heartbeat'):
6033N/A ('oslo_messaging_qpid', 'qpid_heartbeat'),
6033N/A ('DEFAULT', 'qpid_protocol'):
6033N/A ('oslo_messaging_qpid', 'qpid_protocol'),
6033N/A ('DEFAULT', 'qpid_receiver_capacity'):
6033N/A ('oslo_messaging_qpid', 'qpid_receiver_capacity'),
6033N/A ('DEFAULT', 'qpid_topology_version'):
6033N/A ('oslo_messaging_qpid', 'qpid_topology_version'),
6033N/A ('DEFAULT', 'kombu_ssl_version'):
6033N/A ('oslo_messaging_rabbit', 'kombu_ssl_version'),
6033N/A ('DEFAULT', 'kombu_ssl_keyfile'):
6033N/A ('oslo_messaging_rabbit', 'kombu_ssl_keyfile'),
6033N/A ('DEFAULT', 'kombu_ssl_certfile'):
6033N/A ('oslo_messaging_rabbit', 'kombu_ssl_certfile'),
6033N/A ('DEFAULT', 'kombu_ssl_ca_certs'):
6033N/A ('oslo_messaging_rabbit', 'kombu_ssl_ca_certs'),
6033N/A ('DEFAULT', 'kombu_reconnect_delay'):
6033N/A ('oslo_messaging_rabbit', 'kombu_reconnect_delay'),
6033N/A ('DEFAULT', 'rabbit_host'):
6033N/A ('oslo_messaging_rabbit', 'rabbit_host'),
6033N/A ('DEFAULT', 'rabbit_port'):
6033N/A ('oslo_messaging_rabbit', 'rabbit_port'),
6033N/A ('DEFAULT', 'rabbit_hosts'):
6033N/A ('oslo_messaging_rabbit', 'rabbit_hosts'),
6033N/A ('DEFAULT', 'rabbit_use_ssl'):
6033N/A ('oslo_messaging_rabbit', 'rabbit_use_ssl'),
6033N/A ('DEFAULT', 'rabbit_userid'):
6033N/A ('oslo_messaging_rabbit', 'rabbit_userid'),
6033N/A ('DEFAULT', 'rabbit_password'):
6033N/A ('oslo_messaging_rabbit', 'rabbit_password'),
6033N/A ('DEFAULT', 'rabbit_login_method'):
6033N/A ('oslo_messaging_rabbit', 'rabbit_login_method'),
6033N/A ('DEFAULT', 'rabbit_virtual_host'):
6033N/A ('oslo_messaging_rabbit', 'rabbit_virtual_host'),
6033N/A ('DEFAULT', 'rabbit_retry_interval'):
6033N/A ('oslo_messaging_rabbit', 'rabbit_retry_interval'),
6033N/A ('DEFAULT', 'rabbit_retry_backoff'):
6033N/A ('oslo_messaging_rabbit', 'rabbit_retry_backoff'),
6033N/A ('DEFAULT', 'rabbit_max_retries'):
6033N/A ('oslo_messaging_rabbit', 'rabbit_max_retries'),
6033N/A ('DEFAULT', 'rabbit_ha_queues'):
6033N/A ('oslo_messaging_rabbit', 'rabbit_ha_queues'),
6033N/A ('DEFAULT', 'fake_rabbit'):
6033N/A ('oslo_messaging_rabbit', 'fake_rabbit'),
6033N/A ('keystone_authtoken', 'admin_token'): (None, None),
6033N/A ('keystone_authtoken', 'auth_admin_prefix'): (None, None),
6033N/A ('DEFAULT', 'log_format'): (None, None),
6033N/A ('DEFAULT', 'fake_rabbit'): (None, None),
6033N/A}
6033N/A
6033N/AIRONIC_CONF_EXCEPTIONS = [
6033N/A ('keystone_authtoken', 'admin_tenant_name'),
6033N/A ('keystone_authtoken', 'admin_user'),
6033N/A ('keystone_authtoken', 'admin_password'),
6033N/A ('keystone_authtoken', 'signing_dir'),
6033N/A ('ai', 'server'),
6033N/A ('ai', 'username'),
6033N/A]
6033N/A
6033N/A
6033N/Adef start():
6033N/A # pull out the current version of config/upgrade-id
6033N/A p = Popen(['/usr/bin/svcprop', '-p', 'config/upgrade-id',
6033N/A os.environ['SMF_FMRI']], stdout=PIPE, stderr=PIPE)
6033N/A curr_ver, _err = p.communicate()
6033N/A curr_ver = curr_ver.strip()
6033N/A
6033N/A # extract the openstack-upgrade-id from the pkg
6033N/A p = Popen(['/usr/bin/pkg', 'contents', '-H', '-t', 'set', '-o', 'value',
6033N/A '-a', 'name=openstack.upgrade-id',
6033N/A 'pkg:/cloud/openstack/ironic'], stdout=PIPE, stderr=PIPE)
6033N/A pkg_ver, _err = p.communicate()
6033N/A pkg_ver = pkg_ver.strip()
6033N/A
6033N/A if curr_ver == pkg_ver:
6033N/A # No need to upgrade
6033N/A sys.exit(smf_include.SMF_EXIT_OK)
6033N/A
6033N/A # look for any .new files
6033N/A if glob.glob('/etc/ironic/*.new'):
6033N/A # the versions are different, so perform an upgrade
6033N/A # modify the configuration files
6033N/A
6033N/A # backup all the old configuration files
6033N/A create_backups('/etc/ironic')
6033N/A
6033N/A modify_conf('/etc/ironic/ironic.conf', IRONIC_CONF_MAPPINGS,
6033N/A IRONIC_CONF_EXCEPTIONS)
6033N/A
6033N/A # update the current version
6033N/A check_call(['/usr/sbin/svccfg', '-s', os.environ['SMF_FMRI'], 'setprop',
6033N/A 'config/upgrade-id', '=', pkg_ver])
6033N/A check_call(['/usr/sbin/svccfg', '-s', os.environ['SMF_FMRI'], 'refresh'])
6033N/A
6033N/A sys.exit(smf_include.SMF_EXIT_OK)
6033N/A
6033N/A
6033N/Aif __name__ == '__main__':
6033N/A os.putenv('LC_ALL', 'C')
6033N/A try:
6033N/A smf_include.smf_main()
6033N/A except RuntimeError:
6033N/A sys.exit(smf_include.SMF_EXIT_ERR_FATAL)
6033N/A except Exception as err:
6033N/A print 'Unknown error: %s' % err
6033N/A print
6033N/A traceback.print_exc(file=sys.stdout)
6033N/A sys.exit(smf_include.SMF_EXIT_ERR_FATAL)