aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_prox_helpers.py120
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_prox_vnf.py18
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py17
3 files changed, 74 insertions, 81 deletions
diff --git a/tests/unit/network_services/vnf_generic/vnf/test_prox_helpers.py b/tests/unit/network_services/vnf_generic/vnf/test_prox_helpers.py
index 84eb5dc0d..ed49c7000 100644
--- a/tests/unit/network_services/vnf_generic/vnf/test_prox_helpers.py
+++ b/tests/unit/network_services/vnf_generic/vnf/test_prox_helpers.py
@@ -15,13 +15,12 @@
# limitations under the License.
#
-from __future__ import absolute_import
-
+from itertools import repeat, chain
+import mock
import os
import socket
+import time
import unittest
-from itertools import repeat, chain
-import mock
from tests.unit import STL_MOCKS
from yardstick.network_services.vnf_generic.vnf.base import VnfdHelper
@@ -288,29 +287,32 @@ no data length value
"""
-@mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.time')
class TestProxSocketHelper(unittest.TestCase):
+
+ def setUp(self):
+ self.mock_time_sleep = mock.patch.object(time, 'sleep').start()
+
@mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.socket')
- def test___init__(self, mock_socket, mock_time):
+ def test___init__(self, mock_socket):
expected = mock_socket.socket()
prox = ProxSocketHelper()
result = prox._sock
self.assertEqual(result, expected)
- def test_connect(self, mock_time):
+ def test_connect(self):
mock_sock = mock.MagicMock()
prox = ProxSocketHelper(mock_sock)
prox.connect('10.20.30.40', 23456)
self.assertEqual(mock_sock.connect.call_count, 1)
- def test_get_sock(self, mock_time):
+ def test_get_sock(self):
mock_sock = mock.MagicMock()
prox = ProxSocketHelper(mock_sock)
result = prox.get_socket()
self.assertIs(result, mock_sock)
@mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.select')
- def test_get_data(self, mock_select, mock_time):
+ def test_get_data(self, mock_select):
mock_select.select.side_effect = [[1], [0]]
mock_socket = mock.MagicMock()
mock_recv = mock_socket.recv()
@@ -336,7 +338,7 @@ class TestProxSocketHelper(unittest.TestCase):
self.assertEqual(ret, 'jumped over')
self.assertEqual(len(prox._pkt_dumps), 3)
- def test__parse_socket_data_mixed_data(self, mock_time):
+ def test__parse_socket_data_mixed_data(self):
prox = ProxSocketHelper(mock.MagicMock())
ret = prox._parse_socket_data(PACKET_DUMP_NON_1, False)
self.assertEqual(ret, 'not_a_dump,1,2')
@@ -346,7 +348,7 @@ class TestProxSocketHelper(unittest.TestCase):
self.assertEqual(ret, 'not_a_dump,1,2')
self.assertEqual(len(prox._pkt_dumps), 1)
- def test__parse_socket_data_bad_data(self, mock_time):
+ def test__parse_socket_data_bad_data(self):
prox = ProxSocketHelper(mock.MagicMock())
with self.assertRaises(ValueError):
prox._parse_socket_data(PACKET_DUMP_BAD_1, False)
@@ -357,7 +359,7 @@ class TestProxSocketHelper(unittest.TestCase):
ret = prox._parse_socket_data(PACKET_DUMP_BAD_3, False)
self.assertEqual(ret, 'pktdump,3')
- def test__parse_socket_data_pkt_dump_only(self, mock_time):
+ def test__parse_socket_data_pkt_dump_only(self):
prox = ProxSocketHelper(mock.MagicMock())
ret = prox._parse_socket_data('', True)
self.assertFalse(ret)
@@ -368,20 +370,20 @@ class TestProxSocketHelper(unittest.TestCase):
ret = prox._parse_socket_data(PACKET_DUMP_2, True)
self.assertTrue(ret)
- def test_put_command(self, mock_time):
+ def test_put_command(self):
mock_socket = mock.MagicMock()
prox = ProxSocketHelper(mock_socket)
prox.put_command("data")
mock_socket.sendall.assert_called_once()
- def test_put_command_socket_error(self, mock_time):
+ def test_put_command_socket_error(self):
mock_socket = mock.MagicMock()
mock_socket.sendall.side_effect = OSError
prox = ProxSocketHelper(mock_socket)
prox.put_command("data")
mock_socket.sendall.assert_called_once()
- def test_get_packet_dump(self, mock_time):
+ def test_get_packet_dump(self):
mock_socket = mock.MagicMock()
prox = ProxSocketHelper(mock_socket)
prox._pkt_dumps = []
@@ -391,67 +393,67 @@ class TestProxSocketHelper(unittest.TestCase):
self.assertEqual(prox.get_packet_dump(), 234)
self.assertEqual(prox._pkt_dumps, [])
- def test_stop_all_reset(self, mock_time):
+ def test_stop_all_reset(self):
mock_socket = mock.MagicMock()
prox = ProxSocketHelper(mock_socket)
prox.stop_all_reset()
mock_socket.sendall.assert_called()
- def test_stop_all(self, mock_time):
+ def test_stop_all(self):
mock_socket = mock.MagicMock()
prox = ProxSocketHelper(mock_socket)
prox.stop_all()
mock_socket.sendall.assert_called()
- def test_stop(self, mock_time):
+ def test_stop(self):
mock_socket = mock.MagicMock()
prox = ProxSocketHelper(mock_socket)
prox.stop([3, 4, 5], 16)
mock_socket.sendall.assert_called()
- def test_start_all(self, mock_time):
+ def test_start_all(self):
mock_socket = mock.MagicMock()
prox = ProxSocketHelper(mock_socket)
prox.start_all()
mock_socket.sendall.assert_called()
- def test_start(self, mock_time):
+ def test_start(self):
mock_socket = mock.MagicMock()
prox = ProxSocketHelper(mock_socket)
prox.start([3, 4, 5])
mock_socket.sendall.assert_called()
- def test_reset_stats(self, mock_time):
+ def test_reset_stats(self):
mock_socket = mock.MagicMock()
prox = ProxSocketHelper(mock_socket)
prox.reset_stats()
mock_socket.sendall.assert_called()
- def test_set_pkt_size(self, mock_time):
+ def test_set_pkt_size(self):
mock_socket = mock.MagicMock()
prox = ProxSocketHelper(mock_socket)
prox.set_pkt_size([3, 4, 5], 1024)
self.assertEqual(mock_socket.sendall.call_count, 3)
- def test_set_value(self, mock_time):
+ def test_set_value(self):
mock_socket = mock.MagicMock()
prox = ProxSocketHelper(mock_socket)
prox.set_value([3, 4, 5], 10, 20, 30)
self.assertEqual(mock_socket.sendall.call_count, 3)
- def test_reset_values(self, mock_time):
+ def test_reset_values(self):
mock_socket = mock.MagicMock()
prox = ProxSocketHelper(mock_socket)
prox.reset_values([3, 4, 5])
self.assertEqual(mock_socket.sendall.call_count, 3)
- def test_set_speed(self, mock_time):
+ def test_set_speed(self):
mock_socket = mock.MagicMock()
prox = ProxSocketHelper(mock_socket)
prox.set_speed([3, 4, 5], 1000)
self.assertEqual(mock_socket.sendall.call_count, 3)
- def test_slope_speed(self, mock_time):
+ def test_slope_speed(self):
core_data = [
{
'cores': [3, 4, 5],
@@ -473,13 +475,13 @@ class TestProxSocketHelper(unittest.TestCase):
prox.slope_speed(core_data, 5, 5)
self.assertEqual(set_speed.call_count, 10)
- def test_set_pps(self, mock_time):
+ def test_set_pps(self):
mock_socket = mock.MagicMock()
prox = ProxSocketHelper(mock_socket)
prox.set_pps([3, 4, 5], 1000, 512)
self.assertEqual(mock_socket.sendall.call_count, 3)
- def test_lat_stats(self, mock_time):
+ def test_lat_stats(self):
latency_output = [
'1, 2 , 3', # has white space
'4,5', # too short
@@ -510,7 +512,7 @@ class TestProxSocketHelper(unittest.TestCase):
self.assertEqual(mock_socket.sendall.call_count, 5)
self.assertEqual(result, expected)
- def test_get_all_tot_stats_error(self, mock_time):
+ def test_get_all_tot_stats_error(self):
mock_socket = mock.MagicMock()
prox = ProxSocketHelper(mock_socket)
prox.get_data = mock.MagicMock(return_value='3,4,5')
@@ -518,7 +520,7 @@ class TestProxSocketHelper(unittest.TestCase):
result = prox.get_all_tot_stats()
self.assertEqual(result, expected)
- def test_get_all_tot_stats(self, mock_time):
+ def test_get_all_tot_stats(self):
mock_socket = mock.MagicMock()
prox = ProxSocketHelper(mock_socket)
prox.get_data = mock.MagicMock(return_value='3,4,5,6')
@@ -526,7 +528,7 @@ class TestProxSocketHelper(unittest.TestCase):
result = prox.get_all_tot_stats()
self.assertEqual(result, expected)
- def test_hz(self, mock_time):
+ def test_hz(self):
mock_socket = mock.MagicMock()
prox = ProxSocketHelper(mock_socket)
prox.get_data = mock.MagicMock(return_value='3,4,5,6')
@@ -534,7 +536,7 @@ class TestProxSocketHelper(unittest.TestCase):
result = prox.hz()
self.assertEqual(result, expected)
- def test_core_stats(self, mock_time):
+ def test_core_stats(self):
core_stats = [
'3,4,5,6',
'7,8,9,10,NaN',
@@ -548,7 +550,7 @@ class TestProxSocketHelper(unittest.TestCase):
result = prox.core_stats([3, 4, 5], 16)
self.assertEqual(result, expected)
- def test_port_stats(self, mock_time):
+ def test_port_stats(self):
port_stats = [
','.join(str(n) for n in range(3, 15)),
','.join(str(n) for n in range(8, 32, 2)),
@@ -562,7 +564,7 @@ class TestProxSocketHelper(unittest.TestCase):
result = prox.port_stats([3, 4, 5])
self.assertEqual(result, expected)
- def test_measure_tot_stats(self, mock_time):
+ def test_measure_tot_stats(self):
start_tot = 3, 4, 5, 6
end_tot = 7, 9, 11, 13
delta_tot = 4, 5, 6, 7
@@ -584,7 +586,7 @@ class TestProxSocketHelper(unittest.TestCase):
pass
self.assertEqual(result, expected)
- def test_tot_stats(self, mock_time):
+ def test_tot_stats(self):
mock_socket = mock.MagicMock()
prox = ProxSocketHelper(mock_socket)
prox.get_data = mock.MagicMock(return_value='3,4,5,6')
@@ -592,7 +594,7 @@ class TestProxSocketHelper(unittest.TestCase):
result = prox.tot_stats()
self.assertEqual(result, expected)
- def test_tot_ierrors(self, mock_time):
+ def test_tot_ierrors(self):
mock_socket = mock.MagicMock()
prox = ProxSocketHelper(mock_socket)
prox.get_data = mock.MagicMock(return_value='3,4,5,6')
@@ -600,25 +602,25 @@ class TestProxSocketHelper(unittest.TestCase):
result = prox.tot_ierrors()
self.assertEqual(result, expected)
- def test_set_count(self, mock_time):
+ def test_set_count(self):
mock_socket = mock.MagicMock()
prox = ProxSocketHelper(mock_socket)
prox.set_count(432, [3, 4, 5])
self.assertEqual(mock_socket.sendall.call_count, 3)
- def test_dump_rx(self, mock_time):
+ def test_dump_rx(self):
mock_socket = mock.MagicMock()
prox = ProxSocketHelper(mock_socket)
prox.dump_rx(3, 5, 8)
self.assertEqual(mock_socket.sendall.call_count, 1)
- def test_quit(self, mock_time):
+ def test_quit(self):
mock_socket = mock.MagicMock()
prox = ProxSocketHelper(mock_socket)
prox.quit()
mock_socket.sendall.assert_called()
- def test_force_quit(self, mock_time):
+ def test_force_quit(self):
mock_socket = mock.MagicMock()
prox = ProxSocketHelper(mock_socket)
prox.force_quit()
@@ -1062,8 +1064,7 @@ class TestProxDpdkVnfSetupEnvHelper(unittest.TestCase):
self.assertEqual(helper._prox_config_data, '44')
self.assertEqual(helper.remote_path, '55')
- @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.find_relative_file')
- def test_build_config(self, mock_find_path):
+ def test_build_config(self):
vnf1 = {
'prox_args': {'-f': ""},
'prox_path': '/opt/nsb_bin/prox',
@@ -1075,10 +1076,9 @@ class TestProxDpdkVnfSetupEnvHelper(unittest.TestCase):
],
}
- mock_find_path.side_effect = ['1', '2']
- vnfd_helper = mock.MagicMock()
- ssh_helper = mock.MagicMock()
- ssh_helper.provision_tool.return_value = "/opt/nsb_bin/prox"
+ vnfd_helper = mock.Mock()
+ ssh_helper = mock.Mock()
+ ssh_helper.join_bin_path.return_value = '/opt/nsb_bin/prox'
scenario_helper = ScenarioHelper('vnf1')
scenario_helper.scenario_cfg = {
'task_path': 'a/b',
@@ -1087,12 +1087,16 @@ class TestProxDpdkVnfSetupEnvHelper(unittest.TestCase):
},
}
- helper = ProxDpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
- helper.remote_path = "/tmp/prox.cfg"
- expected = "sudo bash -c 'cd /opt/nsb_bin; /opt/nsb_bin/prox -o cli -f -f /tmp/prox.cfg '"
- with mock.patch.object(helper, "build_config_file") as mock_build_config:
+ expected = ("sudo bash -c 'cd /opt/nsb_bin; /opt/nsb_bin/prox -o cli "
+ "-f -f /tmp/prox.cfg '")
+
+ helper = ProxDpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper,
+ scenario_helper)
+ with mock.patch.object(helper, 'build_config_file') as mock_cfg_file:
+ helper.remote_path = '/tmp/prox.cfg'
prox_cmd = helper.build_config()
self.assertEqual(prox_cmd, expected)
+ mock_cfg_file.assert_called_once()
def test__insert_additional_file(self):
vnfd_helper = mock.MagicMock()
@@ -1256,16 +1260,6 @@ class TestProxDpdkVnfSetupEnvHelper(unittest.TestCase):
result = helper.put_string_to_file('my long string', 'a/b')
self.assertEqual(result, expected)
- def test__build_pipeline_kwarags(self):
- vnfd_helper = mock.MagicMock()
- ssh_helper = mock.MagicMock()
- ssh_helper.provision_tool.return_value = "/tmp/nosuch"
- scenario_helper = mock.MagicMock()
-
- helper = ProxDpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
- helper._build_pipeline_kwargs()
- self.assertEqual(helper.pipeline_kwargs, {'tool_path': '/tmp/nosuch', 'tool_dir': '/tmp'})
-
def test_copy_to_target(self):
vnfd_helper = mock.MagicMock()
vnfd_helper.interfaces = []
@@ -1416,7 +1410,7 @@ class TestProxResourceHelper(unittest.TestCase):
@mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.RETRY_INTERVAL', 0)
@mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.ProxSocketHelper')
- def test_sut(self, mock_socket_helper):
+ def test_sut(self, *args):
helper = ProxResourceHelper(mock.MagicMock())
self.assertIsNone(helper.client)
result = helper.sut
@@ -1466,7 +1460,7 @@ class TestProxResourceHelper(unittest.TestCase):
@mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.time')
@mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.ProxSocketHelper')
- def test__connect(self, mock_socket_helper_type, mock_time):
+ def test__connect(self, mock_socket_helper_type, *args):
client = mock_socket_helper_type()
client.connect.side_effect = chain(repeat(socket.error, 5), [None])
@@ -1869,7 +1863,7 @@ class TestProxProfileHelper(unittest.TestCase):
self.assertIs(result, expected)
@mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.time')
- def test_traffic_context(self, mock_time):
+ def test_traffic_context(self, *args):
setup_helper = mock.MagicMock()
setup_helper.vnfd_helper.interfaces = []
diff --git a/tests/unit/network_services/vnf_generic/vnf/test_prox_vnf.py b/tests/unit/network_services/vnf_generic/vnf/test_prox_vnf.py
index ee6c67eb7..769279066 100644
--- a/tests/unit/network_services/vnf_generic/vnf/test_prox_vnf.py
+++ b/tests/unit/network_services/vnf_generic/vnf/test_prox_vnf.py
@@ -373,24 +373,6 @@ class TestProxApproxVnf(unittest.TestCase):
file_path = os.path.join(curr_path, filename)
return file_path
- @mock.patch('yardstick.benchmark.scenarios.networking.vnf_generic.open', create=True)
- @mock.patch('yardstick.network_services.helpers.iniparser.open', create=True)
- @mock.patch(SSH_HELPER)
- def test_run_prox(self, ssh, *args):
- mock_ssh(ssh)
-
- prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0)
- prox_approx_vnf.scenario_helper.scenario_cfg = self.SCENARIO_CFG
- prox_approx_vnf.ssh_helper.provision_tool.return_value = '/tool_path12/tool_file34'
- prox_approx_vnf.setup_helper.remote_path = 'configs/file56.cfg'
-
- expected = "sudo bash -c 'cd /tool_path12; " \
- "/tool_path12/tool_file34 -o cli -t -f /tmp/l3-swap-2.cfg '"
-
- prox_approx_vnf._run()
- result = prox_approx_vnf.ssh_helper.run.call_args[0][0]
- self.assertEqual(result, expected)
-
@mock.patch(SSH_HELPER)
def bad_test_instantiate(self, *args):
prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0)
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 b4306ce61..beb4f8f9f 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
@@ -1879,6 +1879,23 @@ class TestSampleVnf(unittest.TestCase):
self.assertRaises(y_exceptions.FunctionNotImplemented,
sample_vnf.scale)
+ def test__run(self):
+ test_cmd = 'test cmd'
+ run_kwargs = {'arg1': 'val1', 'arg2': 'val2'}
+ vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
+ sample_vnf = SampleVNF('vnf1', vnfd)
+ sample_vnf.ssh_helper = mock.Mock()
+ sample_vnf.setup_helper = mock.Mock()
+ with mock.patch.object(sample_vnf, '_build_config',
+ return_value=test_cmd), \
+ mock.patch.object(sample_vnf, '_build_run_kwargs'):
+ sample_vnf.run_kwargs = run_kwargs
+ sample_vnf._run()
+ sample_vnf.ssh_helper.drop_connection.assert_called_once()
+ sample_vnf.ssh_helper.run.assert_called_once_with(test_cmd,
+ **run_kwargs)
+ sample_vnf.setup_helper.kill_vnf.assert_called_once()
+
class TestSampleVNFTrafficGen(unittest.TestCase):