Merge "Fix os-hosts extension can't return xml response correctly."
This commit is contained in:
commit
28b9872580
|
@ -0,0 +1,31 @@
|
||||||
|
{
|
||||||
|
"host": [
|
||||||
|
{
|
||||||
|
"resource": {
|
||||||
|
"cpu": 1,
|
||||||
|
"disk_gb": 1028,
|
||||||
|
"host": "5ca60c6792a1442f9471ff575443f94d",
|
||||||
|
"memory_mb": 8192,
|
||||||
|
"project": "(total)"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"resource": {
|
||||||
|
"cpu": 0,
|
||||||
|
"disk_gb": 0,
|
||||||
|
"host": "5ca60c6792a1442f9471ff575443f94d",
|
||||||
|
"memory_mb": 512,
|
||||||
|
"project": "(used_now)"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"resource": {
|
||||||
|
"cpu": 0,
|
||||||
|
"disk_gb": 0,
|
||||||
|
"host": "5ca60c6792a1442f9471ff575443f94d",
|
||||||
|
"memory_mb": 0,
|
||||||
|
"project": "(used_max)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
<?xml version='1.0' encoding='UTF-8'?>
|
||||||
|
<host>
|
||||||
|
<resource>
|
||||||
|
<project>(total)</project>
|
||||||
|
<memory_mb>8192</memory_mb>
|
||||||
|
<host>ecf3458ac6bf4a299cc2e0efa740f426</host>
|
||||||
|
<cpu>1</cpu>
|
||||||
|
<disk_gb>1028</disk_gb>
|
||||||
|
</resource>
|
||||||
|
<resource>
|
||||||
|
<project>(used_now)</project>
|
||||||
|
<memory_mb>512</memory_mb>
|
||||||
|
<host>ecf3458ac6bf4a299cc2e0efa740f426</host>
|
||||||
|
<cpu>0</cpu>
|
||||||
|
<disk_gb>0</disk_gb>
|
||||||
|
</resource>
|
||||||
|
<resource>
|
||||||
|
<project>(used_max)</project>
|
||||||
|
<memory_mb>0</memory_mb>
|
||||||
|
<host>ecf3458ac6bf4a299cc2e0efa740f426</host>
|
||||||
|
<cpu>0</cpu>
|
||||||
|
<disk_gb>0</disk_gb>
|
||||||
|
</resource>
|
||||||
|
</host>
|
|
@ -0,0 +1,24 @@
|
||||||
|
{
|
||||||
|
"hosts": [
|
||||||
|
{
|
||||||
|
"host_name": "c5a4acad61bc463ab5f60d164d942516",
|
||||||
|
"service": "compute",
|
||||||
|
"zone": "nova"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"host_name": "9112426abe5f4934a81b494fcdee8c5b",
|
||||||
|
"service": "cert",
|
||||||
|
"zone": "nova"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"host_name": "d483b9e6124d47f2a6ad14e57716a778",
|
||||||
|
"service": "network",
|
||||||
|
"zone": "nova"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"host_name": "3f9c73ba6d634092a70d6640f53930c8",
|
||||||
|
"service": "scheduler",
|
||||||
|
"zone": "nova"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version='1.0' encoding='UTF-8'?>
|
||||||
|
<hosts>
|
||||||
|
<host host_name="e5e145b49d244d97982c922e101859fd" service="compute"/>
|
||||||
|
<host host_name="6d85457c4d884047b41999540c2bf454" service="cert"/>
|
||||||
|
<host host_name="1f9a3cef66bd450aa004655ef239ddee" service="network"/>
|
||||||
|
<host host_name="c6fd14f8e3be44628e76ae4a6e88cffb" service="scheduler"/>
|
||||||
|
</hosts>
|
|
@ -33,11 +33,7 @@ authorize = extensions.extension_authorizer('compute', 'hosts')
|
||||||
|
|
||||||
class HostIndexTemplate(xmlutil.TemplateBuilder):
|
class HostIndexTemplate(xmlutil.TemplateBuilder):
|
||||||
def construct(self):
|
def construct(self):
|
||||||
def shimmer(obj, do_raise=False):
|
root = xmlutil.TemplateElement('hosts')
|
||||||
# A bare list is passed in; we need to wrap it in a dict
|
|
||||||
return dict(hosts=obj)
|
|
||||||
|
|
||||||
root = xmlutil.TemplateElement('hosts', selector=shimmer)
|
|
||||||
elem = xmlutil.SubTemplateElement(root, 'host', selector='hosts')
|
elem = xmlutil.SubTemplateElement(root, 'host', selector='hosts')
|
||||||
elem.set('host_name')
|
elem.set('host_name')
|
||||||
elem.set('service')
|
elem.set('service')
|
||||||
|
|
|
@ -25,11 +25,12 @@ from nova.openstack.common import log as logging
|
||||||
from nova import test
|
from nova import test
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
HOST_LIST = [
|
HOST_LIST = {"hosts": [
|
||||||
{"host_name": "host_c1", "service": "compute", "zone": "nova"},
|
{"host_name": "host_c1", "service": "compute", "zone": "nova"},
|
||||||
{"host_name": "host_c2", "service": "compute", "zone": "nonova"},
|
{"host_name": "host_c2", "service": "compute", "zone": "nonova"},
|
||||||
{"host_name": "host_v1", "service": "volume", "zone": "nova"},
|
{"host_name": "host_v1", "service": "volume", "zone": "nova"},
|
||||||
{"host_name": "host_v2", "service": "volume", "zone": "nonova"}]
|
{"host_name": "host_v2", "service": "volume", "zone": "nonova"}]
|
||||||
|
}
|
||||||
HOST_LIST_NOVA_ZONE = [
|
HOST_LIST_NOVA_ZONE = [
|
||||||
{"host_name": "host_c1", "service": "compute", "zone": "nova"},
|
{"host_name": "host_c1", "service": "compute", "zone": "nova"},
|
||||||
{"host_name": "host_v1", "service": "volume", "zone": "nova"}]
|
{"host_name": "host_v1", "service": "volume", "zone": "nova"}]
|
||||||
|
@ -129,10 +130,10 @@ class HostTestCase(test.TestCase):
|
||||||
def test_list_hosts(self):
|
def test_list_hosts(self):
|
||||||
"""Verify that the compute hosts are returned."""
|
"""Verify that the compute hosts are returned."""
|
||||||
hosts = os_hosts._list_hosts(self.req)
|
hosts = os_hosts._list_hosts(self.req)
|
||||||
self.assertEqual(hosts, HOST_LIST)
|
self.assertEqual(hosts, HOST_LIST['hosts'])
|
||||||
|
|
||||||
compute_hosts = os_hosts._list_hosts(self.req, "compute")
|
compute_hosts = os_hosts._list_hosts(self.req, "compute")
|
||||||
expected = [host for host in HOST_LIST
|
expected = [host for host in HOST_LIST['hosts']
|
||||||
if host["service"] == "compute"]
|
if host["service"] == "compute"]
|
||||||
self.assertEqual(compute_hosts, expected)
|
self.assertEqual(compute_hosts, expected)
|
||||||
|
|
||||||
|
@ -280,12 +281,12 @@ class HostSerializerTest(test.TestCase):
|
||||||
tree = etree.fromstring(text)
|
tree = etree.fromstring(text)
|
||||||
|
|
||||||
self.assertEqual('hosts', tree.tag)
|
self.assertEqual('hosts', tree.tag)
|
||||||
self.assertEqual(len(HOST_LIST), len(tree))
|
self.assertEqual(len(HOST_LIST['hosts']), len(tree))
|
||||||
for i in range(len(HOST_LIST)):
|
for i in range(len(HOST_LIST)):
|
||||||
self.assertEqual('host', tree[i].tag)
|
self.assertEqual('host', tree[i].tag)
|
||||||
self.assertEqual(HOST_LIST[i]['host_name'],
|
self.assertEqual(HOST_LIST['hosts'][i]['host_name'],
|
||||||
tree[i].get('host_name'))
|
tree[i].get('host_name'))
|
||||||
self.assertEqual(HOST_LIST[i]['service'],
|
self.assertEqual(HOST_LIST['hosts'][i]['service'],
|
||||||
tree[i].get('service'))
|
tree[i].get('service'))
|
||||||
|
|
||||||
def test_update_serializer_with_status(self):
|
def test_update_serializer_with_status(self):
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
{
|
||||||
|
"host": [
|
||||||
|
{
|
||||||
|
"resource": {
|
||||||
|
"cpu": 1,
|
||||||
|
"disk_gb": 1028,
|
||||||
|
"host": "%(host_name)s",
|
||||||
|
"memory_mb": 8192,
|
||||||
|
"project": "(total)"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"resource": {
|
||||||
|
"cpu": 0,
|
||||||
|
"disk_gb": 0,
|
||||||
|
"host": "%(host_name)s",
|
||||||
|
"memory_mb": 512,
|
||||||
|
"project": "(used_now)"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"resource": {
|
||||||
|
"cpu": 0,
|
||||||
|
"disk_gb": 0,
|
||||||
|
"host": "%(host_name)s",
|
||||||
|
"memory_mb": 0,
|
||||||
|
"project": "(used_max)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
<?xml version='1.0' encoding='UTF-8'?>
|
||||||
|
<host>
|
||||||
|
<resource>
|
||||||
|
<project>(total)</project>
|
||||||
|
<memory_mb>8192</memory_mb>
|
||||||
|
<host>%(host_name)s</host>
|
||||||
|
<cpu>1</cpu>
|
||||||
|
<disk_gb>1028</disk_gb>
|
||||||
|
</resource>
|
||||||
|
<resource>
|
||||||
|
<project>(used_now)</project>
|
||||||
|
<memory_mb>512</memory_mb>
|
||||||
|
<host>%(host_name)s</host>
|
||||||
|
<cpu>0</cpu>
|
||||||
|
<disk_gb>0</disk_gb>
|
||||||
|
</resource>
|
||||||
|
<resource>
|
||||||
|
<project>(used_max)</project>
|
||||||
|
<memory_mb>0</memory_mb>
|
||||||
|
<host>%(host_name)s</host>
|
||||||
|
<cpu>0</cpu>
|
||||||
|
<disk_gb>0</disk_gb>
|
||||||
|
</resource>
|
||||||
|
</host>
|
|
@ -0,0 +1,24 @@
|
||||||
|
{
|
||||||
|
"hosts": [
|
||||||
|
{
|
||||||
|
"host_name": "%(host_name)s",
|
||||||
|
"service": "compute",
|
||||||
|
"zone": "nova"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"host_name": "%(host_name)s",
|
||||||
|
"service": "cert",
|
||||||
|
"zone": "nova"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"host_name": "%(host_name)s",
|
||||||
|
"service": "network",
|
||||||
|
"zone": "nova"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"host_name": "%(host_name)s",
|
||||||
|
"service": "scheduler",
|
||||||
|
"zone": "nova"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version='1.0' encoding='UTF-8'?>
|
||||||
|
<hosts>
|
||||||
|
<host host_name="%(host_name)s" service="compute"/>
|
||||||
|
<host host_name="%(host_name)s" service="cert"/>
|
||||||
|
<host host_name="%(host_name)s" service="network"/>
|
||||||
|
<host host_name="%(host_name)s" service="scheduler"/>
|
||||||
|
</hosts>
|
|
@ -246,6 +246,7 @@ class ApiSampleTestBase(integrated_helpers._IntegratedTestBase):
|
||||||
# '[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:'
|
# '[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:'
|
||||||
# '[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}',
|
# '[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}',
|
||||||
'host': self._get_host(),
|
'host': self._get_host(),
|
||||||
|
'host_name': '[0-9a-z]{32}',
|
||||||
'glance_host': self._get_glance_host(),
|
'glance_host': self._get_glance_host(),
|
||||||
'compute_host': self.compute.host,
|
'compute_host': self.compute.host,
|
||||||
'text': text,
|
'text': text,
|
||||||
|
@ -458,6 +459,24 @@ class FlavorsSampleXmlTest(FlavorsSampleJsonTest):
|
||||||
ctype = 'xml'
|
ctype = 'xml'
|
||||||
|
|
||||||
|
|
||||||
|
class HostsSampleJsonTest(ApiSampleTestBase):
|
||||||
|
extension_name = "nova.api.openstack.compute.contrib.hosts.Hosts"
|
||||||
|
|
||||||
|
def test_host_get(self):
|
||||||
|
response = self._do_get('os-hosts/%s' % self.compute.host)
|
||||||
|
subs = self._get_regexes()
|
||||||
|
return self._verify_response('host-get-resp', subs, response)
|
||||||
|
|
||||||
|
def test_hosts_list(self):
|
||||||
|
response = self._do_get('os-hosts')
|
||||||
|
subs = self._get_regexes()
|
||||||
|
return self._verify_response('hosts-list-resp', subs, response)
|
||||||
|
|
||||||
|
|
||||||
|
class HostsSampleXmlTest(HostsSampleJsonTest):
|
||||||
|
ctype = 'xml'
|
||||||
|
|
||||||
|
|
||||||
class FlavorsSampleAllExtensionJsonTest(FlavorsSampleJsonTest):
|
class FlavorsSampleAllExtensionJsonTest(FlavorsSampleJsonTest):
|
||||||
all_extensions = True
|
all_extensions = True
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue