Add API Sample tests for Hypervisors extension.

Partially implements blueprint nova-api-samples
Fixes bug 1091750

Change-Id: Ie8e6881ea3533cd43259548594d3debe377345a5
This commit is contained in:
Giampaolo Lauria 2013-02-15 09:27:27 -05:00 committed by Gerrit Code Review
parent 96a4518575
commit 605bf01cf3
29 changed files with 310 additions and 1 deletions

View File

@ -0,0 +1,26 @@
{
"hypervisors": [
{
"cpu_info": "?",
"current_workload": 0,
"disk_available_least": null,
"free_disk_gb": 1028,
"free_ram_mb": 7680,
"hypervisor_hostname": "fake-mini",
"hypervisor_type": "fake",
"hypervisor_version": 1,
"id": 1,
"local_gb": 1028,
"local_gb_used": 0,
"memory_mb": 8192,
"memory_mb_used": 512,
"running_vms": 0,
"service": {
"host": "1e0d7892083548cfb347e782d3b20342",
"id": 2
},
"vcpus": 1,
"vcpus_used": 0
}
]
}

View File

@ -0,0 +1,6 @@
<?xml version='1.0' encoding='UTF-8'?>
<hypervisors>
<hypervisor vcpus_used="0" hypervisor_type="fake" local_gb_used="0" hypervisor_hostname="fake-mini" memory_mb_used="512" memory_mb="8192" current_workload="0" vcpus="1" cpu_info="?" running_vms="0" free_disk_gb="1028" hypervisor_version="1" disk_available_least="None" local_gb="1028" free_ram_mb="7680" id="1">
<service host="4400f556a66d44ce95dfa61e75a23aaf" id="2"/>
</hypervisor>
</hypervisors>

View File

@ -0,0 +1,8 @@
{
"hypervisors": [
{
"hypervisor_hostname": "fake-mini",
"id": 1
}
]
}

View File

@ -0,0 +1,4 @@
<?xml version='1.0' encoding='UTF-8'?>
<hypervisors>
<hypervisor id="1" hypervisor_hostname="fake-mini"/>
</hypervisors>

View File

@ -0,0 +1,8 @@
{
"hypervisors": [
{
"hypervisor_hostname": "fake-mini",
"id": 1
}
]
}

View File

@ -0,0 +1,4 @@
<?xml version='1.0' encoding='UTF-8'?>
<hypervisors>
<hypervisor id="1" hypervisor_hostname="fake-mini"/>
</hypervisors>

View File

@ -0,0 +1,8 @@
{
"hypervisors": [
{
"hypervisor_hostname": "fake-mini",
"id": 1
}
]
}

View File

@ -0,0 +1,6 @@
<?xml version='1.0' encoding='UTF-8'?>
<hypervisors>
<hypervisor id="1" hypervisor_hostname="fake-mini">
<servers/>
</hypervisor>
</hypervisors>

View File

@ -0,0 +1,24 @@
{
"hypervisor": {
"cpu_info": "?",
"current_workload": 0,
"disk_available_least": null,
"free_disk_gb": 1028,
"free_ram_mb": 7680,
"hypervisor_hostname": "fake-mini",
"hypervisor_type": "fake",
"hypervisor_version": 1,
"id": 1,
"local_gb": 1028,
"local_gb_used": 0,
"memory_mb": 8192,
"memory_mb_used": 512,
"running_vms": 0,
"service": {
"host": "5641188ab2964f88a21042b493585ff8",
"id": 2
},
"vcpus": 1,
"vcpus_used": 0
}
}

View File

@ -0,0 +1,4 @@
<?xml version='1.0' encoding='UTF-8'?>
<hypervisor vcpus_used="0" hypervisor_type="fake" local_gb_used="0" hypervisor_hostname="fake-mini" memory_mb_used="512" memory_mb="8192" current_workload="0" vcpus="1" cpu_info="?" running_vms="0" free_disk_gb="1028" hypervisor_version="1" disk_available_least="None" local_gb="1028" free_ram_mb="7680" id="1">
<service host="807e1a43ceb740138eea32969c3e9fe5" id="2"/>
</hypervisor>

View File

@ -0,0 +1,16 @@
{
"hypervisor_statistics": {
"count": 1,
"current_workload": 0,
"disk_available_least": 0,
"free_disk_gb": 1028,
"free_ram_mb": 7680,
"local_gb": 1028,
"local_gb_used": 0,
"memory_mb": 8192,
"memory_mb_used": 512,
"running_vms": 0,
"vcpus": 1,
"vcpus_used": 0
}
}

View File

@ -0,0 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?>
<hypervisor_statistics count="1" vcpus_used="0" local_gb_used="0" memory_mb="8192" current_workload="0" vcpus="1" running_vms="0" free_disk_gb="1028" disk_available_least="0" local_gb="1028" free_ram_mb="7680" memory_mb_used="512"/>

View File

@ -0,0 +1,7 @@
{
"hypervisor": {
"hypervisor_hostname": "fake-mini",
"id": 1,
"uptime": " 08:32:11 up 93 days, 18:25, 12 users, load average: 0.20, 0.12, 0.14"
}
}

View File

@ -0,0 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?>
<hypervisor uptime=" 08:32:11 up 93 days, 18:25, 12 users, load average: 0.20, 0.12, 0.14" id="1" hypervisor_hostname="fake-mini"/>

View File

@ -0,0 +1,26 @@
{
"hypervisors": [
{
"cpu_info": "?",
"current_workload": 0,
"disk_available_least": null,
"free_disk_gb": 1028,
"free_ram_mb": 7680,
"hypervisor_hostname": "fake-mini",
"hypervisor_type": "fake",
"hypervisor_version": 1,
"id": 1,
"local_gb": 1028,
"local_gb_used": 0,
"memory_mb": 8192,
"memory_mb_used": 512,
"running_vms": 0,
"service": {
"host": "%(host_name)s",
"id": 2
},
"vcpus": 1,
"vcpus_used": 0
}
]
}

View File

@ -0,0 +1,6 @@
<?xml version='1.0' encoding='UTF-8'?>
<hypervisors>
<hypervisor vcpus_used="0" hypervisor_type="fake" local_gb_used="0" hypervisor_hostname="fake-mini" memory_mb_used="512" memory_mb="8192" current_workload="0" vcpus="1" cpu_info="?" running_vms="0" free_disk_gb="1028" hypervisor_version="1" disk_available_least="None" local_gb="1028" free_ram_mb="7680" id="1">
<service host="%(host_name)s" id="2"/>
</hypervisor>
</hypervisors>

View File

@ -0,0 +1,8 @@
{
"hypervisors": [
{
"hypervisor_hostname": "fake-mini",
"id": 1
}
]
}

View File

@ -0,0 +1,4 @@
<?xml version='1.0' encoding='UTF-8'?>
<hypervisors>
<hypervisor id="1" hypervisor_hostname="fake-mini"/>
</hypervisors>

View File

@ -0,0 +1,8 @@
{
"hypervisors": [
{
"hypervisor_hostname": "fake-mini",
"id": 1
}
]
}

View File

@ -0,0 +1,4 @@
<?xml version='1.0' encoding='UTF-8'?>
<hypervisors>
<hypervisor id="1" hypervisor_hostname="fake-mini"/>
</hypervisors>

View File

@ -0,0 +1,8 @@
{
"hypervisors": [
{
"hypervisor_hostname": "fake-mini",
"id": 1
}
]
}

View File

@ -0,0 +1,6 @@
<?xml version='1.0' encoding='UTF-8'?>
<hypervisors>
<hypervisor id="1" hypervisor_hostname="fake-mini">
<servers/>
</hypervisor>
</hypervisors>

View File

@ -0,0 +1,24 @@
{
"hypervisor": {
"cpu_info": "?",
"current_workload": 0,
"disk_available_least": null,
"free_disk_gb": 1028,
"free_ram_mb": 7680,
"hypervisor_hostname": "fake-mini",
"hypervisor_type": "fake",
"hypervisor_version": 1,
"id": %(hypervisor_id)s,
"local_gb": 1028,
"local_gb_used": 0,
"memory_mb": 8192,
"memory_mb_used": 512,
"running_vms": 0,
"service": {
"host": "%(host_name)s",
"id": 2
},
"vcpus": 1,
"vcpus_used": 0
}
}

View File

@ -0,0 +1,4 @@
<?xml version='1.0' encoding='UTF-8'?>
<hypervisor vcpus_used="0" hypervisor_type="fake" local_gb_used="0" hypervisor_hostname="fake-mini" memory_mb_used="512" memory_mb="8192" current_workload="0" vcpus="1" cpu_info="?" running_vms="0" free_disk_gb="1028" hypervisor_version="1" disk_available_least="None" local_gb="1028" free_ram_mb="7680" id="%(hypervisor_id)s">
<service host="%(host_name)s" id="2"/>
</hypervisor>

View File

@ -0,0 +1,16 @@
{
"hypervisor_statistics": {
"count": 1,
"current_workload": 0,
"disk_available_least": 0,
"free_disk_gb": 1028,
"free_ram_mb": 7680,
"local_gb": 1028,
"local_gb_used": 0,
"memory_mb": 8192,
"memory_mb_used": 512,
"running_vms": 0,
"vcpus": 1,
"vcpus_used": 0
}
}

View File

@ -0,0 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?>
<hypervisor_statistics count="1" vcpus_used="0" local_gb_used="0" memory_mb="8192" current_workload="0" vcpus="1" running_vms="0" free_disk_gb="1028" disk_available_least="0" local_gb="1028" free_ram_mb="7680" memory_mb_used="512"/>

View File

@ -0,0 +1,7 @@
{
"hypervisor": {
"hypervisor_hostname": "fake-mini",
"id": %(hypervisor_id)s,
"uptime": " 08:32:11 up 93 days, 18:25, 12 users, load average: 0.20, 0.12, 0.14"
}
}

View File

@ -0,0 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?>
<hypervisor uptime=" 08:32:11 up 93 days, 18:25, 12 users, load average: 0.20, 0.12, 0.14" id="%(hypervisor_id)s" hypervisor_hostname="fake-mini"/>

View File

@ -383,7 +383,6 @@ class ApiSamplesTrap(ApiSampleTestBase):
# removed) soon.
do_not_approve_additions = []
do_not_approve_additions.append('os-create-server-ext')
do_not_approve_additions.append('os-hypervisors')
do_not_approve_additions.append('os-volumes')
tests = self._get_extensions_tested()
@ -3333,6 +3332,66 @@ class FlavorAccessSampleJsonTests(ApiSampleTestBase):
class FlavorAccessSampleXmlTests(FlavorAccessSampleJsonTests):
ctype = 'xml'
class HypervisorsSampleJsonTests(ApiSampleTestBase):
extension_name = ("nova.api.openstack.compute.contrib.hypervisors."
"Hypervisors")
def test_hypervisors_list(self):
response = self._do_get('os-hypervisors')
self.assertEqual(response.status, 200)
return self._verify_response('hypervisors-list-resp',
{}, response)
def test_hypervisors_search(self):
response = self._do_get('os-hypervisors/fake/search')
self.assertEqual(response.status, 200)
return self._verify_response('hypervisors-search-resp',
{}, response)
def test_hypervisors_servers(self):
response = self._do_get('os-hypervisors/fake/servers')
self.assertEqual(response.status, 200)
return self._verify_response('hypervisors-servers-resp',
{}, response)
def test_hypervisors_show(self):
hypervisor_id = 1
subs = {
'hypervisor_id': hypervisor_id
}
response = self._do_get('os-hypervisors/%s' % hypervisor_id)
self.assertEqual(response.status, 200)
subs.update(self._get_regexes())
return self._verify_response('hypervisors-show-resp',
subs, response)
def test_hypervisors_statistics(self):
response = self._do_get('os-hypervisors/statistics')
self.assertEqual(response.status, 200)
return self._verify_response('hypervisors-statistics-resp',
{}, response)
def test_hypervisors_uptime(self):
def fake_get_host_uptime(self, context, hyp):
return (" 08:32:11 up 93 days, 18:25, 12 users, load average:"
" 0.20, 0.12, 0.14")
self.stubs.Set(compute_api.HostAPI,
'get_host_uptime', fake_get_host_uptime)
hypervisor_id = 1
response = self._do_get('os-hypervisors/%s/uptime' % hypervisor_id)
self.assertEqual(response.status, 200)
subs = {
'hypervisor_id': hypervisor_id,
}
return self._verify_response('hypervisors-uptime-resp',
subs, response)
class HypervisorsSampleXmlTests(HypervisorsSampleJsonTests):
ctype = "xml"