--- a/components/openstack/heat/files/heat-upgrade Wed May 27 05:22:49 2015 -0700
+++ b/components/openstack/heat/files/heat-upgrade Wed May 27 15:21:04 2015 -0600
@@ -14,21 +14,19 @@
# License for the specific language governing permissions and limitations
# under the License.
-from ConfigParser import NoOptionError
-from datetime import datetime
-import errno
import glob
import os
-import shutil
from subprocess import check_call, Popen, PIPE
import sys
-import time
import traceback
import iniparse
import smf_include
import sqlalchemy
+from openstack_common import alter_mysql_tables, create_backups, modify_conf, \
+ move_conf
+
HEAT_CONF_MAPPINGS = {
# Deprecated group/name
@@ -67,140 +65,26 @@
('DEFAULT', 'list_notifier_drivers'): (None, None),
}
-
-def update_mapping(section, key, mapping):
- """ look for deprecated variables and, if found, convert it to the new
- section/key.
- """
-
- if (section, key) in mapping:
- print "Deprecated value found: [%s] %s" % (section, key)
- section, key = mapping[(section, key)]
- if section is None and key is None:
- print "Removing from configuration"
- else:
- print "Updating to: [%s] %s" % (section, key)
- return section, key
-
-
-def alter_mysql_tables(engine):
- """ Convert MySQL tables to use utf8
- """
-
- import MySQLdb
-
- for _none in range(5):
- try:
- db = MySQLdb.connect(host=engine.url.host,
- user=engine.url.username,
- passwd=engine.url.password,
- db=engine.url.database)
- break
- except MySQLdb.OperationalError as err:
- # mysql is not ready. sleep for 2 more seconds
- time.sleep(2)
- 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.")
- sys.exit(smf_include.SMF_EXIT_ERR_FATAL)
-
- cursor = db.cursor()
- cursor.execute("ALTER DATABASE %s CHARACTER SET = 'utf8'" %
- engine.url.database)
- cursor.execute("ALTER DATABASE %s COLLATE = 'utf8_general_ci'" %
- engine.url.database)
- cursor.execute("SHOW tables")
- res = cursor.fetchall()
- if res:
- cursor.execute("SET foreign_key_checks = 0")
- for item in res:
- cursor.execute("ALTER TABLE %s.%s CONVERT TO "
- "CHARACTER SET 'utf8', COLLATE 'utf8_general_ci'"
- % (engine.url.database, item[0]))
- cursor.execute("SET foreign_key_checks = 1")
- db.commit()
- db.close()
-
-
-def modify_conf(old_file, mapping=None):
- """ Copy over all uncommented options from the old configuration file. In
- addition, look for deprecated section/keys and convert them to the new
- section/key.
- """
-
- new_file = old_file + '.new'
+HEAT_CONF_EXCEPTIONS = [
+ ('database', 'connection'),
+ ('keystone_authtoken', 'auth_uri'),
+ ('keystone_authtoken', 'identity_uri'),
+ ('keystone_authtoken', 'admin_user'),
+ ('keystone_authtoken', 'admin_password'),
+ ('keystone_authtoken', 'admin_tenant_name'),
+ ('keystone_authtoken', 'signing_dir'),
+]
- # open the previous version
- old = iniparse.ConfigParser()
- old.readfp(open(old_file))
-
- # open the new version
- new = iniparse.ConfigParser()
- try:
- new.readfp(open(new_file))
- except IOError as err:
- if err.errno == errno.ENOENT:
- # The upgrade did not deliver a .new file so, return
- print "%s not found - continuing with %s" % (new_file, old_file)
- return
- else:
- raise
- print "\nupdating %s" % old_file
-
- # walk every single section for uncommented options
- default_items = set(old.items('DEFAULT'))
- for section in old.sections() + ['DEFAULT']:
-
- # DEFAULT items show up in every section so remove them
- if section != 'DEFAULT':
- section_items = set(old.items(section)) - default_items
- else:
- section_items = default_items
-
- for key, value in section_items:
- # keep a copy of the old value
- oldvalue = value
- oldsection = section
-
- if mapping is not None:
- section, key = update_mapping(section, key, mapping)
-
- if section is None and key is None:
- # option is deprecated so continue
- continue
-
- if not new.has_section(section):
- if section != 'DEFAULT':
- new.add_section(section)
-
- # print to the log when a value for the same section.key is
- # changing to a new value
- try:
- new_value = new.get(section, key)
- if new_value != value and '%SERVICE' not in new_value:
- print "Changing [%s] %s:\n- %s\n+ %s" % \
- (section, key, oldvalue, new_value)
- 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 or if it contains '%SERVICE'
- if not new.has_option(section, key) or \
- '%SERVICE' in new.get(section, key):
- new.set(section, key, value)
- section = oldsection
-
- # copy the old conf file to a backup
- today = datetime.now().strftime("%Y%m%d%H%M%S")
- shutil.copy2(old_file, old_file + '.' + today)
-
- # copy the new conf file in place
- with open(old_file, 'wb+') as fh:
- new.write(fh)
+HEAT_MOVE_CONFIG = {
+ ('filter:authtoken', 'auth_uri'): ('keystone_authtoken', 'auth_uri'),
+ ('filter:authtoken', 'identity_uri'):
+ ('keystone_authtoken', 'identity_uri'),
+ ('filter:authtoken', 'admin_tenant_name'):
+ ('keystone_authtoken', 'admin_tenant_name'),
+ ('filter:authtoken', 'admin_user'): ('keystone_authtoken', 'admin_user'),
+ ('filter:authtoken', 'admin_password'):
+ ('keystone_authtoken', 'admin_password'),
+}
def start():
@@ -225,8 +109,19 @@
if glob.glob('/etc/heat/*.new'):
# the versions are different, so perform an upgrade
# modify the configuration files
+
+ # backup all the old configuration files
+ create_backups('/etc/heat')
+
modify_conf('/etc/heat/api-paste.ini')
- modify_conf('/etc/heat/heat.conf', HEAT_CONF_MAPPINGS)
+
+ # before modifying heat.conf, move the [filter:authtoken] entries from
+ # the updated api-paste.ini to the old heat.conf
+ move_conf('/etc/heat/api-paste.ini', '/etc/heat/heat.conf',
+ HEAT_MOVE_CONFIG)
+
+ modify_conf('/etc/heat/heat.conf', HEAT_CONF_MAPPINGS,
+ HEAT_CONF_EXCEPTIONS)
config = iniparse.RawConfigParser()
config.read('/etc/heat/heat.conf')
@@ -253,6 +148,8 @@
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