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 000000000000..d11afaed9c06 --- /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 000000000000..2e461bc6d73b --- /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 000000000000..d11afaed9c06 --- /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 000000000000..88b9dc7f92eb --- /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 000000000000..dcda1a46e4a9 --- /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 000000000000..4d48af1b8e48 --- /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 000000000000..8219a43f6400 --- /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 000000000000..4d48af1b8e48 --- /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 000000000000..079b9c76e979 --- /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 000000000000..cc61013385de --- /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 3822ba1096a5..8ed8bd628ca9 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")