Merge "Remove 'verbose' API capability"

This commit is contained in:
Jenkins 2012-08-25 04:13:02 +00:00 committed by Gerrit Code Review
commit e1bb5603c1
16 changed files with 101 additions and 276 deletions

View File

@ -21,7 +21,6 @@ import webob.exc
from quantum.api.v2 import attributes
from quantum.api.v2 import resource as wsgi_resource
from quantum.common import exceptions
from quantum.common import utils
from quantum.openstack.common import cfg
from quantum.openstack.common.notifier import api as notifier_api
from quantum import policy
@ -70,7 +69,7 @@ def _filters(request, attr_info):
Returns a dict of lists for the filters:
check=a&check=b&name=Bob&verbose=True&verbose=other
check=a&check=b&name=Bob&
becomes
@ -78,7 +77,7 @@ def _filters(request, attr_info):
"""
res = {}
for key in set(request.GET):
if key in ('verbose', 'fields'):
if key == 'fields':
continue
values = [v for v in request.GET.getall(key) if v]
if not attr_info.get(key) and values:
@ -100,38 +99,6 @@ def _filters(request, attr_info):
return res
def _verbose(request):
"""
Determines the verbose fields for a request
Returns a list of items that are requested to be verbose:
check=a&check=b&name=Bob&verbose=True&verbose=other
returns
[True]
and
check=a&check=b&name=Bob&verbose=other
returns
['other']
"""
verbose = [utils.boolize(v) for v in request.GET.getall('verbose') if v]
# NOTE(jkoelker) verbose=<bool> trumps all other verbose settings
if True in verbose:
return True
elif False in verbose:
return False
return verbose
class Controller(object):
def __init__(self, plugin, collection, resource, attr_info,
@ -191,7 +158,6 @@ class Controller(object):
# plugin before returning.
original_fields, fields_to_add = self._do_field_list(_fields(request))
kwargs = {'filters': _filters(request, self._attr_info),
'verbose': _verbose(request),
'fields': original_fields}
obj_getter = getattr(self._plugin, "get_%s" % self._collection)
obj_list = obj_getter(request.context, **kwargs)
@ -205,15 +171,13 @@ class Controller(object):
"get_%s" % self._resource,
obj,
plugin=self._plugin)]
return {self._collection: [self._view(obj,
fields_to_strip=fields_to_add)
for obj in obj_list]}
def _item(self, request, id, do_authz=False, field_list=None):
"""Retrieves and formats a single element of the requested entity"""
kwargs = {'verbose': _verbose(request),
'fields': field_list}
kwargs = {'fields': field_list}
action = "get_%s" % self._resource
obj_getter = getattr(self._plugin, action)
obj = obj_getter(request.context, id, **kwargs)

View File

@ -82,21 +82,13 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
query = query.filter(model.tenant_id == context.tenant_id)
return query
def _get_by_id(self, context, model, id, joins=(), verbose=None):
def _get_by_id(self, context, model, id):
query = self._model_query(context, model)
if verbose:
if verbose and isinstance(verbose, list):
options = [orm.joinedload(join) for join in joins
if join in verbose]
else:
options = [orm.joinedload(join) for join in joins]
query = query.options(*options)
return query.filter_by(id=id).one()
def _get_network(self, context, id, verbose=None):
def _get_network(self, context, id):
try:
network = self._get_by_id(context, models_v2.Network, id,
joins=('subnets',), verbose=verbose)
network = self._get_by_id(context, models_v2.Network, id)
except exc.NoResultFound:
raise q_exc.NetworkNotFound(net_id=id)
except exc.MultipleResultsFound:
@ -104,10 +96,9 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
raise q_exc.NetworkNotFound(net_id=id)
return network
def _get_subnet(self, context, id, verbose=None):
def _get_subnet(self, context, id):
try:
subnet = self._get_by_id(context, models_v2.Subnet, id,
verbose=verbose)
subnet = self._get_by_id(context, models_v2.Subnet, id)
except exc.NoResultFound:
raise q_exc.SubnetNotFound(subnet_id=id)
except exc.MultipleResultsFound:
@ -115,10 +106,9 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
raise q_exc.SubnetNotFound(subnet_id=id)
return subnet
def _get_port(self, context, id, verbose=None):
def _get_port(self, context, id):
try:
port = self._get_by_id(context, models_v2.Port, id,
verbose=verbose)
port = self._get_by_id(context, models_v2.Port, id)
except exc.NoResultFound:
# NOTE(jkoelker) The PortNotFound exceptions requires net_id
# kwarg in order to set the message correctly
@ -156,7 +146,7 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
return resource
def _get_collection(self, context, model, dict_func, filters=None,
fields=None, verbose=None):
fields=None):
collection = self._model_query(context, model)
if filters:
for key, value in filters.iteritems():
@ -796,15 +786,14 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
subnets_qry.filter_by(network_id=id).delete()
context.session.delete(network)
def get_network(self, context, id, fields=None, verbose=None):
network = self._get_network(context, id, verbose=verbose)
def get_network(self, context, id, fields=None):
network = self._get_network(context, id)
return self._make_network_dict(network, fields)
def get_networks(self, context, filters=None, fields=None, verbose=None):
def get_networks(self, context, filters=None, fields=None):
return self._get_collection(context, models_v2.Network,
self._make_network_dict,
filters=filters, fields=fields,
verbose=verbose)
filters=filters, fields=fields)
def create_subnet_bulk(self, context, subnets):
return self._create_bulk('subnet', context, subnets)
@ -955,15 +944,14 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
context.session.delete(subnet)
def get_subnet(self, context, id, fields=None, verbose=None):
subnet = self._get_subnet(context, id, verbose=verbose)
def get_subnet(self, context, id, fields=None):
subnet = self._get_subnet(context, id)
return self._make_subnet_dict(subnet, fields)
def get_subnets(self, context, filters=None, fields=None, verbose=None):
def get_subnets(self, context, filters=None, fields=None):
return self._get_collection(context, models_v2.Subnet,
self._make_subnet_dict,
filters=filters, fields=fields,
verbose=verbose)
filters=filters, fields=fields)
def create_port_bulk(self, context, ports):
return self._create_bulk('port', context, ports)
@ -1077,16 +1065,15 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
port_id=id)
context.session.delete(port)
def get_port(self, context, id, fields=None, verbose=None):
port = self._get_port(context, id, verbose=verbose)
def get_port(self, context, id, fields=None):
port = self._get_port(context, id)
return self._make_port_dict(port, fields)
def get_ports(self, context, filters=None, fields=None, verbose=None):
def get_ports(self, context, filters=None, fields=None):
fixed_ips = filters.pop('fixed_ips', []) if filters else []
ports = self._get_collection(context, models_v2.Port,
self._make_port_dict,
filters=filters, fields=fields,
verbose=verbose)
filters=filters, fields=fields)
if ports and fixed_ips:
filtered_ports = []

View File

@ -77,9 +77,9 @@ class FloatingIP(model_base.BASEV2, models_v2.HasId, models_v2.HasTenant):
class L3_NAT_db_mixin(l3.RouterPluginBase):
"""Mixin class to add L3/NAT router methods to db_plugin_base_v2"""
def _get_router(self, context, id, verbose=None):
def _get_router(self, context, id):
try:
router = self._get_by_id(context, Router, id, verbose=verbose)
router = self._get_by_id(context, Router, id)
except exc.NoResultFound:
raise l3.RouterNotFound(router_id=id)
except exc.MultipleResultsFound:
@ -191,15 +191,14 @@ class L3_NAT_db_mixin(l3.RouterPluginBase):
# thanks to cascading on the ORM relationship
context.session.delete(router)
def get_router(self, context, id, fields=None, verbose=None):
router = self._get_router(context, id, verbose=verbose)
def get_router(self, context, id, fields=None):
router = self._get_router(context, id)
return self._make_router_dict(router, fields)
def get_routers(self, context, filters=None, fields=None, verbose=None):
def get_routers(self, context, filters=None, fields=None):
return self._get_collection(context, Router,
self._make_router_dict,
filters=filters, fields=fields,
verbose=verbose)
filters=filters, fields=fields)
def _check_for_dup_router_subnet(self, context, router_id,
network_id, subnet_id):
@ -315,10 +314,9 @@ class L3_NAT_db_mixin(l3.RouterPluginBase):
"interface on subnet %(subnet_id)s"
% locals())
def _get_floatingip(self, context, id, verbose=None):
def _get_floatingip(self, context, id):
try:
floatingip = self._get_by_id(context, FloatingIP, id,
verbose=verbose)
floatingip = self._get_by_id(context, FloatingIP, id)
except exc.NoResultFound:
raise l3.FloatingIPNotFound(floatingip_id=id)
except exc.MultipleResultsFound:
@ -508,16 +506,14 @@ class L3_NAT_db_mixin(l3.RouterPluginBase):
context.session.delete(floatingip)
self.delete_port(context, floatingip['floating_port_id'])
def get_floatingip(self, context, id, fields=None, verbose=None):
floatingip = self._get_floatingip(context, id, verbose=verbose)
def get_floatingip(self, context, id, fields=None):
floatingip = self._get_floatingip(context, id)
return self._make_floatingip_dict(floatingip, fields)
def get_floatingips(self, context, filters=None, fields=None,
verbose=None):
def get_floatingips(self, context, filters=None, fields=None):
return self._get_collection(context, FloatingIP,
self._make_floatingip_dict,
filters=filters, fields=fields,
verbose=verbose)
filters=filters, fields=fields)
def disassociate_floatingips(self, context, port_id):
with context.session.begin(subtransactions=True):

View File

@ -169,7 +169,7 @@ class RouterPluginBase(object):
pass
@abstractmethod
def get_router(self, context, id, fields=None, verbose=None):
def get_router(self, context, id, fields=None):
pass
@abstractmethod
@ -177,7 +177,7 @@ class RouterPluginBase(object):
pass
@abstractmethod
def get_routers(self, context, filters=None, fields=None, verbose=None):
def get_routers(self, context, filters=None, fields=None):
pass
@abstractmethod
@ -197,7 +197,7 @@ class RouterPluginBase(object):
pass
@abstractmethod
def get_floatingip(self, context, id, fields=None, verbose=None):
def get_floatingip(self, context, id, fields=None):
pass
@abstractmethod
@ -205,6 +205,5 @@ class RouterPluginBase(object):
pass
@abstractmethod
def get_floatingips(self, context, filters=None, fields=None,
verbose=None):
def get_floatingips(self, context, filters=None, fields=None):
pass

View File

@ -148,11 +148,11 @@ class NetworkMultiBladeV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
# TODO (Sumit): Check if we need to perform any rollback here
raise
def get_network(self, context, id, fields=None, verbose=None):
def get_network(self, context, id, fields=None):
"""Currently there is no processing required for the device plugins"""
pass
def get_networks(self, context, filters=None, fields=None, verbose=None):
def get_networks(self, context, filters=None, fields=None):
"""Currently there is no processing required for the device plugins"""
pass
@ -210,11 +210,11 @@ class NetworkMultiBladeV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
# TODO (Sumit): Check if we need to perform any rollback here
raise
def get_port(self, context, id, fields=None, verbose=None):
def get_port(self, context, id, fields=None):
"""Currently there is no processing required for the device plugins"""
pass
def get_ports(self, context, filters=None, fields=None, verbose=None):
def get_ports(self, context, filters=None, fields=None):
"""Currently there is no processing required for the device plugins"""
pass
@ -244,7 +244,7 @@ class NetworkMultiBladeV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
"""Currently there is no processing required for the device plugins"""
pass
def get_subnet(self, context, id, fields=None, verbose=None):
def get_subnet(self, context, id, fields=None):
"""Currently there is no processing required for the device plugins"""
pass
@ -252,7 +252,7 @@ class NetworkMultiBladeV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
"""Currently there is no processing required for the device plugins"""
pass
def get_subnets(self, context, filters=None, fields=None, verbose=None):
def get_subnets(self, context, filters=None, fields=None):
"""Currently there is no processing required for the device plugins"""
pass

View File

@ -251,11 +251,11 @@ class VirtualPhysicalSwitchModelV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
except:
raise
def get_network(self, context, id, fields=None, verbose=None):
def get_network(self, context, id, fields=None):
"""For this model this method will be delegated to vswitch plugin"""
pass
def get_networks(self, context, filters=None, fields=None, verbose=None):
def get_networks(self, context, filters=None, fields=None):
"""For this model this method will be delegated to vswitch plugin"""
pass
@ -263,11 +263,11 @@ class VirtualPhysicalSwitchModelV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
"""For this model this method will be delegated to vswitch plugin"""
pass
def get_port(self, context, id, fields=None, verbose=None):
def get_port(self, context, id, fields=None):
"""For this model this method will be delegated to vswitch plugin"""
pass
def get_ports(self, context, filters=None, fields=None, verbose=None):
def get_ports(self, context, filters=None, fields=None):
"""For this model this method will be delegated to vswitch plugin"""
pass
@ -287,7 +287,7 @@ class VirtualPhysicalSwitchModelV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
"""For this model this method will be delegated to vswitch plugin"""
pass
def get_subnet(self, context, id, fields=None, verbose=None):
def get_subnet(self, context, id, fields=None):
"""For this model this method will be delegated to vswitch plugin"""
pass
@ -295,6 +295,6 @@ class VirtualPhysicalSwitchModelV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
"""For this model this method will be delegated to vswitch plugin"""
pass
def get_subnets(self, context, filters=None, fields=None, verbose=None):
def get_subnets(self, context, filters=None, fields=None):
"""For this model this method will be delegated to vswitch plugin"""
pass

View File

@ -150,21 +150,19 @@ class PluginV2(db_base_plugin_v2.QuantumDbPluginV2):
except:
raise
def get_network(self, context, id, fields=None, verbose=None):
def get_network(self, context, id, fields=None):
"""
Gets a particular network
"""
LOG.debug("get_network() called\n")
return super(PluginV2, self).get_network(context, id,
fields, verbose)
return super(PluginV2, self).get_network(context, id, fields)
def get_networks(self, context, filters=None, fields=None, verbose=None):
def get_networks(self, context, filters=None, fields=None):
"""
Gets all networks
"""
LOG.debug("get_networks() called\n")
return super(PluginV2, self).get_networks(context, filters,
fields, verbose)
return super(PluginV2, self).get_networks(context, filters, fields)
def create_port(self, context, port):
"""

View File

@ -330,15 +330,14 @@ class LinuxBridgePluginV2(db_base_plugin_v2.QuantumDbPluginV2,
if self.agent_rpc:
self.notifier.network_delete(self.rpc_context, id)
def get_network(self, context, id, fields=None, verbose=None):
net = super(LinuxBridgePluginV2, self).get_network(context, id,
None, verbose)
def get_network(self, context, id, fields=None):
net = super(LinuxBridgePluginV2, self).get_network(context, id, None)
self._extend_network_dict(context, net)
return self._fields(net, fields)
def get_networks(self, context, filters=None, fields=None, verbose=None):
def get_networks(self, context, filters=None, fields=None):
nets = super(LinuxBridgePluginV2, self).get_networks(context, filters,
None, verbose)
None)
for net in nets:
self._extend_network_dict(context, net)
# TODO(rkukura): Filter on extended attributes.

View File

@ -144,16 +144,16 @@ class MetaPluginV2(db_base_plugin_v2.QuantumDbPluginV2):
plugin = self._get_plugin(flavor)
return plugin.delete_network(context, id)
def get_network(self, context, id, fields=None, verbose=None):
def get_network(self, context, id, fields=None):
flavor = meta_db_v2.get_flavor_by_network(id)
plugin = self._get_plugin(flavor)
net = plugin.get_network(context, id, fields, verbose)
net = plugin.get_network(context, id, fields)
if not fields or 'flavor:id' in fields:
self._extend_network_dict(context, net)
return net
def get_networks_with_flavor(self, context, filters=None,
fields=None, verbose=None):
fields=None):
collection = self._model_query(context, models_v2.Network)
collection = collection.join(Flavor,
models_v2.Network.id == Flavor.network_id)
@ -167,11 +167,9 @@ class MetaPluginV2(db_base_plugin_v2.QuantumDbPluginV2):
collection = collection.filter(column.in_(value))
return [self._make_network_dict(c, fields) for c in collection.all()]
def get_networks(self, context, filters=None, fields=None, verbose=None):
nets = self.get_networks_with_flavor(context, filters,
None, verbose)
return [self.get_network(context, net['id'],
fields, verbose)
def get_networks(self, context, filters=None, fields=None):
nets = self.get_networks_with_flavor(context, filters, None)
return [self.get_network(context, net['id'], fields)
for net in nets]
def _get_flavor_by_network_id(self, network_id):

View File

@ -52,10 +52,9 @@ class NECPluginV2Base(db_base_plugin_v2.QuantumDbPluginV2):
'status': packet_filter['status']}
return self._fields(res, fields)
def _get_packet_filter(self, context, id, verbose=None):
def _get_packet_filter(self, context, id):
try:
packet_filter = self._get_by_id(context, nmodels.PacketFilter, id,
verbose=verbose)
packet_filter = self._get_by_id(context, nmodels.PacketFilter, id)
except exc.NoResultFound:
raise q_exc.PacketFilterNotFound(id=id)
except exc.MultipleResultsFound:
@ -63,18 +62,16 @@ class NECPluginV2Base(db_base_plugin_v2.QuantumDbPluginV2):
raise q_exc.PacketFilterNotFound(id=id)
return packet_filter
def get_packet_filter(self, context, id, fields=None, verbose=None):
packet_filter = self._get_packet_filter(context, id, verbose=verbose)
def get_packet_filter(self, context, id, fields=None):
packet_filter = self._get_packet_filter(context, id)
return self._make_packet_filter_dict(packet_filter, fields)
def get_packet_filters(self, context, filters=None, fields=None,
verbose=None):
def get_packet_filters(self, context, filters=None, fields=None):
return self._get_collection(context,
nmodels.PacketFilter,
self._make_packet_filter_dict,
filters=filters,
fields=fields,
verbose=verbose)
fields=fields)
def create_packet_filter(self, context, packet_filter):
pf = packet_filter['packet_filter']

View File

@ -358,7 +358,7 @@ class NvpPluginV2(db_base_plugin_v2.QuantumDbPluginV2):
LOG.debug("Returning pairs for network: %s" % (pairs))
return pairs
def get_network(self, context, id, fields=None, verbose=None):
def get_network(self, context, id, fields=None):
"""
Retrieves all attributes of the network, NOT including
the ports of that network.
@ -387,7 +387,7 @@ class NvpPluginV2(db_base_plugin_v2.QuantumDbPluginV2):
# the context, as with shared networks context.tenant_id and
# network['tenant_id'] might differ on GETs
# goto to the plugin DB and fecth the network
network = self._get_network(context, id, verbose)
network = self._get_network(context, id)
# TODO(salvatore-orlando): verify whether the query on os_tid is
# redundant or not.
if context.is_admin is False:
@ -429,7 +429,7 @@ class NvpPluginV2(db_base_plugin_v2.QuantumDbPluginV2):
context.tenant_id, d))
return d
def get_networks(self, context, filters=None, fields=None, verbose=None):
def get_networks(self, context, filters=None, fields=None):
"""
Retrieves all attributes of the network, NOT including
the ports of that network.
@ -567,7 +567,7 @@ class NvpPluginV2(db_base_plugin_v2.QuantumDbPluginV2):
context.tenant_id)
return super(NvpPluginV2, self).update_network(context, id, network)
def get_ports(self, context, filters=None, fields=None, verbose=None):
def get_ports(self, context, filters=None, fields=None):
"""
Returns all ports from given tenant
@ -806,7 +806,7 @@ class NvpPluginV2(db_base_plugin_v2.QuantumDbPluginV2):
LOG.debug("delete_port() completed for tenant: %s" % context.tenant_id)
return super(NvpPluginV2, self).delete_port(context, id)
def get_port(self, context, id, fields=None, verbose=None):
def get_port(self, context, id, fields=None):
"""
This method allows the user to retrieve a remote interface
that is attached to this particular port.
@ -823,8 +823,7 @@ class NvpPluginV2(db_base_plugin_v2.QuantumDbPluginV2):
:raises: exception.NetworkNotFound
"""
quantum_db = super(NvpPluginV2, self).get_port(context, id, fields,
verbose)
quantum_db = super(NvpPluginV2, self).get_port(context, id, fields)
port, cluster = (
nvplib.get_port_by_quantum_tag(self.clusters,

View File

@ -338,15 +338,14 @@ class OVSQuantumPluginV2(db_base_plugin_v2.QuantumDbPluginV2,
self.notifier.network_delete(self.context, id)
return result
def get_network(self, context, id, fields=None, verbose=None):
net = super(OVSQuantumPluginV2, self).get_network(context, id,
None, verbose)
def get_network(self, context, id, fields=None):
net = super(OVSQuantumPluginV2, self).get_network(context, id, None)
self._extend_network_dict(context, net)
return self._fields(net, fields)
def get_networks(self, context, filters=None, fields=None, verbose=None):
def get_networks(self, context, filters=None, fields=None):
nets = super(OVSQuantumPluginV2, self).get_networks(context, filters,
None, verbose)
None)
for net in nets:
self._extend_network_dict(context, net)
# TODO(rkukura): Filter on extended attributes.

View File

@ -66,7 +66,7 @@ class QuantumPluginBaseV2(object):
pass
@abstractmethod
def get_subnet(self, context, id, fields=None, verbose=None):
def get_subnet(self, context, id, fields=None):
pass
@abstractmethod
@ -74,7 +74,7 @@ class QuantumPluginBaseV2(object):
pass
@abstractmethod
def get_subnets(self, context, filters=None, fields=None, verbose=None):
def get_subnets(self, context, filters=None, fields=None):
pass
@abstractmethod
@ -105,11 +105,11 @@ class QuantumPluginBaseV2(object):
pass
@abstractmethod
def get_network(self, context, id, fields=None, verbose=None):
def get_network(self, context, id, fields=None):
pass
@abstractmethod
def get_networks(self, context, filters=None, fields=None, verbose=None):
def get_networks(self, context, filters=None, fields=None):
pass
@abstractmethod
@ -188,9 +188,9 @@ class QuantumPluginBaseV2(object):
pass
@abstractmethod
def get_port(self, context, id, fields=None, verbose=None):
def get_port(self, context, id, fields=None):
pass
@abstractmethod
def get_ports(self, context, filters=None, fields=None, verbose=None):
def get_ports(self, context, filters=None, fields=None):
pass

View File

@ -165,77 +165,6 @@ class APIv2TestCase(APIv2TestBase):
# raises without being caught. Using unittest2
# or dropping 2.6 support so we can use addCleanup
# will get around this.
def test_verbose_attr(self):
instance = self.plugin.return_value
instance.get_networks.return_value = []
self.api.get(_get_path('networks'), {'verbose': 'foo'})
instance.get_networks.assert_called_once_with(mock.ANY,
filters=mock.ANY,
fields=mock.ANY,
verbose=['foo'])
def test_multiple_verbose_attr(self):
instance = self.plugin.return_value
instance.get_networks.return_value = []
self.api.get(_get_path('networks'), {'verbose': ['foo', 'bar']})
instance.get_networks.assert_called_once_with(mock.ANY,
filters=mock.ANY,
fields=mock.ANY,
verbose=['foo',
'bar'])
def test_verbose_false_str(self):
instance = self.plugin.return_value
instance.get_networks.return_value = []
self.api.get(_get_path('networks'), {'verbose': 'false'})
instance.get_networks.assert_called_once_with(mock.ANY,
filters=mock.ANY,
fields=mock.ANY,
verbose=False)
def test_verbose_true_str(self):
instance = self.plugin.return_value
instance.get_networks.return_value = []
self.api.get(_get_path('networks'), {'verbose': 'true'})
instance.get_networks.assert_called_once_with(mock.ANY,
filters=mock.ANY,
fields=mock.ANY,
verbose=True)
def test_verbose_true_trump_attr(self):
instance = self.plugin.return_value
instance.get_networks.return_value = []
self.api.get(_get_path('networks'), {'verbose': ['true', 'foo']})
instance.get_networks.assert_called_once_with(mock.ANY,
filters=mock.ANY,
fields=mock.ANY,
verbose=True)
def test_verbose_false_trump_attr(self):
instance = self.plugin.return_value
instance.get_networks.return_value = []
self.api.get(_get_path('networks'), {'verbose': ['false', 'foo']})
instance.get_networks.assert_called_once_with(mock.ANY,
filters=mock.ANY,
fields=mock.ANY,
verbose=False)
def test_verbose_true_trump_false(self):
instance = self.plugin.return_value
instance.get_networks.return_value = []
self.api.get(_get_path('networks'), {'verbose': ['true', 'false']})
instance.get_networks.assert_called_once_with(mock.ANY,
filters=mock.ANY,
fields=mock.ANY,
verbose=True)
def _do_field_list(self, resource, base_fields):
attr_info = attributes.RESOURCE_ATTRIBUTE_MAP[resource]
policy_attrs = [name for (name, info) in attr_info.items()
@ -252,8 +181,7 @@ class APIv2TestCase(APIv2TestBase):
fields = self._do_field_list('networks', ['foo'])
instance.get_networks.assert_called_once_with(mock.ANY,
filters=mock.ANY,
fields=fields,
verbose=mock.ANY)
fields=fields)
def test_fields_multiple(self):
instance = self.plugin.return_value
@ -263,8 +191,7 @@ class APIv2TestCase(APIv2TestBase):
self.api.get(_get_path('networks'), {'fields': ['foo', 'bar']})
instance.get_networks.assert_called_once_with(mock.ANY,
filters=mock.ANY,
fields=fields,
verbose=mock.ANY)
fields=fields)
def test_fields_multiple_with_empty(self):
instance = self.plugin.return_value
@ -274,8 +201,7 @@ class APIv2TestCase(APIv2TestBase):
self.api.get(_get_path('networks'), {'fields': ['foo', '']})
instance.get_networks.assert_called_once_with(mock.ANY,
filters=mock.ANY,
fields=fields,
verbose=mock.ANY)
fields=fields)
def test_fields_empty(self):
instance = self.plugin.return_value
@ -284,8 +210,7 @@ class APIv2TestCase(APIv2TestBase):
self.api.get(_get_path('networks'), {'fields': ''})
instance.get_networks.assert_called_once_with(mock.ANY,
filters=mock.ANY,
fields=[],
verbose=mock.ANY)
fields=[])
def test_fields_multiple_empty(self):
instance = self.plugin.return_value
@ -294,8 +219,7 @@ class APIv2TestCase(APIv2TestBase):
self.api.get(_get_path('networks'), {'fields': ['', '']})
instance.get_networks.assert_called_once_with(mock.ANY,
filters=mock.ANY,
fields=[],
verbose=mock.ANY)
fields=[])
def test_filters(self):
instance = self.plugin.return_value
@ -305,8 +229,7 @@ class APIv2TestCase(APIv2TestBase):
filters = {'foo': ['bar']}
instance.get_networks.assert_called_once_with(mock.ANY,
filters=filters,
fields=mock.ANY,
verbose=mock.ANY)
fields=mock.ANY)
def test_filters_empty(self):
instance = self.plugin.return_value
@ -316,8 +239,7 @@ class APIv2TestCase(APIv2TestBase):
filters = {}
instance.get_networks.assert_called_once_with(mock.ANY,
filters=filters,
fields=mock.ANY,
verbose=mock.ANY)
fields=mock.ANY)
def test_filters_multiple_empty(self):
instance = self.plugin.return_value
@ -327,8 +249,7 @@ class APIv2TestCase(APIv2TestBase):
filters = {}
instance.get_networks.assert_called_once_with(mock.ANY,
filters=filters,
fields=mock.ANY,
verbose=mock.ANY)
fields=mock.ANY)
def test_filters_multiple_with_empty(self):
instance = self.plugin.return_value
@ -338,8 +259,7 @@ class APIv2TestCase(APIv2TestBase):
filters = {'foo': ['bar']}
instance.get_networks.assert_called_once_with(mock.ANY,
filters=filters,
fields=mock.ANY,
verbose=mock.ANY)
fields=mock.ANY)
def test_filters_multiple_values(self):
instance = self.plugin.return_value
@ -349,8 +269,7 @@ class APIv2TestCase(APIv2TestBase):
filters = {'foo': ['bar', 'bar2']}
instance.get_networks.assert_called_once_with(mock.ANY,
filters=filters,
fields=mock.ANY,
verbose=mock.ANY)
fields=mock.ANY)
def test_filters_multiple(self):
instance = self.plugin.return_value
@ -361,8 +280,7 @@ class APIv2TestCase(APIv2TestBase):
filters = {'foo': ['bar'], 'foo2': ['bar2']}
instance.get_networks.assert_called_once_with(mock.ANY,
filters=filters,
fields=mock.ANY,
verbose=mock.ANY)
fields=mock.ANY)
def test_filters_with_fields(self):
instance = self.plugin.return_value
@ -373,34 +291,7 @@ class APIv2TestCase(APIv2TestBase):
fields = self._do_field_list('networks', ['foo'])
instance.get_networks.assert_called_once_with(mock.ANY,
filters=filters,
fields=fields,
verbose=mock.ANY)
def test_filters_with_verbose(self):
instance = self.plugin.return_value
instance.get_networks.return_value = []
self.api.get(_get_path('networks'), {'foo': 'bar',
'verbose': 'true'})
filters = {'foo': ['bar']}
instance.get_networks.assert_called_once_with(mock.ANY,
filters=filters,
fields=mock.ANY,
verbose=True)
def test_filters_with_fields_and_verbose(self):
instance = self.plugin.return_value
instance.get_networks.return_value = []
self.api.get(_get_path('networks'), {'foo': 'bar',
'fields': 'foo',
'verbose': 'true'})
filters = {'foo': ['bar']}
fields = self._do_field_list('networks', ['foo'])
instance.get_networks.assert_called_once_with(mock.ANY,
filters=filters,
fields=fields,
verbose=True)
fields=fields)
# Note: since all resources use the same controller and validation

View File

@ -136,7 +136,6 @@ class L3NatExtensionTestCase(unittest.TestCase):
res = self.api.get(_get_path('routers'))
instance.get_routers.assert_called_with(mock.ANY, fields=mock.ANY,
verbose=mock.ANY,
filters=mock.ANY)
self.assertEqual(res.status_int, exc.HTTPOk.code)
@ -174,8 +173,7 @@ class L3NatExtensionTestCase(unittest.TestCase):
res = self.api.get(_get_path('routers', id=router_id))
instance.get_router.assert_called_with(mock.ANY, router_id,
fields=mock.ANY,
verbose=mock.ANY)
fields=mock.ANY)
self.assertEqual(res.status_int, exc.HTTPOk.code)
self.assertTrue('router' in res.json)
router = res.json['router']

View File

@ -250,7 +250,7 @@ class QuantumPolicyTestCase(unittest.TestCase):
def tearDown(self):
self.patcher.stop()
quantum.policy.reset()
policy.reset()
def test_nonadmin_write_on_private_returns_403(self):
action = "update_network"