From 264aa87f2ea4e52387b671a4d5e1394d46faf5ea Mon Sep 17 00:00:00 2001 From: Manuel Buil Date: Fri, 18 Jan 2019 16:41:28 +0100 Subject: Simplify deletion test and fix unittest Removing the port groups when deleting the first chain simplifies things because we don't need port_groups to be a variable of the SfcCommonTestCase class There were also some missing unittest Change-Id: I6ae780bdc72116907a9e6037571c29f28a6ba334 Signed-off-by: Manuel Buil --- sfc/unit_tests/unit/lib/test_openstack_utils.py | 35 +++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'sfc/unit_tests') diff --git a/sfc/unit_tests/unit/lib/test_openstack_utils.py b/sfc/unit_tests/unit/lib/test_openstack_utils.py index 78be88f0..ffaace68 100644 --- a/sfc/unit_tests/unit/lib/test_openstack_utils.py +++ b/sfc/unit_tests/unit/lib/test_openstack_utils.py @@ -65,6 +65,18 @@ class SfcOpenStackUtilsTesting(unittest.TestCase): self.patcher7.stop() self.patcher8.stop() + @patch('sfc.lib.openstack_utils.logger', autospec=True) + @patch('os.environ', {'OS_NETWORK_API_VERSION': '1'}) + def test_get_neutron_client_version(self, + mock_log): + """ + Checks the proper functionality of get_neutron_client_version + """ + log_calls = [call("OS_NETWORK_API_VERSION is 1")] + result = self.os_sfc.get_neutron_client_version() + assert result is '1' + mock_log.info.assert_has_calls(log_calls) + @patch('sfc.lib.openstack_utils.logger', autospec=True) def test_register_glance_image_already_exists(self, mock_log): @@ -554,6 +566,18 @@ class SfcOpenStackUtilsTesting(unittest.TestCase): self.conn.compute.hypervisors.assert_called_once() self.assertEqual(nodes, result) + @patch('sfc.lib.openstack_utils.logger', autospec=True) + def test_get_hypervisor_hosts_exception(self, mock_log): + """ + Checks the proper functionality of get_av_zone + function when an exception appears + """ + log_calls = [call('Error [get_hypervisors(compute)]: Error MSG')] + self.conn.compute.hypervisors.side_effect = Exception('Error MSG') + result = self.os_sfc.get_hypervisor_hosts() + mock_log.error.assert_has_calls(log_calls) + self.assertIsNone(result) + @patch('sfc.lib.openstack_utils.OpenStackSFC.get_vm_compute', autospec=True, return_value='mock_client') def test_compute_client(self, mock_get_vm_compute): @@ -851,6 +875,17 @@ class SfcOpenStackUtilsTesting(unittest.TestCase): self.conn.network.delete_security_group.assert_has_calls(del_calls) mock_log.info.assert_has_calls(log_calls_info) + @patch('sfc.lib.openstack_utils.cr_inst.OpenStackVmInstance', + autospec=True) + def test_wait_for_vnf(self, mock_os_vm): + """ + Checks the proper functionality of wait_for_vnf function + """ + + mock_os_vm.vm_active.return_value = "x" + result = self.os_sfc.wait_for_vnf(mock_os_vm) + self.assertEqual('x', result) + @patch('sfc.lib.openstack_utils.logger', autospec=True) def test_create_port_groups_raises_exception(self, mock_log): """ -- cgit 1.2.3-korg