summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorivan-zhu <bozhu@linux.vnet.ibm.com>2013-01-09 22:52:46 +0800
committerivan-zhu <bozhu@linux.vnet.ibm.com>2013-02-13 17:49:16 +0800
commit43485291881d0af431ac0ff1ff7bbc0d5c528441 (patch)
tree6afa41d0295a90dd8699c3643d965fd7e6672886
parentd980805880c681881504e269e03130e4452630ab (diff)
Add API sample tests to Services extension
Partially implements blueprint nova-api-samples Bug 1091755 Change-Id: I7a0e124871c248bbb7613bfcdf335fee29a887f2
-rw-r--r--doc/api_samples/os-services/service-disable-put-req.json4
-rw-r--r--doc/api_samples/os-services/service-disable-put-resp.json5
-rw-r--r--doc/api_samples/os-services/service-enable-put-req.json4
-rw-r--r--doc/api_samples/os-services/service-enable-put-resp.json5
-rw-r--r--doc/api_samples/os-services/services-list-get-resp.json36
-rw-r--r--nova/tests/integrated/api_samples/os-services/service-disable-put-req.json.tpl4
-rw-r--r--nova/tests/integrated/api_samples/os-services/service-disable-put-resp.json.tpl5
-rw-r--r--nova/tests/integrated/api_samples/os-services/service-enable-put-req.json.tpl4
-rw-r--r--nova/tests/integrated/api_samples/os-services/service-enable-put-resp.json.tpl5
-rw-r--r--nova/tests/integrated/api_samples/os-services/services-list-get-resp.json.tpl36
-rw-r--r--nova/tests/integrated/test_api_samples.py57
11 files changed, 164 insertions, 1 deletions
diff --git a/doc/api_samples/os-services/service-disable-put-req.json b/doc/api_samples/os-services/service-disable-put-req.json
new file mode 100644
index 000000000..d11afaed9
--- /dev/null
+++ b/doc/api_samples/os-services/service-disable-put-req.json
@@ -0,0 +1,4 @@
+{
+ "host": "host1",
+ "service": "nova-compute"
+} \ No newline at end of file
diff --git a/doc/api_samples/os-services/service-disable-put-resp.json b/doc/api_samples/os-services/service-disable-put-resp.json
new file mode 100644
index 000000000..2e461bc6d
--- /dev/null
+++ b/doc/api_samples/os-services/service-disable-put-resp.json
@@ -0,0 +1,5 @@
+{
+ "disabled": true,
+ "host": "host1",
+ "service": "nova-compute"
+} \ No newline at end of file
diff --git a/doc/api_samples/os-services/service-enable-put-req.json b/doc/api_samples/os-services/service-enable-put-req.json
new file mode 100644
index 000000000..d11afaed9
--- /dev/null
+++ b/doc/api_samples/os-services/service-enable-put-req.json
@@ -0,0 +1,4 @@
+{
+ "host": "host1",
+ "service": "nova-compute"
+} \ No newline at end of file
diff --git a/doc/api_samples/os-services/service-enable-put-resp.json b/doc/api_samples/os-services/service-enable-put-resp.json
new file mode 100644
index 000000000..88b9dc7f9
--- /dev/null
+++ b/doc/api_samples/os-services/service-enable-put-resp.json
@@ -0,0 +1,5 @@
+{
+ "disabled": false,
+ "host": "host1",
+ "service": "nova-compute"
+} \ No newline at end of file
diff --git a/doc/api_samples/os-services/services-list-get-resp.json b/doc/api_samples/os-services/services-list-get-resp.json
new file mode 100644
index 000000000..dcda1a46e
--- /dev/null
+++ b/doc/api_samples/os-services/services-list-get-resp.json
@@ -0,0 +1,36 @@
+{
+ "services": [
+ {
+ "binary": "nova-scheduler",
+ "host": "host1",
+ "state": "up",
+ "status": "disabled",
+ "updated_at": "2012-10-29T13:42:02.000000",
+ "zone": "internal"
+ },
+ {
+ "binary": "nova-compute",
+ "host": "host1",
+ "state": "up",
+ "status": "disabled",
+ "updated_at": "2012-10-29T13:42:05.000000",
+ "zone": "nova"
+ },
+ {
+ "binary": "nova-scheduler",
+ "host": "host2",
+ "state": "down",
+ "status": "enabled",
+ "updated_at": "2012-09-19T06:55:34.000000",
+ "zone": "internal"
+ },
+ {
+ "binary": "nova-compute",
+ "host": "host2",
+ "state": "down",
+ "status": "disabled",
+ "updated_at": "2012-09-18T08:03:38.000000",
+ "zone": "nova"
+ }
+ ]
+} \ No newline at end of file
diff --git a/nova/tests/integrated/api_samples/os-services/service-disable-put-req.json.tpl b/nova/tests/integrated/api_samples/os-services/service-disable-put-req.json.tpl
new file mode 100644
index 000000000..4d48af1b8
--- /dev/null
+++ b/nova/tests/integrated/api_samples/os-services/service-disable-put-req.json.tpl
@@ -0,0 +1,4 @@
+{
+ "host": "%(host)s",
+ "service": "%(service)s"
+}
diff --git a/nova/tests/integrated/api_samples/os-services/service-disable-put-resp.json.tpl b/nova/tests/integrated/api_samples/os-services/service-disable-put-resp.json.tpl
new file mode 100644
index 000000000..8219a43f6
--- /dev/null
+++ b/nova/tests/integrated/api_samples/os-services/service-disable-put-resp.json.tpl
@@ -0,0 +1,5 @@
+{
+ "disabled": true,
+ "host": "%(host)s",
+ "service": "%(service)s"
+}
diff --git a/nova/tests/integrated/api_samples/os-services/service-enable-put-req.json.tpl b/nova/tests/integrated/api_samples/os-services/service-enable-put-req.json.tpl
new file mode 100644
index 000000000..4d48af1b8
--- /dev/null
+++ b/nova/tests/integrated/api_samples/os-services/service-enable-put-req.json.tpl
@@ -0,0 +1,4 @@
+{
+ "host": "%(host)s",
+ "service": "%(service)s"
+}
diff --git a/nova/tests/integrated/api_samples/os-services/service-enable-put-resp.json.tpl b/nova/tests/integrated/api_samples/os-services/service-enable-put-resp.json.tpl
new file mode 100644
index 000000000..079b9c76e
--- /dev/null
+++ b/nova/tests/integrated/api_samples/os-services/service-enable-put-resp.json.tpl
@@ -0,0 +1,5 @@
+{
+ "disabled": false,
+ "host": "%(host)s",
+ "service": "%(service)s"
+}
diff --git a/nova/tests/integrated/api_samples/os-services/services-list-get-resp.json.tpl b/nova/tests/integrated/api_samples/os-services/services-list-get-resp.json.tpl
new file mode 100644
index 000000000..cc6101338
--- /dev/null
+++ b/nova/tests/integrated/api_samples/os-services/services-list-get-resp.json.tpl
@@ -0,0 +1,36 @@
+{
+ "services": [
+ {
+ "binary": "nova-scheduler",
+ "host": "host1",
+ "state": "up",
+ "status": "disabled",
+ "updated_at": "%(timestamp)s",
+ "zone": "internal"
+ },
+ {
+ "binary": "nova-compute",
+ "host": "host1",
+ "state": "up",
+ "status": "disabled",
+ "updated_at": "%(timestamp)s",
+ "zone": "nova"
+ },
+ {
+ "binary": "nova-scheduler",
+ "host": "host2",
+ "state": "down",
+ "status": "enabled",
+ "updated_at": "%(timestamp)s",
+ "zone": "internal"
+ },
+ {
+ "binary": "nova-compute",
+ "host": "host2",
+ "state": "down",
+ "status": "disabled",
+ "updated_at": "%(timestamp)s",
+ "zone": "nova"
+ }
+ ]
+}
diff --git a/nova/tests/integrated/test_api_samples.py b/nova/tests/integrated/test_api_samples.py
index 3822ba109..8ed8bd628 100644
--- a/nova/tests/integrated/test_api_samples.py
+++ b/nova/tests/integrated/test_api_samples.py
@@ -46,6 +46,7 @@ from nova.servicegroup import api as service_group_api
from nova import test
from nova.tests.api.openstack.compute.contrib import test_fping
from nova.tests.api.openstack.compute.contrib import test_networks
+from nova.tests.api.openstack.compute.contrib import test_services
from nova.tests.baremetal.db import base as bm_db_base
from nova.tests import fake_network
from nova.tests.image import fake
@@ -381,7 +382,6 @@ class ApiSamplesTrap(ApiSampleTestBase):
do_not_approve_additions.append('os-create-server-ext')
do_not_approve_additions.append('os-flavor-access')
do_not_approve_additions.append('os-hypervisors')
- do_not_approve_additions.append('os-services')
do_not_approve_additions.append('os-volumes')
tests = self._get_extensions_tested()
@@ -1908,6 +1908,61 @@ class MultipleCreateXmlTest(MultipleCreateJsonTest):
ctype = 'xml'
+class ServicesJsonTest(ApiSampleTestBase):
+ extension_name = "nova.api.openstack.compute.contrib.services.Services"
+
+ def setUp(self):
+ super(ServicesJsonTest, self).setUp()
+ self.stubs.Set(db, "service_get_all",
+ test_services.fake_service_get_all)
+ self.stubs.Set(timeutils, "utcnow", test_services.fake_utcnow)
+ self.stubs.Set(db, "service_get_by_args",
+ test_services.fake_service_get_by_host_binary)
+ self.stubs.Set(db, "service_update",
+ test_services.fake_service_update)
+
+ def tearDown(self):
+ super(ServicesJsonTest, self).tearDown()
+ timeutils.clear_time_override()
+
+ def test_services_list(self):
+ """Return a list of all agent builds."""
+ response = self._do_get('os-services')
+ self.assertEqual(response.status, 200)
+ subs = {'binary': 'nova-compute',
+ 'host': 'host1',
+ 'zone': 'nova',
+ 'status': 'disabled',
+ 'state': 'up'}
+ subs.update(self._get_regexes())
+ return self._verify_response('services-list-get-resp',
+ subs, response)
+
+ def test_service_enable(self):
+ """Enable an existing agent build."""
+ subs = {"host": "host1",
+ 'service': 'nova-compute'}
+ response = self._do_put('/os-services/enable',
+ 'service-enable-put-req', subs)
+ self.assertEqual(response.status, 200)
+ subs = {"host": "host1",
+ "service": "nova-compute"}
+ return self._verify_response('service-enable-put-resp',
+ subs, response)
+
+ def test_service_disable(self):
+ """Disable an existing agent build."""
+ subs = {"host": "host1",
+ 'service': 'nova-compute'}
+ response = self._do_put('/os-services/disable',
+ 'service-disable-put-req', subs)
+ self.assertEqual(response.status, 200)
+ subs = {"host": "host1",
+ "service": "nova-compute"}
+ return self._verify_response('service-disable-put-resp',
+ subs, response)
+
+
class SimpleTenantUsageSampleJsonTest(ServersSampleBase):
extension_name = ("nova.api.openstack.compute.contrib.simple_tenant_usage."
"Simple_tenant_usage")