#
# 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
#
#
# 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.
""" openstack_upgrade - common functions used by the various OpenStack
components to facilitate upgrading of configuration files and MySQL
"""
import errno
import glob
import os
import shutil
import time
import iniparse
""" create backups of each configuration file which also has a .new file
from the upgrade.
"""
# copy the old conf file to a backup
try:
print 'unable to create a backup of %s' % old_file
""" look for deprecated variables and, if found, convert it to the new
"""
print "Removing from configuration"
else:
""" Convert MySQL tables to use utf8
"""
import MySQLdb
try:
break
# mysql is not ready. sleep for 2 more seconds
else:
print "Unable to connect to MySQL: %s" % err
print ("Please verify MySQL is properly configured and online "
"before using svcadm(1M) to clear this service.")
raise RuntimeError
if res:
"CHARACTER SET 'utf8', COLLATE 'utf8_general_ci'"
""" Copy over all uncommented options from the old configuration file. In
"""
# open the previous version
# open the new version
try:
# The upgrade did not deliver a .new file so, return
return
else:
raise
print "\nupdating %s" % old_file
# walk every single section for uncommented options
# DEFAULT items show up in every section so remove them
if old_section != 'DEFAULT':
else:
if mapping is not None:
if new_section is None and new_key is None:
# option is deprecated so continue
continue
else:
# no deprecated values for this file so just copy the values
# over
# Look for exceptions
if exception_list:
if (new_section != 'DEFAULT' and
print "Preserving [%s] %s = %s" % \
continue
# print to the log when a value for old_section.old_key is changing
# to a new value
try:
print "Changing [%s] %s:\n- %s\n+ %s" % \
print
except NoOptionError:
# the new configuration file does not have this option set so
# just continue
pass
# Only copy the old value to the new conf file if the entry doesn't
# exist in the new file or if it contains '%SERVICE'
# copy the new conf file in place
""" move each entry in mapping from the original file to the new file.
"""
# open the original file
# open the new file
# The mappings dictionary look similar to the deprecation mappings:
# (original_section, original_key): (new_section, new_key)
try:
except NoOptionError:
# the original file does not contain this mapping so continue
continue
print 'Moving [%s] %s from %s to [%s] %s in %s' % \
# set the option in the new file
# remove the option from the old file