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