Fix oslo_db deprecation warnings
Migrate neutron.db.sqlalchemyutils.paginate_query to oslo_db.sqlalchemy.utils.paginate_query. All calls to to paginate_query now require a sort key, so tests and defaults had to be updated which trickle down to paginate_query in quark/db/api.py . JIRA:NCP-2067 Change-Id: I9133c5d8e128e62fbf4e23004315a3bb55891db6
This commit is contained in:
parent
391fd5bb7c
commit
2c748d7937
|
@ -18,8 +18,8 @@ import inspect
|
|||
|
||||
import json
|
||||
import netaddr
|
||||
from neutron.db.sqlalchemyutils import paginate_query
|
||||
from oslo_config import cfg
|
||||
from oslo_db.sqlalchemy.utils import paginate_query
|
||||
from oslo_log import log as logging
|
||||
from oslo_utils import timeutils
|
||||
from oslo_utils import uuidutils
|
||||
|
@ -200,7 +200,7 @@ def scoped(f):
|
|||
|
||||
|
||||
@scoped
|
||||
def port_find(context, limit=None, sorts=None, marker_obj=None, fields=None,
|
||||
def port_find(context, limit=None, sorts=['id'], marker_obj=None, fields=None,
|
||||
**filters):
|
||||
query = context.session.query(models.Port).options(
|
||||
orm.joinedload(models.Port.ip_addresses))
|
||||
|
@ -571,7 +571,7 @@ INVERT_DEFAULTS = 'invert_defaults'
|
|||
|
||||
|
||||
@scoped
|
||||
def network_find(context, limit=None, sorts=None, marker=None,
|
||||
def network_find(context, limit=None, sorts=['id'], marker=None,
|
||||
page_reverse=False, fields=None, **filters):
|
||||
ids = []
|
||||
defaults = []
|
||||
|
@ -748,7 +748,7 @@ def subnet_update_set_alloc_pool_cache(context, subnet, cache_data=None):
|
|||
|
||||
|
||||
@scoped
|
||||
def subnet_find(context, limit=None, page_reverse=False, sorts=None,
|
||||
def subnet_find(context, limit=None, page_reverse=False, sorts=['id'],
|
||||
marker_obj=None, fields=None, **filters):
|
||||
ids = []
|
||||
defaults = []
|
||||
|
@ -1025,7 +1025,7 @@ def transaction_create(context):
|
|||
|
||||
|
||||
@scoped
|
||||
def floating_ip_find(context, lock_mode=False, limit=None, sorts=None,
|
||||
def floating_ip_find(context, lock_mode=False, limit=None, sorts=['id'],
|
||||
marker=None, page_reverse=False, fields=None, **filters):
|
||||
query = context.session.query(models.IPAddress)
|
||||
|
||||
|
|
|
@ -205,7 +205,7 @@ class Plugin(neutron_plugin_base_v2.NeutronPluginBaseV2,
|
|||
|
||||
@sessioned
|
||||
def get_security_groups(self, context, filters=None, fields=None,
|
||||
sorts=None, limit=None, marker=None,
|
||||
sorts=['id'], limit=None, marker=None,
|
||||
page_reverse=False):
|
||||
return security_groups.get_security_groups(context, filters, fields,
|
||||
sorts, limit, marker,
|
||||
|
@ -213,7 +213,7 @@ class Plugin(neutron_plugin_base_v2.NeutronPluginBaseV2,
|
|||
|
||||
@sessioned
|
||||
def get_security_group_rules(self, context, filters=None, fields=None,
|
||||
sorts=None, limit=None, marker=None,
|
||||
sorts=['id'], limit=None, marker=None,
|
||||
page_reverse=False):
|
||||
return security_groups.get_security_group_rules(context, filters,
|
||||
fields, sorts, limit,
|
||||
|
@ -285,14 +285,14 @@ class Plugin(neutron_plugin_base_v2.NeutronPluginBaseV2,
|
|||
port)
|
||||
|
||||
@sessioned
|
||||
def get_ports(self, context, limit=None, page_reverse=False, sorts=None,
|
||||
def get_ports(self, context, limit=None, page_reverse=False, sorts=['id'],
|
||||
marker=None, filters=None, fields=None):
|
||||
return ports.get_ports(context, limit, sorts, marker, page_reverse,
|
||||
filters, fields)
|
||||
|
||||
@sessioned
|
||||
def get_ports_for_ip_address(self, context, ip, limit=None,
|
||||
page_reverse=False, sorts=None, marker=None,
|
||||
page_reverse=False, sorts=['id'], marker=None,
|
||||
filters=None, fields=None):
|
||||
return ip_addresses.get_ports_for_ip_address(context, ip, limit, sorts,
|
||||
marker, page_reverse,
|
||||
|
@ -349,8 +349,8 @@ class Plugin(neutron_plugin_base_v2.NeutronPluginBaseV2,
|
|||
return subnets.get_subnet(context, id, fields)
|
||||
|
||||
@sessioned
|
||||
def get_subnets(self, context, limit=None, page_reverse=False, sorts=None,
|
||||
marker=None, filters=None, fields=None):
|
||||
def get_subnets(self, context, limit=None, page_reverse=False,
|
||||
sorts=['id'], marker=None, filters=None, fields=None):
|
||||
return subnets.get_subnets(context, limit, page_reverse, sorts, marker,
|
||||
filters, fields)
|
||||
|
||||
|
@ -380,7 +380,7 @@ class Plugin(neutron_plugin_base_v2.NeutronPluginBaseV2,
|
|||
return networks.get_network(context, id, fields)
|
||||
|
||||
@sessioned
|
||||
def get_networks(self, context, limit=None, sorts=None, marker=None,
|
||||
def get_networks(self, context, limit=None, sorts=['id'], marker=None,
|
||||
page_reverse=False, filters=None, fields=None):
|
||||
return networks.get_networks(context, limit, sorts, marker,
|
||||
page_reverse, filters, fields)
|
||||
|
@ -413,7 +413,7 @@ class Plugin(neutron_plugin_base_v2.NeutronPluginBaseV2,
|
|||
raise NotImplementedError()
|
||||
|
||||
def get_routers(self, context, filters=None, fields=None,
|
||||
sorts=None, limit=None, marker=None, page_reverse=False):
|
||||
sorts=['id'], limit=None, marker=None, page_reverse=False):
|
||||
return router.get_routers(context, filters=filters, fields=fields,
|
||||
sorts=sorts, limit=limit, marker=marker,
|
||||
page_reverse=page_reverse)
|
||||
|
@ -445,7 +445,7 @@ class Plugin(neutron_plugin_base_v2.NeutronPluginBaseV2,
|
|||
|
||||
@sessioned
|
||||
def get_floatingips(self, context, filters=None, fields=None,
|
||||
sorts=None, limit=None, marker=None,
|
||||
sorts=['id'], limit=None, marker=None,
|
||||
page_reverse=False):
|
||||
return floating_ips.get_floatingips(context, filters=filters,
|
||||
fields=fields, sorts=sorts,
|
||||
|
@ -502,7 +502,7 @@ class Plugin(neutron_plugin_base_v2.NeutronPluginBaseV2,
|
|||
|
||||
@sessioned
|
||||
def get_scalingips(self, context, filters=None, fields=None,
|
||||
sorts=None, limit=None, marker=None,
|
||||
sorts=['id'], limit=None, marker=None,
|
||||
page_reverse=False):
|
||||
return floating_ips.get_scalingips(context, filters=filters,
|
||||
fields=fields, sorts=sorts,
|
||||
|
|
|
@ -459,8 +459,8 @@ def get_floatingip(context, id, fields=None):
|
|||
return v._make_floating_ip_dict(floating_ip)
|
||||
|
||||
|
||||
def get_floatingips(context, filters=None, fields=None, sorts=None, limit=None,
|
||||
marker=None, page_reverse=False):
|
||||
def get_floatingips(context, filters=None, fields=None, sorts=['id'],
|
||||
limit=None, marker=None, page_reverse=False):
|
||||
"""Retrieve a list of floating ips.
|
||||
|
||||
:param context: neutron api request context.
|
||||
|
@ -607,8 +607,8 @@ def get_scalingip(context, id, fields=None):
|
|||
return v._make_scaling_ip_dict(scaling_ip)
|
||||
|
||||
|
||||
def get_scalingips(context, filters=None, fields=None, sorts=None, limit=None,
|
||||
marker=None, page_reverse=False):
|
||||
def get_scalingips(context, filters=None, fields=None, sorts=['id'],
|
||||
limit=None, marker=None, page_reverse=False):
|
||||
"""Retrieve a list of scaling ips.
|
||||
|
||||
:param context: neutron api request context.
|
||||
|
|
|
@ -196,7 +196,8 @@ def create_ip_address(context, body):
|
|||
msg="network_id is required.")
|
||||
if network_id == "":
|
||||
raise n_exc.NetworkNotFound(net_id=network_id)
|
||||
net = db_api.network_find(context, None, None, None, False,
|
||||
net = db_api.network_find(context=context, limit=None, sorts=['id'],
|
||||
marker=None, page_reverse=False,
|
||||
id=network_id, scope=db_api.ONE)
|
||||
if not net:
|
||||
raise n_exc.NetworkNotFound(net_id=network_id)
|
||||
|
@ -395,7 +396,7 @@ def delete_ip_address(context, id):
|
|||
ipam_driver.deallocate_ip_address(context, ip_address)
|
||||
|
||||
|
||||
def get_ports_for_ip_address(context, ip_id, limit=None, sorts=None,
|
||||
def get_ports_for_ip_address(context, ip_id, limit=None, sorts=['id'],
|
||||
marker=None, page_reverse=False, filters=None,
|
||||
fields=None):
|
||||
"""Retrieve a list of ports.
|
||||
|
|
|
@ -97,8 +97,10 @@ def create_network(context, network):
|
|||
net_uuid = utils.pop_param(net_attrs, "id", None)
|
||||
net_type = None
|
||||
if net_uuid and context.is_admin:
|
||||
net = db_api.network_find(context, None, None, None, False,
|
||||
id=net_uuid, scope=db_api.ONE)
|
||||
net = db_api.network_find(context=context, limit=None,
|
||||
sorts=['id'], marker=None,
|
||||
page_reverse=False, id=net_uuid,
|
||||
scope=db_api.ONE)
|
||||
net_type = utils.pop_param(net_attrs, "network_plugin", None)
|
||||
if net:
|
||||
raise q_exc.NetworkAlreadyExists(id=net_uuid)
|
||||
|
@ -187,14 +189,15 @@ def get_network(context, id, fields=None):
|
|||
LOG.info("get_network %s for tenant %s fields %s" %
|
||||
(id, context.tenant_id, fields))
|
||||
|
||||
network = db_api.network_find(context, None, None, None, False,
|
||||
network = db_api.network_find(context=context, limit=None, sorts=['id'],
|
||||
marker=None, page_reverse=False,
|
||||
id=id, join_subnets=True, scope=db_api.ONE)
|
||||
if not network:
|
||||
raise n_exc.NetworkNotFound(net_id=id)
|
||||
return v._make_network_dict(network, fields=fields)
|
||||
|
||||
|
||||
def get_networks(context, limit=None, sorts=None, marker=None,
|
||||
def get_networks(context, limit=None, sorts=['id'], marker=None,
|
||||
page_reverse=False, filters=None, fields=None):
|
||||
"""Retrieve a list of networks.
|
||||
|
||||
|
@ -253,7 +256,8 @@ def delete_network(context, id):
|
|||
"""
|
||||
LOG.info("delete_network %s for tenant %s" % (id, context.tenant_id))
|
||||
with context.session.begin():
|
||||
net = db_api.network_find(context, None, None, None, False, id=id,
|
||||
net = db_api.network_find(context=context, limit=None, sorts=['id'],
|
||||
marker=None, page_reverse=False, id=id,
|
||||
scope=db_api.ONE)
|
||||
if not net:
|
||||
raise n_exc.NetworkNotFound(net_id=id)
|
||||
|
|
|
@ -169,8 +169,9 @@ def create_port(context, port):
|
|||
|
||||
port_id = uuidutils.generate_uuid()
|
||||
|
||||
net = db_api.network_find(context, None, None, None, False, id=net_id,
|
||||
scope=db_api.ONE)
|
||||
net = db_api.network_find(context=context, limit=None, sorts=['id'],
|
||||
marker=None, page_reverse=False, fields=None,
|
||||
id=net_id, scope=db_api.ONE)
|
||||
|
||||
if not net:
|
||||
raise n_exc.NetworkNotFound(net_id=net_id)
|
||||
|
@ -523,8 +524,8 @@ def get_port(context, id, fields=None):
|
|||
return v._make_port_dict(results)
|
||||
|
||||
|
||||
def get_ports(context, limit=None, sorts=None, marker=None, page_reverse=False,
|
||||
filters=None, fields=None):
|
||||
def get_ports(context, limit=None, sorts=['id'], marker=None,
|
||||
page_reverse=False, filters=None, fields=None):
|
||||
"""Retrieve a list of ports.
|
||||
|
||||
The contents of the list depends on the identity of the user
|
||||
|
|
|
@ -38,7 +38,7 @@ def get_router(context, id, fields):
|
|||
return _get_floating_ip_default_router(context.tenant_id)
|
||||
|
||||
|
||||
def get_routers(context, filters=None, fields=None, sorts=None, limit=None,
|
||||
def get_routers(context, filters=None, fields=None, sorts=['id'], limit=None,
|
||||
marker=None, page_reverse=False):
|
||||
LOG.info("get_routers for tenant %s filters %s fields %s" %
|
||||
(context.tenant_id, filters, fields))
|
||||
|
|
|
@ -148,7 +148,7 @@ def get_security_group(context, id, fields=None):
|
|||
|
||||
|
||||
def get_security_groups(context, filters=None, fields=None,
|
||||
sorts=None, limit=None, marker=None,
|
||||
sorts=['id'], limit=None, marker=None,
|
||||
page_reverse=False):
|
||||
LOG.info("get_security_groups for tenant %s" %
|
||||
(context.tenant_id))
|
||||
|
@ -233,7 +233,7 @@ def delete_security_group_rule(context, id):
|
|||
|
||||
|
||||
def get_security_group_rules(context, filters=None, fields=None,
|
||||
sorts=None, limit=None, marker=None,
|
||||
sorts=['id'], limit=None, marker=None,
|
||||
page_reverse=False):
|
||||
LOG.info("get_security_group_rules for tenant %s" %
|
||||
(context.tenant_id))
|
||||
|
|
|
@ -109,7 +109,8 @@ def create_subnet(context, subnet):
|
|||
net_id = subnet["subnet"]["network_id"]
|
||||
|
||||
with context.session.begin():
|
||||
net = db_api.network_find(context, None, None, None, False,
|
||||
net = db_api.network_find(context=context, limit=None, sorts=['id'],
|
||||
marker=None, page_reverse=False, fields=None,
|
||||
id=net_id, scope=db_api.ONE)
|
||||
if not net:
|
||||
raise n_exc.NetworkNotFound(net_id=net_id)
|
||||
|
@ -259,8 +260,10 @@ def update_subnet(context, id, subnet):
|
|||
(id, context.tenant_id))
|
||||
|
||||
with context.session.begin():
|
||||
subnet_db = db_api.subnet_find(context, None, None, None, False, id=id,
|
||||
scope=db_api.ONE)
|
||||
subnet_db = db_api.subnet_find(context=context, limit=None,
|
||||
page_reverse=False, sorts=['id'],
|
||||
marker_obj=None, fields=None,
|
||||
id=id, scope=db_api.ONE)
|
||||
if not subnet_db:
|
||||
raise n_exc.SubnetNotFound(subnet_id=id)
|
||||
|
||||
|
@ -370,7 +373,9 @@ def get_subnet(context, id, fields=None):
|
|||
"""
|
||||
LOG.info("get_subnet %s for tenant %s with fields %s" %
|
||||
(id, context.tenant_id, fields))
|
||||
subnet = db_api.subnet_find(context, None, None, None, False, id=id,
|
||||
subnet = db_api.subnet_find(context=context, limit=None,
|
||||
page_reverse=False, sorts=['id'],
|
||||
marker_obj=None, fields=None, id=id,
|
||||
join_dns=True, join_routes=True,
|
||||
scope=db_api.ONE)
|
||||
if not subnet:
|
||||
|
@ -383,7 +388,7 @@ def get_subnet(context, id, fields=None):
|
|||
return v._make_subnet_dict(subnet)
|
||||
|
||||
|
||||
def get_subnets(context, limit=None, page_reverse=False, sorts=None,
|
||||
def get_subnets(context, limit=None, page_reverse=False, sorts=['id'],
|
||||
marker=None, filters=None, fields=None):
|
||||
"""Retrieve a list of subnets.
|
||||
|
||||
|
|
|
@ -69,7 +69,9 @@ class QuarkFindSubnetAllocationCount(QuarkIpamBaseFunctionalTest):
|
|||
|
||||
def _create_ip_address(self, ip_address, ip_version, subnet_cidr, net_id):
|
||||
with self.context.session.begin():
|
||||
subnet = db_api.subnet_find(self.context, None, False, None, None,
|
||||
subnet = db_api.subnet_find(context=self.context, limit=None,
|
||||
page_reverse=False, sorts=['id'],
|
||||
marker_obj=None,
|
||||
cidr=subnet_cidr).all()
|
||||
ip = dict(subnet_id=subnet[0].id,
|
||||
network_id=net_id,
|
||||
|
|
|
@ -36,8 +36,7 @@ class QuarkNetworksPaginationFunctionalTest(BaseFunctionalTest):
|
|||
db_api.network_create(self.context, **networkA)
|
||||
db_api.network_create(self.context, **networkB)
|
||||
res = network_api.get_networks(self.context, networks_per_page,
|
||||
[('id', 'asc')], None, False,
|
||||
None)
|
||||
['id'], None, False)
|
||||
self.assertEqual(len(res), networks_per_page)
|
||||
res = network_api.get_networks(self.context)
|
||||
self.assertNotEqual(len(res), networks_per_page)
|
||||
|
@ -67,7 +66,7 @@ class QuarkSubnetsPaginationFunctionalTest(BaseFunctionalTest):
|
|||
subnets_unpaged = subnet_api.get_subnets(self.context, filters={})
|
||||
subnets_paged = subnet_api.get_subnets(self.context,
|
||||
subnets_per_page, False,
|
||||
[('id', 'asc')],
|
||||
['id'],
|
||||
filters={})
|
||||
self.assertEqual(len(subnets_paged), subnets_per_page)
|
||||
self.assertNotEqual(len(subnets_unpaged), subnets_per_page)
|
||||
|
@ -114,16 +113,19 @@ class QuarkPortsPaginationFunctionalTest(BaseFunctionalTest):
|
|||
ports_per_page = 1
|
||||
with self._stubs(network, subnet_info) as (
|
||||
net, sub_ports):
|
||||
port_api.create_port(self.context, _make_body())
|
||||
port_api.create_port(self.context, _make_body())
|
||||
port1 = port_api.create_port(self.context, _make_body())
|
||||
port2 = port_api.create_port(self.context, _make_body())
|
||||
res_ports = port_api.get_ports(self.context, ports_per_page,
|
||||
[('id', 'asc')], None)
|
||||
['id'], None)
|
||||
self.assertEqual(len(res_ports), ports_per_page)
|
||||
res_ports = port_api.get_ports(self.context)
|
||||
self.assertNotEqual(len(res_ports), ports_per_page)
|
||||
# Note (Perkins): Testing for a default sort on created_at,
|
||||
# but created_at is not available, so check that mac addresses,
|
||||
# which are created sequentially, are ordered correctly.
|
||||
res_ports = port_api.get_ports(self.context, 2, None, None)
|
||||
res_ports = port_api.get_ports(self.context, 2, ['mac_address'],
|
||||
None)
|
||||
self.assertTrue(res_ports[0]['mac_address'] <
|
||||
res_ports[1]['mac_address'])
|
||||
self.assertTrue(port1['id'] == res_ports[0]['id'])
|
||||
self.assertTrue(port2['id'] == res_ports[1]['id'])
|
||||
|
|
|
@ -41,10 +41,14 @@ class QuarkFindPortsSorted(BaseFunctionalTest):
|
|||
port_mod1 = db_api.port_create(self.context, **port1)
|
||||
port_mod2 = db_api.port_create(self.context, **port2)
|
||||
port_mod3 = db_api.port_create(self.context, **port3)
|
||||
res = db_api.port_find(self.context, None, None, None, None,
|
||||
scope=db_api.ALL)
|
||||
res = db_api.port_find(context=self.context, limit=None,
|
||||
sorts=['created_at'], marker_obj=None,
|
||||
fields=None, scope=db_api.ALL)
|
||||
self.assertTrue(res[0]["created_at"] < res[1]["created_at"] <
|
||||
res[2]['created_at'])
|
||||
self.assertTrue(res[0]['id'] == port_mod1['id'])
|
||||
self.assertTrue(res[1]['id'] == port_mod2['id'])
|
||||
self.assertTrue(res[2]['id'] == port_mod3['id'])
|
||||
db_api.network_delete(self.context, net_mod)
|
||||
db_api.port_delete(self.context, port_mod1)
|
||||
db_api.port_delete(self.context, port_mod2)
|
||||
|
@ -308,13 +312,13 @@ class QuarkFindPortsFilterByDeviceOwner(BaseFunctionalTest):
|
|||
port_mod1 = db_api.port_create(self.context, **port1)
|
||||
port_mod2 = db_api.port_create(self.context, **port2)
|
||||
port_mod3 = db_api.port_create(self.context, **port3)
|
||||
res = db_api.port_find(self.context, None, None, None,
|
||||
scope=db_api.ALL,
|
||||
res = db_api.port_find(context=self.context, limit=None, sorts=['id'],
|
||||
marker_obj=None, fields=None, scope=db_api.ALL,
|
||||
device_owner=port3["device_owner"])
|
||||
self.assertTrue(len(res) == 1)
|
||||
self.assertTrue(res[0]["device_owner"] == port3["device_owner"])
|
||||
res = db_api.port_find(self.context, None, None, None,
|
||||
scope=db_api.ALL,
|
||||
res = db_api.port_find(context=self.context, limit=None, sorts=['id'],
|
||||
marker_obj=None, fields=None, scope=db_api.ALL,
|
||||
device_owner=port1["device_owner"])
|
||||
self.assertTrue(len(res) == 2)
|
||||
self.assertTrue(res[0]["device_owner"] == res[1]["device_owner"] ==
|
||||
|
|
|
@ -220,8 +220,10 @@ class QuarkIPAddressAllocateWithFullSubnetsNotMarkedAsFull(
|
|||
self.assertEqual(ipaddress[0].address_readable, "2.2.2.1")
|
||||
|
||||
with self.context.session.begin():
|
||||
subnets = db_api.subnet_find(self.context, None, None, None,
|
||||
False).all()
|
||||
subnets = db_api.subnet_find(context=self.context, limit=None,
|
||||
page_reverse=False, sorts=['id'],
|
||||
marker_obj=None,
|
||||
fields=None).all()
|
||||
self.assertEqual(len(subnets), 3)
|
||||
|
||||
full_subnets = [s for s in subnets
|
||||
|
|
|
@ -686,7 +686,8 @@ class TestQuarkGetIpAddressPort(test_quark_plugin.TestQuarkPlugin):
|
|||
self._alloc_stub(ip_model))
|
||||
|
||||
res = self.plugin.get_ports_for_ip_address(self.context, 1)[0]
|
||||
mock_dbapi.port_find.assert_called_with(self.context, None, None, None,
|
||||
mock_dbapi.port_find.assert_called_with(self.context, None, ['id'],
|
||||
None,
|
||||
join_security_groups=True,
|
||||
fields=None,
|
||||
ip_address_id=[1])
|
||||
|
|
Loading…
Reference in New Issue