aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/network_services
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/network_services')
-rw-r--r--tests/unit/network_services/traffic_profile/test_prox_mpls.py95
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_base.py34
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py73
3 files changed, 33 insertions, 169 deletions
diff --git a/tests/unit/network_services/traffic_profile/test_prox_mpls.py b/tests/unit/network_services/traffic_profile/test_prox_mpls.py
deleted file mode 100644
index 00a690d2a..000000000
--- a/tests/unit/network_services/traffic_profile/test_prox_mpls.py
+++ /dev/null
@@ -1,95 +0,0 @@
-# Copyright (c) 2017 Intel Corporation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-from __future__ import absolute_import
-
-import unittest
-import mock
-
-from tests.unit import STL_MOCKS
-
-STLClient = mock.MagicMock()
-stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
-stl_patch.start()
-
-if stl_patch:
- from yardstick.network_services.vnf_generic.vnf.prox_helpers import ProxTestDataTuple
- from yardstick.network_services.traffic_profile.prox_mpls_tag_untag import ProxMplsTagUntagProfile
-
-
-class TestProxMplsTagUntagProfile(unittest.TestCase):
-
- def test_mpls_1(self):
- def target(*args, **kwargs):
- runs.append(args[2])
- if args[2] < 0 or args[2] > 100:
- raise RuntimeError(' '.join([str(args), str(runs)]))
- if args[2] > 75.0:
- return fail_tuple, {}
- return success_tuple, {}
-
- tp_config = {
- 'traffic_profile': {
- 'packet_sizes': [200],
- },
- }
-
- runs = []
- success_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.1, 5.2, 5.3], 995, 1000, 123.4)
- fail_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.6, 5.7, 5.8], 850, 1000, 123.4)
-
- traffic_generator = mock.MagicMock()
-
- profile = ProxMplsTagUntagProfile(tp_config)
- profile.init(mock.MagicMock())
- profile._profile_helper = profile_helper = mock.MagicMock()
- profile_helper.run_test = target
-
- profile.execute_traffic(traffic_generator)
- self.assertEqual(round(profile.current_lower, 2), 74.69)
- self.assertEqual(round(profile.current_upper, 2), 75.39)
- self.assertEqual(len(runs), 8)
-
- def test_mpls_2(self):
- def target(*args, **kwargs):
- runs.append(args[2])
- if args[2] < 0 or args[2] > 100:
- raise RuntimeError(' '.join([str(args), str(runs)]))
- if args[2] > 25.0:
- return fail_tuple, {}
- return success_tuple, {}
-
- tp_config = {
- 'traffic_profile': {
- 'packet_sizes': [200],
- 'test_precision': 2.0,
- },
- }
-
- runs = []
- success_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.1, 5.2, 5.3], 995, 1000, 123.4)
- fail_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.6, 5.7, 5.8], 850, 1000, 123.4)
-
- traffic_generator = mock.MagicMock()
-
- profile = ProxMplsTagUntagProfile(tp_config)
- profile.init(mock.MagicMock())
- profile._profile_helper = profile_helper = mock.MagicMock()
- profile_helper.run_test = target
-
- profile.execute_traffic(traffic_generator)
- self.assertEqual(round(profile.current_lower, 2), 24.06)
- self.assertEqual(round(profile.current_upper, 2), 25.47)
- self.assertEqual(len(runs), 7)
diff --git a/tests/unit/network_services/vnf_generic/vnf/test_base.py b/tests/unit/network_services/vnf_generic/vnf/test_base.py
index 478ce186b..f812d67ef 100644
--- a/tests/unit/network_services/vnf_generic/vnf/test_base.py
+++ b/tests/unit/network_services/vnf_generic/vnf/test_base.py
@@ -243,31 +243,13 @@ class TestGenericVNF(unittest.TestCase):
class TestGenericTrafficGen(unittest.TestCase):
- def test___init__(self):
- vnfd = TestGenericVNF.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- generic_traffic_gen = GenericTrafficGen('vnf1', vnfd)
- assert generic_traffic_gen.name == "vnf1"
-
- def test_listen_traffic(self):
- vnfd = TestGenericVNF.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- generic_traffic_gen = GenericTrafficGen('vnf1', vnfd)
- traffic_profile = {}
- self.assertIsNone(generic_traffic_gen.listen_traffic(traffic_profile))
-
- def test_run_traffic(self):
- vnfd = TestGenericVNF.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- generic_traffic_gen = GenericTrafficGen('vnf1', vnfd)
- traffic_profile = {}
- self.assertRaises(NotImplementedError,
- generic_traffic_gen.run_traffic, traffic_profile)
-
- def test_terminate(self):
- vnfd = TestGenericVNF.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- generic_traffic_gen = GenericTrafficGen('vnf1', vnfd)
- self.assertRaises(NotImplementedError, generic_traffic_gen.terminate)
- def test_verify_traffic(self):
+ def test_definition(self):
+ """Make sure that the abstract class cannot be instantiated"""
vnfd = TestGenericVNF.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- generic_traffic_gen = GenericTrafficGen('vnf1', vnfd)
- traffic_profile = {}
- self.assertIsNone(generic_traffic_gen.verify_traffic(traffic_profile))
+ name = 'vnf1'
+ with self.assertRaises(TypeError) as exc:
+ GenericTrafficGen(name, vnfd)
+ msg = ("Can't instantiate abstract class GenericTrafficGen with "
+ "abstract methods run_traffic, terminate")
+ self.assertEqual(msg, str(exc.exception))
diff --git a/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py b/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py
index 57f9fac61..85b10c5a9 100644
--- a/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py
+++ b/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py
@@ -2022,55 +2022,32 @@ class TestSampleVNFTrafficGen(unittest.TestCase):
sample_vnf_tg.terminate()
- @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.time')
- @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.LOG')
- def test_wait_for_instantiate(self, mock_logger, mock_time):
+ def test__wait_for_process(self):
sample_vnf_tg = SampleVNFTrafficGen('tg1', self.VNFD_0)
- sample_vnf_tg._check_status = mock.Mock(side_effect=iter([1, 0]))
- sample_vnf_tg._tg_process = mock.Mock()
- sample_vnf_tg._tg_process.is_alive.return_value = True
- sample_vnf_tg._tg_process.exitcode = 234
-
- self.assertEqual(sample_vnf_tg.wait_for_instantiate(), 234)
-
- @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.time')
- @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.LOG')
- def test_wait_for_instantiate_not_alive(self, mock_logger, mock_time):
+ with mock.patch.object(sample_vnf_tg, '_check_status',
+ return_value=0) as mock_status, \
+ mock.patch.object(sample_vnf_tg, '_tg_process') as mock_proc:
+ mock_proc.is_alive.return_value = True
+ mock_proc.exitcode = 234
+ self.assertEqual(sample_vnf_tg._wait_for_process(), 234)
+ mock_proc.is_alive.assert_called_once()
+ mock_status.assert_called_once()
+
+ def test__wait_for_process_not_alive(self):
sample_vnf_tg = SampleVNFTrafficGen('tg1', self.VNFD_0)
- sample_vnf_tg._check_status = mock.Mock(return_value=1)
- sample_vnf_tg._tg_process = mock.Mock()
- sample_vnf_tg._tg_process.is_alive.side_effect = iter([True, False])
- sample_vnf_tg._tg_process.exitcode = 234
-
- with self.assertRaises(RuntimeError):
- sample_vnf_tg.wait_for_instantiate()
-
- @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.time')
- @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.LOG')
- @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.Process')
- def test_wait_for_instantiate_delayed(self, mock_process, mock_logger, mock_time):
- class MockClientStarted(mock.Mock):
-
- def __init__(self, *args, **kwargs):
- super(MockClientStarted, self).__init__(*args, **kwargs)
- self.iter = iter([0, 0, 1])
-
- @property
- def value(self):
- return next(self.iter)
-
- mock_traffic_profile = mock.Mock(autospec=TrafficProfile)
- mock_traffic_profile.get_traffic_definition.return_value = "64"
- mock_traffic_profile.execute_traffic.return_value = "64"
- mock_traffic_profile.params = self.TRAFFIC_PROFILE
+ with mock.patch.object(sample_vnf_tg, '_tg_process') as mock_proc:
+ mock_proc.is_alive.return_value = False
+ self.assertRaises(RuntimeError, sample_vnf_tg._wait_for_process)
+ mock_proc.is_alive.assert_called_once()
+ def test__wait_for_process_delayed(self):
sample_vnf_tg = SampleVNFTrafficGen('tg1', self.VNFD_0)
- sample_vnf_tg._check_status = mock.Mock(side_effect=iter([1, 0]))
- sample_vnf_tg._tg_process = mock.Mock()
- sample_vnf_tg._tg_process.is_alive.return_value = True
- sample_vnf_tg._tg_process.exitcode = 234
- sample_vnf_tg.resource_helper = mock.Mock()
- sample_vnf_tg.resource_helper.client_started = MockClientStarted()
-
- self.assertTrue(sample_vnf_tg.run_traffic(mock_traffic_profile))
- self.assertEqual(mock_time.sleep.call_count, 2)
+ with mock.patch.object(sample_vnf_tg, '_check_status',
+ side_effect=[1, 0]) as mock_status, \
+ mock.patch.object(sample_vnf_tg,
+ '_tg_process') as mock_proc:
+ mock_proc.is_alive.return_value = True
+ mock_proc.exitcode = 234
+ self.assertEqual(sample_vnf_tg._wait_for_process(), 234)
+ mock_proc.is_alive.assert_has_calls([mock.call(), mock.call()])
+ mock_status.assert_has_calls([mock.call(), mock.call()])