# See the License for the specific language governing permissions and
# limitations under the License.
+from __future__ import absolute_import
import unittest
import mock
import os
instantiation_validation_benchmark as iv_module
from experimental_framework.benchmarks.\
instantiation_validation_benchmark import InstantiationValidationBenchmark
+from six.moves import map
+from six.moves import range
kill_counter = [0, 0]
def dummy_run_command(command, get_counters=None):
if get_counters:
return command_counter
- if command == 'smcroute -k':
+ if command == 'sudo smcroute -k':
command_counter[0] += 1
return
- elif command == 'ip link delete interface.100':
+ elif command == 'sudo ip link delete interface.100':
command_counter[1] += 1
return
+ elif command == 'sudo kill 1234':
+ kill_counter[0] += 1
+ return
+ elif command == 'sudo kill 4321':
+ kill_counter[1] += 1
+ return
raise Exception(command)
def dummy_run_command_2(command, get_counters=None):
if get_counters:
return command_counter
- if command == 'ip link add link interface name interface.' \
+ if command == 'sudo ip link add link interface name interface.' \
'100 type vlan id 100':
command_counter[0] += 1
return
- elif command == 'ifconfig interface.100 10.254.254.254 up':
+ elif command == 'sudo ifconfig interface.100 10.254.254.254 up' \
+ ' netmask 255.255.255.248':
command_counter[1] += 1
return
- elif command == "echo 'mgroup from interface.100 group 224.192.16.1' > " \
- "/etc/smcroute.conf":
+ elif command == "sudo echo 'mgroup from interface.100 group" \
+ " 224.192.16.1' > /etc/smcroute.conf":
command_counter[2] += 1
return
- elif command == "smcroute -d":
+ elif command == "sudo smcroute -d":
command_counter[3] += 1
return
- elif command == "test_sniff interface.100 128 &":
+ elif command == "sudo test_sniff interface.100 128 &":
command_counter[4] += 1
return
]
expected['allowed_values'] = dict()
expected['allowed_values'][iv_module.THROUGHPUT] = \
- map(str, range(0, 100))
+ list(map(str, list(range(0, 100))))
expected['allowed_values'][iv_module.VLAN_SENDER] = \
- map(str, range(-1, 4096))
+ list(map(str, list(range(-1, 4096))))
expected['allowed_values'][iv_module.VLAN_RECEIVER] = \
- map(str, range(-1, 4096))
+ list(map(str, list(range(-1, 4096))))
expected['default_values'] = dict()
expected['default_values'][iv_module.THROUGHPUT] = '1'
expected['default_values'][iv_module.VLAN_SENDER] = '-1'
output = self.iv.get_features()
self.assertEqual(expected, output)
- @mock.patch('commands.getoutput')
+ @mock.patch('subprocess.check_output')
def test__get_pids_for_success(self, mock_getoutput):
expected = [1234]
mock_getoutput.return_value = '1234'
self.assertEqual(dummy_os_kill('', '', True), [1, 1])
self.assertEqual(dummy_run_command('', True), [1, 1, 0, 0, 0])
+ @mock.patch('experimental_framework.benchmarks.instantiation_validation_benchmark.time')
+ @mock.patch('os.chdir')
@mock.patch('experimental_framework.common.run_command',
side_effect=dummy_run_command_2)
@mock.patch('experimental_framework.benchmarks.'
'instantiation_validation_benchmark.'
'InstantiationValidationBenchmark._get_pids')
@mock.patch('os.kill', side_effect=dummy_os_kill)
- def test__init_packet_checker_for_success(self, mock_kill,
- mock_pids, mock_run_command):
+ def test__init_packet_checker_for_success(self, mock_kill, mock_pids,
+ mock_run_command, mock_chdir, mock_time):
global command_counter
command_counter = [0, 0, 0, 0, 0]
mock_pids.return_value = [1234, 4321]
self.assertEqual(dummy_replace_in_file('', '', '', True),
[0, 0, 0, 1, 1, 1])
+ @mock.patch('experimental_framework.benchmarks.instantiation_validation_benchmark.time')
@mock.patch('experimental_framework.common.LOG')
@mock.patch('experimental_framework.packet_generators.'
'dpdk_packet_generator.DpdkPacketGenerator',
side_effect=DummyDpdkPacketGenerator)
@mock.patch('experimental_framework.common.get_dpdk_pktgen_vars')
def test_run_for_success(self, mock_common_get_vars, mock_pktgen,
- mock_log):
+ mock_log, mock_time):
rval = dict()
rval[cfs.CFSP_DPDK_BUS_SLOT_NIC_2] = 'bus_2'
rval[cfs.CFSP_DPDK_NAME_IF_2] = 'if_2'