Implement db get_[un]associated_nodes
These method were just stubs. This patch implements them in db/sqlalchemy/api.py, and a subsequent patch will expose this functionality via the API. Change-Id: Iae68cbe3bf4e84a0f47a0770695bed9dae78aa95
This commit is contained in:
parent
5f664f279c
commit
982b8ba204
@ -196,11 +196,15 @@ class Connection(api.Connection):
|
||||
|
||||
@objects.objectify(objects.Node)
|
||||
def get_associated_nodes(self):
|
||||
pass
|
||||
query = model_query(models.Node).\
|
||||
filter(models.Node.instance_uuid != None)
|
||||
return query.all()
|
||||
|
||||
@objects.objectify(objects.Node)
|
||||
def get_unassociated_nodes(self):
|
||||
pass
|
||||
query = model_query(models.Node).\
|
||||
filter(models.Node.instance_uuid == None)
|
||||
return query.all()
|
||||
|
||||
@objects.objectify(objects.Node)
|
||||
def reserve_nodes(self, tag, nodes):
|
||||
@ -277,11 +281,8 @@ class Connection(api.Connection):
|
||||
|
||||
@objects.objectify(objects.Node)
|
||||
def get_node_by_instance(self, instance):
|
||||
query = model_query(models.Node)
|
||||
if uuidutils.is_uuid_like(instance):
|
||||
query = query.filter_by(instance_uuid=instance)
|
||||
else:
|
||||
query = query.filter_by(instance_name=instance)
|
||||
query = model_query(models.Node).\
|
||||
filter_by(instance_uuid=instance)
|
||||
|
||||
try:
|
||||
result = query.one()
|
||||
|
@ -44,6 +44,28 @@ class DbNodeTestCase(base.DbTestCase):
|
||||
uuids.sort()
|
||||
return uuids
|
||||
|
||||
def _create_associated_nodes(self):
|
||||
uuids = []
|
||||
uuids_with_instance = []
|
||||
|
||||
for i in xrange(1, 5):
|
||||
uuid = uuidutils.generate_uuid()
|
||||
uuids.append(unicode(uuid))
|
||||
if i < 3:
|
||||
instance_uuid = uuidutils.generate_uuid()
|
||||
uuids_with_instance.append(unicode(uuid))
|
||||
else:
|
||||
instance_uuid = None
|
||||
|
||||
n = utils.get_test_node(id=i,
|
||||
uuid=uuid,
|
||||
instance_uuid=instance_uuid)
|
||||
self.dbapi.create_node(n)
|
||||
|
||||
uuids.sort()
|
||||
uuids_with_instance.sort()
|
||||
return (uuids, uuids_with_instance)
|
||||
|
||||
def test_create_node(self):
|
||||
self._create_test_node()
|
||||
|
||||
@ -98,7 +120,7 @@ class DbNodeTestCase(base.DbTestCase):
|
||||
self.assertEqual(uuids.sort(), res_uuids.sort())
|
||||
|
||||
def test_get_node_by_instance(self):
|
||||
n = self._create_test_node()
|
||||
n = self._create_test_node(instance_uuid='fake-uuid-1234')
|
||||
|
||||
res = self.dbapi.get_node_by_instance(n['instance_uuid'])
|
||||
self.assertEqual(n['uuid'], res['uuid'])
|
||||
@ -295,3 +317,21 @@ class DbNodeTestCase(base.DbTestCase):
|
||||
for uuid in uuids:
|
||||
res = self.dbapi.get_node(uuid)
|
||||
self.assertEqual(None, res['reservation'])
|
||||
|
||||
def test_get_associated_nodes(self):
|
||||
(uuids, uuids_with_instance) = self._create_associated_nodes()
|
||||
|
||||
res = self.dbapi.get_associated_nodes()
|
||||
res_uuids = [r.uuid for r in res]
|
||||
res_uuids.sort()
|
||||
self.assertEqual(uuids_with_instance, res_uuids)
|
||||
|
||||
def test_get_unassociated_nodes(self):
|
||||
(uuids, uuids_with_instance) = self._create_associated_nodes()
|
||||
uuids_without_instance = list(set(uuids) - set(uuids_with_instance))
|
||||
uuids_without_instance.sort()
|
||||
|
||||
res = self.dbapi.get_unassociated_nodes()
|
||||
res_uuids = [r.uuid for r in res]
|
||||
res_uuids.sort()
|
||||
self.assertEqual(uuids_without_instance, res_uuids)
|
||||
|
@ -73,8 +73,7 @@ def get_test_node(**kw):
|
||||
'provision_state': kw.get('provision_state', states.NOSTATE),
|
||||
'target_provision_state': kw.get('target_provision_state',
|
||||
states.NOSTATE),
|
||||
'instance_uuid': kw.get('instance_uuid',
|
||||
'8227348d-5f1d-4488-aad1-7c92b2d42504'),
|
||||
'instance_uuid': kw.get('instance_uuid', None),
|
||||
'driver': kw.get('driver', 'fake'),
|
||||
'driver_info': kw.get('driver_info', fake_info),
|
||||
'properties': kw.get('properties', properties),
|
||||
|
Loading…
Reference in New Issue
Block a user