# under the License.
from oslo_log import log as logging
+import oslo_messaging
from cinder.api import extensions
from cinder.api.openstack import wsgi
from cinder.api.views import capabilities as capabilities_view
+from cinder import exception
+from cinder.i18n import _
+from cinder import objects
from cinder.volume import rpcapi
"""Return capabilities list of given backend."""
context = req.environ['cinder.context']
authorize(context, 'capabilities')
- capabilities = self.volume_api.get_capabilities(context, id, False)
+ filters = {'host': id, 'binary': 'cinder-volume'}
+ service = objects.ServiceList.get_all(context, filters)
+ if not service:
+ msg = (_("Can't find service: %s") % id)
+ raise exception.NotFound(msg)
+ try:
+ capabilities = self.volume_api.get_capabilities(context, id, False)
+ except oslo_messaging.MessagingTimeout:
+ raise exception.RPCTimeout(service=id)
return self._view_builder.summary(req, capabilities, id)
import mock
+import oslo_messaging
+
from cinder.api.contrib import capabilities
from cinder import context
+from cinder import exception
from cinder import test
from cinder.tests.unit.api import fakes
return capabilities
-@mock.patch('cinder.volume.rpcapi.VolumeAPI.get_capabilities',
- rpcapi_get_capabilities)
class CapabilitiesAPITest(test.TestCase):
def setUp(self):
super(CapabilitiesAPITest, self).setUp()
self.controller = capabilities.CapabilitiesController()
self.ctxt = context.RequestContext('admin', 'fake', True)
- def test_capabilities_summary(self):
+ @mock.patch('cinder.db.service_get_all')
+ @mock.patch('cinder.volume.rpcapi.VolumeAPI.get_capabilities',
+ rpcapi_get_capabilities)
+ def test_capabilities_summary(self, mock_services):
+ mock_services.return_value = [{'name': 'fake'}]
req = fakes.HTTPRequest.blank('/fake/capabilities/fake')
req.environ['cinder.context'] = self.ctxt
res = self.controller.show(req, 'fake')
}
self.assertDictMatch(expected, res)
+
+ @mock.patch('cinder.db.service_get_all')
+ @mock.patch('cinder.volume.rpcapi.VolumeAPI.get_capabilities')
+ def test_get_capabilities_rpc_timeout(self, mock_rpc, mock_services):
+ mock_rpc.side_effect = oslo_messaging.MessagingTimeout
+ mock_services.return_value = [{'name': 'fake'}]
+
+ req = fakes.HTTPRequest.blank('/fake/capabilities/fake')
+ req.environ['cinder.context'] = self.ctxt
+ self.assertRaises(exception.RPCTimeout,
+ self.controller.show, req, 'fake')
+
+ @mock.patch('cinder.db.service_get_all')
+ def test_get_capabilities_service_not_found(self, mock_services):
+ mock_services.return_value = []
+
+ req = fakes.HTTPRequest.blank('/fake/capabilities/fake')
+ req.environ['cinder.context'] = self.ctxt
+ self.assertRaises(exception.NotFound,
+ self.controller.show, req, 'fake')