Merge "Throwing an exception when creating a node with tags"
This commit is contained in:
@@ -143,6 +143,7 @@ class Connection(object):
|
||||
'properties': { ... },
|
||||
'extra': { ... },
|
||||
}
|
||||
:raises: InvalidParameterValue if create a node with tags.
|
||||
:returns: A node.
|
||||
"""
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -242,6 +242,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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user