--- a/components/openstack/glance/files/glance-upgrade Wed May 13 04:53:25 2015 -0700
+++ b/components/openstack/glance/files/glance-upgrade Tue May 19 13:51:17 2015 -0700
@@ -14,21 +14,18 @@
# 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
+
GLANCE_API_MAPPINGS = {
# Deprecated group/name
@@ -52,8 +49,133 @@
('DEFAULT', 'sql_connection_debug'): ('database', 'connection_debug'),
('DEFAULT', 'sql_connection_trace'): ('database', 'connection_trace'),
('DATABASE', 'sqlalchemy_pool_timeout'): ('database', 'pool_timeout'),
+ ('DEFAULT', 'filesystem_store_datadir'):
+ ('glance_store', 'filesystem_store_datadir'),
+ ('DEFAULT', 'swift_store_auth_version'):
+ ('glance_store', 'swift_store_auth_version'),
+ ('DEFAULT', 'swift_store_auth_address'):
+ ('glance_store', 'swift_store_auth_address'),
+ ('DEFAULT', 'swift_store_user'): ('glance_store', 'swift_store_user'),
+ ('DEFAULT', 'swift_store_key'): ('glance_store', 'swift_store_key'),
+ ('DEFAULT', 'swift_store_container'):
+ ('glance_store', 'swift_store_container'),
+ ('DEFAULT', 'swift_store_create_container_on_put'):
+ ('glance_store', 'swift_store_create_container_on_put'),
+ ('DEFAULT', 'swift_store_large_object_size'):
+ ('glance_store', 'swift_store_large_object_size'),
+ ('DEFAULT', 'swift_store_large_object_chunk_size'):
+ ('glance_store', 'swift_store_large_object_chunk_size'),
+ ('DEFAULT', 'swift_enable_snet'): ('glance_store', 'swift_enable_snet'),
+ ('DEFAULT', 's3_store_host'): ('glance_store', 's3_store_host'),
+ ('DEFAULT', 's3_store_access_key'):
+ ('glance_store', 's3_store_access_key'),
+ ('DEFAULT', 's3_store_secret_key'):
+ ('glance_store', 's3_store_secret_key'),
+ ('DEFAULT', 's3_store_bucket'): ('glance_store', 's3_store_bucket'),
+ ('DEFAULT', 's3_store_create_bucket_on_put'):
+ ('glance_store', 's3_store_create_bucket_on_put'),
+ ('DEFAULT', 'sheepdog_store_address'):
+ ('glance_store', 'sheepdog_store_address'),
+ ('DEFAULT', 'sheepdog_store_port'):
+ ('glance_store', 'sheepdog_store_port'),
+ ('DEFAULT', 'sheepdog_store_chunk_size'):
+ ('glance_store', 'sheepdog_store_chunk_size'),
}
+GLANCE_API_EXCEPTIONS = [
+ ('DEFAULT', 'bind_host'),
+ ('DEFAULT', 'bind_port'),
+ ('DEFAULT', 'log_file'),
+ ('DEFAULT', 'backlog'),
+ ('DEFAULT', 'workers'),
+ ('DEFAULT', 'registry_host'),
+ ('DEFAULT', 'registry_port'),
+ ('DEFAULT', 'registry_client_protocol'),
+ ('DEFAULT', 'rabbit_host'),
+ ('DEFAULT', 'rabbit_port'),
+ ('DEFAULT', 'rabbit_use_ssl'),
+ ('DEFAULT', 'rabbit_userid'),
+ ('DEFAULT', 'rabbit_password'),
+ ('DEFAULT', 'rabbit_virtual_host'),
+ ('DEFAULT', 'rabbit_notification_exchange'),
+ ('DEFAULT', 'rabbit_notification_topic'),
+ ('DEFAULT', 'rabbit_durable_queues'),
+ ('DEFAULT', 'qpid_notification_exchange'),
+ ('DEFAULT', 'qpid_notification_topic'),
+ ('DEFAULT', 'qpid_hostname'),
+ ('DEFAULT', 'qpid_port'),
+ ('DEFAULT', 'qpid_usernamd'),
+ ('DEFAULT', 'qpid_password'),
+ ('DEFAULT', 'qpid_sasl_mechanisms'),
+ ('DEFAULT', 'qpid_reconnect_timeout'),
+ ('DEFAULT', 'qpid_reconnect_limit'),
+ ('DEFAULT', 'qpid_reconnect_interval_min'),
+ ('DEFAULT', 'qpid_reconnect_interval_max'),
+ ('DEFAULT', 'qpid_reconnect_interval'),
+ ('DEFAULT', 'qpid_heartbeat'),
+ ('DEFAULT', 'qpid_protocol'),
+ ('DEFAULT', 'qpid_tcp_nodelay'),
+ ('DEFAULT', 'delayed_delete'),
+ ('DEFAULT', 'scrub_time'),
+ ('DEFAULT', 'scrubber_datadir'),
+ ('DEFAULT', 'image_cache_dir'),
+ ('database', 'connection'),
+ ('keystone_authtoken', 'auth_uri'),
+ ('keystone_authtoken', 'identity_uri'),
+ ('keystone_authtoken', 'admin_tenant_name'),
+ ('keystone_authtoken', 'admin_user'),
+ ('keystone_authtoken', 'admin_password'),
+ ('keystone_authtoken', 'revocation_cache_time'),
+ ('keystone_authtoken', 'signing_dir'),
+ ('paste_deploy', 'flavor'),
+ ('glance_store', 'filesystem_store_datadir'),
+ ('glance_store', 'swift_store_auth_version'),
+ ('glance_store', 'swift_store_auth_address'),
+ ('glance_store', 'swift_store_user'),
+ ('glance_store', 'swift_store_key'),
+ ('glance_store', 'swift_store_container'),
+ ('glance_store', 'swift_store_create_container_on_put'),
+ ('glance_store', 'swift_store_large_object_size'),
+ ('glance_store', 'swift_store_large_object_chunk_size'),
+ ('glance_store', 'swift_enable_snet'),
+ ('glance_store', 's3_store_host'),
+ ('glance_store', 's3_store_access_key'),
+ ('glance_store', 's3_store_secret_key'),
+ ('glance_store', 's3_store_bucket'),
+ ('glance_store', 's3_store_create_bucket_on_put'),
+ ('glance_store', 'sheepdog_store_address'),
+ ('glance_store', 'sheepdog_store_port'),
+ ('glance_store', 'sheepdog_store_chunk_size'),
+]
+
+GLANCE_CACHE_EXCEPTIONS = [
+ ('DEFAULT', 'log_file'),
+ ('DEFAULT', 'image_cache_dir'),
+ ('DEFAULT', 'image_cache_stall_time'),
+ ('DEFAULT', 'image_cache_max_size'),
+ ('DEFAULT', 'registry_host'),
+ ('DEFAULT', 'registry_port'),
+ ('DEFAULT', 'auth_url'),
+ ('DEFAULT', 'admin_tenant_name'),
+ ('DEFAULT', 'admin_user'),
+ ('DEFAULT', 'admin_password'),
+ ('DEFAULT', 'filesystem_store_datadir'),
+ ('DEFAULT', 'swift_store_auth_version'),
+ ('DEFAULT', 'swift_store_auth_address'),
+ ('DEFAULT', 'swift_store_user'),
+ ('DEFAULT', 'swift_store_key'),
+ ('DEFAULT', 'swift_store_container'),
+ ('DEFAULT', 'swift_store_create_container_on_put'),
+ ('DEFAULT', 'swift_store_large_object_size'),
+ ('DEFAULT', 'swift_store_large_object_chunk_size'),
+ ('DEFAULT', 'swift_enable_snet'),
+ ('DEFAULT', 's3_store_host'),
+ ('DEFAULT', 's3_store_access_key'),
+ ('DEFAULT', 's3_store_secret_key'),
+ ('DEFAULT', 's3_store_bucket'),
+ ('DEFAULT', 's3_store_create_bucket_on_put'),
+]
+
GLANCE_REGISTRY_MAPPINGS = {
# Deprecated group/name
('DEFAULT', 'db_backend'): ('database', 'backend'),
@@ -78,140 +200,69 @@
('DATABASE', 'sqlalchemy_pool_timeout'): ('database', 'pool_timeout'),
}
-
-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'
+GLANCE_REGISTRY_EXCEPTIONS = [
+ ('DEFAULT', 'bind_host'),
+ ('DEFAULT', 'bind_host'),
+ ('DEFAULT', 'log_file'),
+ ('DEFAULT', 'backlog'),
+ ('DEFAULT', 'workers'),
+ ('DEFAULT', 'api_limit_max'),
+ ('DEFAULT', 'limit_param_default'),
+ ('DEFAULT', 'rabbit_host'),
+ ('DEFAULT', 'rabbit_port'),
+ ('DEFAULT', 'rabbit_use_ssl'),
+ ('DEFAULT', 'rabbit_userid'),
+ ('DEFAULT', 'rabbit_password'),
+ ('DEFAULT', 'rabbit_virtual_host'),
+ ('DEFAULT', 'rabbit_notification_exchange'),
+ ('DEFAULT', 'rabbit_notification_topic'),
+ ('DEFAULT', 'rabbit_durable_queues'),
+ ('DEFAULT', 'qpid_notification_exchange'),
+ ('DEFAULT', 'qpid_notification_topic'),
+ ('DEFAULT', 'qpid_hostname'),
+ ('DEFAULT', 'qpid_port'),
+ ('DEFAULT', 'qpid_usernamd'),
+ ('DEFAULT', 'qpid_password'),
+ ('DEFAULT', 'qpid_sasl_mechanisms'),
+ ('DEFAULT', 'qpid_reconnect_timeout'),
+ ('DEFAULT', 'qpid_reconnect_limit'),
+ ('DEFAULT', 'qpid_reconnect_interval_min'),
+ ('DEFAULT', 'qpid_reconnect_interval_max'),
+ ('DEFAULT', 'qpid_reconnect_interval'),
+ ('DEFAULT', 'qpid_heartbeat'),
+ ('DEFAULT', 'qpid_protocol'),
+ ('DEFAULT', 'qpid_tcp_nodelay'),
+ ('database', 'connection'),
+ ('keystone_authtoken', 'auth_uri'),
+ ('keystone_authtoken', 'identity_uri'),
+ ('keystone_authtoken', 'admin_tenant_name'),
+ ('keystone_authtoken', 'admin_user'),
+ ('keystone_authtoken', 'admin_password'),
+ ('keystone_authtoken', 'signing_dir'),
+ ('paste_deploy', 'flavor'),
+]
- # 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)
+GLANCE_SCRUBBER_MAPPINGS = {
+ # Deprecated group/name
+ ('DEFAULT', 'filesystem_store_datadir'):
+ ('glance_store', 'filesystem_store_datadir'),
+}
- 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)
+GLANCE_SCRUBBER_EXCEPTIONS = [
+ ('DEFAULT', 'log_file'),
+ ('DEFAULT', 'wakeup_time'),
+ ('DEFAULT', 'scrubber_datadir'),
+ ('DEFAULT', 'cleanup_scrubber'),
+ ('DEFAULT', 'cleanup_scrubber_time'),
+ ('DEFAULT', 'registry_host'),
+ ('DEFAULT', 'registry_port'),
+ ('DEFAULT', 'auth_url'),
+ ('DEFAULT', 'admin_tenant_name'),
+ ('DEFAULT', 'admin_user'),
+ ('DEFAULT', 'admin_password'),
+ ('database', 'connection'),
+ ('glance_store', 'filesystem_store_datadir'),
+]
def start():
@@ -236,13 +287,22 @@
if glob.glob('/etc/glance/*.new'):
# the versions are different, so perform an upgrade
# modify the configuration files
- modify_conf('/etc/glance/glance-api.conf', GLANCE_API_MAPPINGS)
+
+ # backup all the old configuration files
+ create_backups('/etc/glance')
+
+ modify_conf('/etc/glance/glance-api.conf', GLANCE_API_MAPPINGS,
+ GLANCE_API_EXCEPTIONS)
modify_conf('/etc/glance/glance-api-paste.ini')
- modify_conf('/etc/glance/glance-cache.conf')
+ modify_conf('/etc/glance/glance-cache.conf',
+ exception_list=GLANCE_CACHE_EXCEPTIONS)
modify_conf('/etc/glance/glance-registry.conf',
- GLANCE_REGISTRY_MAPPINGS)
+ GLANCE_REGISTRY_MAPPINGS,
+ GLANCE_REGISTRY_EXCEPTIONS)
modify_conf('/etc/glance/glance-registry-paste.ini')
- modify_conf('/etc/glance/glance-scrubber.conf')
+ modify_conf('/etc/glance/glance-scrubber.conf',
+ GLANCE_SCRUBBER_MAPPINGS,
+ GLANCE_SCRUBBER_EXCEPTIONS)
modify_conf('/etc/glance/logging.conf')
config = iniparse.RawConfigParser()
@@ -262,6 +322,7 @@
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)
@@ -269,6 +330,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