From 2273794919795b86d5fcec1a3970fc151b3db9f2 Mon Sep 17 00:00:00 2001 From: Luigi Toscano Date: Fri, 3 Aug 2018 17:11:14 +0200 Subject: [PATCH] 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 --- config_tempest/services/horizon.py | 14 ++++++++++++-- config_tempest/tests/services/test_horizon.py | 12 ++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/config_tempest/services/horizon.py b/config_tempest/services/horizon.py index 93f66ff8..e54f7fb1 100644 --- a/config_tempest/services/horizon.py +++ b/config_tempest/services/horizon.py @@ -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)) - conf.set('dashboard', 'dashboard_url', base + '/') - conf.set('dashboard', 'login_url', base + '/auth/login/') + if has_horizon: + conf.set('dashboard', 'dashboard_url', base + '/') + conf.set('dashboard', 'login_url', base + '/auth/login/') diff --git a/config_tempest/tests/services/test_horizon.py b/config_tempest/tests/services/test_horizon.py index 33e847ac..e5ba40bd 100644 --- a/config_tempest/tests/services/test_horizon.py +++ b/config_tempest/tests/services/test_horizon.py @@ -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'))