|
1 #!/usr/bin/python2.7 |
|
2 |
|
3 # Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. |
|
4 # |
|
5 # Licensed under the Apache License, Version 2.0 (the "License"); you may |
|
6 # not use this file except in compliance with the License. You may obtain |
|
7 # a copy of the License at |
|
8 # |
|
9 # http://www.apache.org/licenses/LICENSE-2.0 |
|
10 # |
|
11 # Unless required by applicable law or agreed to in writing, software |
|
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 |
|
14 # License for the specific language governing permissions and limitations |
|
15 # under the License. |
|
16 |
|
17 import glob |
|
18 import os |
|
19 from subprocess import check_call, Popen, PIPE |
|
20 import sys |
|
21 import traceback |
|
22 |
|
23 import smf_include |
|
24 import sqlalchemy |
|
25 |
|
26 from openstack_common import alter_mysql_tables, create_backups, modify_conf |
|
27 |
|
28 IRONIC_CONF_MAPPINGS = { |
|
29 # Deprecated group/name |
|
30 ('DEFAULT', 'amqp_durable_queues'): |
|
31 ('oslo_messaging_qpid', 'amqp_durable_queues'), |
|
32 ('DEFAULT', 'amqp_auto_delete'): |
|
33 ('oslo_messaging_qpid', 'amqp_auto_delete'), |
|
34 ('DEFAULT', 'rpc_conn_pool_size'): |
|
35 ('oslo_messaging_qpid', 'rpc_conn_pool_size'), |
|
36 ('DEFAULT', 'qpid_hostname'): |
|
37 ('oslo_messaging_qpid', 'qpid_hostname'), |
|
38 ('DEFAULT', 'qpid_port'): |
|
39 ('oslo_messaging_qpid', 'qpid_port'), |
|
40 ('DEFAULT', 'qpid_hosts'): |
|
41 ('oslo_messaging_qpid', 'qpid_hosts'), |
|
42 ('DEFAULT', 'qpid_username'): |
|
43 ('oslo_messaging_qpid', 'qpid_username'), |
|
44 ('DEFAULT', 'qpid_password'): |
|
45 ('oslo_messaging_qpid', 'qpid_password'), |
|
46 ('DEFAULT', 'qpid_sasl_mechanisms'): |
|
47 ('oslo_messaging_qpid', 'qpid_sasl_mechanisms'), |
|
48 ('DEFAULT', 'qpid_tcp_nodelay'): |
|
49 ('oslo_messaging_qpid', 'qpid_tcp_nodelay'), |
|
50 ('DEFAULT', 'qpid_heartbeat'): |
|
51 ('oslo_messaging_qpid', 'qpid_heartbeat'), |
|
52 ('DEFAULT', 'qpid_protocol'): |
|
53 ('oslo_messaging_qpid', 'qpid_protocol'), |
|
54 ('DEFAULT', 'qpid_receiver_capacity'): |
|
55 ('oslo_messaging_qpid', 'qpid_receiver_capacity'), |
|
56 ('DEFAULT', 'qpid_topology_version'): |
|
57 ('oslo_messaging_qpid', 'qpid_topology_version'), |
|
58 ('DEFAULT', 'kombu_ssl_version'): |
|
59 ('oslo_messaging_rabbit', 'kombu_ssl_version'), |
|
60 ('DEFAULT', 'kombu_ssl_keyfile'): |
|
61 ('oslo_messaging_rabbit', 'kombu_ssl_keyfile'), |
|
62 ('DEFAULT', 'kombu_ssl_certfile'): |
|
63 ('oslo_messaging_rabbit', 'kombu_ssl_certfile'), |
|
64 ('DEFAULT', 'kombu_ssl_ca_certs'): |
|
65 ('oslo_messaging_rabbit', 'kombu_ssl_ca_certs'), |
|
66 ('DEFAULT', 'kombu_reconnect_delay'): |
|
67 ('oslo_messaging_rabbit', 'kombu_reconnect_delay'), |
|
68 ('DEFAULT', 'rabbit_host'): |
|
69 ('oslo_messaging_rabbit', 'rabbit_host'), |
|
70 ('DEFAULT', 'rabbit_port'): |
|
71 ('oslo_messaging_rabbit', 'rabbit_port'), |
|
72 ('DEFAULT', 'rabbit_hosts'): |
|
73 ('oslo_messaging_rabbit', 'rabbit_hosts'), |
|
74 ('DEFAULT', 'rabbit_use_ssl'): |
|
75 ('oslo_messaging_rabbit', 'rabbit_use_ssl'), |
|
76 ('DEFAULT', 'rabbit_userid'): |
|
77 ('oslo_messaging_rabbit', 'rabbit_userid'), |
|
78 ('DEFAULT', 'rabbit_password'): |
|
79 ('oslo_messaging_rabbit', 'rabbit_password'), |
|
80 ('DEFAULT', 'rabbit_login_method'): |
|
81 ('oslo_messaging_rabbit', 'rabbit_login_method'), |
|
82 ('DEFAULT', 'rabbit_virtual_host'): |
|
83 ('oslo_messaging_rabbit', 'rabbit_virtual_host'), |
|
84 ('DEFAULT', 'rabbit_retry_interval'): |
|
85 ('oslo_messaging_rabbit', 'rabbit_retry_interval'), |
|
86 ('DEFAULT', 'rabbit_retry_backoff'): |
|
87 ('oslo_messaging_rabbit', 'rabbit_retry_backoff'), |
|
88 ('DEFAULT', 'rabbit_max_retries'): |
|
89 ('oslo_messaging_rabbit', 'rabbit_max_retries'), |
|
90 ('DEFAULT', 'rabbit_ha_queues'): |
|
91 ('oslo_messaging_rabbit', 'rabbit_ha_queues'), |
|
92 ('DEFAULT', 'fake_rabbit'): |
|
93 ('oslo_messaging_rabbit', 'fake_rabbit'), |
|
94 ('keystone_authtoken', 'admin_token'): (None, None), |
|
95 ('keystone_authtoken', 'auth_admin_prefix'): (None, None), |
|
96 ('DEFAULT', 'log_format'): (None, None), |
|
97 ('DEFAULT', 'fake_rabbit'): (None, None), |
|
98 } |
|
99 |
|
100 IRONIC_CONF_EXCEPTIONS = [ |
|
101 ('keystone_authtoken', 'admin_tenant_name'), |
|
102 ('keystone_authtoken', 'admin_user'), |
|
103 ('keystone_authtoken', 'admin_password'), |
|
104 ('keystone_authtoken', 'signing_dir'), |
|
105 ('ai', 'server'), |
|
106 ('ai', 'username'), |
|
107 ] |
|
108 |
|
109 |
|
110 def start(): |
|
111 # pull out the current version of config/upgrade-id |
|
112 p = Popen(['/usr/bin/svcprop', '-p', 'config/upgrade-id', |
|
113 os.environ['SMF_FMRI']], stdout=PIPE, stderr=PIPE) |
|
114 curr_ver, _err = p.communicate() |
|
115 curr_ver = curr_ver.strip() |
|
116 |
|
117 # extract the openstack-upgrade-id from the pkg |
|
118 p = Popen(['/usr/bin/pkg', 'contents', '-H', '-t', 'set', '-o', 'value', |
|
119 '-a', 'name=openstack.upgrade-id', |
|
120 'pkg:/cloud/openstack/ironic'], stdout=PIPE, stderr=PIPE) |
|
121 pkg_ver, _err = p.communicate() |
|
122 pkg_ver = pkg_ver.strip() |
|
123 |
|
124 if curr_ver == pkg_ver: |
|
125 # No need to upgrade |
|
126 sys.exit(smf_include.SMF_EXIT_OK) |
|
127 |
|
128 # look for any .new files |
|
129 if glob.glob('/etc/ironic/*.new'): |
|
130 # the versions are different, so perform an upgrade |
|
131 # modify the configuration files |
|
132 |
|
133 # backup all the old configuration files |
|
134 create_backups('/etc/ironic') |
|
135 |
|
136 modify_conf('/etc/ironic/ironic.conf', IRONIC_CONF_MAPPINGS, |
|
137 IRONIC_CONF_EXCEPTIONS) |
|
138 |
|
139 # update the current version |
|
140 check_call(['/usr/sbin/svccfg', '-s', os.environ['SMF_FMRI'], 'setprop', |
|
141 'config/upgrade-id', '=', pkg_ver]) |
|
142 check_call(['/usr/sbin/svccfg', '-s', os.environ['SMF_FMRI'], 'refresh']) |
|
143 |
|
144 sys.exit(smf_include.SMF_EXIT_OK) |
|
145 |
|
146 |
|
147 if __name__ == '__main__': |
|
148 os.putenv('LC_ALL', 'C') |
|
149 try: |
|
150 smf_include.smf_main() |
|
151 except RuntimeError: |
|
152 sys.exit(smf_include.SMF_EXIT_ERR_FATAL) |
|
153 except Exception as err: |
|
154 print 'Unknown error: %s' % err |
|
155 print |
|
156 traceback.print_exc(file=sys.stdout) |
|
157 sys.exit(smf_include.SMF_EXIT_ERR_FATAL) |