Skip to content

Commit

Permalink
Fix XenServer's ability to boot xen type images
Browse files Browse the repository at this point in the history
Fixes bug 1055431.

As the scheduler wants to boot a vm_mode=xen type of image, the host's
"supported_instances" capability is used for finding a good candidate.
In the Xapi case, this field was not populated.

This fix modifies the xapi xenhost plugin, so the Xen host capabilities
are returned back to the compute node, as "host_capabilities".
On the compute side, the mentioned information is used, to extract the
"supported_instances" information.

Change-Id: I2da11ab81f74b5b52e2c30832a694470978e21b0
  • Loading branch information
Mate Lakat committed Sep 25, 2012
1 parent 13a08f6 commit 25b2062
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
38 changes: 38 additions & 0 deletions nova/tests/test_xenapi.py
Expand Up @@ -44,6 +44,7 @@
from nova.virt.xenapi import agent
from nova.virt.xenapi import driver as xenapi_conn
from nova.virt.xenapi import fake as xenapi_fake
from nova.virt.xenapi import host
from nova.virt.xenapi import pool
from nova.virt.xenapi import pool_states
from nova.virt.xenapi import vm_utils
Expand Down Expand Up @@ -1275,6 +1276,43 @@ def test_get_host_uptime(self):
result = self.conn.get_host_uptime('host')
self.assertEqual(result, 'fake uptime')

def test_supported_instances_is_included_in_host_state(self):
stats = self.conn.get_host_stats()
self.assertTrue('supported_instances' in stats)

def test_supported_instances_is_calculated_by_to_supported_instances(self):

def to_supported_instances(somedata):
self.assertEquals(None, somedata)
return "SOMERETURNVALUE"
self.stubs.Set(host, 'to_supported_instances', to_supported_instances)

stats = self.conn.get_host_stats()
self.assertEquals("SOMERETURNVALUE", stats['supported_instances'])


class ToSupportedInstancesTestCase(test.TestCase):
def test_default_return_value(self):
self.assertEquals([],
host.to_supported_instances(None))

def test_return_value(self):
self.assertEquals([('x86_64', 'xapi', 'xen')],
host.to_supported_instances([u'xen-3.0-x86_64']))

def test_invalid_values_do_not_break(self):
self.assertEquals([('x86_64', 'xapi', 'xen')],
host.to_supported_instances([u'xen-3.0-x86_64', 'spam']))

def test_multiple_values(self):
self.assertEquals(
[
('x86_64', 'xapi', 'xen'),
('x86_32', 'xapi', 'hvm')
],
host.to_supported_instances([u'xen-3.0-x86_64', 'hvm-3.0-x86_32'])
)


class XenAPIAutoDiskConfigTestCase(stubs.XenAPITestBase):
def setUp(self):
Expand Down
19 changes: 19 additions & 0 deletions nova/virt/xenapi/host.py
Expand Up @@ -162,6 +162,9 @@ def update_status(self):
data["disk_total"] = total
data["disk_used"] = used
data["disk_available"] = total - used
data["supported_instances"] = to_supported_instances(
data.get("host_capabilities")
)
host_memory = data.get('host_memory', None)
if host_memory:
data["host_memory_total"] = host_memory.get('total', 0)
Expand All @@ -173,6 +176,22 @@ def update_status(self):
self._stats = data


def to_supported_instances(host_capabilities):
if not host_capabilities:
return []

result = []
for capability in host_capabilities:
try:
ostype, _version, arch = capability.split("-")
result.append((arch, 'xapi', ostype))
except ValueError:
LOG.warning(
_("Failed to extract instance support from %s"), capability)

return result


def call_xenhost(session, method, arg_dict):
"""There will be several methods that will need this general
handling for interacting with the xenhost plugin, so this abstracts
Expand Down
4 changes: 3 additions & 1 deletion plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost
Expand Up @@ -398,7 +398,9 @@ def cleanup(dct):
for oc_fld in oc.split("; "):
ock, ocv = strip_kv(oc_fld)
ocd[ock] = ocv
# out["host_capabilities"] = dct.get("capabilities", "").split("; ")

capabilities = dct.get("capabilities", "")
out["host_capabilities"] = capabilities.replace(";", "").split()
# out["host_allowed-operations"] = dct.get(
# "allowed-operations", "").split("; ")
# lsrv = dct.get("license-server", "")
Expand Down

0 comments on commit 25b2062

Please sign in to comment.