Merge "Check keyword arguments"
This commit is contained in:
commit
d868e9bade
@ -271,8 +271,7 @@ class UpdateNodeTestCase(mgr_utils.ServiceSetUpMixin,
|
|||||||
node = obj_utils.create_test_node(self.context,
|
node = obj_utils.create_test_node(self.context,
|
||||||
driver=existing_driver,
|
driver=existing_driver,
|
||||||
extra={'test': 'one'},
|
extra={'test': 'one'},
|
||||||
instance_uuid=None,
|
instance_uuid=None)
|
||||||
task_state=states.POWER_ON)
|
|
||||||
# check that it fails because driver not found
|
# check that it fails because driver not found
|
||||||
node.driver = wrong_driver
|
node.driver = wrong_driver
|
||||||
node.driver_info = {}
|
node.driver_info = {}
|
||||||
|
@ -363,8 +363,7 @@ class TestNeutron(db_base.DbTestCase):
|
|||||||
address='aa:bb:cc:dd:ee:ff',
|
address='aa:bb:cc:dd:ee:ff',
|
||||||
uuid=uuidutils.generate_uuid(),
|
uuid=uuidutils.generate_uuid(),
|
||||||
extra={'vif_port_id':
|
extra={'vif_port_id':
|
||||||
'test-vif-A'},
|
'test-vif-A'})
|
||||||
driver='fake')
|
|
||||||
mock_gfia.return_value = expected
|
mock_gfia.return_value = expected
|
||||||
with task_manager.acquire(self.context,
|
with task_manager.acquire(self.context,
|
||||||
self.node.uuid) as task:
|
self.node.uuid) as task:
|
||||||
@ -380,8 +379,7 @@ class TestNeutron(db_base.DbTestCase):
|
|||||||
port = object_utils.create_test_port(self.context,
|
port = object_utils.create_test_port(self.context,
|
||||||
node_id=self.node.id,
|
node_id=self.node.id,
|
||||||
address='aa:bb:cc:dd:ee:ff',
|
address='aa:bb:cc:dd:ee:ff',
|
||||||
uuid=uuidutils.generate_uuid(),
|
uuid=uuidutils.generate_uuid())
|
||||||
driver='fake')
|
|
||||||
mock_gfia.return_value = expected
|
mock_gfia.return_value = expected
|
||||||
with task_manager.acquire(self.context,
|
with task_manager.acquire(self.context,
|
||||||
self.node.uuid) as task:
|
self.node.uuid) as task:
|
||||||
@ -397,8 +395,7 @@ class TestNeutron(db_base.DbTestCase):
|
|||||||
pg = object_utils.create_test_portgroup(self.context,
|
pg = object_utils.create_test_portgroup(self.context,
|
||||||
node_id=self.node.id,
|
node_id=self.node.id,
|
||||||
address='aa:bb:cc:dd:ee:ff',
|
address='aa:bb:cc:dd:ee:ff',
|
||||||
uuid=uuidutils.generate_uuid(),
|
uuid=uuidutils.generate_uuid())
|
||||||
driver='fake')
|
|
||||||
mock_gfia.return_value = expected
|
mock_gfia.return_value = expected
|
||||||
with task_manager.acquire(self.context,
|
with task_manager.acquire(self.context,
|
||||||
self.node.uuid) as task:
|
self.node.uuid) as task:
|
||||||
@ -416,8 +413,7 @@ class TestNeutron(db_base.DbTestCase):
|
|||||||
address='aa:bb:cc:dd:ee:ff',
|
address='aa:bb:cc:dd:ee:ff',
|
||||||
uuid=uuidutils.generate_uuid(),
|
uuid=uuidutils.generate_uuid(),
|
||||||
extra={'vif_port_id':
|
extra={'vif_port_id':
|
||||||
'test-vif-A'},
|
'test-vif-A'})
|
||||||
driver='fake')
|
|
||||||
mock_gfia.return_value = ip_address
|
mock_gfia.return_value = ip_address
|
||||||
with task_manager.acquire(self.context, self.node.uuid) as task:
|
with task_manager.acquire(self.context, self.node.uuid) as task:
|
||||||
api = dhcp_factory.DHCPFactory().provider
|
api = dhcp_factory.DHCPFactory().provider
|
||||||
@ -434,8 +430,7 @@ class TestNeutron(db_base.DbTestCase):
|
|||||||
address='aa:bb:cc:dd:ee:ff',
|
address='aa:bb:cc:dd:ee:ff',
|
||||||
uuid=uuidutils.generate_uuid(),
|
uuid=uuidutils.generate_uuid(),
|
||||||
extra={'vif_port_id':
|
extra={'vif_port_id':
|
||||||
'test-vif-A'},
|
'test-vif-A'})
|
||||||
driver='fake')
|
|
||||||
mock_gfia.return_value = ip_address
|
mock_gfia.return_value = ip_address
|
||||||
with task_manager.acquire(self.context, self.node.uuid) as task:
|
with task_manager.acquire(self.context, self.node.uuid) as task:
|
||||||
api = dhcp_factory.DHCPFactory().provider
|
api = dhcp_factory.DHCPFactory().provider
|
||||||
@ -463,8 +458,7 @@ class TestNeutron(db_base.DbTestCase):
|
|||||||
address='aa:bb:cc:dd:ee:ff',
|
address='aa:bb:cc:dd:ee:ff',
|
||||||
uuid=uuidutils.generate_uuid(),
|
uuid=uuidutils.generate_uuid(),
|
||||||
extra={'vif_port_id':
|
extra={'vif_port_id':
|
||||||
'test-vif-A'},
|
'test-vif-A'})
|
||||||
driver='fake')
|
|
||||||
with task_manager.acquire(self.context, self.node.uuid) as task:
|
with task_manager.acquire(self.context, self.node.uuid) as task:
|
||||||
api = dhcp_factory.DHCPFactory().provider
|
api = dhcp_factory.DHCPFactory().provider
|
||||||
api.get_ip_addresses(task)
|
api.get_ip_addresses(task)
|
||||||
|
@ -1449,7 +1449,7 @@ class VirtualMediaDeployUtilsTestCase(db_base.DbTestCase):
|
|||||||
obj_utils.create_test_port(
|
obj_utils.create_test_port(
|
||||||
self.context, node_id=self.node.id, address='aa:bb:cc:dd:ee:ff',
|
self.context, node_id=self.node.id, address='aa:bb:cc:dd:ee:ff',
|
||||||
uuid=uuidutils.generate_uuid(),
|
uuid=uuidutils.generate_uuid(),
|
||||||
extra={'vif_port_id': 'test-vif-A'}, driver='iscsi_ilo')
|
extra={'vif_port_id': 'test-vif-A'})
|
||||||
with task_manager.acquire(self.context, self.node.uuid,
|
with task_manager.acquire(self.context, self.node.uuid,
|
||||||
shared=False) as task:
|
shared=False) as task:
|
||||||
address = utils.get_single_nic_with_vif_port_id(task)
|
address = utils.get_single_nic_with_vif_port_id(task)
|
||||||
@ -1459,8 +1459,7 @@ class VirtualMediaDeployUtilsTestCase(db_base.DbTestCase):
|
|||||||
obj_utils.create_test_port(
|
obj_utils.create_test_port(
|
||||||
self.context, node_id=self.node.id, address='aa:bb:cc:dd:ee:ff',
|
self.context, node_id=self.node.id, address='aa:bb:cc:dd:ee:ff',
|
||||||
uuid=uuidutils.generate_uuid(),
|
uuid=uuidutils.generate_uuid(),
|
||||||
internal_info={'cleaning_vif_port_id': 'test-vif-A'},
|
internal_info={'cleaning_vif_port_id': 'test-vif-A'})
|
||||||
driver='iscsi_ilo')
|
|
||||||
with task_manager.acquire(self.context, self.node.uuid,
|
with task_manager.acquire(self.context, self.node.uuid,
|
||||||
shared=False) as task:
|
shared=False) as task:
|
||||||
address = utils.get_single_nic_with_vif_port_id(task)
|
address = utils.get_single_nic_with_vif_port_id(task)
|
||||||
@ -1470,8 +1469,7 @@ class VirtualMediaDeployUtilsTestCase(db_base.DbTestCase):
|
|||||||
obj_utils.create_test_port(
|
obj_utils.create_test_port(
|
||||||
self.context, node_id=self.node.id, address='aa:bb:cc:dd:ee:ff',
|
self.context, node_id=self.node.id, address='aa:bb:cc:dd:ee:ff',
|
||||||
uuid=uuidutils.generate_uuid(),
|
uuid=uuidutils.generate_uuid(),
|
||||||
internal_info={'provisioning_vif_port_id': 'test-vif-A'},
|
internal_info={'provisioning_vif_port_id': 'test-vif-A'})
|
||||||
driver='iscsi_ilo')
|
|
||||||
with task_manager.acquire(self.context, self.node.uuid,
|
with task_manager.acquire(self.context, self.node.uuid,
|
||||||
shared=False) as task:
|
shared=False) as task:
|
||||||
address = utils.get_single_nic_with_vif_port_id(task)
|
address = utils.get_single_nic_with_vif_port_id(task)
|
||||||
|
@ -13,18 +13,43 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
"""Ironic object test utilities."""
|
"""Ironic object test utilities."""
|
||||||
|
import six
|
||||||
|
|
||||||
|
from ironic.common import exception
|
||||||
|
from ironic.common.i18n import _
|
||||||
from ironic import objects
|
from ironic import objects
|
||||||
from ironic.tests.unit.db import utils as db_utils
|
from ironic.tests.unit.db import utils as db_utils
|
||||||
|
|
||||||
|
|
||||||
|
def check_keyword_arguments(func):
|
||||||
|
@six.wraps(func)
|
||||||
|
def wrapper(**kw):
|
||||||
|
obj_type = kw.pop('object_type')
|
||||||
|
result = func(**kw)
|
||||||
|
|
||||||
|
extra_args = set(kw) - set(result)
|
||||||
|
if extra_args:
|
||||||
|
raise exception.InvalidParameterValue(
|
||||||
|
_("Unknown keyword arguments (%(extra)s) were passed "
|
||||||
|
"while creating a test %(object_type)s object.") %
|
||||||
|
{"extra": ", ".join(extra_args),
|
||||||
|
"object_type": obj_type})
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
def get_test_node(ctxt, **kw):
|
def get_test_node(ctxt, **kw):
|
||||||
"""Return a Node object with appropriate attributes.
|
"""Return a Node object with appropriate attributes.
|
||||||
|
|
||||||
NOTE: The object leaves the attributes marked as changed, such
|
NOTE: The object leaves the attributes marked as changed, such
|
||||||
that a create() could be used to commit it to the DB.
|
that a create() could be used to commit it to the DB.
|
||||||
"""
|
"""
|
||||||
db_node = db_utils.get_test_node(**kw)
|
kw['object_type'] = 'node'
|
||||||
|
get_db_node_checked = check_keyword_arguments(db_utils.get_test_node)
|
||||||
|
db_node = get_db_node_checked(**kw)
|
||||||
|
|
||||||
# Let DB generate ID if it isn't specified explicitly
|
# Let DB generate ID if it isn't specified explicitly
|
||||||
if 'id' not in kw:
|
if 'id' not in kw:
|
||||||
del db_node['id']
|
del db_node['id']
|
||||||
@ -51,7 +76,11 @@ def get_test_port(ctxt, **kw):
|
|||||||
NOTE: The object leaves the attributes marked as changed, such
|
NOTE: The object leaves the attributes marked as changed, such
|
||||||
that a create() could be used to commit it to the DB.
|
that a create() could be used to commit it to the DB.
|
||||||
"""
|
"""
|
||||||
db_port = db_utils.get_test_port(**kw)
|
kw['object_type'] = 'port'
|
||||||
|
get_db_port_checked = check_keyword_arguments(
|
||||||
|
db_utils.get_test_port)
|
||||||
|
db_port = get_db_port_checked(**kw)
|
||||||
|
|
||||||
# Let DB generate ID if it isn't specified explicitly
|
# Let DB generate ID if it isn't specified explicitly
|
||||||
if 'id' not in kw:
|
if 'id' not in kw:
|
||||||
del db_port['id']
|
del db_port['id']
|
||||||
@ -78,7 +107,11 @@ def get_test_chassis(ctxt, **kw):
|
|||||||
NOTE: The object leaves the attributes marked as changed, such
|
NOTE: The object leaves the attributes marked as changed, such
|
||||||
that a create() could be used to commit it to the DB.
|
that a create() could be used to commit it to the DB.
|
||||||
"""
|
"""
|
||||||
db_chassis = db_utils.get_test_chassis(**kw)
|
kw['object_type'] = 'chassis'
|
||||||
|
get_db_chassis_checked = check_keyword_arguments(
|
||||||
|
db_utils.get_test_chassis)
|
||||||
|
db_chassis = get_db_chassis_checked(**kw)
|
||||||
|
|
||||||
# Let DB generate ID if it isn't specified explicitly
|
# Let DB generate ID if it isn't specified explicitly
|
||||||
if 'id' not in kw:
|
if 'id' not in kw:
|
||||||
del db_chassis['id']
|
del db_chassis['id']
|
||||||
@ -105,7 +138,11 @@ def get_test_portgroup(ctxt, **kw):
|
|||||||
NOTE: The object leaves the attributes marked as changed, such
|
NOTE: The object leaves the attributes marked as changed, such
|
||||||
that a create() could be used to commit it to the DB.
|
that a create() could be used to commit it to the DB.
|
||||||
"""
|
"""
|
||||||
db_portgroup = db_utils.get_test_portgroup(**kw)
|
kw['object_type'] = 'portgroup'
|
||||||
|
get_db_port_group_checked = check_keyword_arguments(
|
||||||
|
db_utils.get_test_portgroup)
|
||||||
|
db_portgroup = get_db_port_group_checked(**kw)
|
||||||
|
|
||||||
# Let DB generate ID if it isn't specified explicitly
|
# Let DB generate ID if it isn't specified explicitly
|
||||||
if 'id' not in kw:
|
if 'id' not in kw:
|
||||||
del db_portgroup['id']
|
del db_portgroup['id']
|
||||||
|
Loading…
x
Reference in New Issue
Block a user