5403N/A#!/usr/bin/python2.7
5403N/A
5717N/A# Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
5403N/A#
5403N/A# Licensed under the Apache License, Version 2.0 (the "License"); you may
5403N/A# not use this file except in compliance with the License. You may obtain
5403N/A# a copy of the License at
5403N/A#
5403N/A# http://www.apache.org/licenses/LICENSE-2.0
5403N/A#
5403N/A# Unless required by applicable law or agreed to in writing, software
5403N/A# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
5403N/A# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
5403N/A# License for the specific language governing permissions and limitations
5403N/A# under the License.
5403N/A
5403N/Aimport glob
5403N/Aimport os
5403N/Afrom subprocess import check_call, Popen, PIPE
5403N/Aimport sys
5403N/Aimport traceback
5403N/A
5403N/Aimport smf_include
5403N/Aimport sqlalchemy
5403N/A
5403N/Afrom openstack_common import alter_mysql_tables, create_backups, modify_conf
5403N/A
5403N/AIRONIC_CONF_MAPPINGS = {
6853N/A # Deprecated group/name LIBERTY
6853N/A ('DEFAULT', 'rpc_thread_pool_size'):
6853N/A ('DEFAULT', 'executor_thread_pool_size'),
5403N/A ('DEFAULT', 'log_format'): (None, None),
6853N/A ('DEFAULT', 'use_syslog'): (None, None),
6853N/A ('agent', 'agent_pxe_append_params'): (None, None),
6853N/A ('agent', 'agent_erase_devices_priority'):
6853N/A ('deploy', 'erase_devices_priority'),
6853N/A ('agent', 'agent_pxe_config_template'): (None, None),
6853N/A ('agent', 'manage_tftp'): ('agent', 'manage_agent_boot'),
6853N/A # Deprecated group/name MITAKA
6853N/A ('profiler', 'profiler_enabled'): ('profiler', 'enabled'),
5403N/A}
5403N/A
5717N/AIRONIC_CONF_EXCEPTIONS = [
6853N/A ('DEFAULT', 'auth_strategy'),
6853N/A ('DEFAULT', 'enabled_drivers'),
6853N/A ('DEFAULT', 'pybasedir'),
6853N/A ('DEFAULT', 'bindir'),
6853N/A ('DEFAULT', 'state_path'),
6853N/A ('ai', 'server'),
6853N/A ('ai', 'username'),
6853N/A ('api', 'api_workers'),
6853N/A ('database', 'connection'),
5717N/A ('keystone_authtoken', 'admin_tenant_name'),
5717N/A ('keystone_authtoken', 'admin_user'),
5717N/A ('keystone_authtoken', 'admin_password'),
6853N/A ('keystone_authtoken', 'auth_host'),
6853N/A ('keystone_authtoken', 'auth_uri'),
6853N/A ('keystone_authtoken', 'identity_uri'),
5717N/A ('keystone_authtoken', 'signing_dir'),
6853N/A ('solaris_ipmi', 'imagecache_dirname'),
6853N/A ('solaris_ipmi', 'imagecache_lock_timeout'),
5717N/A]
5403N/A
5403N/A
5403N/Adef start():
5403N/A # pull out the current version of config/upgrade-id
5403N/A p = Popen(['/usr/bin/svcprop', '-p', 'config/upgrade-id',
5403N/A os.environ['SMF_FMRI']], stdout=PIPE, stderr=PIPE)
5403N/A curr_ver, _err = p.communicate()
5403N/A curr_ver = curr_ver.strip()
5403N/A
5403N/A # extract the openstack-upgrade-id from the pkg
5403N/A p = Popen(['/usr/bin/pkg', 'contents', '-H', '-t', 'set', '-o', 'value',
5403N/A '-a', 'name=openstack.upgrade-id',
5403N/A 'pkg:/cloud/openstack/ironic'], stdout=PIPE, stderr=PIPE)
5403N/A pkg_ver, _err = p.communicate()
5403N/A pkg_ver = pkg_ver.strip()
5403N/A
5403N/A if curr_ver == pkg_ver:
5403N/A # No need to upgrade
5403N/A sys.exit(smf_include.SMF_EXIT_OK)
5403N/A
5403N/A # look for any .new files
5403N/A if glob.glob('/etc/ironic/*.new'):
5403N/A # the versions are different, so perform an upgrade
5403N/A # modify the configuration files
5403N/A
5403N/A # backup all the old configuration files
5403N/A create_backups('/etc/ironic')
5403N/A
5403N/A modify_conf('/etc/ironic/ironic.conf', IRONIC_CONF_MAPPINGS,
5403N/A IRONIC_CONF_EXCEPTIONS)
5403N/A
5403N/A # update the current version
5403N/A check_call(['/usr/sbin/svccfg', '-s', os.environ['SMF_FMRI'], 'setprop',
5403N/A 'config/upgrade-id', '=', pkg_ver])
5403N/A check_call(['/usr/sbin/svccfg', '-s', os.environ['SMF_FMRI'], 'refresh'])
5403N/A
5403N/A sys.exit(smf_include.SMF_EXIT_OK)
5403N/A
5403N/A
5403N/Aif __name__ == '__main__':
5403N/A os.putenv('LC_ALL', 'C')
5403N/A try:
5403N/A smf_include.smf_main()
5403N/A except RuntimeError:
5403N/A sys.exit(smf_include.SMF_EXIT_ERR_FATAL)
5403N/A except Exception as err:
5403N/A print 'Unknown error: %s' % err
5403N/A print
5403N/A traceback.print_exc(file=sys.stdout)
5403N/A sys.exit(smf_include.SMF_EXIT_ERR_FATAL)