Revision 2609da63
b/lib/hypervisor/hv_xen.py | ||
---|---|---|
104 | 104 |
return result.stdout.splitlines() |
105 | 105 |
|
106 | 106 |
|
107 |
def _ParseXmList(lines, include_node):
|
|
108 |
"""Parses the output of C{xm list}.
|
|
107 |
def _ParseInstanceList(lines, include_node):
|
|
108 |
"""Parses the output of listing instances by xen.
|
|
109 | 109 |
|
110 | 110 |
@type lines: list |
111 |
@param lines: Output lines of C{xm list}
|
|
111 |
@param lines: Result of retrieving the instance list from xen
|
|
112 | 112 |
@type include_node: boolean |
113 | 113 |
@param include_node: If True, return information for Dom0 |
114 | 114 |
@return: list of tuple containing (name, id, memory, vcpus, state, time |
... | ... | |
124 | 124 |
# Domain-0 0 3418 4 r----- 266.2 |
125 | 125 |
data = line.split() |
126 | 126 |
if len(data) != 6: |
127 |
raise errors.HypervisorError("Can't parse output of xm list,"
|
|
127 |
raise errors.HypervisorError("Can't parse instance list,"
|
|
128 | 128 |
" line: %s" % line) |
129 | 129 |
try: |
130 | 130 |
data[1] = int(data[1]) |
... | ... | |
132 | 132 |
data[3] = int(data[3]) |
133 | 133 |
data[5] = float(data[5]) |
134 | 134 |
except (TypeError, ValueError), err: |
135 |
raise errors.HypervisorError("Can't parse output of xm list,"
|
|
135 |
raise errors.HypervisorError("Can't parse instance list,"
|
|
136 | 136 |
" line: %s, error: %s" % (line, err)) |
137 | 137 |
|
138 | 138 |
# skip the Domain-0 (optional) |
... | ... | |
145 | 145 |
def _GetInstanceList(fn, include_node, _timeout=5): |
146 | 146 |
"""Return the list of running instances. |
147 | 147 |
|
148 |
See L{_RunInstanceList} and L{_ParseXmList} for parameter details.
|
|
148 |
See L{_RunInstanceList} and L{_ParseInstanceList} for parameter details.
|
|
149 | 149 |
|
150 | 150 |
""" |
151 | 151 |
instance_list_errors = [] |
... | ... | |
163 | 163 |
|
164 | 164 |
raise errors.HypervisorError(errmsg) |
165 | 165 |
|
166 |
return _ParseXmList(lines, include_node)
|
|
166 |
return _ParseInstanceList(lines, include_node)
|
|
167 | 167 |
|
168 | 168 |
|
169 | 169 |
def _ParseNodeInfo(info): |
... | ... | |
231 | 231 |
@type info: dict |
232 | 232 |
@param info: Result from L{_ParseNodeInfo} |
233 | 233 |
@type fn: callable |
234 |
@param fn: Function returning result of running C{xm list}
|
|
234 |
@param fn: Function retrieving the instance list
|
|
235 | 235 |
@rtype: dict |
236 | 236 |
|
237 | 237 |
""" |
... | ... | |
612 | 612 |
""" |
613 | 613 |
result = self._RunXen(["info"]) |
614 | 614 |
if result.failed: |
615 |
logging.error("Can't run 'xm info' (%s): %s", result.fail_reason,
|
|
616 |
result.output) |
|
615 |
logging.error("Can't retrieve xen hypervisor information (%s): %s",
|
|
616 |
result.fail_reason, result.output)
|
|
617 | 617 |
return None |
618 | 618 |
|
619 | 619 |
return _GetNodeInfo(result.stdout, self._GetInstanceList) |
b/test/py/ganeti.hypervisor.hv_xen_unittest.py | ||
---|---|---|
115 | 115 |
self.assertRaises(errors.ProgrammerError, hv._GetCommand, test_hvparams) |
116 | 116 |
|
117 | 117 |
|
118 |
class TestParseXmList(testutils.GanetiTestCase):
|
|
118 |
class TestParseInstanceList(testutils.GanetiTestCase):
|
|
119 | 119 |
def test(self): |
120 | 120 |
data = testutils.ReadTestData("xen-xm-list-4.0.1-dom0-only.txt") |
121 | 121 |
|
122 | 122 |
# Exclude node |
123 |
self.assertEqual(hv_xen._ParseXmList(data.splitlines(), False), [])
|
|
123 |
self.assertEqual(hv_xen._ParseInstanceList(data.splitlines(), False), [])
|
|
124 | 124 |
|
125 | 125 |
# Include node |
126 |
result = hv_xen._ParseXmList(data.splitlines(), True)
|
|
126 |
result = hv_xen._ParseInstanceList(data.splitlines(), True)
|
|
127 | 127 |
self.assertEqual(len(result), 1) |
128 | 128 |
self.assertEqual(len(result[0]), 6) |
129 | 129 |
|
... | ... | |
153 | 153 |
|
154 | 154 |
for lines in tests: |
155 | 155 |
try: |
156 |
hv_xen._ParseXmList(["Header would be here"] + lines, False)
|
|
156 |
hv_xen._ParseInstanceList(["Header would be here"] + lines, False)
|
|
157 | 157 |
except errors.HypervisorError, err: |
158 |
self.assertTrue("Can't parse output of xm list" in str(err))
|
|
158 |
self.assertTrue("Can't parse instance list" in str(err))
|
|
159 | 159 |
else: |
160 | 160 |
self.fail("Exception was not raised") |
161 | 161 |
|
Also available in: Unified diff