提交 2a404e02 编写于 作者: H Harish

Added method to get NUMA nodes with memory

This patch adds method to get list of nodes with memory on given
machine.
Signed-off-by: NHarish <harish@linux.vnet.ibm.com>
上级 0e1bb61e
......@@ -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.
先完成此消息的编辑!
想要评论请 注册