diff options
-rw-r--r-- | tests/opnfv/test_suites/opnfv_os-odl-ovs-noha_daily.yaml | 64 | ||||
-rw-r--r-- | yardstick/network_services/vnf_generic/vnf/prox_vnf.py | 10 | ||||
-rw-r--r-- | yardstick/tests/unit/common/test_openstack_utils.py | 67 | ||||
-rw-r--r-- | yardstick/tests/unit/common/test_process.py | 10 |
4 files changed, 111 insertions, 40 deletions
diff --git a/tests/opnfv/test_suites/opnfv_os-odl-ovs-noha_daily.yaml b/tests/opnfv/test_suites/opnfv_os-odl-ovs-noha_daily.yaml new file mode 100644 index 000000000..83b370066 --- /dev/null +++ b/tests/opnfv/test_suites/opnfv_os-odl-ovs-noha_daily.yaml @@ -0,0 +1,64 @@ +############################################################################## +# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## +--- +# os-odl-ovs-noha daily task suite + +schema: "yardstick:suite:0.1" + +name: "os-odl-ovs-noha" +test_cases_dir: "tests/opnfv/test_cases/" +test_cases: +- + file_name: opnfv_yardstick_tc002.yaml +- + file_name: opnfv_yardstick_tc005.yaml +- + file_name: opnfv_yardstick_tc010.yaml +- + file_name: opnfv_yardstick_tc011.yaml + constraint: + installer: compass,fuel +- + file_name: opnfv_yardstick_tc012.yaml +- + file_name: opnfv_yardstick_tc014.yaml +- + file_name: opnfv_yardstick_tc037.yaml +- + file_name: opnfv_yardstick_tc055.yaml + constraint: + installer: compass + pod: huawei-pod1 + task_args: + huawei-pod1: '{"file": "etc/yardstick/nodes/compass_sclab_physical/pod.yaml", + "host": "node5"}' +- + file_name: opnfv_yardstick_tc063.yaml + constraint: + installer: compass + pod: huawei-pod1 + task_args: + huawei-pod1: '{"file": "etc/yardstick/nodes/compass_sclab_physical/pod.yaml", + "host": "node5"}' +- + file_name: opnfv_yardstick_tc069.yaml +- + file_name: opnfv_yardstick_tc070.yaml +- + file_name: opnfv_yardstick_tc071.yaml +- + file_name: opnfv_yardstick_tc072.yaml +- + file_name: opnfv_yardstick_tc075.yaml + constraint: + installer: compass + pod: huawei-pod1 + task_args: + huawei-pod1: '{"file": "etc/yardstick/nodes/compass_sclab_physical/pod.yaml", + "host": "node1"}' diff --git a/yardstick/network_services/vnf_generic/vnf/prox_vnf.py b/yardstick/network_services/vnf_generic/vnf/prox_vnf.py index 63295c2e6..366c5b26b 100644 --- a/yardstick/network_services/vnf_generic/vnf/prox_vnf.py +++ b/yardstick/network_services/vnf_generic/vnf/prox_vnf.py @@ -90,16 +90,18 @@ class ProxApproxVnf(SampleVNF): "1, 2 or 4 ports only supported at this time") all_port_stats = self.vnf_execute('multi_port_stats', range(port_count)) - rx_total = tx_total = 0 + rx_total = tx_total = tsc = 0 try: for single_port_stats in all_port_stats: rx_total = rx_total + single_port_stats[1] tx_total = tx_total + single_port_stats[2] - tsc = single_port_stats[5] + tsc = tsc + single_port_stats[5] except (TypeError, IndexError): LOG.error("Invalid data ...") return {} + tsc = tsc / port_count + result = { "packets_in": rx_total, "packets_dropped": max((tx_total - rx_total), 0), @@ -110,14 +112,14 @@ class ProxApproxVnf(SampleVNF): } try: curr_packets_in = int(((rx_total - self.prev_packets_in) * self.tsc_hz) - / (tsc - self.prev_tsc) * port_count) + / (tsc - self.prev_tsc)) except ZeroDivisionError: LOG.error("Error.... Divide by Zero") curr_packets_in = 0 try: curr_packets_fwd = int(((tx_total - self.prev_packets_sent) * self.tsc_hz) - / (tsc - self.prev_tsc) * port_count) + / (tsc - self.prev_tsc)) except ZeroDivisionError: LOG.error("Error.... Divide by Zero") curr_packets_fwd = 0 diff --git a/yardstick/tests/unit/common/test_openstack_utils.py b/yardstick/tests/unit/common/test_openstack_utils.py index d02a34d24..f6a0bdcc1 100644 --- a/yardstick/tests/unit/common/test_openstack_utils.py +++ b/yardstick/tests/unit/common/test_openstack_utils.py @@ -7,11 +7,13 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -from oslo_utils import uuidutils -import unittest +import os + import mock +from oslo_utils import uuidutils import shade from shade import exc +import unittest from yardstick.common import constants from yardstick.common import openstack_utils @@ -28,11 +30,12 @@ class GetCredentialsTestCase(unittest.TestCase): class GetHeatApiVersionTestCase(unittest.TestCase): - def test_get_heat_api_version_check_result(self): + @mock.patch.object(openstack_utils, 'log') + def test_get_heat_api_version_check_result(self, *args): API = 'HEAT_API_VERSION' expected_result = '2' - with mock.patch.dict('os.environ', {API: '2'}, clear=True): + with mock.patch.dict(os.environ, {API: '2'}, clear=True): api_version = openstack_utils.get_heat_api_version() self.assertEqual(api_version, expected_result) @@ -277,6 +280,12 @@ class CreateSecurityGroupRuleTestCase(unittest.TestCase): self.mock_shade_client = mock.Mock() self.secgroup_name_or_id = 'sg_name_id' self.mock_shade_client.create_security_group_rule = mock.Mock() + self._mock_log = mock.patch.object(openstack_utils, 'log') + self.mock_log = self._mock_log.start() + self.addCleanup(self._stop_mock) + + def _stop_mock(self): + self._mock_log.stop() def test_create_security_group_rule(self): self.mock_shade_client.create_security_group_rule.return_value = ( @@ -285,14 +294,13 @@ class CreateSecurityGroupRuleTestCase(unittest.TestCase): self.mock_shade_client, self.secgroup_name_or_id) self.assertTrue(output) - @mock.patch.object(openstack_utils, 'log') - def test_create_security_group_rule_exception(self, mock_logger): + def test_create_security_group_rule_exception(self): self.mock_shade_client.create_security_group_rule.side_effect = ( exc.OpenStackCloudException('error message')) output = openstack_utils.create_security_group_rule( self.mock_shade_client, self.secgroup_name_or_id) - mock_logger.error.assert_called_once() + self.mock_log.error.assert_called_once() self.assertFalse(output) @@ -321,6 +329,12 @@ class SecurityGroupTestCase(unittest.TestCase): self.sg_name = 'sg_name' self.sg_description = 'sg_description' self._uuid = uuidutils.generate_uuid() + self._mock_log = mock.patch.object(openstack_utils, 'log') + self.mock_log = self._mock_log.start() + self.addCleanup(self._stop_mock) + + def _stop_mock(self): + self._mock_log.stop() def test_create_security_group_full_existing_security_group(self): self.mock_shade_client.get_security_group.return_value = ( @@ -330,21 +344,18 @@ class SecurityGroupTestCase(unittest.TestCase): self.mock_shade_client.get_security_group.assert_called_once() self.assertEqual(self._uuid, output) - @mock.patch.object(openstack_utils, 'log') - def test_create_security_group_full_non_existing_security_group( - self, mock_logger): + def test_create_security_group_full_non_existing_security_group(self): self.mock_shade_client.get_security_group.return_value = None self.mock_shade_client.create_security_group.side_effect = ( exc.OpenStackCloudException('error message')) output = openstack_utils.create_security_group_full( self.mock_shade_client, self.sg_name, self.sg_description) - mock_logger.error.assert_called_once() + self.mock_log.error.assert_called_once() self.assertIsNone(output) @mock.patch.object(openstack_utils, 'create_security_group_rule') - @mock.patch.object(openstack_utils, 'log') def test_create_security_group_full_create_rule_fail( - self, mock_logger, mock_create_security_group_rule): + self, mock_create_security_group_rule): self.mock_shade_client.get_security_group.return_value = None self.mock_shade_client.create_security_group.return_value = ( {'name': 'name', 'id': self._uuid}) @@ -353,7 +364,7 @@ class SecurityGroupTestCase(unittest.TestCase): self.mock_shade_client, self.sg_name, self.sg_description) mock_create_security_group_rule.assert_called() self.mock_shade_client.delete_security_group(self.sg_name) - mock_logger.error.assert_called_once() + self.mock_log.error.assert_called_once() self.assertIsNone(output) @mock.patch.object(openstack_utils, 'create_security_group_rule') @@ -369,10 +380,6 @@ class SecurityGroupTestCase(unittest.TestCase): self.mock_shade_client.delete_security_group(self.sg_name) self.assertEqual(self._uuid, output) -# ********************************************* -# NOVA -# ********************************************* - class CreateInstanceTestCase(unittest.TestCase): @@ -543,10 +550,6 @@ class GetFlavorTestCase(unittest.TestCase): mock_logger.error.assert_called_once() self.assertIsNone(output) -# ********************************************* -# CINDER -# ********************************************* - class GetVolumeIDTestCase(unittest.TestCase): @@ -664,22 +667,23 @@ class DetachVolumeTestCase(unittest.TestCase): self.assertFalse(output) -# ********************************************* -# GLANCE -# ********************************************* - class CreateImageTestCase(unittest.TestCase): def setUp(self): self.mock_shade_client = mock.Mock() self._uuid = uuidutils.generate_uuid() self.name = 'image_name' + self._mock_log = mock.patch.object(openstack_utils, 'log') + self.mock_log = self._mock_log.start() + self.addCleanup(self._stop_mock) - @mock.patch.object(openstack_utils, 'log') - def test_create_image_already_exit(self, mock_logger): + def _stop_mock(self): + self._mock_log.stop() + + def test_create_image_already_exit(self): self.mock_shade_client.get_image_id.return_value = self._uuid output = openstack_utils.create_image(self.mock_shade_client, self.name) - mock_logger.info.assert_called_once() + self.mock_log.info.assert_called_once() self.assertEqual(self._uuid, output) def test_create_image(self): @@ -688,15 +692,14 @@ class CreateImageTestCase(unittest.TestCase): output = openstack_utils.create_image(self.mock_shade_client, self.name) self.assertEqual(self._uuid, output) - @mock.patch.object(openstack_utils, 'log') - def test_create_image_exception(self, mock_logger): + def test_create_image_exception(self): self.mock_shade_client.get_image_id.return_value = None self.mock_shade_client.create_image.side_effect = ( exc.OpenStackCloudException('error message')) output = openstack_utils.create_image(self.mock_shade_client, self.name) - mock_logger.error.assert_called_once() + self.mock_log.error.assert_called_once() self.assertIsNone(output) diff --git a/yardstick/tests/unit/common/test_process.py b/yardstick/tests/unit/common/test_process.py index 1c6dfec27..e0933c6ac 100644 --- a/yardstick/tests/unit/common/test_process.py +++ b/yardstick/tests/unit/common/test_process.py @@ -90,10 +90,11 @@ class ExecuteTestCase(unittest.TestCase): additional_env=self.additional_env) self.assertEqual(self.stdout, out) - def test_execute_exception(self): + @mock.patch.object(process, 'LOG') + def test_execute_exception(self, *args): self.obj.returncode = self.RET_CODE_WRONG - self.assertRaises(exceptions.ProcessExecutionError, process.execute, - self.input_cmd, additional_env=self.additional_env) + with self.assertRaises(exceptions.ProcessExecutionError): + process.execute(self.input_cmd, additional_env=self.additional_env) self.obj.communicate.assert_called_once_with(None) def test_execute_with_extra_code(self): @@ -107,7 +108,8 @@ class ExecuteTestCase(unittest.TestCase): additional_env=self.additional_env) self.assertEqual(self.stdout, out) - def test_execute_exception_no_check(self): + @mock.patch.object(process, 'LOG') + def test_execute_exception_no_check(self, *args): self.obj.returncode = self.RET_CODE_WRONG out = process.execute(self.input_cmd, additional_env=self.additional_env, |