未验证 提交 f5420480 编写于 作者: L Lukáš Doktor

Merging pull request 2636

Signed-off-by: NLukáš Doktor <ldoktor@redhat.com>

* https://github.com/avocado-framework/avocado:
  Added method to get NUMA nodes with memory
......@@ -26,6 +26,7 @@ import logging
from . import process
from . import genio
from . import wait
from . import data_structures
from .data_structures import DataSize
......@@ -216,6 +217,22 @@ def numa_nodes():
return (sorted(nodes))
def numa_nodes_with_memory():
"""
Get a list of NUMA nodes present with memory on the system.
:return: List with nodes which has memory.
"""
mem_path = '/sys/devices/system/node/has_normal_memory'
if not os.path.exists(mem_path):
mem_path = '/sys/devices/system/node/has_memory'
if not os.path.exists(mem_path):
raise MemError("No NUMA nodes have memory")
node_list = str(genio.read_file(mem_path).rstrip('\n'))
return data_structures.comma_separated_ranges_to_list(node_list)
def node_size():
"""
Return node size.
......
import unittest
try:
from unittest import mock
except ImportError:
import mock
from avocado.utils import memory
class UtilsMemoryTest(unittest.TestCase):
def test_numa_nodes_with_memory(self):
file_values = [u"0\n", u"1-3", u"0-1,12-14\n"]
expected_values = [[0], [1, 2, 3], [0, 1, 12, 13, 14]]
for value, exp in zip(file_values, expected_values):
with mock.patch('os.path.exists', return_value=True):
with mock.patch('avocado.utils.genio.read_file', return_value=value):
self.assertEqual(
memory.numa_nodes_with_memory(), exp)
if __name__ == '__main__':
unittest.main()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册