horizon: don't error out for certificate issues

The code should be rewritten anyway (see
https://storyboard.openstack.org/#!/story/2002787)
and in general the detection of the dashboard location
should be more roboust, but the code should not raise
an exception.
and horizon settings are relevant only for the (few)
Horizon Tempest tests, but the system can otherwise work.

Change-Id: I62607ce4de65062a0c37bdd23220edf9ea7e6818
Story: 2003024
Task: 23048
This commit is contained in:
Luigi Toscano 2018-08-03 17:11:14 +02:00
parent 3b95b8eacb
commit 2273794919
2 changed files with 24 additions and 2 deletions

View File

@ -13,8 +13,13 @@
# License for the specific language governing permissions and limitations
# under the License.
from ssl import CertificateError
from six.moves import urllib
from config_tempest import constants as C
def configure_horizon(conf):
"""Derive the horizon URIs from the identity's URI."""
@ -28,6 +33,11 @@ def configure_horizon(conf):
urllib.request.urlopen(base)
except urllib.error.URLError:
has_horizon = False
except CertificateError as ex:
C.LOG.info('Certificate Error while discovering Horizon: %s', (ex))
has_horizon = False
conf.set('service_available', 'horizon', str(has_horizon))
if has_horizon:
conf.set('dashboard', 'dashboard_url', base + '/')
conf.set('dashboard', 'login_url', base + '/auth/login/')

View File

@ -13,6 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.
from ssl import CertificateError
from fixtures import MonkeyPatch
import mock
@ -48,3 +50,13 @@ class TestConfigTempest(BaseConfigTempestTest):
"http://[::1]/dashboard/")
self.assertEqual(self.conf.get('dashboard', 'login_url'),
"http://[::1]/dashboard/auth/login/")
def test_configure_horizon_certificate_error(self):
mock_function = mock.Mock(return_value=True)
mock_function.side_effect = CertificateError
self.useFixture(MonkeyPatch('six.moves.urllib.request.urlopen',
mock_function))
horizon.configure_horizon(self.conf)
self.assertEqual(self.conf.get('service_available', 'horizon'),
"False")
self.assertFalse(self.conf.has_section('dashboard'))