6854N/A#!/usr/bin/python2.7
6854N/A
6854N/A# Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
6854N/A#
6854N/A# Licensed under the Apache License, Version 2.0 (the "License"); you may
6854N/A# not use this file except in compliance with the License. You may obtain
6854N/A# a copy of the License at
6854N/A#
6854N/A# http://www.apache.org/licenses/LICENSE-2.0
6854N/A#
6854N/A# Unless required by applicable law or agreed to in writing, software
6854N/A# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
6854N/A# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
6854N/A# License for the specific language governing permissions and limitations
6854N/A# under the License.
6854N/A
6854N/Aimport os
6854N/Afrom subprocess import check_call, Popen, PIPE
6854N/Aimport sys
6854N/Aimport traceback
6854N/A
6854N/Aimport smf_include
6854N/A
6854N/A
6854N/Adef start():
6854N/A # pull out the current version of config/upgrade-id
6854N/A p = Popen(['/usr/bin/svcprop', '-p', 'config/upgrade-id',
6854N/A os.environ['SMF_FMRI']], stdout=PIPE, stderr=PIPE)
6854N/A curr_ver, _err = p.communicate()
6854N/A curr_ver = curr_ver.strip()
6854N/A
6854N/A # extract the openstack-upgrade-id from the pkg
6854N/A p = Popen(['/usr/bin/pkg', 'contents', '-H', '-t', 'set', '-o', 'value',
6854N/A '-a', 'name=openstack.upgrade-id',
6854N/A 'pkg:/cloud/openstack/horizon'], stdout=PIPE, stderr=PIPE)
6854N/A pkg_ver, _err = p.communicate()
6854N/A pkg_ver = pkg_ver.strip()
6854N/A
6854N/A if curr_ver == pkg_ver:
6854N/A # No need to upgrade
6854N/A sys.exit(smf_include.SMF_EXIT_OK)
6854N/A
6854N/A # In versions of OpenStack prior to Mitaka, 'openstack-dashboard-http.conf'
6854N/A # and 'openstack-dashboard-tls.conf' were delivered by the
6854N/A # cloud/openstack/horizon package. Look for the existence of either file
6854N/A # in Apache's conf.d directory. If either are found, exit the service
6854N/A # degraded so the administrator can investigate why.
6854N/A for filename in ['openstack-dashboard-http.conf',
6854N/A 'openstack-dashboard-tls.conf']:
6854N/A path = os.path.join('/etc/apache2/2.4/conf.d', filename)
6854N/A if os.path.exists(path) or os.path.islink(path):
6854N/A reason = '/etc/apache2/2.4/conf.d/%s found. ' % filename + \
6854N/A 'Starting with the Mitaka release, Horizon is now a ' + \
6854N/A 'stand-alone service and should be configured ' + \
6854N/A 'independently from the ' + \
6854N/A 'svc:/network/http:apache24 service. ' + \
6854N/A '/etc/apache2/2.4/conf.d/%s should be ' % filename + \
6854N/A 'removed before restarting the ' + \
6854N/A 'svc:/network/http:apache24 service'
6854N/A smf_include.smf_method_exit(smf_include.SMF_EXIT_DEGRADED,
6854N/A 'Apache_Configured', reason)
6854N/A
6854N/A # update the current version
6854N/A check_call(['/usr/sbin/svccfg', '-s', os.environ['SMF_FMRI'], 'setprop',
6854N/A 'config/upgrade-id', '=', pkg_ver])
6854N/A check_call(['/usr/sbin/svccfg', '-s', os.environ['SMF_FMRI'], 'refresh'])
6854N/A
6854N/A sys.exit(smf_include.SMF_EXIT_OK)
6854N/A
6854N/A
6854N/Aif __name__ == '__main__':
6854N/A os.putenv('LC_ALL', 'C')
6854N/A try:
6854N/A smf_include.smf_main()
6854N/A except RuntimeError:
6854N/A sys.exit(smf_include.SMF_EXIT_ERR_FATAL)
6854N/A except Exception as err:
6854N/A print 'Unknown error: %s' % err
6854N/A print
6854N/A traceback.print_exc(file=sys.stdout)
6854N/A sys.exit(smf_include.SMF_EXIT_ERR_FATAL)