Commit e3e66f02 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

Remove utils.CheckDaemonAlive and use “xm info” instead

There are a couple of reasons for doing so:
- /proc is not OS independent, it's only supported by Linux (there are
  emulations on other systems, but those might differ from the way
  Linux represents data).
- Checking a daemon's state doesn't necessarily mean it's usable.
  Connecting to the socket using “xm info” is much safer.
- Reduce code size.

Reviewed-by: iustinp
parent f860ff4e
......@@ -214,15 +214,15 @@ class XenHypervisor(hv_base.BaseHypervisor):
"""
raise NotImplementedError
def Verify(self):
"""Verify the hypervisor.
For Xen, this verifies that the xend process is running.
"""
if not utils.CheckDaemonAlive('/var/run/xend.pid', 'xend'):
return "xend daemon is not running"
result = utils.RunCmd(["xm", "info"])
if result.failed:
return "'xm info' failed: %s" % result.fail_reason
@staticmethod
def _GetConfigFileDiskData(disk_template, block_devices):
......
......@@ -569,59 +569,6 @@ def NiceSort(name_list):
return [tup[1] for tup in to_sort]
def CheckDaemonAlive(pid_file, process_string):
"""Check wether the specified daemon is alive.
Args:
- pid_file: file to read the daemon pid from, the file is
expected to contain only a single line containing
only the PID
- process_string: a substring that we expect to find in
the command line of the daemon process
Returns:
- True if the daemon is judged to be alive (that is:
- the PID file exists, is readable and contains a number
- a process of the specified PID is running
- that process contains the specified string in its
command line
- the process is not in state Z (zombie))
- False otherwise
"""
try:
pid_file = file(pid_file, 'r')
try:
pid = int(pid_file.readline())
finally:
pid_file.close()
cmdline_file_path = "/proc/%s/cmdline" % (pid)
cmdline_file = open(cmdline_file_path, 'r')
try:
cmdline = cmdline_file.readline()
finally:
cmdline_file.close()
if not process_string in cmdline:
return False
stat_file_path = "/proc/%s/stat" % (pid)
stat_file = open(stat_file_path, 'r')
try:
process_state = stat_file.readline().split()[2]
finally:
stat_file.close()
if process_state == 'Z':
return False
except (IndexError, IOError, ValueError):
return False
return True
def TryConvert(fn, val):
"""Try to convert a value ignoring errors.
......
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