12 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
12 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
13 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
13 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
14 # License for the specific language governing permissions and limitations |
14 # License for the specific language governing permissions and limitations |
15 # under the License. |
15 # under the License. |
16 |
16 |
17 from ConfigParser import NoOptionError |
|
18 from datetime import datetime |
|
19 import errno |
|
20 import glob |
17 import glob |
21 import os |
18 import os |
22 import shutil |
|
23 from subprocess import check_call, Popen, PIPE |
19 from subprocess import check_call, Popen, PIPE |
24 import sys |
20 import sys |
25 import traceback |
21 import traceback |
26 |
22 |
27 import iniparse |
|
28 import smf_include |
23 import smf_include |
29 |
24 |
|
25 from openstack_common import create_backups, modify_conf |
30 |
26 |
31 def modify_conf(old_file): |
|
32 """ Copy over all uncommented options from the old configuration file. |
|
33 """ |
|
34 |
27 |
35 new_file = old_file + '.new' |
28 ACCOUNT_SERVER_EXCEPTIONS = [ |
|
29 ('DEFAULT', 'bind_port'), |
|
30 ('DEFAULT', 'workers'), |
|
31 ] |
36 |
32 |
37 # open the previous version |
33 CONTAINER_SERVER_EXCEPTIONS = [ |
38 old = iniparse.ConfigParser() |
34 ('DEFAULT', 'bind_port'), |
39 old.readfp(open(old_file)) |
35 ('DEFAULT', 'workers'), |
|
36 ] |
40 |
37 |
41 # open the new version |
38 DISPERSION_CONF_EXCEPTIONS = [ |
42 new = iniparse.ConfigParser() |
39 ('dispersion', 'auth_url'), |
43 try: |
40 ('dispersion', 'auth_user'), |
44 new.readfp(open(new_file)) |
41 ('dispersion', 'auth_key'), |
45 except IOError as err: |
42 ] |
46 if err.errno == errno.ENOENT: |
|
47 # The upgrade did not deliver a .new file so, return |
|
48 print "%s not found - continuing with %s" % (new_file, old_file) |
|
49 return |
|
50 else: |
|
51 raise |
|
52 print "\nupdating %s" % old_file |
|
53 |
43 |
54 # walk every single section for uncommented options |
44 OBJECT_SERVER_EXCEPTIONS = [ |
55 default_items = set(old.items('DEFAULT')) |
45 ('DEFAULT', 'bind_port'), |
56 for section in old.sections() + ['DEFAULT']: |
46 ('DEFAULT', 'workers'), |
|
47 ] |
57 |
48 |
58 # DEFAULT items show up in every section so remove them |
49 PROXY_SERVER_EXCEPTIONS = [ |
59 if section != 'DEFAULT': |
50 ('DEFAULT', 'bind_port'), |
60 section_items = set(old.items(section)) - default_items |
51 ('filter:authtoken', 'auth_uri'), |
61 else: |
52 ('filter:authtoken', 'identity_uri'), |
62 section_items = default_items |
53 ('filter:authtoken', 'admin_tenant_name'), |
|
54 ('filter:authtoken', 'admin_user'), |
|
55 ('filter:authtoken', 'admin_password'), |
|
56 ('filter:authtoken', 'delay_auth_decision'), |
|
57 ('filter:authtoken', 'cache'), |
|
58 ('filter:authtoken', 'include_service_catalog'), |
|
59 ('filter:authtoken', 'signing_dir'), |
|
60 ] |
63 |
61 |
64 for key, value in section_items: |
62 SWIFT_CONF_EXCEPTIONS = [ |
65 # keep a copy of the old value |
63 ('swift-hash', 'swift_hash_path_suffix'), |
66 oldvalue = value |
64 ('swift-hash', 'swift_hash_path_prefix'), |
67 oldsection = section |
65 ('storage-policy:0', 'name'), |
68 |
66 ('storage-policy:0', 'default'), |
69 if not new.has_section(section): |
67 ] |
70 if section != 'DEFAULT': |
|
71 new.add_section(section) |
|
72 |
|
73 # print to the log when a value for the same section.key is |
|
74 # changing to a new value |
|
75 try: |
|
76 new_value = new.get(section, key) |
|
77 if new_value != value and '%SERVICE' not in new_value: |
|
78 print "Changing [%s] %s:\n- %s\n+ %s" % \ |
|
79 (section, key, oldvalue, new_value) |
|
80 print |
|
81 except NoOptionError: |
|
82 # the new configuration file does not have this option set so |
|
83 # just continue |
|
84 pass |
|
85 |
|
86 # Only copy the old value to the new conf file if the entry doesn't |
|
87 # exist or if it contains '%SERVICE' |
|
88 if not new.has_option(section, key) or \ |
|
89 '%SERVICE' in new.get(section, key): |
|
90 new.set(section, key, value) |
|
91 section = oldsection |
|
92 |
|
93 # copy the old conf file to a backup |
|
94 today = datetime.now().strftime("%Y%m%d%H%M%S") |
|
95 shutil.copy2(old_file, old_file + '.' + today) |
|
96 |
|
97 # copy the new conf file in place |
|
98 with open(old_file, 'wb+') as fh: |
|
99 new.write(fh) |
|
100 |
68 |
101 |
69 |
102 def start(): |
70 def start(): |
103 # pull out the current version of config/upgrade-id |
71 # pull out the current version of config/upgrade-id |
104 p = Popen(['/usr/bin/svcprop', '-p', 'config/upgrade-id', |
72 p = Popen(['/usr/bin/svcprop', '-p', 'config/upgrade-id', |
119 |
87 |
120 # look for any .new files |
88 # look for any .new files |
121 if glob.glob('/etc/swift/*.new'): |
89 if glob.glob('/etc/swift/*.new'): |
122 # the versions are different, so perform an upgrade |
90 # the versions are different, so perform an upgrade |
123 # modify the configuration files |
91 # modify the configuration files |
124 modify_conf('/etc/swift/account-server.conf') |
92 |
|
93 # backup all the old configuration files |
|
94 create_backups('/etc/swift') |
|
95 |
|
96 modify_conf('/etc/swift/account-server.conf', None, |
|
97 ACCOUNT_SERVER_EXCEPTIONS) |
125 modify_conf('/etc/swift/container-reconciler.conf') |
98 modify_conf('/etc/swift/container-reconciler.conf') |
126 modify_conf('/etc/swift/container-server.conf') |
99 modify_conf('/etc/swift/container-server.conf', None, |
|
100 CONTAINER_SERVER_EXCEPTIONS) |
127 modify_conf('/etc/swift/container-sync-realms.conf') |
101 modify_conf('/etc/swift/container-sync-realms.conf') |
128 modify_conf('/etc/swift/dispersion.conf') |
102 modify_conf('/etc/swift/dispersion.conf', None, |
|
103 DISPERSION_CONF_EXCEPTIONS) |
129 modify_conf('/etc/swift/memcache.conf') |
104 modify_conf('/etc/swift/memcache.conf') |
130 modify_conf('/etc/swift/object-expirer.conf') |
105 modify_conf('/etc/swift/object-expirer.conf') |
131 modify_conf('/etc/swift/object-server.conf') |
106 modify_conf('/etc/swift/object-server.conf', None, |
132 modify_conf('/etc/swift/proxy-server.conf') |
107 OBJECT_SERVER_EXCEPTIONS) |
133 modify_conf('/etc/swift/swift.conf') |
108 modify_conf('/etc/swift/proxy-server.conf', None, |
|
109 PROXY_SERVER_EXCEPTIONS) |
|
110 modify_conf('/etc/swift/swift.conf', None, SWIFT_CONF_EXCEPTIONS) |
134 |
111 |
135 # update the current version |
112 # update the current version |
136 check_call(['/usr/sbin/svccfg', '-s', os.environ['SMF_FMRI'], 'setprop', |
113 check_call(['/usr/sbin/svccfg', '-s', os.environ['SMF_FMRI'], 'setprop', |
137 'config/upgrade-id', '=', pkg_ver]) |
114 'config/upgrade-id', '=', pkg_ver]) |
138 check_call(['/usr/sbin/svccfg', '-s', os.environ['SMF_FMRI'], 'refresh']) |
115 check_call(['/usr/sbin/svccfg', '-s', os.environ['SMF_FMRI'], 'refresh']) |