#
# 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
Wrapper functions around ovs-vsctl(8) command used by Nova and Neutron to
determine the lower-link needed for VNIC creation.
"""
import collections
import errno
import glob
import json
import os
import shutil
import time
import uuid
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
"""
return
# 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
"""Convert a json ovsdb return value to native python object"""
return val
"""Return a list of dictionaries where-in each dictionary captures the
requested (or all) column name and its value"""
if columns:
if p.returncode != 0:
try:
results = []
obj = {}
return results
""" Keeps issuing SIGTERM to contract-id at specified intervals until
either the contract is empty or the specified number of attempts are made.
Returns 0 if pkill failed, 1 if contract was successfully emptied and 2
if attempts were exhausted before the contract could be emptied.
"""
# Kill the SMF contract
try:
except CalledProcessError as err:
print "failed to kill the SMF contract: %s" % err
return 0
try:
# check if contract is empty
except:
# contract is empty
return 1
return 2