diff options
author | Deepak S <deepak.s@linux.intel.com> | 2017-06-20 14:31:19 -0700 |
---|---|---|
committer | Ross Brattain <ross.b.brattain@intel.com> | 2017-08-08 08:54:23 -0700 |
commit | 5ce3b6f8c8b3217091e51a6041455738603d90b8 (patch) | |
tree | ca34e15a85d69e2b23ce498fead47761624ae42c /tests/unit/network_services/helpers/test_cpu.py | |
parent | 72778951d6b8968f562fb8fefa02a57159ea1b83 (diff) |
NSB update
Refactored main NSB VNF classes accroding to class diagram
https://wiki.opnfv.org/display/yardstick/NSB+class+diagram
All the SampleVNFs have been separated and placed under
the SampleVNF class.
Added AutoConnectSSH to automatically create SSH conneciton on demand.
Added VnfdHelper class to wrap the VNFD dictionary in prepartion for
class-based modeling.
Extracted DpdkVnfSetupEnvHelper for DPDK based VNF setup.
Extracted Stats and other client config to ResourceHelper
Had to replace dict_key_flatten with deepgetitem due to Python 2.7
Jinja2 infinite recursion.
Change-Id: Ia8840e9c44cdbdf39aab6b02e6d2176b31937dc9
Signed-off-by: Deepak S <deepak.s@linux.intel.com>
Signed-off-by: Edward MacGillivray <edward.s.macgillivray@intel.com>
Signed-off-by: Ross Brattain <ross.b.brattain@intel.com>
Diffstat (limited to 'tests/unit/network_services/helpers/test_cpu.py')
-rw-r--r-- | tests/unit/network_services/helpers/test_cpu.py | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/tests/unit/network_services/helpers/test_cpu.py b/tests/unit/network_services/helpers/test_cpu.py new file mode 100644 index 000000000..7ea6bd0fc --- /dev/null +++ b/tests/unit/network_services/helpers/test_cpu.py @@ -0,0 +1,119 @@ +#!/usr/bin/env python + +# Copyright (c) 2016-2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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 +from __future__ import division +import unittest +import mock +import subprocess + +from yardstick.network_services.helpers.cpu import \ + CpuSysCores + + +class TestCpuSysCores(unittest.TestCase): + + def test___init__(self): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(1, "", "")) + ssh_mock.put = \ + mock.Mock(return_value=(1, "", "")) + cpu_topo = CpuSysCores(ssh_mock) + self.assertIsNotNone(cpu_topo.connection) + + def test__get_core_details(self): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(1, "", "")) + ssh_mock.put = \ + mock.Mock(return_value=(1, "", "")) + cpu_topo = CpuSysCores(ssh_mock) + subprocess.check_output = mock.Mock(return_value=0) + lines = ["cpu:1", "topo:2", ""] + self.assertEqual([{'topo': '2', 'cpu': '1'}], + cpu_topo._get_core_details(lines)) + + def test_get_core_socket(self): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(1, "cpu:1\ntest:2\n \n", "")) + ssh_mock.put = \ + mock.Mock(return_value=(1, "", "")) + cpu_topo = CpuSysCores(ssh_mock) + subprocess.check_output = mock.Mock(return_value=0) + cpu_topo._get_core_details = \ + mock.Mock(side_effect=[[{'Core(s) per socket': '2', 'Thread(s) per core': '1'}], + [{'physical id': '2', 'processor': '1'}]]) + self.assertEqual({'thread_per_core': '1', '2': ['1'], + 'cores_per_socket': '2'}, + cpu_topo.get_core_socket()) + + def test_validate_cpu_cfg(self): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(1, "cpu:1\ntest:2\n \n", "")) + ssh_mock.put = \ + mock.Mock(return_value=(1, "", "")) + cpu_topo = CpuSysCores(ssh_mock) + subprocess.check_output = mock.Mock(return_value=0) + cpu_topo._get_core_details = \ + mock.Mock(side_effect=[[{'Core(s) per socket': '2', 'Thread(s) per core': '1'}], + [{'physical id': '2', 'processor': '1'}]]) + cpu_topo.core_map = \ + {'thread_per_core': '1', '2':['1'], 'cores_per_socket': '2'} + self.assertEqual(-1, cpu_topo.validate_cpu_cfg()) + + def test_validate_cpu_cfg_2t(self): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(1, "cpu:1\ntest:2\n \n", "")) + ssh_mock.put = \ + mock.Mock(return_value=(1, "", "")) + cpu_topo = CpuSysCores(ssh_mock) + subprocess.check_output = mock.Mock(return_value=0) + cpu_topo._get_core_details = \ + mock.Mock(side_effect=[[{'Core(s) per socket': '2', 'Thread(s) per core': '1'}], + [{'physical id': '2', 'processor': '1'}]]) + cpu_topo.core_map = \ + {'thread_per_core': 1, '2':['1'], 'cores_per_socket': '2'} + vnf_cfg = {'lb_config': 'SW', 'lb_count': 1, 'worker_config': + '1C/2T', 'worker_threads': 1} + self.assertEqual(-1, cpu_topo.validate_cpu_cfg(vnf_cfg)) + + def test_validate_cpu_cfg_fail(self): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(1, "cpu:1\ntest:2\n \n", "")) + ssh_mock.put = \ + mock.Mock(return_value=(1, "", "")) + cpu_topo = CpuSysCores(ssh_mock) + subprocess.check_output = mock.Mock(return_value=0) + cpu_topo._get_core_details = \ + mock.Mock(side_effect=[[{'Core(s) per socket': '2', 'Thread(s) per core': '1'}], + [{'physical id': '2', 'processor': '1'}]]) + cpu_topo.core_map = \ + {'thread_per_core': 1, '2':[1], 'cores_per_socket': 2} + vnf_cfg = {'lb_config': 'SW', 'lb_count': 1, 'worker_config': + '1C/1T', 'worker_threads': 1} + self.assertEqual(-1, cpu_topo.validate_cpu_cfg(vnf_cfg)) |