diff options
author | 2017-11-28 16:39:15 +0000 | |
---|---|---|
committer | 2018-01-04 01:25:47 +0000 | |
commit | f07dc0ecbad33522627df9cd9bc5b12f8cde0159 (patch) | |
tree | c5eb26257c3926fa9d2fe12b3fd1f5f69ceb873d /tests/unit/network_services/vnf_generic/vnf/test_prox_helpers.py | |
parent | 67bd29933789e7f31c52290fdd43835e54f89eaf (diff) |
Remove tool provisioning in PROX helper
Tool provisioning in PROX setup environment helper is not needed [1]. The
tool (PROX traffic injector) is already provided during the VNF building:
./ansible/nsb_setup.yml -->
./ansible/build_yardstick_image.yml -->
./ansible/ubuntu_server_cloudimg_modify_samplevnfs.yml -->
./ansible/roles/install_samplevnf
[1]https://github.com/opnfv/yardstick/blob/master/yardstick/network_services/vnf_generic/vnf/prox_helpers.py#L641
JIRA: YARDSTICK-872
Change-Id: I0f925a7967a35a97901fbe5053793a791a7b1b01
Signed-off-by: Rodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com>
Diffstat (limited to 'tests/unit/network_services/vnf_generic/vnf/test_prox_helpers.py')
-rw-r--r-- | tests/unit/network_services/vnf_generic/vnf/test_prox_helpers.py | 120 |
1 files changed, 57 insertions, 63 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 = [] |