node_tag_exists(): raise exception if bad node

To make tags consistent with traits, change db.api.node_tag_exists()
to raise a NodeNotFound exception if the node doesn't exist.

This is a follow up to bbff319f02.

Change-Id: Id0ddf448d97b5ac22ef5dc27154a1b229514a968
Partial-Bug:#1526266
This commit is contained in:
Ruby Loo 2018-01-15 10:11:50 -05:00
parent e9425da77e
commit afc432af4d
4 changed files with 10 additions and 2 deletions

View File

@ -662,6 +662,7 @@ class Connection(object):
:param node_id: The id of a node.
:param tag: A tag string.
:returns: True if the tag exists otherwise False.
:raises: NodeNotFound if the node is not found.
"""
@abc.abstractmethod

View File

@ -968,6 +968,7 @@ class Connection(api.Connection):
raise exception.NodeTagNotFound(node_id=node_id, tag=tag)
def node_tag_exists(self, node_id, tag):
self._check_node_exists(node_id)
q = model_query(models.NodeTag).filter_by(node_id=node_id, tag=tag)
return model_query(q.exists()).scalar()

View File

@ -108,3 +108,7 @@ class DbNodeTagTestCase(base.DbTestCase):
def test_node_tag_not_exists(self):
ret = self.dbapi.node_tag_exists(self.node.id, 'tag1')
self.assertFalse(ret)
def test_node_tag_node_not_exist(self):
self.assertRaises(exception.NodeNotFound,
self.dbapi.node_tag_exists, '123', 'tag1')

View File

@ -353,7 +353,8 @@ class DbNodeTestCase(base.DbTestCase):
self.assertTrue(self.dbapi.node_tag_exists(node.id, tag.tag))
self.dbapi.destroy_node(node.id)
self.assertFalse(self.dbapi.node_tag_exists(node.id, tag.tag))
self.assertRaises(exception.NodeNotFound,
self.dbapi.node_tag_exists, node.id, tag.tag)
def test_tags_get_destroyed_after_destroying_a_node_by_uuid(self):
node = utils.create_test_node()
@ -362,7 +363,8 @@ class DbNodeTestCase(base.DbTestCase):
self.assertTrue(self.dbapi.node_tag_exists(node.id, tag.tag))
self.dbapi.destroy_node(node.uuid)
self.assertFalse(self.dbapi.node_tag_exists(node.id, tag.tag))
self.assertRaises(exception.NodeNotFound,
self.dbapi.node_tag_exists, node.id, tag.tag)
def test_volume_connector_get_destroyed_after_destroying_a_node(self):
node = utils.create_test_node()