From cc1fb066aeae936a97bcace5cb853d2e5470bb87 Mon Sep 17 00:00:00 2001 From: Cédric Ollivier Date: Wed, 19 Oct 2016 20:30:29 +0200 Subject: Cover KeyError in ODLTestCases.run() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It simply tests if run returns EX_RUN_ERROR when a mandatory env var is unset (for instance SDN_CONTROLLER_IP in case of apex). Change-Id: Ib172975d84eb0953dd13bad32506bbd750ec4b8d Signed-off-by: Cédric Ollivier --- unit_tests/odl/test_odl.py | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) (limited to 'unit_tests/odl/test_odl.py') diff --git a/unit_tests/odl/test_odl.py b/unit_tests/odl/test_odl.py index e943dcaf..76732593 100644 --- a/unit_tests/odl/test_odl.py +++ b/unit_tests/odl/test_odl.py @@ -35,8 +35,9 @@ class ODLTestCasesTesting(unittest.TestCase): _odl_password = "admin" def setUp(self): - if "INSTALLER_TYPE" in os.environ: - del os.environ["INSTALLER_TYPE"] + for var in ("INSTALLER_TYPE", "SDN_CONTROLLER", "SDN_CONTROLLER_IP"): + if var in os.environ: + del os.environ[var] os.environ["OS_USERNAME"] = self._os_username os.environ["OS_PASSWORD"] = self._os_password os.environ["OS_TENANT_NAME"] = self._os_tenantname @@ -63,11 +64,6 @@ class ODLTestCasesTesting(unittest.TestCase): def test_set_robotframework_vars(self, args): self.assertTrue(self.test.set_robotframework_vars()) - def _test_run_missing_env_var(self, var): - del os.environ[var] - self.assertEqual(self.test.run(), - TestCasesBase.TestCasesBase.EX_RUN_ERROR) - @classmethod def _fake_url_for(cls, service_type='identity', **kwargs): if service_type == 'identity': @@ -274,6 +270,11 @@ class ODLTestCasesTesting(unittest.TestCase): mock.patch.object(self.test, 'parse_results'): self._test_main(TestCasesBase.TestCasesBase.EX_OK, *args) + def _test_run_missing_env_var(self, var): + del os.environ[var] + self.assertEqual(self.test.run(), + TestCasesBase.TestCasesBase.EX_RUN_ERROR) + def _test_run(self, status=TestCasesBase.TestCasesBase.EX_OK, exception=None, odlip="127.0.0.3", odlwebport="8080"): with mock.patch('functest.utils.openstack_utils.get_keystone_client', @@ -314,6 +315,12 @@ class ODLTestCasesTesting(unittest.TestCase): odlip=self._sdn_controller_ip, 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()): + self.assertEqual(self.test.run(), + TestCasesBase.TestCasesBase.EX_RUN_ERROR) + def test_run_without_installer_type(self): os.environ["SDN_CONTROLLER_IP"] = self._sdn_controller_ip self._test_run(TestCasesBase.TestCasesBase.EX_OK, @@ -325,12 +332,26 @@ class ODLTestCasesTesting(unittest.TestCase): self._test_run(TestCasesBase.TestCasesBase.EX_OK, 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()): + os.environ["INSTALLER_TYPE"] = "apex" + self.assertEqual(self.test.run(), + TestCasesBase.TestCasesBase.EX_RUN_ERROR) + def test_run_apex(self): os.environ["SDN_CONTROLLER_IP"] = self._sdn_controller_ip os.environ["INSTALLER_TYPE"] = "apex" self._test_run(TestCasesBase.TestCasesBase.EX_OK, 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()): + os.environ["INSTALLER_TYPE"] = "joid" + self.assertEqual(self.test.run(), + TestCasesBase.TestCasesBase.EX_RUN_ERROR) + def test_run_joid(self): os.environ["SDN_CONTROLLER"] = self._sdn_controller_ip os.environ["INSTALLER_TYPE"] = "joid" -- cgit 1.2.3-korg