nova-upgrade revision 5720
4049N/A#!/usr/bin/python2.7
3998N/A
5403N/A# Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
3998N/A#
3998N/A# Licensed under the Apache License, Version 2.0 (the "License"); you may
3998N/A# not use this file except in compliance with the License. You may obtain
3998N/A# a copy of the License at
3998N/A#
3998N/A# http://www.apache.org/licenses/LICENSE-2.0
3998N/A#
3998N/A# Unless required by applicable law or agreed to in writing, software
3998N/A# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
3998N/A# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
3998N/A# License for the specific language governing permissions and limitations
3998N/A# under the License.
3998N/A
3998N/Aimport glob
3998N/Aimport os
3998N/Afrom subprocess import check_call, Popen, PIPE
3998N/Aimport sys
3998N/Aimport traceback
3998N/A
3998N/Aimport iniparse
3998N/Aimport smf_include
3998N/Aimport sqlalchemy
3998N/A
4285N/Afrom openstack_common import alter_mysql_tables, create_backups, modify_conf, \
4285N/A move_conf
4285N/A
3998N/ANOVA_CONF_MAPPINGS = {
5403N/A # Deprecated group/name for Kilo
5403N/A ('DEFAULT', 'network_device_mtu'): (None, None),
5403N/A ('DEFAULT', 'log-format'): (None, None),
5403N/A ('DEFAULT', 'use-syslog'): (None, None),
5403N/A ('cinder', 'http_timeout'): ('cinder', 'timeout'),
5403N/A ('ironic', 'client_log_level'): (None, None),
5720N/A ('DEFAULT', 'amqp_durable_queues'):
5720N/A ('oslo_messaging_qpid', 'amqp_durable_queues'),
5720N/A ('DEFAULT', 'amqp_auto_delete'):
5720N/A ('oslo_messaging_qpid', 'amqp_auto_delete'),
5720N/A ('DEFAULT', 'rpc_conn_pool_size'):
5720N/A ('oslo_messaging_qpid', 'rpc_conn_pool_size'),
5720N/A ('DEFAULT', 'qpid_hostname'):
5720N/A ('oslo_messaging_qpid', 'qpid_hostname'),
5720N/A ('DEFAULT', 'qpid_port'):
5720N/A ('oslo_messaging_qpid', 'qpid_port'),
5720N/A ('DEFAULT', 'qpid_hosts'):
5720N/A ('oslo_messaging_qpid', 'qpid_hosts'),
5720N/A ('DEFAULT', 'qpid_username'):
5720N/A ('oslo_messaging_qpid', 'qpid_username'),
5720N/A ('DEFAULT', 'qpid_password'):
5720N/A ('oslo_messaging_qpid', 'qpid_password'),
5720N/A ('DEFAULT', 'qpid_sasl_mechanisms'):
5720N/A ('oslo_messaging_qpid', 'qpid_sasl_mechanisms'),
5720N/A ('DEFAULT', 'qpid_heartbeat'):
5720N/A ('oslo_messaging_qpid', 'qpid_heartbeat'),
5720N/A ('DEFAULT', 'qpid_protocol'):
5720N/A ('oslo_messaging_qpid', 'qpid_protocol'),
5720N/A ('DEFAULT', 'qpid_tcp_nodelay'):
5720N/A ('oslo_messaging_qpid', 'qpid_tcp_nodelay'),
5720N/A ('DEFAULT', 'qpid_receiver_capacity'):
5720N/A ('oslo_messaging_qpid', 'qpid_receiver_capacity'),
5720N/A ('DEFAULT', 'qpid_topology_version'):
5720N/A ('oslo_messaging_qpid', 'qpid_topology_version'),
5720N/A ('DEFAULT', 'kombu_ssl_version'):
5720N/A ('oslo_messaging_rabbit', 'kombu_ssl_version'),
5720N/A ('DEFAULT', 'kombu_ssl_keyfile'):
5720N/A ('oslo_messaging_rabbit', 'kombu_ssl_keyfile'),
5720N/A ('DEFAULT', 'kombu_ssl_certfile'):
5720N/A ('oslo_messaging_rabbit', 'kombu_ssl_certfile'),
5720N/A ('DEFAULT', 'kombu_ssl_ca_certs'):
5720N/A ('oslo_messaging_rabbit', 'kombu_ssl_ca_certs'),
5720N/A ('DEFAULT', 'kombu_reconnect_delay'):
5720N/A ('oslo_messaging_rabbit', 'kombu_reconnect_delay'),
5720N/A ('DEFAULT', 'rabbit_host'):
5720N/A ('oslo_messaging_rabbit', 'rabbit_host'),
5720N/A ('DEFAULT', 'rabbit_port'):
5720N/A ('oslo_messaging_rabbit', 'rabbit_port'),
5720N/A ('DEFAULT', 'rabbit_hosts'):
5720N/A ('oslo_messaging_rabbit', 'rabbit_hosts'),
5720N/A ('DEFAULT', 'rabbit_use_ssl'):
5720N/A ('oslo_messaging_rabbit', 'rabbit_use_ssl'),
5720N/A ('DEFAULT', 'rabbit_userid'):
5720N/A ('oslo_messaging_rabbit', 'rabbit_userid'),
5720N/A ('DEFAULT', 'rabbit_password'):
5720N/A ('oslo_messaging_rabbit', 'rabbit_password'),
5720N/A ('DEFAULT', 'rabbit_login_method'):
5720N/A ('oslo_messaging_rabbit', 'rabbit_login_method'),
5720N/A ('DEFAULT', 'rabbit_virtual_host'):
5720N/A ('oslo_messaging_rabbit', 'rabbit_virtual_host'),
5720N/A ('DEFAULT', 'rabbit_retry_backoff'):
5720N/A ('oslo_messaging_rabbit', 'rabbit_retry_backoff'),
5720N/A ('DEFAULT', 'rabbit_max_retries'):
5720N/A ('oslo_messaging_rabbit', 'rabbit_max_retries'),
5720N/A ('DEFAULT', 'rabbit_ha_queues'):
5720N/A ('oslo_messaging_rabbit', 'rabbit_ha_queues'),
5720N/A ('DEFAULT', 'fake_rabbit'):
5720N/A ('oslo_messaging_rabbit', 'fake_rabbit'),
5403N/A ('DEFAULT', 'osapi_max_request_body_size'):
5403N/A ('oslo_middleware', 'max_request_body_size'),
5403N/A ('neutron', 'ca_certificates_file'): ('neutron', 'cafile'),
5403N/A ('neutron', 'admin_user_id'): (None, None),
5403N/A ('neutron', 'admin_tenant_id'): (None, None),
5403N/A ('DEFAULT', 'log_format'): (None, None),
5403N/A ('cinder', 'api_insecure'): ('cinder', 'insecure'),
5403N/A ('DEFAULT', 'share_dhcp_address'): (None, None),
5403N/A ('neutron', 'api_insecure'): ('neutron', 'insecure'),
5403N/A ('cinder', 'ca_certificates_file'): ('cinder', 'cafile'),
5403N/A ('neutron', 'url_timeout'): ('neutron', 'timeout'),
5403N/A ('neutron', 'allow_duplicate_networks'): (None, None),
3998N/A}
3998N/A
4285N/ANOVA_CONF_EXCEPTIONS = [
4285N/A ('DEFAULT', 'ec2_workers'),
4285N/A ('DEFAULT', 'osapi_compute_workers'),
4285N/A ('DEFAULT', 'metadata_workers'),
4285N/A ('DEFAULT', 'lock_path'),
4285N/A ('DEFAULT', 'novncproxy_base_url'),
4285N/A ('conductor', 'workers'),
4285N/A ('database', 'connection'),
4285N/A ('keystone_authtoken', 'auth_uri'),
4285N/A ('keystone_authtoken', 'signing_dir'),
4285N/A ('keystone_authtoken', 'identity_uri'),
4285N/A ('keystone_authtoken', 'admin_user'),
4285N/A ('keystone_authtoken', 'admin_password'),
4285N/A ('keystone_authtoken', 'admin_tenant_name'),
4285N/A ('neutron', 'service_metadata_proxy'),
4285N/A]
3998N/A
3998N/A
3998N/Adef start():
3998N/A # pull out the current version of config/upgrade-id
3998N/A p = Popen(['/usr/bin/svcprop', '-p', 'config/upgrade-id',
3998N/A os.environ['SMF_FMRI']], stdout=PIPE, stderr=PIPE)
3998N/A curr_ver, _err = p.communicate()
3998N/A curr_ver = curr_ver.strip()
3998N/A
3998N/A # extract the openstack-upgrade-id from the pkg
3998N/A p = Popen(['/usr/bin/pkg', 'contents', '-H', '-t', 'set', '-o', 'value',
3998N/A '-a', 'name=openstack.upgrade-id',
3998N/A 'pkg:/cloud/openstack/nova'], stdout=PIPE, stderr=PIPE)
3998N/A pkg_ver, _err = p.communicate()
3998N/A pkg_ver = pkg_ver.strip()
3998N/A
3998N/A if curr_ver == pkg_ver:
3998N/A # No need to upgrade
3998N/A sys.exit(smf_include.SMF_EXIT_OK)
3998N/A
3998N/A # look for any .new files
3998N/A if glob.glob('/etc/nova/*.new'):
3998N/A # the versions are different, so perform an upgrade
3998N/A # modify the configuration files
4285N/A
4285N/A # backup all the old configuration files
4285N/A create_backups('/etc/nova')
4285N/A
3998N/A modify_conf('/etc/nova/api-paste.ini')
3998N/A modify_conf('/etc/nova/logging.conf')
4285N/A
4285N/A # It's possible that nova.conf has database.connection commented out
4285N/A # (to use the default value). If it is, and none of other deprecated
4285N/A # values are set, manually set database.connection in the new conf
4285N/A # file.
4285N/A if os.path.exists('/etc/nova/nova.conf.new'):
4285N/A
4285N/A # open the previous version
4285N/A old = iniparse.ConfigParser()
4285N/A old.readfp(open('/etc/nova/nova.conf'))
4285N/A
4285N/A # open the new version
4285N/A new = iniparse.ConfigParser()
4285N/A new.readfp(open('/etc/nova/nova.conf.new'))
4285N/A
4285N/A options = [
4285N/A ('database', 'sql_connection'),
4285N/A ('sql', 'connection'),
4285N/A ('database', 'connection'),
4285N/A ('DEFAULT', 'sql_connection')
4285N/A ]
4285N/A test = lambda x: old.has_section(x[0]) and \
5403N/A old.has_option(x[0], x[1])
4285N/A
4285N/A if not any(map(test, options)):
4285N/A if old.has_option('DEFAULT', 'state_path'):
4285N/A state_path = old.get('DEFAULT', 'state_path')
4285N/A else:
4285N/A state_path = '/var/lib/nova'
4285N/A
4285N/A if old.has_option('DEFAULT', 'sqlite_db'):
4285N/A sqlite_db = old.get('DEFAULT', 'sqlite_db')
4285N/A else:
4285N/A sqlite_db = 'nova.sqlite'
4285N/A
4285N/A new.set('database', 'connection',
4285N/A 'sqlite:///%s/%s' % (state_path, sqlite_db))
4285N/A
4285N/A with open('/etc/nova/nova.conf.new', 'w+') as fh:
4285N/A new.write(fh)
4285N/A
4285N/A modify_conf('/etc/nova/nova.conf', NOVA_CONF_MAPPINGS,
4285N/A NOVA_CONF_EXCEPTIONS)
3998N/A
3998N/A config = iniparse.RawConfigParser()
3998N/A config.read('/etc/nova/nova.conf')
3998N/A # In certain cases the database section does not exist and the
3998N/A # default database chosen is sqlite.
3998N/A if config.has_section('database'):
3998N/A db_connection = config.get('database', 'connection')
3998N/A
3998N/A if db_connection.startswith('mysql'):
3998N/A engine = sqlalchemy.create_engine(db_connection)
3998N/A if engine.url.username != '%SERVICE_USER%':
3998N/A alter_mysql_tables(engine)
3998N/A print "altered character set to utf8 in nova tables"
3998N/A
3998N/A # update the current version
3998N/A check_call(['/usr/sbin/svccfg', '-s', os.environ['SMF_FMRI'], 'setprop',
3998N/A 'config/upgrade-id', '=', pkg_ver])
3998N/A check_call(['/usr/sbin/svccfg', '-s', os.environ['SMF_FMRI'], 'refresh'])
3998N/A
3998N/A sys.exit(smf_include.SMF_EXIT_OK)
3998N/A
3998N/A
3998N/Aif __name__ == '__main__':
3998N/A os.putenv('LC_ALL', 'C')
3998N/A try:
3998N/A smf_include.smf_main()
4285N/A except RuntimeError:
4285N/A sys.exit(smf_include.SMF_EXIT_ERR_FATAL)
3998N/A except Exception as err:
3998N/A print 'Unknown error: %s' % err
3998N/A print
3998N/A traceback.print_exc(file=sys.stdout)
3998N/A sys.exit(smf_include.SMF_EXIT_ERR_FATAL)