Browse Source

Remove method which has no rpc calls

API like bay-list/container-list/magnum-service-list etc..
there is no rpc call and only access the database in these methods
move them to api controller.

Change-Id: Icdee1c5d3d835efd57238fb4cb8e897485da9b6d
Closes-Bug:#1552131
changes/71/289771/1
Aaron-DH 6 years ago
parent
commit
bc5a61d212
  1. 7
      magnum/api/controllers/v1/bay.py
  2. 17
      magnum/api/controllers/v1/container.py
  3. 10
      magnum/api/controllers/v1/magnum_services.py
  4. 2
      magnum/api/controllers/v1/x509keypair.py
  5. 25
      magnum/conductor/api.py
  6. 4
      magnum/tests/unit/api/controllers/v1/test_container.py
  7. 6
      magnum/tests/unit/api/controllers/v1/test_magnum_service.py

7
magnum/api/controllers/v1/bay.py

@ -211,10 +211,9 @@ class BaysController(rest.RestController):
marker_obj = objects.Bay.get_by_uuid(pecan.request.context,
marker)
bays = pecan.request.rpcapi.bay_list(
pecan.request.context, limit,
marker_obj, sort_key=sort_key,
sort_dir=sort_dir)
bays = objects.Bay.list(pecan.request.context, limit,
marker_obj, sort_key=sort_key,
sort_dir=sort_dir)
return BayCollection.convert_with_links(bays, limit,
url=resource_url,

17
magnum/api/controllers/v1/container.py

@ -286,16 +286,21 @@ class ContainersController(rest.RestController):
limit = api_utils.validate_limit(limit)
sort_dir = api_utils.validate_sort_dir(sort_dir)
filters = None
marker_obj = None
if marker:
marker_obj = objects.Container.get_by_uuid(context,
marker)
containers = pecan.request.rpcapi.container_list(context, limit,
marker_obj,
sort_key=sort_key,
sort_dir=sort_dir,
bay_ident=bay_ident)
if bay_ident:
bay_obj = api_utils.get_resource('Bay', bay_ident)
filters = {'bay_uuid': bay_obj.uuid}
containers = objects.Container.list(context,
limit,
marker_obj,
sort_key,
sort_dir,
filters=filters)
for i, c in enumerate(containers):
try:

10
magnum/api/controllers/v1/magnum_services.py

@ -92,9 +92,11 @@ class MagnumServiceController(rest.RestController):
"""Retrieve a list of magnum-services.
"""
msvcs = pecan.request.rpcapi.magnum_services_list(
pecan.request.context, limit=None,
marker=None, sort_key='id',
sort_dir='asc')
msvcs = objects.MagnumService.list(pecan.request.context,
limit=None,
marker=None,
sort_key='id',
sort_dir='asc')
return MagnumServiceCollection.convert_db_rec_list_to_collection(
self.servicegroup_api, msvcs)

2
magnum/api/controllers/v1/x509keypair.py

@ -174,7 +174,7 @@ class X509KeyPairController(rest.RestController):
marker_obj = objects.X509KeyPair.get_by_uuid(pecan.request.context,
marker)
x509keypairs = pecan.request.rpcapi.x509keypair_list(
x509keypairs = objects.X509KeyPair.list(
pecan.request.context, limit,
marker_obj, sort_key=sort_key,
sort_dir=sort_dir)

25
magnum/conductor/api.py

@ -14,8 +14,6 @@
from oslo_config import cfg
from magnum.common import rpc_service
from magnum.conductor import utils as conductor_utils
from magnum import objects
# The Backend API class serves as a AMQP client for communicating
@ -36,15 +34,9 @@ class API(rpc_service.API):
return self._call('bay_create', bay=bay,
bay_create_timeout=bay_create_timeout)
def bay_list(self, context, limit, marker, sort_key, sort_dir):
return objects.Bay.list(context, limit, marker, sort_key, sort_dir)
def bay_delete(self, uuid):
return self._call('bay_delete', uuid=uuid)
def bay_show(self, context, uuid):
return objects.Bay.get_by_uuid(context, uuid)
def bay_update(self, bay):
return self._call('bay_update', bay=bay)
@ -113,15 +105,6 @@ class API(rpc_service.API):
def container_create(self, container):
return self._call('container_create', container=container)
def container_list(self, context, limit, marker, sort_key, sort_dir,
bay_ident):
filters = None
if bay_ident is not None:
bay_uuid = conductor_utils.retrieve_bay_uuid(context, bay_ident)
filters = {'bay_uuid': bay_uuid}
return objects.Container.list(context, limit, marker, sort_key,
sort_dir, filters=filters)
def container_delete(self, container_uuid):
return self._call('container_delete', container_uuid=container_uuid)
@ -158,9 +141,6 @@ class API(rpc_service.API):
def x509keypair_delete(self, uuid):
return self._call('x509keypair_delete', uuid=uuid)
def x509keypair_list(self, context, limit, marker, sort_key, sort_dir):
return objects.X509KeyPair.list(context, limit, marker,
sort_key, sort_dir)
# CA operations
def sign_certificate(self, bay, certificate):
@ -169,11 +149,6 @@ class API(rpc_service.API):
def get_ca_certificate(self, bay):
return self._call('get_ca_certificate', bay=bay)
# magnum-services
def magnum_services_list(self, context, limit, marker, sort_key, sort_dir):
return objects.MagnumService.list(context, limit, marker, sort_key,
sort_dir)
# Versioned Objects indirection API
def object_class_action(self, context, objname, objmethod, objver,

4
magnum/tests/unit/api/controllers/v1/test_container.py

@ -330,7 +330,7 @@ class TestContainerController(api_base.FunctionalTest):
actual_containers[0].get('status'))
@patch('magnum.conductor.api.API.container_show')
@patch('magnum.conductor.utils.retrieve_bay_uuid')
@patch('magnum.api.utils.get_resource')
@patch('magnum.objects.Container.list')
def test_get_all_containers_with_bay_ident(self, mock_container_list,
mock_retrive_bay_uuid,
@ -338,7 +338,7 @@ class TestContainerController(api_base.FunctionalTest):
test_container = utils.get_test_container()
containers = [objects.Container(self.context, **test_container)]
mock_container_list.return_value = containers
mock_retrive_bay_uuid.return_value = '12'
mock_retrive_bay_uuid.return_value.uuid = '12'
mock_container_show.return_value = containers[0]
response = self.app.get('/v1/containers/?bay_ident=12')

6
magnum/tests/unit/api/controllers/v1/test_magnum_service.py

@ -14,7 +14,7 @@ import mock
from magnum.api.controllers.v1 import magnum_services as mservice
from magnum.api import servicegroup as servicegroup
from magnum.conductor import api as rpcapi
from magnum import objects
from magnum.tests import base
from magnum.tests.unit.api import base as api_base
from magnum.tests.unit.api import utils as apiutils
@ -60,7 +60,7 @@ class TestMagnumServiceController(api_base.FunctionalTest):
reclist.append(rec)
return reclist
@mock.patch.object(rpcapi.API, 'magnum_services_list')
@mock.patch.object(objects.MagnumService, 'list')
@mock.patch.object(servicegroup.ServiceGroup, 'service_is_up')
def test_get_one(self, svc_up, rpc_patcher):
rpc_patcher.return_value = self._rpc_api_reply()
@ -70,7 +70,7 @@ class TestMagnumServiceController(api_base.FunctionalTest):
self.assertEqual(1, len(response['mservices']))
self.assertEqual(1, response['mservices'][0]['id'])
@mock.patch.object(rpcapi.API, 'magnum_services_list')
@mock.patch.object(objects.MagnumService, 'list')
@mock.patch.object(servicegroup.ServiceGroup, 'service_is_up')
def test_get_many(self, svc_up, rpc_patcher):
svc_num = 5

Loading…
Cancel
Save