Merge "Make os-services API extensions consistent."
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
{
|
{
|
||||||
"host": "host1",
|
"host": "host1",
|
||||||
"service": "nova-compute"
|
"binary": "nova-compute"
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
{
|
{
|
||||||
"disabled": true,
|
"service": {
|
||||||
"host": "host1",
|
"host": "host1",
|
||||||
"service": "nova-compute"
|
"binary": "nova-compute",
|
||||||
|
"status": "disabled"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
{
|
{
|
||||||
"disabled": false,
|
"service": {
|
||||||
"host": "host1",
|
"host": "host1",
|
||||||
"service": "nova-compute"
|
"binary": "nova-compute",
|
||||||
|
"status": "enabled"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -51,8 +51,8 @@ class ServicesUpdateTemplate(xmlutil.TemplateBuilder):
|
|||||||
def construct(self):
|
def construct(self):
|
||||||
root = xmlutil.TemplateElement('host')
|
root = xmlutil.TemplateElement('host')
|
||||||
root.set('host')
|
root.set('host')
|
||||||
root.set('service')
|
root.set('binary')
|
||||||
root.set('disabled')
|
root.set('status')
|
||||||
|
|
||||||
return xmlutil.MasterTemplate(root, 1)
|
return xmlutil.MasterTemplate(root, 1)
|
||||||
|
|
||||||
@@ -76,13 +76,13 @@ class ServiceController(object):
|
|||||||
host = ''
|
host = ''
|
||||||
if 'host' in req.GET:
|
if 'host' in req.GET:
|
||||||
host = req.GET['host']
|
host = req.GET['host']
|
||||||
service = ''
|
binary = ''
|
||||||
if 'service' in req.GET:
|
if 'binary' in req.GET:
|
||||||
service = req.GET['service']
|
binary = req.GET['binary']
|
||||||
if host:
|
if host:
|
||||||
services = [s for s in services if s['host'] == host]
|
services = [s for s in services if s['host'] == host]
|
||||||
if service:
|
if binary:
|
||||||
services = [s for s in services if s['binary'] == service]
|
services = [s for s in services if s['binary'] == binary]
|
||||||
|
|
||||||
svcs = []
|
svcs = []
|
||||||
for svc in services:
|
for svc in services:
|
||||||
@@ -113,12 +113,12 @@ class ServiceController(object):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
host = body['host']
|
host = body['host']
|
||||||
service = body['service']
|
binary = body['binary']
|
||||||
except (TypeError, KeyError):
|
except (TypeError, KeyError):
|
||||||
raise webob.exc.HTTPUnprocessableEntity()
|
raise webob.exc.HTTPUnprocessableEntity()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
svc = db.service_get_by_args(context, host, service)
|
svc = db.service_get_by_args(context, host, binary)
|
||||||
if not svc:
|
if not svc:
|
||||||
raise webob.exc.HTTPNotFound('Unknown service')
|
raise webob.exc.HTTPNotFound('Unknown service')
|
||||||
|
|
||||||
@@ -126,7 +126,8 @@ class ServiceController(object):
|
|||||||
except exception.ServiceNotFound:
|
except exception.ServiceNotFound:
|
||||||
raise webob.exc.HTTPNotFound("service not found")
|
raise webob.exc.HTTPNotFound("service not found")
|
||||||
|
|
||||||
return {'host': host, 'service': service, 'disabled': disabled}
|
status = id + 'd'
|
||||||
|
return {'service': {'host': host, 'binary': binary, 'status': status}}
|
||||||
|
|
||||||
|
|
||||||
class Services(extensions.ExtensionDescriptor):
|
class Services(extensions.ExtensionDescriptor):
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ class FakeRequest(object):
|
|||||||
|
|
||||||
class FakeRequestWithService(object):
|
class FakeRequestWithService(object):
|
||||||
environ = {"nova.context": context.get_admin_context()}
|
environ = {"nova.context": context.get_admin_context()}
|
||||||
GET = {"service": "nova-compute"}
|
GET = {"binary": "nova-compute"}
|
||||||
|
|
||||||
|
|
||||||
class FakeRequestWithHost(object):
|
class FakeRequestWithHost(object):
|
||||||
@@ -74,7 +74,7 @@ class FakeRequestWithHost(object):
|
|||||||
|
|
||||||
class FakeRequestWithHostService(object):
|
class FakeRequestWithHostService(object):
|
||||||
environ = {"nova.context": context.get_admin_context()}
|
environ = {"nova.context": context.get_admin_context()}
|
||||||
GET = {"host": "host1", "service": "nova-compute"}
|
GET = {"host": "host1", "binary": "nova-compute"}
|
||||||
|
|
||||||
|
|
||||||
def fake_host_api_service_get_all(context, filters=None, set_zones=False):
|
def fake_host_api_service_get_all(context, filters=None, set_zones=False):
|
||||||
@@ -190,15 +190,15 @@ class ServicesTest(test.TestCase):
|
|||||||
self.assertEqual(res_dict, response)
|
self.assertEqual(res_dict, response)
|
||||||
|
|
||||||
def test_services_enable(self):
|
def test_services_enable(self):
|
||||||
body = {'host': 'host1', 'service': 'nova-compute'}
|
body = {'host': 'host1', 'binary': 'nova-compute'}
|
||||||
req = fakes.HTTPRequest.blank('/v2/fake/os-services/enable')
|
req = fakes.HTTPRequest.blank('/v2/fake/os-services/enable')
|
||||||
res_dict = self.controller.update(req, "enable", body)
|
res_dict = self.controller.update(req, "enable", body)
|
||||||
|
|
||||||
self.assertEqual(res_dict['disabled'], False)
|
self.assertEqual(res_dict['service']['status'], 'enabled')
|
||||||
|
|
||||||
def test_services_disable(self):
|
def test_services_disable(self):
|
||||||
req = fakes.HTTPRequest.blank('/v2/fake/os-services/disable')
|
req = fakes.HTTPRequest.blank('/v2/fake/os-services/disable')
|
||||||
body = {'host': 'host1', 'service': 'nova-compute'}
|
body = {'host': 'host1', 'binary': 'nova-compute'}
|
||||||
res_dict = self.controller.update(req, "disable", body)
|
res_dict = self.controller.update(req, "disable", body)
|
||||||
|
|
||||||
self.assertEqual(res_dict['disabled'], True)
|
self.assertEqual(res_dict['service']['status'], 'disabled')
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
{
|
{
|
||||||
"host": "%(host)s",
|
"host": "%(host)s",
|
||||||
"service": "%(service)s"
|
"binary": "%(binary)s"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
{
|
{
|
||||||
"disabled": true,
|
"service": {
|
||||||
"host": "%(host)s",
|
"host": "%(host)s",
|
||||||
"service": "%(service)s"
|
"binary": "%(binary)s",
|
||||||
|
"status": "disabled"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
{
|
{
|
||||||
"host": "%(host)s",
|
"host": "%(host)s",
|
||||||
"service": "%(service)s"
|
"binary": "%(binary)s"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
{
|
{
|
||||||
"disabled": false,
|
"service": {
|
||||||
"host": "%(host)s",
|
"host": "%(host)s",
|
||||||
"service": "%(service)s"
|
"binary": "%(binary)s",
|
||||||
|
"status": "enabled"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1990,24 +1990,24 @@ class ServicesJsonTest(ApiSampleTestBase):
|
|||||||
def test_service_enable(self):
|
def test_service_enable(self):
|
||||||
"""Enable an existing agent build."""
|
"""Enable an existing agent build."""
|
||||||
subs = {"host": "host1",
|
subs = {"host": "host1",
|
||||||
'service': 'nova-compute'}
|
'binary': 'nova-compute'}
|
||||||
response = self._do_put('/os-services/enable',
|
response = self._do_put('os-services/enable',
|
||||||
'service-enable-put-req', subs)
|
'service-enable-put-req', subs)
|
||||||
self.assertEqual(response.status, 200)
|
self.assertEqual(response.status, 200)
|
||||||
subs = {"host": "host1",
|
subs = {"host": "host1",
|
||||||
"service": "nova-compute"}
|
"binary": "nova-compute"}
|
||||||
return self._verify_response('service-enable-put-resp',
|
return self._verify_response('service-enable-put-resp',
|
||||||
subs, response)
|
subs, response)
|
||||||
|
|
||||||
def test_service_disable(self):
|
def test_service_disable(self):
|
||||||
"""Disable an existing agent build."""
|
"""Disable an existing agent build."""
|
||||||
subs = {"host": "host1",
|
subs = {"host": "host1",
|
||||||
'service': 'nova-compute'}
|
'binary': 'nova-compute'}
|
||||||
response = self._do_put('/os-services/disable',
|
response = self._do_put('os-services/disable',
|
||||||
'service-disable-put-req', subs)
|
'service-disable-put-req', subs)
|
||||||
self.assertEqual(response.status, 200)
|
self.assertEqual(response.status, 200)
|
||||||
subs = {"host": "host1",
|
subs = {"host": "host1",
|
||||||
"service": "nova-compute"}
|
"binary": "nova-compute"}
|
||||||
return self._verify_response('service-disable-put-resp',
|
return self._verify_response('service-disable-put-resp',
|
||||||
subs, response)
|
subs, response)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user