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

No changes for the callers, but it's now possible to test the function more
Signed-off-by: default avatarMichele Tartara <>
Reviewed-by: default avatarHelga Velroyen <>
parent b1633ed9
......@@ -447,7 +447,7 @@ class BaseHypervisor(object):
raise NotImplementedError
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
@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):
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
fh = open("/proc/cpuinfo")
fh = open(cpuinfo)
cpu_total = len(re.findall("(?m)^processor\s*:\s*[0-9]+\s*$",
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