Merge "Remove a DB query for get_ports_by_node()"
This commit is contained in:
commit
e7d1dd3486
@ -175,10 +175,15 @@ class PortsController(rest.RestController):
|
||||
marker)
|
||||
|
||||
if node_uuid:
|
||||
ports = pecan.request.dbapi.get_ports_by_node(node_uuid, limit,
|
||||
marker_obj,
|
||||
sort_key=sort_key,
|
||||
sort_dir=sort_dir)
|
||||
# FIXME(comstud): Since all we need is the node ID, we can
|
||||
# make this more efficient by only querying
|
||||
# for that column. This will get cleaned up
|
||||
# as we move to the object interface.
|
||||
node = pecan.request.dbapi.get_node(node_uuid)
|
||||
ports = pecan.request.dbapi.get_ports_by_node_id(node.id, limit,
|
||||
marker_obj,
|
||||
sort_key=sort_key,
|
||||
sort_dir=sort_dir)
|
||||
elif address:
|
||||
ports = self._get_ports_by_address(address)
|
||||
else:
|
||||
|
@ -165,7 +165,7 @@ class TaskManager(object):
|
||||
locked_node_list.append(node.id)
|
||||
else:
|
||||
node = self.dbapi.get_node(id)
|
||||
ports = self.dbapi.get_ports_by_node(id)
|
||||
ports = self.dbapi.get_ports_by_node_id(node.id)
|
||||
driver = driver_factory.get_driver(driver_name or node.driver)
|
||||
|
||||
self.resources.append(NodeResource(node, ports, driver))
|
||||
|
@ -208,11 +208,11 @@ class Connection(object):
|
||||
"""
|
||||
|
||||
@abc.abstractmethod
|
||||
def get_ports_by_node(self, node_id, limit=None, marker=None,
|
||||
sort_key=None, sort_dir=None):
|
||||
def get_ports_by_node_id(self, node_id, limit=None, marker=None,
|
||||
sort_key=None, sort_dir=None):
|
||||
"""List all the ports for a given node.
|
||||
|
||||
:param node_id: The id or uuid of a node.
|
||||
:param node_id: The integer node ID.
|
||||
:param limit: Maximum number of ports to return.
|
||||
:param marker: the last item of the previous page; we return the next
|
||||
result set.
|
||||
|
@ -403,12 +403,10 @@ class Connection(api.Connection):
|
||||
sort_key, sort_dir)
|
||||
|
||||
@objects.objectify(objects.Port)
|
||||
def get_ports_by_node(self, node_id, limit=None, marker=None,
|
||||
sort_key=None, sort_dir=None):
|
||||
# get_node() to raise an exception if the node is not found
|
||||
node_obj = self.get_node(node_id)
|
||||
def get_ports_by_node_id(self, node_id, limit=None, marker=None,
|
||||
sort_key=None, sort_dir=None):
|
||||
query = model_query(models.Port)
|
||||
query = query.filter_by(node_id=node_obj.id)
|
||||
query = query.filter_by(node_id=node_id)
|
||||
return _paginate_query(models.Port, limit, marker,
|
||||
sort_key, sort_dir, query)
|
||||
|
||||
|
@ -73,23 +73,12 @@ class DbPortTestCase(base.DbTestCase):
|
||||
def test_get_ports_by_node_id(self):
|
||||
p = db_utils.get_test_port(node_id=self.n.id)
|
||||
self.dbapi.create_port(p)
|
||||
res = self.dbapi.get_ports_by_node(self.n.id)
|
||||
res = self.dbapi.get_ports_by_node_id(self.n.id)
|
||||
self.assertEqual(self.p['address'], res[0].address)
|
||||
|
||||
def test_get_ports_by_node_uuid(self):
|
||||
p = db_utils.get_test_port(node_id=self.n.id)
|
||||
self.dbapi.create_port(p)
|
||||
res = self.dbapi.get_ports_by_node(self.n.uuid)
|
||||
self.assertEqual(self.p['address'], res[0].address)
|
||||
|
||||
def test_get_ports_by_node_that_does_not_exist(self):
|
||||
def test_get_ports_by_node_id_that_does_not_exist(self):
|
||||
self.dbapi.create_port(self.p)
|
||||
self.assertRaises(exception.NodeNotFound,
|
||||
self.dbapi.get_ports_by_node,
|
||||
99)
|
||||
self.assertRaises(exception.NodeNotFound,
|
||||
self.dbapi.get_ports_by_node,
|
||||
'12345678-9999-0000-aaaa-123456789012')
|
||||
self.assertEqual([], self.dbapi.get_ports_by_node_id(99))
|
||||
|
||||
def test_destroy_port(self):
|
||||
self.dbapi.create_port(self.p)
|
||||
|
Loading…
x
Reference in New Issue
Block a user