#!/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 Liberty
('DEFAULT', 'network_device_mtu'): (None, None),
('DEFAULT', 'vnc_keymap'): ('vnc', 'keymap'),
('DEFAULT', 'vnc_enabled'): ('vnc', 'enabled'),
('DEFAULT', 'xvpvncproxy_base_url'): ('vnc', 'xvpvncproxy_base_url'),
('ironic', 'client_log_level'): (None, None),
('neutron', 'admin_username'): ('neutron', 'username'),
('DEFAULT', 'ssl_ca_file'): ('ssl', 'ca_file'),
('osapi_v21', 'enabled'): (None, None),
('DEFAULT', 'novncproxy_base_url'): ('vnc', 'novncproxy_base_url'),
('neutron', 'admin_user_id'): (None, None),
('neutron', 'admin_tenant_id'): (None, None),
('DEFAULT', 'ssl_cert_file'): ('ssl', 'cert_file'),
('DEFAULT', 'log_format'): (None, None),
('DEFAULT', 'vncserver_proxyclient_address'):
('vnc', 'vncserver_proxyclient_address'),
('osapi_v21', 'extensions_blacklist'): (None, None),
('workarounds', 'destroy_after_evacuate'): (None, None),
('neutron', 'admin_tenant_name'): ('neutron', 'tenant_name'),
('DEFAULT', 'osapi_compute_ext_list'): (None, None),
('DEFAULT', 'rpc_thread_pool_size'):
('DEFAULT', 'executor_thread_pool_size'),
('DEFAULT', 'vncserver_listen'): ('vnc', 'vncserver_listen'),
('neutron', 'admin_password'): ('neutron', 'password'),
('DEFAULT', 'ssl_key_file'): ('ssl', 'key_file'),
('neutron', 'admin_auth_url'): ('neutron', 'auth_url'),
# Deprecated group/name for Mitaka
('DEFAULT', 'cert_manager'): (None, None),
('DEFAULT', 'compute_available_monitors'): (None, None),
('DEFAULT', 'compute_manager'): (None, None),
('DEFAULT', 'compute_resources'): (None, None),
('DEFAULT', 'compute_stats_class'): (None, None),
('DEFAULT', 'console_manager'): (None, None),
('DEFAULT', 'consoleauth_manager'): (None, None),
('DEFAULT', 'db_driver'): (None, None),
('DEFAULT', 'memcached_servers'): (None, None),
('DEFAULT', 'metadata_manager'): (None, None),
('DEFAULT', 'network_api_class'): (None, None),
('DEFAULT', 'network_device_mtu'): (None, None),
('DEFAULT', 'osapi_compute_ext_list'): (None, None),
('DEFAULT', 'scheduler_manager'): (None, None),
('DEFAULT', 'security_group_api'): (None, None),
('DEFAULT', 'share_dhcp_address'): (None, None),
('DEFAULT', 'use_syslog'): (None, None),
('DEFAULT', 'vendordata_driver'): (None, None),
('DEFAULT', 'volume_api_class'): (None, None),
('cells', 'manager'): (None, None),
('conductor', 'manager'): (None, None),
('conductor', 'use_local'): (None, None),
('hyperv', 'force_volumeutils_v1'): (None, None),
('ironic', 'admin_auth_token'): (None, None),
('ironic', 'api_version'): (None, None),
('ironic', 'client_log_level'): (None, None),
('libvirt', 'remove_unused_kernels'): (None, None),
('osapi_v21', 'enabled'): (None, None),
('osapi_v21', 'extensions_blacklist'): (None, None),
('osapi_v21', 'extensions_whitelist'): (None, None),
('osapi_v21', 'project_id_regex'): (None, None),
('serial_console', 'listen'): (None, None),
('workarounds', 'destroy_after_evacuate'): (None, None),
# move noVNC proxy configuration from DEFAULT to the vnc group
('DEFAULT', 'novncproxy_port'): ('vnc', 'novncproxy_port'),
('DEFAULT', 'novncproxy_host'): ('vnc', 'novncproxy_host'),
# move entries from DEFAULT.nova.virt.solariszones.driver to its own
# section
('DEFAULT', 'boot_volume_type'): ('solariszones', 'boot_volume_type'),
('DEFAULT', 'boot_volume_az'): ('solariszones', 'boot_volume_az'),
('DEFAULT', 'glancecache_dirname'):
('solariszones', 'glancecache_dirname'),
('DEFAULT', 'live_migration_cipher'):
('solariszones', 'live_migration_cipher'),
('DEFAULT', 'solariszones_snapshots_directory'):
('solariszones', 'solariszones_snapshots_directory'),
('DEFAULT', 'zones_suspend_path'): ('solariszones', 'zones_suspend_path'),
('DEFAULT', 'solariszones_boot_options'):
('solariszones', 'solariszones_boot_options'),
}
API_PASTE_MAPPING = {
('composite:osapi_compute', '/v1.1'): (None, None),
('composite:osapi_compute', '/v3'): (None, None),
}
NOVA_CONF_EXCEPTIONS = [
('DEFAULT', 'ec2_workers'),
('DEFAULT', 'osapi_compute_workers'),
('DEFAULT', 'metadata_workers'),
('DEFAULT', 'lock_path'),
('DEFAULT', 'ovs_bridge'),
('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'),
('neutron', 'username'),
('neutron', 'password'),
('neutron', 'tenant_name'),
('neutron', 'auth_url'),
('vnc', 'novncproxy_base_url'),
]
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', API_PASTE_MAPPING)
modify_conf('/etc/nova/logging.conf')
modify_conf('/etc/nova/nova.conf', NOVA_CONF_MAPPINGS,
NOVA_CONF_EXCEPTIONS)
# 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)