From 703d4477d2385d3c654cdac549b936c08b9c5b31 Mon Sep 17 00:00:00 2001 From: helenyao Date: Wed, 7 Dec 2016 21:24:24 -0500 Subject: Authenticate clients with keystoneauth1.session JIRA: FUNCTEST-529 1. use keystoneauth1.session to initialize the client for each service The keystoneauth1.session.Session class was introduced into keystoneauth1 as an attempt to bring a unified interface to the various OpenStack clients that share common authentication and request parameters between a variety of services. 2. update ODL case to leverage session to get the endpoint info Change-Id: Ic8c01b9b7ed86d3bdd9f5125504bc47f46a37700 Signed-off-by: helenyao --- functest/tests/unit/odl/test_odl.py | 43 +++++++++++++------------------------ 1 file changed, 15 insertions(+), 28 deletions(-) mode change 100644 => 100755 functest/tests/unit/odl/test_odl.py (limited to 'functest/tests/unit') diff --git a/functest/tests/unit/odl/test_odl.py b/functest/tests/unit/odl/test_odl.py old mode 100644 new mode 100755 index ef18016b..c29bfd7f --- a/functest/tests/unit/odl/test_odl.py +++ b/functest/tests/unit/odl/test_odl.py @@ -59,14 +59,6 @@ class ODLTesting(unittest.TestCase): else: return None - @classmethod - def _get_fake_keystone_client(cls): - kclient = mock.Mock() - kclient.service_catalog = mock.Mock() - kclient.service_catalog.url_for = mock.Mock( - side_effect=cls._fake_url_for) - return kclient - def _get_main_kwargs(self, key=None): kwargs = {'odlusername': self._odl_username, 'odlpassword': self._odl_password, @@ -247,8 +239,9 @@ class ODLTesting(unittest.TestCase): def _test_run(self, status=testcase_base.TestcaseBase.EX_OK, exception=None, odlip="127.0.0.3", odlwebport="8080"): - with mock.patch('functest.utils.openstack_utils.get_keystone_client', - return_value=self._get_fake_keystone_client()): + with mock.patch('functest.utils.openstack_utils.get_endpoint', + side_effect=[self._fake_url_for('identity'), + self._fake_url_for('network')]): if exception: self.test.main = mock.Mock(side_effect=exception) else: @@ -288,12 +281,10 @@ class ODLTesting(unittest.TestCase): odlwebport=self._odl_webport) def test_run_missing_sdn_controller_ip(self): - with mock.patch('functest.utils.openstack_utils.get_keystone_client', - return_value=self._get_fake_keystone_client()): - ft_constants.CI_INSTALLER_TYPE = None - ft_constants.SDN_CONTROLLER_IP = None - self.assertEqual(self.test.run(), - testcase_base.TestcaseBase.EX_RUN_ERROR) + ft_constants.CI_INSTALLER_TYPE = None + ft_constants.SDN_CONTROLLER_IP = None + self.assertEqual(self.test.run(), + testcase_base.TestcaseBase.EX_RUN_ERROR) def test_run_without_installer_type(self): ft_constants.SDN_CONTROLLER_IP = self._sdn_controller_ip @@ -308,12 +299,10 @@ class ODLTesting(unittest.TestCase): odlip=self._neutron_ip, odlwebport='8282') def test_run_apex_missing_sdn_controller_ip(self): - with mock.patch('functest.utils.openstack_utils.get_keystone_client', - return_value=self._get_fake_keystone_client()): - ft_constants.CI_INSTALLER_TYPE = "apex" - ft_constants.SDN_CONTROLLER_IP = None - self.assertEqual(self.test.run(), - testcase_base.TestcaseBase.EX_RUN_ERROR) + ft_constants.CI_INSTALLER_TYPE = "apex" + ft_constants.SDN_CONTROLLER_IP = None + self.assertEqual(self.test.run(), + testcase_base.TestcaseBase.EX_RUN_ERROR) def test_run_apex(self): ft_constants.SDN_CONTROLLER_IP = self._sdn_controller_ip @@ -322,12 +311,10 @@ class ODLTesting(unittest.TestCase): odlip=self._sdn_controller_ip, odlwebport='8181') def test_run_joid_missing_sdn_controller(self): - with mock.patch('functest.utils.openstack_utils.get_keystone_client', - return_value=self._get_fake_keystone_client()): - ft_constants.CI_INSTALLER_TYPE = "joid" - ft_constants.SDN_CONTROLLER = None - self.assertEqual(self.test.run(), - testcase_base.TestcaseBase.EX_RUN_ERROR) + ft_constants.CI_INSTALLER_TYPE = "joid" + ft_constants.SDN_CONTROLLER = None + self.assertEqual(self.test.run(), + testcase_base.TestcaseBase.EX_RUN_ERROR) def test_run_joid(self): ft_constants.SDN_CONTROLLER = self._sdn_controller_ip -- cgit 1.2.3-korg