From 605bf01cf3f06959f1ca652dc27ba2ae42b515bd Mon Sep 17 00:00:00 2001 From: Giampaolo Lauria Date: Fri, 15 Feb 2013 09:27:27 -0500 Subject: Add API Sample tests for Hypervisors extension. Partially implements blueprint nova-api-samples Fixes bug 1091750 Change-Id: Ie8e6881ea3533cd43259548594d3debe377345a5 --- .../os-hypervisors/hypervisors-detail-resp.json | 26 +++++++++ .../os-hypervisors/hypervisors-detail-resp.xml | 6 +++ .../os-hypervisors/hypervisors-list-resp.json | 8 +++ .../os-hypervisors/hypervisors-list-resp.xml | 4 ++ .../os-hypervisors/hypervisors-search-resp.json | 8 +++ .../os-hypervisors/hypervisors-search-resp.xml | 4 ++ .../os-hypervisors/hypervisors-servers-resp.json | 8 +++ .../os-hypervisors/hypervisors-servers-resp.xml | 6 +++ .../os-hypervisors/hypervisors-show-resp.json | 24 +++++++++ .../os-hypervisors/hypervisors-show-resp.xml | 4 ++ .../hypervisors-statistics-resp.json | 16 ++++++ .../os-hypervisors/hypervisors-statistics-resp.xml | 2 + .../os-hypervisors/hypervisors-uptime-resp.json | 7 +++ .../os-hypervisors/hypervisors-uptime-resp.xml | 2 + .../hypervisors-detail-resp.json.tpl | 26 +++++++++ .../os-hypervisors/hypervisors-detail-resp.xml.tpl | 6 +++ .../os-hypervisors/hypervisors-list-resp.json.tpl | 8 +++ .../os-hypervisors/hypervisors-list-resp.xml.tpl | 4 ++ .../hypervisors-search-resp.json.tpl | 8 +++ .../os-hypervisors/hypervisors-search-resp.xml.tpl | 4 ++ .../hypervisors-servers-resp.json.tpl | 8 +++ .../hypervisors-servers-resp.xml.tpl | 6 +++ .../os-hypervisors/hypervisors-show-resp.json.tpl | 24 +++++++++ .../os-hypervisors/hypervisors-show-resp.xml.tpl | 4 ++ .../hypervisors-statistics-resp.json.tpl | 16 ++++++ .../hypervisors-statistics-resp.xml.tpl | 2 + .../hypervisors-uptime-resp.json.tpl | 7 +++ .../os-hypervisors/hypervisors-uptime-resp.xml.tpl | 2 + nova/tests/integrated/test_api_samples.py | 61 +++++++++++++++++++++- 29 files changed, 310 insertions(+), 1 deletion(-) create mode 100644 doc/api_samples/os-hypervisors/hypervisors-detail-resp.json create mode 100644 doc/api_samples/os-hypervisors/hypervisors-detail-resp.xml create mode 100644 doc/api_samples/os-hypervisors/hypervisors-list-resp.json create mode 100644 doc/api_samples/os-hypervisors/hypervisors-list-resp.xml create mode 100644 doc/api_samples/os-hypervisors/hypervisors-search-resp.json create mode 100644 doc/api_samples/os-hypervisors/hypervisors-search-resp.xml create mode 100644 doc/api_samples/os-hypervisors/hypervisors-servers-resp.json create mode 100644 doc/api_samples/os-hypervisors/hypervisors-servers-resp.xml create mode 100644 doc/api_samples/os-hypervisors/hypervisors-show-resp.json create mode 100644 doc/api_samples/os-hypervisors/hypervisors-show-resp.xml create mode 100644 doc/api_samples/os-hypervisors/hypervisors-statistics-resp.json create mode 100644 doc/api_samples/os-hypervisors/hypervisors-statistics-resp.xml create mode 100644 doc/api_samples/os-hypervisors/hypervisors-uptime-resp.json create mode 100644 doc/api_samples/os-hypervisors/hypervisors-uptime-resp.xml create mode 100644 nova/tests/integrated/api_samples/os-hypervisors/hypervisors-detail-resp.json.tpl create mode 100644 nova/tests/integrated/api_samples/os-hypervisors/hypervisors-detail-resp.xml.tpl create mode 100644 nova/tests/integrated/api_samples/os-hypervisors/hypervisors-list-resp.json.tpl create mode 100644 nova/tests/integrated/api_samples/os-hypervisors/hypervisors-list-resp.xml.tpl create mode 100644 nova/tests/integrated/api_samples/os-hypervisors/hypervisors-search-resp.json.tpl create mode 100644 nova/tests/integrated/api_samples/os-hypervisors/hypervisors-search-resp.xml.tpl create mode 100644 nova/tests/integrated/api_samples/os-hypervisors/hypervisors-servers-resp.json.tpl create mode 100644 nova/tests/integrated/api_samples/os-hypervisors/hypervisors-servers-resp.xml.tpl create mode 100644 nova/tests/integrated/api_samples/os-hypervisors/hypervisors-show-resp.json.tpl create mode 100644 nova/tests/integrated/api_samples/os-hypervisors/hypervisors-show-resp.xml.tpl create mode 100644 nova/tests/integrated/api_samples/os-hypervisors/hypervisors-statistics-resp.json.tpl create mode 100644 nova/tests/integrated/api_samples/os-hypervisors/hypervisors-statistics-resp.xml.tpl create mode 100644 nova/tests/integrated/api_samples/os-hypervisors/hypervisors-uptime-resp.json.tpl create mode 100644 nova/tests/integrated/api_samples/os-hypervisors/hypervisors-uptime-resp.xml.tpl diff --git a/doc/api_samples/os-hypervisors/hypervisors-detail-resp.json b/doc/api_samples/os-hypervisors/hypervisors-detail-resp.json new file mode 100644 index 000000000..b124901ea --- /dev/null +++ b/doc/api_samples/os-hypervisors/hypervisors-detail-resp.json @@ -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 + } + ] +} \ No newline at end of file diff --git a/doc/api_samples/os-hypervisors/hypervisors-detail-resp.xml b/doc/api_samples/os-hypervisors/hypervisors-detail-resp.xml new file mode 100644 index 000000000..709f4fcd6 --- /dev/null +++ b/doc/api_samples/os-hypervisors/hypervisors-detail-resp.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/doc/api_samples/os-hypervisors/hypervisors-list-resp.json b/doc/api_samples/os-hypervisors/hypervisors-list-resp.json new file mode 100644 index 000000000..8d9402127 --- /dev/null +++ b/doc/api_samples/os-hypervisors/hypervisors-list-resp.json @@ -0,0 +1,8 @@ +{ + "hypervisors": [ + { + "hypervisor_hostname": "fake-mini", + "id": 1 + } + ] +} \ No newline at end of file diff --git a/doc/api_samples/os-hypervisors/hypervisors-list-resp.xml b/doc/api_samples/os-hypervisors/hypervisors-list-resp.xml new file mode 100644 index 000000000..8a784c592 --- /dev/null +++ b/doc/api_samples/os-hypervisors/hypervisors-list-resp.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/doc/api_samples/os-hypervisors/hypervisors-search-resp.json b/doc/api_samples/os-hypervisors/hypervisors-search-resp.json new file mode 100644 index 000000000..8d9402127 --- /dev/null +++ b/doc/api_samples/os-hypervisors/hypervisors-search-resp.json @@ -0,0 +1,8 @@ +{ + "hypervisors": [ + { + "hypervisor_hostname": "fake-mini", + "id": 1 + } + ] +} \ No newline at end of file diff --git a/doc/api_samples/os-hypervisors/hypervisors-search-resp.xml b/doc/api_samples/os-hypervisors/hypervisors-search-resp.xml new file mode 100644 index 000000000..8a784c592 --- /dev/null +++ b/doc/api_samples/os-hypervisors/hypervisors-search-resp.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/doc/api_samples/os-hypervisors/hypervisors-servers-resp.json b/doc/api_samples/os-hypervisors/hypervisors-servers-resp.json new file mode 100644 index 000000000..8d9402127 --- /dev/null +++ b/doc/api_samples/os-hypervisors/hypervisors-servers-resp.json @@ -0,0 +1,8 @@ +{ + "hypervisors": [ + { + "hypervisor_hostname": "fake-mini", + "id": 1 + } + ] +} \ No newline at end of file diff --git a/doc/api_samples/os-hypervisors/hypervisors-servers-resp.xml b/doc/api_samples/os-hypervisors/hypervisors-servers-resp.xml new file mode 100644 index 000000000..950a5ab11 --- /dev/null +++ b/doc/api_samples/os-hypervisors/hypervisors-servers-resp.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/doc/api_samples/os-hypervisors/hypervisors-show-resp.json b/doc/api_samples/os-hypervisors/hypervisors-show-resp.json new file mode 100644 index 000000000..c0feecd02 --- /dev/null +++ b/doc/api_samples/os-hypervisors/hypervisors-show-resp.json @@ -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 + } +} \ No newline at end of file diff --git a/doc/api_samples/os-hypervisors/hypervisors-show-resp.xml b/doc/api_samples/os-hypervisors/hypervisors-show-resp.xml new file mode 100644 index 000000000..04feef067 --- /dev/null +++ b/doc/api_samples/os-hypervisors/hypervisors-show-resp.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/doc/api_samples/os-hypervisors/hypervisors-statistics-resp.json b/doc/api_samples/os-hypervisors/hypervisors-statistics-resp.json new file mode 100644 index 000000000..2cfb51e70 --- /dev/null +++ b/doc/api_samples/os-hypervisors/hypervisors-statistics-resp.json @@ -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 + } +} \ No newline at end of file diff --git a/doc/api_samples/os-hypervisors/hypervisors-statistics-resp.xml b/doc/api_samples/os-hypervisors/hypervisors-statistics-resp.xml new file mode 100644 index 000000000..5d10411e3 --- /dev/null +++ b/doc/api_samples/os-hypervisors/hypervisors-statistics-resp.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/doc/api_samples/os-hypervisors/hypervisors-uptime-resp.json b/doc/api_samples/os-hypervisors/hypervisors-uptime-resp.json new file mode 100644 index 000000000..f5f9d19e7 --- /dev/null +++ b/doc/api_samples/os-hypervisors/hypervisors-uptime-resp.json @@ -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" + } +} \ No newline at end of file diff --git a/doc/api_samples/os-hypervisors/hypervisors-uptime-resp.xml b/doc/api_samples/os-hypervisors/hypervisors-uptime-resp.xml new file mode 100644 index 000000000..5c1b2cd7d --- /dev/null +++ b/doc/api_samples/os-hypervisors/hypervisors-uptime-resp.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/nova/tests/integrated/api_samples/os-hypervisors/hypervisors-detail-resp.json.tpl b/nova/tests/integrated/api_samples/os-hypervisors/hypervisors-detail-resp.json.tpl new file mode 100644 index 000000000..88eb4ad86 --- /dev/null +++ b/nova/tests/integrated/api_samples/os-hypervisors/hypervisors-detail-resp.json.tpl @@ -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 + } + ] +} diff --git a/nova/tests/integrated/api_samples/os-hypervisors/hypervisors-detail-resp.xml.tpl b/nova/tests/integrated/api_samples/os-hypervisors/hypervisors-detail-resp.xml.tpl new file mode 100644 index 000000000..f0c20662d --- /dev/null +++ b/nova/tests/integrated/api_samples/os-hypervisors/hypervisors-detail-resp.xml.tpl @@ -0,0 +1,6 @@ + + + + + + diff --git a/nova/tests/integrated/api_samples/os-hypervisors/hypervisors-list-resp.json.tpl b/nova/tests/integrated/api_samples/os-hypervisors/hypervisors-list-resp.json.tpl new file mode 100644 index 000000000..8d9402127 --- /dev/null +++ b/nova/tests/integrated/api_samples/os-hypervisors/hypervisors-list-resp.json.tpl @@ -0,0 +1,8 @@ +{ + "hypervisors": [ + { + "hypervisor_hostname": "fake-mini", + "id": 1 + } + ] +} \ No newline at end of file diff --git a/nova/tests/integrated/api_samples/os-hypervisors/hypervisors-list-resp.xml.tpl b/nova/tests/integrated/api_samples/os-hypervisors/hypervisors-list-resp.xml.tpl new file mode 100644 index 000000000..6b7d9d7ca --- /dev/null +++ b/nova/tests/integrated/api_samples/os-hypervisors/hypervisors-list-resp.xml.tpl @@ -0,0 +1,4 @@ + + + + diff --git a/nova/tests/integrated/api_samples/os-hypervisors/hypervisors-search-resp.json.tpl b/nova/tests/integrated/api_samples/os-hypervisors/hypervisors-search-resp.json.tpl new file mode 100644 index 000000000..8d9402127 --- /dev/null +++ b/nova/tests/integrated/api_samples/os-hypervisors/hypervisors-search-resp.json.tpl @@ -0,0 +1,8 @@ +{ + "hypervisors": [ + { + "hypervisor_hostname": "fake-mini", + "id": 1 + } + ] +} \ No newline at end of file diff --git a/nova/tests/integrated/api_samples/os-hypervisors/hypervisors-search-resp.xml.tpl b/nova/tests/integrated/api_samples/os-hypervisors/hypervisors-search-resp.xml.tpl new file mode 100644 index 000000000..6b7d9d7ca --- /dev/null +++ b/nova/tests/integrated/api_samples/os-hypervisors/hypervisors-search-resp.xml.tpl @@ -0,0 +1,4 @@ + + + + diff --git a/nova/tests/integrated/api_samples/os-hypervisors/hypervisors-servers-resp.json.tpl b/nova/tests/integrated/api_samples/os-hypervisors/hypervisors-servers-resp.json.tpl new file mode 100644 index 000000000..8d9402127 --- /dev/null +++ b/nova/tests/integrated/api_samples/os-hypervisors/hypervisors-servers-resp.json.tpl @@ -0,0 +1,8 @@ +{ + "hypervisors": [ + { + "hypervisor_hostname": "fake-mini", + "id": 1 + } + ] +} \ No newline at end of file diff --git a/nova/tests/integrated/api_samples/os-hypervisors/hypervisors-servers-resp.xml.tpl b/nova/tests/integrated/api_samples/os-hypervisors/hypervisors-servers-resp.xml.tpl new file mode 100644 index 000000000..7782732ba --- /dev/null +++ b/nova/tests/integrated/api_samples/os-hypervisors/hypervisors-servers-resp.xml.tpl @@ -0,0 +1,6 @@ + + + + + + diff --git a/nova/tests/integrated/api_samples/os-hypervisors/hypervisors-show-resp.json.tpl b/nova/tests/integrated/api_samples/os-hypervisors/hypervisors-show-resp.json.tpl new file mode 100644 index 000000000..4eaded8d7 --- /dev/null +++ b/nova/tests/integrated/api_samples/os-hypervisors/hypervisors-show-resp.json.tpl @@ -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 + } +} diff --git a/nova/tests/integrated/api_samples/os-hypervisors/hypervisors-show-resp.xml.tpl b/nova/tests/integrated/api_samples/os-hypervisors/hypervisors-show-resp.xml.tpl new file mode 100644 index 000000000..336f23be2 --- /dev/null +++ b/nova/tests/integrated/api_samples/os-hypervisors/hypervisors-show-resp.xml.tpl @@ -0,0 +1,4 @@ + + + + diff --git a/nova/tests/integrated/api_samples/os-hypervisors/hypervisors-statistics-resp.json.tpl b/nova/tests/integrated/api_samples/os-hypervisors/hypervisors-statistics-resp.json.tpl new file mode 100644 index 000000000..2cfb51e70 --- /dev/null +++ b/nova/tests/integrated/api_samples/os-hypervisors/hypervisors-statistics-resp.json.tpl @@ -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 + } +} \ No newline at end of file diff --git a/nova/tests/integrated/api_samples/os-hypervisors/hypervisors-statistics-resp.xml.tpl b/nova/tests/integrated/api_samples/os-hypervisors/hypervisors-statistics-resp.xml.tpl new file mode 100644 index 000000000..5d10411e3 --- /dev/null +++ b/nova/tests/integrated/api_samples/os-hypervisors/hypervisors-statistics-resp.xml.tpl @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/nova/tests/integrated/api_samples/os-hypervisors/hypervisors-uptime-resp.json.tpl b/nova/tests/integrated/api_samples/os-hypervisors/hypervisors-uptime-resp.json.tpl new file mode 100644 index 000000000..8a36c65f2 --- /dev/null +++ b/nova/tests/integrated/api_samples/os-hypervisors/hypervisors-uptime-resp.json.tpl @@ -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" + } +} diff --git a/nova/tests/integrated/api_samples/os-hypervisors/hypervisors-uptime-resp.xml.tpl b/nova/tests/integrated/api_samples/os-hypervisors/hypervisors-uptime-resp.xml.tpl new file mode 100644 index 000000000..04219f5b5 --- /dev/null +++ b/nova/tests/integrated/api_samples/os-hypervisors/hypervisors-uptime-resp.xml.tpl @@ -0,0 +1,2 @@ + + diff --git a/nova/tests/integrated/test_api_samples.py b/nova/tests/integrated/test_api_samples.py index 05d528ec2..8282990f9 100644 --- a/nova/tests/integrated/test_api_samples.py +++ b/nova/tests/integrated/test_api_samples.py @@ -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" -- cgit