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
changes/00/533700/1
Ruby Loo 5 years ago
parent e9425da77e
commit afc432af4d
  1. 1
      ironic/db/api.py
  2. 1
      ironic/db/sqlalchemy/api.py
  3. 4
      ironic/tests/unit/db/test_node_tags.py
  4. 6
      ironic/tests/unit/db/test_nodes.py

@ -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

@ -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()

@ -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')

@ -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()

Loading…
Cancel
Save