From 7c7a14132588f99c6291da9037dc61d0d8ea935a Mon Sep 17 00:00:00 2001 From: Serhiy Pshyk Date: Thu, 4 Oct 2018 10:21:33 +0100 Subject: Setup hugepages on SA host(sriov, ovs_dpdk) JIRA: YARDSTICK-1461 Change-Id: Ia1f5026eee989672aac57775ec9dd182df658fa4 Signed-off-by: Serhiy Pshyk --- .../benchmark/contexts/standalone/test_ovs_dpdk.py | 23 ++++++----- .../benchmark/contexts/standalone/test_sriov.py | 14 ++++--- yardstick/tests/unit/common/test_utils.py | 17 ++++++++ .../vnf_generic/vnf/test_sample_vnf.py | 47 ++++------------------ 4 files changed, 47 insertions(+), 54 deletions(-) (limited to 'yardstick/tests/unit') diff --git a/yardstick/tests/unit/benchmark/contexts/standalone/test_ovs_dpdk.py b/yardstick/tests/unit/benchmark/contexts/standalone/test_ovs_dpdk.py index 6cc8b11f3..707d45207 100644 --- a/yardstick/tests/unit/benchmark/contexts/standalone/test_ovs_dpdk.py +++ b/yardstick/tests/unit/benchmark/contexts/standalone/test_ovs_dpdk.py @@ -24,6 +24,7 @@ from yardstick.benchmark.contexts import base from yardstick.benchmark.contexts.standalone import model from yardstick.benchmark.contexts.standalone import ovs_dpdk from yardstick.common import exceptions +from yardstick.common import utils as common_utils from yardstick.network_services import utils @@ -171,11 +172,9 @@ class OvsDpdkContextTestCase(unittest.TestCase): self.ovs_dpdk.wait_for_vswitchd = 0 self.assertIsNone(self.ovs_dpdk.cleanup_ovs_dpdk_env()) - @mock.patch.object(ovs_dpdk.OvsDpdkContext, '_check_hugepages') @mock.patch.object(utils, 'get_nsb_option') @mock.patch.object(model.OvsDeploy, 'ovs_deploy') - def test_check_ovs_dpdk_env(self, mock_ovs_deploy, mock_get_nsb_option, - mock_check_hugepages): + def test_check_ovs_dpdk_env(self, mock_ovs_deploy, mock_get_nsb_option): self.ovs_dpdk.connection = mock.Mock() self.ovs_dpdk.connection.execute = mock.Mock( return_value=(1, 0, 0)) @@ -189,11 +188,9 @@ class OvsDpdkContextTestCase(unittest.TestCase): self.ovs_dpdk.check_ovs_dpdk_env() mock_ovs_deploy.assert_called_once() - mock_check_hugepages.assert_called_once() mock_get_nsb_option.assert_called_once_with('bin_path') - @mock.patch.object(ovs_dpdk.OvsDpdkContext, '_check_hugepages') - def test_check_ovs_dpdk_env_wrong_version(self, mock_check_hugepages): + def test_check_ovs_dpdk_env_wrong_version(self): self.ovs_dpdk.connection = mock.Mock() self.ovs_dpdk.connection.execute = mock.Mock( return_value=(1, 0, 0)) @@ -206,7 +203,6 @@ class OvsDpdkContextTestCase(unittest.TestCase): with self.assertRaises(exceptions.OVSUnsupportedVersion): self.ovs_dpdk.check_ovs_dpdk_env() - mock_check_hugepages.assert_called_once() @mock.patch('yardstick.ssh.SSH') def test_deploy(self, *args): @@ -391,13 +387,18 @@ class OvsDpdkContextTestCase(unittest.TestCase): 'fake_path', 0, self.NETWORKS['private_0']['vpci'], self.NETWORKS['private_0']['mac'], 'test') + @mock.patch.object(ovs_dpdk.OvsDpdkContext, '_check_hugepages') + @mock.patch.object(common_utils, 'setup_hugepages') @mock.patch.object(model.StandaloneContextHelper, 'check_update_key') @mock.patch.object(model.Libvirt, 'write_file') @mock.patch.object(model.Libvirt, 'build_vm_xml') @mock.patch.object(model.Libvirt, 'check_if_vm_exists_and_delete') @mock.patch.object(model.Libvirt, 'virsh_create_vm') - def test_setup_ovs_dpdk_context(self, mock_create_vm, mock_check_if_exists, mock_build_xml, - mock_write_file, mock_check_update_key): + def test_setup_ovs_dpdk_context(self, mock_create_vm, mock_check_if_exists, + mock_build_xml, mock_write_file, + mock_check_update_key, + mock_setup_hugepages, + mock__check_hugepages): self.ovs_dpdk.vm_deploy = True self.ovs_dpdk.connection = mock.Mock() self.ovs_dpdk.vm_names = ['vm-0', 'vm-1'] @@ -413,7 +414,7 @@ class OvsDpdkContextTestCase(unittest.TestCase): } self.ovs_dpdk.networks = self.NETWORKS self.ovs_dpdk.host_mgmt = {} - self.ovs_dpdk.flavor = {} + self.ovs_dpdk.vm_flavor = {'ram': '1024'} self.ovs_dpdk.file_path = '/var/lib/libvirt/images/cdrom-0.img' self.ovs_dpdk.configure_nics_for_ovs_dpdk = mock.Mock(return_value="") self.ovs_dpdk._name_task_id = 'fake_name' @@ -429,6 +430,8 @@ class OvsDpdkContextTestCase(unittest.TestCase): self.assertEqual([vnf_instance_2], self.ovs_dpdk.setup_ovs_dpdk_context()) + mock_setup_hugepages.assert_called_once_with(self.ovs_dpdk.connection, 1024 * 1024) + mock__check_hugepages.assert_called_once() mock_create_vm.assert_called_once_with( self.ovs_dpdk.connection, '/tmp/vm_ovs_0.xml') mock_check_if_exists.assert_called_once_with( diff --git a/yardstick/tests/unit/benchmark/contexts/standalone/test_sriov.py b/yardstick/tests/unit/benchmark/contexts/standalone/test_sriov.py index 316aca72a..0809a983a 100644 --- a/yardstick/tests/unit/benchmark/contexts/standalone/test_sriov.py +++ b/yardstick/tests/unit/benchmark/contexts/standalone/test_sriov.py @@ -22,6 +22,7 @@ from yardstick.benchmark import contexts from yardstick.benchmark.contexts import base from yardstick.benchmark.contexts.standalone import model from yardstick.benchmark.contexts.standalone import sriov +from yardstick.common import utils class SriovContextTestCase(unittest.TestCase): @@ -276,13 +277,15 @@ class SriovContextTestCase(unittest.TestCase): mock_add_sriov.assert_called_once_with( '0000:00:0a.0', 0, self.NETWORKS['private_0']['mac'], 'test') + @mock.patch.object(utils, 'setup_hugepages') @mock.patch.object(model.StandaloneContextHelper, 'check_update_key') @mock.patch.object(model.Libvirt, 'build_vm_xml') @mock.patch.object(model.Libvirt, 'check_if_vm_exists_and_delete') @mock.patch.object(model.Libvirt, 'write_file') @mock.patch.object(model.Libvirt, 'virsh_create_vm') - def test_setup_sriov_context(self, mock_create_vm, mock_write_file, mock_check, - mock_build_vm_xml, mock_check_update_key): + def test_setup_sriov_context(self, mock_create_vm, mock_write_file, + mock_check, mock_build_vm_xml, + mock_check_update_key, mock_setup_hugepages): self.sriov.servers = { 'vnf_0': { 'network_ports': { @@ -295,7 +298,7 @@ class SriovContextTestCase(unittest.TestCase): connection = mock.Mock() self.sriov.connection = connection self.sriov.host_mgmt = {'ip': '1.2.3.4'} - self.sriov.vm_flavor = 'flavor' + self.sriov.vm_flavor = {'ram': '1024'} self.sriov.networks = 'networks' self.sriov.configure_nics_for_sriov = mock.Mock() self.sriov._name_task_id = 'fake_name' @@ -314,15 +317,16 @@ class SriovContextTestCase(unittest.TestCase): mock_vnf_node.generate_vnf_instance = mock.Mock( return_value='node_1') nodes_out = self.sriov.setup_sriov_context() + mock_setup_hugepages.assert_called_once_with(connection, 1024*1024) mock_check_update_key.assert_called_once_with(connection, 'node_1', vm_name, self.sriov._name_task_id, cdrom_img, mac) self.assertEqual(['node_2'], nodes_out) mock_vnf_node.generate_vnf_instance.assert_called_once_with( - 'flavor', 'networks', '1.2.3.4', 'vnf_0', + self.sriov.vm_flavor, 'networks', '1.2.3.4', 'vnf_0', self.sriov.servers['vnf_0'], '00:00:00:00:00:01') mock_build_vm_xml.assert_called_once_with( - connection, 'flavor', vm_name, 0, cdrom_img) + connection, self.sriov.vm_flavor, vm_name, 0, cdrom_img) mock_create_vm.assert_called_once_with(connection, cfg) mock_check.assert_called_once_with(vm_name, connection) mock_write_file.assert_called_once_with(cfg, 'out_xml') diff --git a/yardstick/tests/unit/common/test_utils.py b/yardstick/tests/unit/common/test_utils.py index 3cf6c4d05..c0c928916 100644 --- a/yardstick/tests/unit/common/test_utils.py +++ b/yardstick/tests/unit/common/test_utils.py @@ -1407,3 +1407,20 @@ class SafeCaseTestCase(unittest.TestCase): def test_default_value(self): self.assertEqual(0, utils.safe_cast('', 'int', 0)) + + +class SetupHugepagesTestCase(unittest.TestCase): + + @mock.patch.object(six, 'BytesIO', return_value=six.BytesIO(b'5\n')) + @mock.patch.object(utils, 'read_meminfo', + return_value={'Hugepagesize': '1024'}) + def test_setup_hugepages(self, mock_meminfo, *args): + ssh = mock.Mock() + ssh.execute = mock.Mock() + hp_size_kb, hp_number, hp_number_set = utils.setup_hugepages(ssh, 10 * 1024) + mock_meminfo.assert_called_once_with(ssh) + ssh.execute.assert_called_once_with( + 'echo 10 | sudo tee /proc/sys/vm/nr_hugepages') + self.assertEqual(hp_size_kb, 1024) + self.assertEqual(hp_number, 10) + self.assertEqual(hp_number_set, 5) diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py index 4a1d8c30e..eda7b6e3f 100644 --- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py +++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py @@ -16,7 +16,6 @@ from copy import deepcopy import unittest import mock -import six from yardstick.common import exceptions as y_exceptions from yardstick.common import utils @@ -521,38 +520,6 @@ class TestDpdkVnfSetupEnvHelper(unittest.TestCase): result = DpdkVnfSetupEnvHelper._update_traffic_type(ip_pipeline_cfg, traffic_options) self.assertEqual(result, expected) - @mock.patch.object(six, 'BytesIO', return_value=six.BytesIO(b'100\n')) - @mock.patch.object(utils, 'read_meminfo', - return_value={'Hugepagesize': '2048'}) - def test__setup_hugepages_no_hugepages_defined(self, mock_meminfo, *args): - ssh_helper = mock.Mock() - scenario_helper = mock.Mock() - scenario_helper.all_options = {} - dpdk_setup_helper = DpdkVnfSetupEnvHelper( - mock.ANY, ssh_helper, scenario_helper) - with mock.patch.object(sample_vnf.LOG, 'info') as mock_info: - dpdk_setup_helper._setup_hugepages() - mock_info.assert_called_once_with( - 'Hugepages size (kB): %s, number claimed: %s, number set: ' - '%s', 2048, 8192, 100) - mock_meminfo.assert_called_once_with(ssh_helper) - - @mock.patch.object(six, 'BytesIO', return_value=six.BytesIO(b'100\n')) - @mock.patch.object(utils, 'read_meminfo', - return_value={'Hugepagesize': '1048576'}) - def test__setup_hugepages_8gb_hugepages_defined(self, mock_meminfo, *args): - ssh_helper = mock.Mock() - scenario_helper = mock.Mock() - scenario_helper.all_options = {'hugepages_gb': 8} - dpdk_setup_helper = DpdkVnfSetupEnvHelper( - mock.ANY, ssh_helper, scenario_helper) - with mock.patch.object(sample_vnf.LOG, 'info') as mock_info: - dpdk_setup_helper._setup_hugepages() - mock_info.assert_called_once_with( - 'Hugepages size (kB): %s, number claimed: %s, number set: ' - '%s', 1048576, 8, 100) - mock_meminfo.assert_called_once_with(ssh_helper) - @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.open') @mock.patch.object(utils, 'find_relative_file') @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.MultiPortConfig') @@ -638,15 +605,17 @@ class TestDpdkVnfSetupEnvHelper(unittest.TestCase): dpdk_vnf_setup_env_helper.setup_vnf_environment(), ResourceProfile) - def test__setup_dpdk(self): + @mock.patch.object(utils, 'setup_hugepages') + def test__setup_dpdk(self, mock_setup_hugepages): ssh_helper = mock.Mock() 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() + scenario_helper = mock.Mock() + scenario_helper.all_options = {'hugepages_gb': 8} + dpdk_setup_helper = DpdkVnfSetupEnvHelper(mock.ANY, ssh_helper, + scenario_helper) + dpdk_setup_helper._setup_dpdk() + mock_setup_hugepages.assert_called_once_with(ssh_helper, 8*1024*1024) ssh_helper.execute.assert_has_calls([ mock.call('sudo modprobe uio && sudo modprobe igb_uio'), mock.call('lsmod | grep -i igb_uio') -- cgit 1.2.3-korg