Debian Codegraph @

config_tempest/services/horizon.py

raw
1 # Copyright 2016 Red Hat, Inc.
2 # All Rights Reserved.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License"); you may
5 # not use this file except in compliance with the License. You may obtain
6 # a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # License for the specific language governing permissions and limitations
14 # under the License.
15
16
17 from ssl import CertificateError
18
19 from six.moves import urllib
20
21 from config_tempest import constants as C
22
23
24 def configure_horizon(conf, **kwargs):
25 """Verify horizon is working (fallback to introspect from identity URI)"""
26 if conf.has_option("dashboard", "dashboard_url"):
27 base = conf.get("dashboard", "dashboard_url")
28 else:
29 uri = conf.get('identity', 'uri')
30 u = urllib.parse.urlparse(uri)
31 base = '%s://%s%s' % (u.scheme, u.netloc.replace(
32 ':' + str(u.port), ''), '/dashboard')
33 assert base.startswith('http:') or base.startswith('https:')
34 has_horizon = True
35 try:
36 urllib.request.urlopen(base)
37 except urllib.error.URLError:
38 has_horizon = False
39 except CertificateError as ex:
40 C.LOG.info('Certificate Error while discovering Horizon: %s', (ex))
41 has_horizon = False
42
43 conf.set('service_available', 'horizon', str(has_horizon))
44 if has_horizon:
45 conf.set('dashboard', 'dashboard_url', base + '/')
46 conf.set('dashboard', 'login_url', base + '/auth/login/')
47 ssl = kwargs.get('disable_ssl_certificate_validation', False)
48 conf.set('dashboard', 'disable_ssl_certificate_validation', str(ssl))