Merge "node_tag_exists(): raise exception if bad node"

This commit is contained in:
Zuul 2018-02-02 00:38:37 +00:00 committed by Gerrit Code Review
commit 25274b0dc9
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

@ -984,6 +984,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

@ -372,7 +372,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()
@ -381,7 +382,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()