diff options
Diffstat (limited to 'tests/unit')
-rw-r--r-- | tests/unit/network_services/traffic_profile/test_traffic_profile.py | 45 | ||||
-rw-r--r-- | tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py | 53 |
2 files changed, 58 insertions, 40 deletions
diff --git a/tests/unit/network_services/traffic_profile/test_traffic_profile.py b/tests/unit/network_services/traffic_profile/test_traffic_profile.py index 0bb0a88a6..37b9a08d0 100644 --- a/tests/unit/network_services/traffic_profile/test_traffic_profile.py +++ b/tests/unit/network_services/traffic_profile/test_traffic_profile.py @@ -13,14 +13,15 @@ # 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 ipaddress -import unittest import mock +import six +import unittest from tests.unit import STL_MOCKS +from yardstick.common import exceptions as y_exc STLClient = mock.MagicMock() stl_patch = mock.patch.dict("sys.modules", STL_MOCKS) @@ -215,11 +216,27 @@ class TestTrexProfile(unittest.TestCase): TrexProfile(TrafficProfile) self.assertEqual({}, trex_profile.generate_imix_data(False)) - def test__get_start_end_ipv6(self): - trex_profile = \ - TrexProfile(TrafficProfile) - self.assertRaises(SystemExit, trex_profile._get_start_end_ipv6, - "1.1.1.3", "1.1.1.1") + def test__count_ip_ipv4(self): + start, end, count = TrexProfile._count_ip('1.1.1.1', '1.2.3.4') + self.assertEqual('1.1.1.1', str(start)) + self.assertEqual('1.2.3.4', str(end)) + diff = (int(ipaddress.IPv4Address(six.u('1.2.3.4'))) - + int(ipaddress.IPv4Address(six.u('1.1.1.1')))) + self.assertEqual(diff, count) + + def test__count_ip_ipv6(self): + start_ip = '0064:ff9b:0:0:0:0:9810:6414' + end_ip = '0064:ff9b:0:0:0:0:9810:6420' + start, end, count = TrexProfile._count_ip(start_ip, end_ip) + self.assertEqual(0x98106414, start) + self.assertEqual(0x98106420, end) + self.assertEqual(0x98106420 - 0x98106414, count) + + def test__count_ip_ipv6_exception(self): + start_ip = '0064:ff9b:0:0:0:0:9810:6420' + end_ip = '0064:ff9b:0:0:0:0:9810:6414' + with self.assertRaises(y_exc.IPv6RangeError): + TrexProfile._count_ip(start_ip, end_ip) def test__dscp_range_action_partial_actual_count_zero(self): traffic_profile = TrexProfile(TrafficProfile) @@ -258,13 +275,17 @@ class TestTrexProfile(unittest.TestCase): def test__general_single_action_partial(self): trex_profile = TrexProfile(TrafficProfile) - trex_profile._general_single_action_partial(ETHERNET)(SRC)(self.EXAMPLE_ETHERNET_ADDR) - self.assertEqual(self.EXAMPLE_ETHERNET_ADDR, trex_profile.ether_packet.src) + trex_profile._general_single_action_partial(ETHERNET)(SRC)( + self.EXAMPLE_ETHERNET_ADDR) + self.assertEqual(self.EXAMPLE_ETHERNET_ADDR, + trex_profile.ether_packet.src) - trex_profile._general_single_action_partial(IP)(DST)(self.EXAMPLE_IP_ADDR) + trex_profile._general_single_action_partial(IP)(DST)( + self.EXAMPLE_IP_ADDR) self.assertEqual(self.EXAMPLE_IP_ADDR, trex_profile.ip_packet.dst) - trex_profile._general_single_action_partial(IPv6)(DST)(self.EXAMPLE_IPv6_ADDR) + trex_profile._general_single_action_partial(IPv6)(DST)( + self.EXAMPLE_IPv6_ADDR) self.assertEqual(self.EXAMPLE_IPv6_ADDR, trex_profile.ip6_packet.dst) trex_profile._general_single_action_partial(UDP)(SRC_PORT)(5060) 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 af941c04f..25633384e 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 @@ -624,37 +624,34 @@ class TestDpdkVnfSetupEnvHelper(unittest.TestCase): self.assertIsInstance(dpdk_vnf_setup_env_helper.setup_vnf_environment(), ResourceProfile) - def test__setup_dpdk_early_success(self): - vnfd_helper = VnfdHelper(self.VNFD_0) + def test__setup_dpdk(self): ssh_helper = mock.Mock() - ssh_helper.execute.return_value = 0, 'output', '' - ssh_helper.join_bin_path.return_value = 'joined_path' - ssh_helper.provision_tool.return_value = 'provision string' - scenario_helper = mock.Mock() - dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) - dpdk_setup_helper._setup_hugepages = mock.Mock() - - self.assertIsNone(dpdk_setup_helper._setup_dpdk()) - self.assertEqual(dpdk_setup_helper.ssh_helper.execute.call_count, 2) - - @mock.patch('yardstick.ssh.SSH') - def test__setup_dpdk_short(self, _): - def execute_side(cmd): - if 'joined_path' in cmd: - return 0, 'output', '' - return 1, 'bad output', 'error output' + ssh_helper.execute = mock.Mock() + ssh_helper.execute.return_value = (0, 0, 0) + dpdk_setup_helper = DpdkVnfSetupEnvHelper(mock.ANY, ssh_helper, mock.ANY) + with mock.patch.object(dpdk_setup_helper, '_setup_hugepages') as \ + mock_setup_hp: + dpdk_setup_helper._setup_dpdk() + mock_setup_hp.assert_called_once() + ssh_helper.execute.assert_has_calls([ + mock.call('sudo modprobe uio && sudo modprobe igb_uio'), + mock.call('lsmod | grep -i igb_uio') + ]) - vnfd_helper = VnfdHelper(self.VNFD_0) + def test__setup_dpdk_igb_uio_not_loaded(self): ssh_helper = mock.Mock() - ssh_helper.execute.side_effect = execute_side - ssh_helper.join_bin_path.return_value = 'joined_path' - ssh_helper.provision_tool.return_value = 'provision string' - scenario_helper = mock.Mock() - dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) - dpdk_setup_helper._setup_hugepages = mock.Mock() - - self.assertIsNone(dpdk_setup_helper._setup_dpdk()) - self.assertEqual(dpdk_setup_helper.ssh_helper.execute.call_count, 3) + ssh_helper.execute = mock.Mock() + ssh_helper.execute.side_effect = [(0, 0, 0), (1, 0, 0)] + dpdk_setup_helper = DpdkVnfSetupEnvHelper(mock.ANY, ssh_helper, mock.ANY) + with mock.patch.object(dpdk_setup_helper, '_setup_hugepages') as \ + mock_setup_hp: + with self.assertRaises(y_exceptions.DPDKSetupDriverError): + dpdk_setup_helper._setup_dpdk() + mock_setup_hp.assert_called_once() + ssh_helper.execute.assert_has_calls([ + mock.call('sudo modprobe uio && sudo modprobe igb_uio'), + mock.call('lsmod | grep -i igb_uio') + ]) @mock.patch('yardstick.ssh.SSH') def test__setup_resources(self, _): |