Revision e3e66f02
b/lib/hypervisor/hv_xen.py | ||
---|---|---|
214 | 214 |
""" |
215 | 215 |
raise NotImplementedError |
216 | 216 |
|
217 |
|
|
218 | 217 |
def Verify(self): |
219 | 218 |
"""Verify the hypervisor. |
220 | 219 |
|
221 | 220 |
For Xen, this verifies that the xend process is running. |
222 | 221 |
|
223 | 222 |
""" |
224 |
if not utils.CheckDaemonAlive('/var/run/xend.pid', 'xend'): |
|
225 |
return "xend daemon is not running" |
|
223 |
result = utils.RunCmd(["xm", "info"]) |
|
224 |
if result.failed: |
|
225 |
return "'xm info' failed: %s" % result.fail_reason |
|
226 | 226 |
|
227 | 227 |
@staticmethod |
228 | 228 |
def _GetConfigFileDiskData(disk_template, block_devices): |
b/lib/utils.py | ||
---|---|---|
569 | 569 |
return [tup[1] for tup in to_sort] |
570 | 570 |
|
571 | 571 |
|
572 |
def CheckDaemonAlive(pid_file, process_string): |
|
573 |
"""Check wether the specified daemon is alive. |
|
574 |
|
|
575 |
Args: |
|
576 |
- pid_file: file to read the daemon pid from, the file is |
|
577 |
expected to contain only a single line containing |
|
578 |
only the PID |
|
579 |
- process_string: a substring that we expect to find in |
|
580 |
the command line of the daemon process |
|
581 |
|
|
582 |
Returns: |
|
583 |
- True if the daemon is judged to be alive (that is: |
|
584 |
- the PID file exists, is readable and contains a number |
|
585 |
- a process of the specified PID is running |
|
586 |
- that process contains the specified string in its |
|
587 |
command line |
|
588 |
- the process is not in state Z (zombie)) |
|
589 |
- False otherwise |
|
590 |
|
|
591 |
""" |
|
592 |
try: |
|
593 |
pid_file = file(pid_file, 'r') |
|
594 |
try: |
|
595 |
pid = int(pid_file.readline()) |
|
596 |
finally: |
|
597 |
pid_file.close() |
|
598 |
|
|
599 |
cmdline_file_path = "/proc/%s/cmdline" % (pid) |
|
600 |
cmdline_file = open(cmdline_file_path, 'r') |
|
601 |
try: |
|
602 |
cmdline = cmdline_file.readline() |
|
603 |
finally: |
|
604 |
cmdline_file.close() |
|
605 |
|
|
606 |
if not process_string in cmdline: |
|
607 |
return False |
|
608 |
|
|
609 |
stat_file_path = "/proc/%s/stat" % (pid) |
|
610 |
stat_file = open(stat_file_path, 'r') |
|
611 |
try: |
|
612 |
process_state = stat_file.readline().split()[2] |
|
613 |
finally: |
|
614 |
stat_file.close() |
|
615 |
|
|
616 |
if process_state == 'Z': |
|
617 |
return False |
|
618 |
|
|
619 |
except (IndexError, IOError, ValueError): |
|
620 |
return False |
|
621 |
|
|
622 |
return True |
|
623 |
|
|
624 |
|
|
625 | 572 |
def TryConvert(fn, val): |
626 | 573 |
"""Try to convert a value ignoring errors. |
627 | 574 |
|
Also available in: Unified diff