from abc import ABCMeta, abstractmethod
+from quantum.common import exceptions
+
class QuantumPluginBaseV2(object):
"""
pass
- @abstractmethod
def get_subnets_count(self, context, filters=None):
"""
Return the number of subnets. The result depends on the identity of
match comparison for that value. Each result returned by this
function will have matched one of the values for each key in
filters.
+
+ NOTE: this method is optional, as it was not part of the originally
+ defined plugin API.
"""
- pass
+ raise exceptions.NotImplementedError()
@abstractmethod
def delete_subnet(self, context, id):
"""
pass
- @abstractmethod
def get_networks_count(self, context, filters=None):
"""
Return the number of networks. The result depends on the identity
match comparison for that value. Each result returned by this
function will have matched one of the values for each key in
filters.
+
+ NOTE: this method is optional, as it was not part of the originally
+ defined plugin API.
"""
- pass
+ raise exceptions.NotImplementedError()
@abstractmethod
def delete_network(self, context, id):
"""
pass
- @abstractmethod
def get_ports_count(self, context, filters=None):
"""
Return the number of ports. The result depends on the identity of
match comparison for that value. Each result returned by this
function will have matched one of the values for each key in
filters.
+
+ NOTE: this method is optional, as it was not part of the originally
+ defined plugin API.
"""
- pass
+ raise exceptions.NotImplementedError()
@abstractmethod
def delete_port(self, context, id):
# using a DB's optimized counting features. We try to use that one
# if present. Otherwise just use regular getter to retrieve all objects
# and count in python, allowing older plugins to still be supported
- if hasattr(plugin, count_getter_name):
+ try:
obj_count_getter = getattr(plugin, count_getter_name)
return obj_count_getter(context, filters={'tenant_id': [tenant_id]})
- else:
+ except (exceptions.NotImplementedError, AttributeError):
obj_getter = getattr(plugin, "get_%s" % resources)
obj_list = obj_getter(context, filters={'tenant_id': [tenant_id]})
return len(obj_list) if obj_list else 0
self.assertTrue("Quota exceeded for resources" in
res.json['QuantumError'])
+ def test_create_network_quota_no_counts(self):
+ cfg.CONF.set_override('quota_network', 1, group='QUOTAS')
+ initial_input = {'network': {'name': 'net1', 'tenant_id': _uuid()}}
+ full_input = {'network': {'admin_state_up': True, 'subnets': []}}
+ full_input['network'].update(initial_input['network'])
+
+ instance = self.plugin.return_value
+ instance.get_networks_count.side_effect = (
+ q_exc.NotImplementedError())
+ instance.get_networks.return_value = ["foo"]
+ res = self.api.post_json(
+ _get_path('networks'), initial_input, expect_errors=True)
+ instance.get_networks_count.assert_called_with(mock.ANY,
+ filters=mock.ANY)
+ self.assertTrue("Quota exceeded for resources" in
+ res.json['QuantumError'])
+
def test_create_network_quota_without_limit(self):
cfg.CONF.set_override('quota_network', -1, group='QUOTAS')
initial_input = {'network': {'name': 'net1', 'tenant_id': _uuid()}}