aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManuel Buil <mbuil@suse.com>2019-01-18 16:41:28 +0100
committerManuel Buil <mbuil@suse.com>2019-01-21 10:19:01 +0100
commit264aa87f2ea4e52387b671a4d5e1394d46faf5ea (patch)
tree9fd0ed5264672c0bb046fd9f8769e6337a6ab753
parent402517b52e126650c1403927fa0c2f34483e3ff0 (diff)
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 <mbuil@suse.com>
-rw-r--r--sfc/lib/openstack_utils.py3
-rw-r--r--sfc/tests/functest/sfc_chain_deletion.py2
-rw-r--r--sfc/tests/functest/sfc_parent_function.py40
-rw-r--r--sfc/unit_tests/unit/lib/test_openstack_utils.py35
4 files changed, 56 insertions, 24 deletions
diff --git a/sfc/lib/openstack_utils.py b/sfc/lib/openstack_utils.py
index 0f5da884..3d620e2b 100644
--- a/sfc/lib/openstack_utils.py
+++ b/sfc/lib/openstack_utils.py
@@ -43,8 +43,7 @@ class OpenStackSFC:
def get_neutron_client_version(self):
api_version = os.getenv('OS_NETWORK_API_VERSION')
if api_version is not None:
- logger.info("OS_NETWORK_API_VERSION is set in env as '%s'",
- api_version)
+ logger.info("OS_NETWORK_API_VERSION is %s" % api_version)
return api_version
return DEFAULT_API_VERSION
diff --git a/sfc/tests/functest/sfc_chain_deletion.py b/sfc/tests/functest/sfc_chain_deletion.py
index dac32143..5f73d0c7 100644
--- a/sfc/tests/functest/sfc_chain_deletion.py
+++ b/sfc/tests/functest/sfc_chain_deletion.py
@@ -65,7 +65,7 @@ class SfcChainDeletion(sfc_parent_function.SfcCommonTestCase):
self.create_vnffg(self.testcase_config.test_vnffgd_red, 'blue',
'blue_http', port=80, protocol='tcp',
- symmetric=False, only_chain=True)
+ symmetric=False)
t2 = threading.Thread(target=odl_utils.wait_for_classification_rules,
args=(self.ovs_logger, self.compute_nodes,
diff --git a/sfc/tests/functest/sfc_parent_function.py b/sfc/tests/functest/sfc_parent_function.py
index dab6abc0..9558eb8c 100644
--- a/sfc/tests/functest/sfc_parent_function.py
+++ b/sfc/tests/functest/sfc_parent_function.py
@@ -58,9 +58,6 @@ class SfcCommonTestCase(object):
self.server_ip = None
self.port_client = None
- # n-sfc variables
- self.port_groups = []
-
self.prepare_env(testcase_config, supported_installers, vnfs)
def prepare_env(self, testcase_config, supported_installers, vnfs):
@@ -404,10 +401,10 @@ class SfcCommonTestCase(object):
# TODO: If we had a testcase where only one chains must be removed
# we would need to add the logic. Now it removes all of them
openstack_sfc.delete_chain()
+ openstack_sfc.delete_port_groups()
def create_vnffg(self, testcase_config_name, vnffgd_name, vnffg_name,
- port=80, protocol='tcp', symmetric=False,
- only_chain=False):
+ port=80, protocol='tcp', symmetric=False):
"""Create the vnffg components following the instructions from
relevant templates.
@@ -451,31 +448,32 @@ class SfcCommonTestCase(object):
self.neutron_port.id)
elif COMMON_CONFIG.mano_component == 'no-mano':
- if not only_chain:
- for vnf in self.vnfs:
- # vnf_instance is in [0] and vnf_port in [1]
- vnf_instance = self.vnf_objects[vnf][0]
- vnf_port = self.vnf_objects[vnf][1]
- if symmetric:
- # VNFs have two ports
- neutron_port1 = vnf_port[0]
- neutron_port2 = vnf_port[1]
- neutron_ports = [neutron_port1, neutron_port2]
- else:
- neutron_port1 = vnf_port[0]
- neutron_ports = [neutron_port1]
+ port_groups = []
+ for vnf in self.vnfs:
+ # vnf_instance is in [0] and vnf_port in [1]
+ vnf_instance = self.vnf_objects[vnf][0]
+ vnf_port = self.vnf_objects[vnf][1]
+ if symmetric:
+ # VNFs have two ports
+ neutron_port1 = vnf_port[0]
+ neutron_port2 = vnf_port[1]
+ neutron_ports = [neutron_port1, neutron_port2]
+ else:
+ neutron_port1 = vnf_port[0]
+ neutron_ports = [neutron_port1]
port_group = \
openstack_sfc.create_port_groups(neutron_ports,
vnf_instance)
- self.port_groups.append(port_group)
+ port_groups.append(port_group)
+
self.neutron_port = self.port_client
if symmetric:
# We must pass the server_port and server_ip in the symmetric
# case. Otherwise ODL does not work well
server_ip_prefix = self.server_ip + '/32'
- openstack_sfc.create_chain(self.port_groups,
+ openstack_sfc.create_chain(port_groups,
self.neutron_port.id,
port, protocol, vnffg_name,
symmetric,
@@ -483,7 +481,7 @@ class SfcCommonTestCase(object):
server_ip=server_ip_prefix)
else:
- openstack_sfc.create_chain(self.port_groups,
+ openstack_sfc.create_chain(port_groups,
self.neutron_port.id,
port, protocol, vnffg_name,
symmetric)
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
@@ -66,6 +66,18 @@ class SfcOpenStackUtilsTesting(unittest.TestCase):
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):
"""