Commit 23cb5697 authored by Michele Tartara's avatar Michele Tartara
Browse files

Prepare GetLinuxNodeInfo for testing



The names of the input files are not hardcoded anymore, but they are now default
parameters.

No changes for the callers, but it's now possible to test the function more
easily.
Signed-off-by: default avatarMichele Tartara <mtartara@google.com>
Reviewed-by: default avatarHelga Velroyen <helgav@google.com>
parent b1633ed9
......@@ -447,7 +447,7 @@ class BaseHypervisor(object):
raise NotImplementedError
@staticmethod
def GetLinuxNodeInfo():
def GetLinuxNodeInfo(meminfo="/proc/meminfo", cpuinfo="/proc/cpuinfo"):
"""For linux systems, return actual OS information.
This is an abstraction for all non-hypervisor-based classes, where
......@@ -456,6 +456,10 @@ class BaseHypervisor(object):
xen, where you only see the hardware resources via xen-specific
tools.
@param meminfo: name of the file containing meminfo
@type meminfo: string
@param cpuinfo: name of the file containing cpuinfo
@type cpuinfo: string
@return: a dict with the following keys (values in MiB):
- memory_total: the total memory size on the node
- memory_free: the available memory on the node for instances
......@@ -463,7 +467,7 @@ class BaseHypervisor(object):
"""
try:
data = utils.ReadFile("/proc/meminfo").splitlines()
data = utils.ReadFile(meminfo).splitlines()
except EnvironmentError, err:
raise errors.HypervisorError("Failed to list node info: %s" % (err,))
......@@ -489,7 +493,7 @@ class BaseHypervisor(object):
cpu_total = 0
try:
fh = open("/proc/cpuinfo")
fh = open(cpuinfo)
try:
cpu_total = len(re.findall("(?m)^processor\s*:\s*[0-9]+\s*$",
fh.read()))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment