Add API sample tests to Services extension

Partially implements blueprint nova-api-samples
Bug 1091755

Change-Id: I7a0e124871c248bbb7613bfcdf335fee29a887f2
This commit is contained in:
ivan-zhu 2013-01-09 22:52:46 +08:00
parent d980805880
commit 4348529188
11 changed files with 164 additions and 1 deletions

View File

@ -0,0 +1,4 @@
{
"host": "host1",
"service": "nova-compute"
}

View File

@ -0,0 +1,5 @@
{
"disabled": true,
"host": "host1",
"service": "nova-compute"
}

View File

@ -0,0 +1,4 @@
{
"host": "host1",
"service": "nova-compute"
}

View File

@ -0,0 +1,5 @@
{
"disabled": false,
"host": "host1",
"service": "nova-compute"
}

View File

@ -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"
}
]
}

View File

@ -0,0 +1,4 @@
{
"host": "%(host)s",
"service": "%(service)s"
}

View File

@ -0,0 +1,5 @@
{
"disabled": true,
"host": "%(host)s",
"service": "%(service)s"
}

View File

@ -0,0 +1,4 @@
{
"host": "%(host)s",
"service": "%(service)s"
}

View File

@ -0,0 +1,5 @@
{
"disabled": false,
"host": "%(host)s",
"service": "%(service)s"
}

View File

@ -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"
}
]
}

View File

@ -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")