From 957e8d16b18cb07aa7cada4079cd97ec3a72ab84 Mon Sep 17 00:00:00 2001 From: Lin Tan Date: Wed, 1 Jun 2016 14:40:52 +0800 Subject: [PATCH] Throwing an exception when creating a node with tags Currently, creating node with tags is not supported. If tags values were passed over, an exception should be thrown. A follow-up patch of 19ef56cf00a78871e0d30a160b07f280488ddd0c Change-Id: I83e7db6a8da014962454e2b1248fe061985d98d8 --- ironic/db/api.py | 1 + ironic/db/sqlalchemy/api.py | 7 ++----- ironic/tests/unit/db/test_nodes.py | 9 ++++----- ironic/tests/unit/db/utils.py | 4 ++++ 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/ironic/db/api.py b/ironic/db/api.py index f8ab5a68690..dbbbb34946e 100644 --- a/ironic/db/api.py +++ b/ironic/db/api.py @@ -143,6 +143,7 @@ class Connection(object): 'properties': { ... }, 'extra': { ... }, } + :raises: InvalidParameterValue if create a node with tags. :returns: A node. """ diff --git a/ironic/db/sqlalchemy/api.py b/ironic/db/sqlalchemy/api.py index 02bf4782c1e..faad75f479f 100644 --- a/ironic/db/sqlalchemy/api.py +++ b/ironic/db/sqlalchemy/api.py @@ -298,11 +298,8 @@ class Connection(api.Connection): # TODO(zhenguo): Support creating node with tags if 'tags' in values: - LOG.warning( - _LW('Ignore the specified tags %(tags)s when creating node: ' - '%(node)s.'), {'tags': values['tags'], - 'node': values['uuid']}) - del values['tags'] + msg = _("Cannot create node with tags.") + raise exception.InvalidParameterValue(err=msg) node = models.Node() node.update(values) diff --git a/ironic/tests/unit/db/test_nodes.py b/ironic/tests/unit/db/test_nodes.py index 33522a1e4cf..da5744a7f17 100644 --- a/ironic/tests/unit/db/test_nodes.py +++ b/ironic/tests/unit/db/test_nodes.py @@ -24,7 +24,6 @@ import six from ironic.common import exception from ironic.common import states -from ironic.db.sqlalchemy import api from ironic.tests.unit.db import base from ironic.tests.unit.db import utils @@ -34,10 +33,10 @@ class DbNodeTestCase(base.DbTestCase): def test_create_node(self): utils.create_test_node() - @mock.patch.object(api.LOG, 'warning', autospec=True) - def test_create_node_with_tags(self, mock_log): - utils.create_test_node(tags=['tag1', 'tag2']) - self.assertTrue(mock_log.called) + def test_create_node_with_tags(self): + self.assertRaises(exception.InvalidParameterValue, + utils.create_test_node, + tags=['tag1', 'tag2']) def test_create_node_already_exists(self): utils.create_test_node() diff --git a/ironic/tests/unit/db/utils.py b/ironic/tests/unit/db/utils.py index e336967034a..676158ef6a8 100644 --- a/ironic/tests/unit/db/utils.py +++ b/ironic/tests/unit/db/utils.py @@ -241,6 +241,10 @@ def create_test_node(**kw): # Let DB generate ID if it isn't specified explicitly if 'id' not in kw: del node['id'] + # Create node with tags will raise an exception. If tags are not + # specified explicitly just delete it. + if 'tags' not in kw: + del node['tags'] dbapi = db_api.get_instance() return dbapi.create_node(node)