components/openstack/nova/files/nova-upgrade
author Devjani Ray <devjani.ray@oracle.com>
Fri, 05 Feb 2016 17:54:17 -0500
changeset 5405 66fd59fecd68
parent 4287 aba3ed31b37a
child 5722 255021c1e96c
permissions -rw-r--r--
PSARC 2015/535 OpenStack service updates for Kilo PSARC 2015/458 aioeventlet - asyncio event loop scheduling callbacks in eventlet PSARC 2015/460 msgpack - C/Python bindings for MessagePack (de)serializer data PSARC 2015/466 openstackclient - OpenStack Command-line Client PSARC 2015/467 oslo.versionedobjects - Oslo Versioned Objects library PSARC 2015/468 pint - A physical quantities module PSARC 2015/469 pysaml2 - A pure Python implementation of SAML2 PSARC 2015/471 semantic_version - A library implementing the 'SemVer' scheme PSARC 2015/472 testresources - PyUnit extension for managing expensive test resources PSARC 2015/473 testscenarios - Extensions to Python unittest to support scenarios PSARC 2015/474 trollius - Port of the Tulip project (asyncio module, PEP 3156) on Python 2 PSARC 2015/475 urllib3 - HTTP library with thread-safe connection pooling, file post, and more PSARC 2015/520 oslo.concurrency - Oslo Concurrency library PSARC 2015/521 oslo.log - Oslo Logging Configuration library PSARC 2015/529 oslo.policy - Oslo Policy library PSARC 2015/530 psutil - Python system and process utilities PSARC 2015/538 fixtures - Python module to support reusable state for writing clean tests PSARC 2015/539 sqlparse - An SQL parser module for Python PSARC 2016/017 extras - Useful extra utilities for Python PSARC 2016/018 linecache2 - Port of the standard linecache module PSARC 2016/019 python-mimeparse - Basic functions for parsing mime-types PSARC 2016/020 testtools - Extensions to the Python unit testing framework PSARC 2016/021 traceback2 - Port of the standard traceback module PSARC 2016/014 OpenStack Cinder NFS driver for Solaris 22384068 OpenStack service updates for Kilo (Umbrella) 21974208 The Python module msgpack should be added to Userland 22010630 The Python trollius module should be added to Userland 22011755 The Python module pint should be added to Userland 22012256 The Python aioeventlet module should be added to Userland 22012282 The Python oslo.versionedobjects module should be added to Userland 22012317 The Python semantic_version module should be added to Userland 22012321 The Python testresources module should be added to Userland 22012329 The Python testscenarios module should be added to Userland 22012336 The Python urllib3 module should be added to Userland 22012343 The Python openstackclient module should be added to Userland 22299389 The Python oslo.concurrency module should be added to Userland 22299409 The Python oslo.log module should be added to Userland 22299418 The Python oslo.policy module should be added to Userland 22299469 The Python psutil module should be added to Userland 22337793 The Python sqlparse module should be added to Userland 22338325 The Python fixtures module should be added to Userland 22535728 The Python testtools module should be added to Userland 22535739 The Python extras module should be added to Userland 22535748 The Python linecache2 module should be added to Userland 22535753 The Python traceback2 module should be added to Userland 22535760 The Python python-mimeparse module should be added to Userland 18961001 Image filtering does not function as expected 21678935 NFS for Cinder in Solaris OpenStack 22548630 derived manifest should not enforce presence of global when installing from UAR 22629795 problem in SERVICE/KEYSTONE

#!/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, \
    move_conf

NOVA_CONF_MAPPINGS = {
    # Deprecated group/name for Kilo
    ('DEFAULT', 'network_device_mtu'): (None, None),
    ('DEFAULT', 'log-format'): (None, None),
    ('DEFAULT', 'use-syslog'): (None, None),
    ('cinder', 'http_timeout'): ('cinder', 'timeout'),
    ('ironic', 'client_log_level'): (None, None),
    ('DEFAULT', 'osapi_max_request_body_size'):
        ('oslo_middleware', 'max_request_body_size'),
    ('neutron', 'ca_certificates_file'): ('neutron', 'cafile'),
    ('neutron', 'admin_user_id'): (None, None),
    ('neutron', 'admin_tenant_id'): (None, None),
    ('DEFAULT', 'log_format'): (None, None),
    ('cinder', 'api_insecure'): ('cinder', 'insecure'),
    ('DEFAULT', 'share_dhcp_address'): (None, None),
    ('neutron', 'api_insecure'): ('neutron', 'insecure'),
    ('cinder', 'ca_certificates_file'): ('cinder', 'cafile'),
    ('neutron', 'url_timeout'): ('neutron', 'timeout'),
    ('neutron', 'allow_duplicate_networks'): (None, None),
}

NOVA_CONF_EXCEPTIONS = [
    ('DEFAULT', 'ec2_workers'),
    ('DEFAULT', 'osapi_compute_workers'),
    ('DEFAULT', 'metadata_workers'),
    ('DEFAULT', 'lock_path'),
    ('DEFAULT', 'novncproxy_base_url'),
    ('conductor', 'workers'),
    ('database', 'connection'),
    ('keystone_authtoken', 'auth_uri'),
    ('keystone_authtoken', 'signing_dir'),
    ('keystone_authtoken', 'identity_uri'),
    ('keystone_authtoken', 'admin_user'),
    ('keystone_authtoken', 'admin_password'),
    ('keystone_authtoken', 'admin_tenant_name'),
    ('neutron', 'service_metadata_proxy'),
]


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/nova'], 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/nova/*.new'):
        # the versions are different, so perform an upgrade
        # modify the configuration files

        # backup all the old configuration files
        create_backups('/etc/nova')

        modify_conf('/etc/nova/api-paste.ini')
        modify_conf('/etc/nova/logging.conf')

        # It's possible that nova.conf has database.connection commented out
        # (to use the default value).  If it is, and none of other deprecated
        # values are set, manually set database.connection in the new conf
        # file.
        if os.path.exists('/etc/nova/nova.conf.new'):

            # open the previous version
            old = iniparse.ConfigParser()
            old.readfp(open('/etc/nova/nova.conf'))

            # open the new version
            new = iniparse.ConfigParser()
            new.readfp(open('/etc/nova/nova.conf.new'))

            options = [
                ('database', 'sql_connection'),
                ('sql', 'connection'),
                ('database', 'connection'),
                ('DEFAULT', 'sql_connection')
            ]
            test = lambda x: old.has_section(x[0]) and \
                old.has_option(x[0], x[1])

            if not any(map(test, options)):
                if old.has_option('DEFAULT', 'state_path'):
                    state_path = old.get('DEFAULT', 'state_path')
                else:
                    state_path = '/var/lib/nova'

                if old.has_option('DEFAULT', 'sqlite_db'):
                    sqlite_db = old.get('DEFAULT', 'sqlite_db')
                else:
                    sqlite_db = 'nova.sqlite'

                new.set('database', 'connection',
                        'sqlite:///%s/%s' % (state_path, sqlite_db))

                with open('/etc/nova/nova.conf.new', 'w+') as fh:
                    new.write(fh)

        modify_conf('/etc/nova/nova.conf', NOVA_CONF_MAPPINGS,
                    NOVA_CONF_EXCEPTIONS)

    config = iniparse.RawConfigParser()
    config.read('/etc/nova/nova.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 nova 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)