示例#1
0
    def test_save(self):
        uuid = self.fake_node['uuid']
        test_time = datetime.datetime(2000, 1, 1, 0, 0)
        with mock.patch.object(self.dbapi, 'get_node_by_uuid',
                               autospec=True) as mock_get_node:
            mock_get_node.return_value = self.fake_node
            with mock.patch.object(self.dbapi, 'update_node',
                                   autospec=True) as mock_update_node:
                mock_update_node.return_value = db_utils.get_test_node(
                    properties={"fake": "property"}, driver='fake-driver',
                    driver_internal_info={}, updated_at=test_time)
                n = objects.Node.get(self.context, uuid)
                self.assertEqual({"private_state": "secret value"},
                                 n.driver_internal_info)
                n.properties = {"fake": "property"}
                n.driver = "fake-driver"
                n.save()

                mock_get_node.assert_called_once_with(uuid)
                mock_update_node.assert_called_once_with(
                    uuid, {'properties': {"fake": "property"},
                           'driver': 'fake-driver',
                           'driver_internal_info': {},
                           'version': objects.Node.VERSION})
                self.assertEqual(self.context, n._context)
                res_updated_at = (n.updated_at).replace(tzinfo=None)
                self.assertEqual(test_time, res_updated_at)
                self.assertEqual({}, n.driver_internal_info)
示例#2
0
def node_post_data(**kw):
    node = utils.get_test_node(**kw)
    # These values are not part of the API object
    node.pop('conductor_affinity')
    node.pop('chassis_id')
    node.pop('tags')
    internal = node_controller.NodePatchType.internal_attrs()
    return remove_internal(node, internal)
示例#3
0
    def test_save_truncated(self, log_mock):
        uuid = self.fake_node['uuid']
        test_time = datetime.datetime(2000, 1, 1, 0, 0)
        with mock.patch.object(self.dbapi, 'get_node_by_uuid',
                               autospec=True) as mock_get_node:
            mock_get_node.return_value = self.fake_node
            with mock.patch.object(self.dbapi, 'update_node',
                                   autospec=True) as mock_update_node:
                mock_update_node.return_value = db_utils.get_test_node(
                    properties={'fake': 'property'}, driver='fake-driver',
                    driver_internal_info={}, updated_at=test_time)
                n = objects.Node.get(self.context, uuid)
                self.assertEqual({'private_state': 'secret value'},
                                 n.driver_internal_info)
                n.properties = {'fake': 'property'}
                n.driver = 'fake-driver'
                last_error = 'BOOM' * 2000
                maintenance_reason = last_error
                n.last_error = last_error
                n.maintenance_reason = maintenance_reason

                n.save()

                self.assertEqual([
                    mock.call.info(
                        'Truncating too long %s to %s characters for node %s',
                        'last_error',
                        node_objects.CONF.log_in_db_max_size,
                        uuid),
                    mock.call.info(
                        'Truncating too long %s to %s characters for node %s',
                        'maintenance_reason',
                        node_objects.CONF.log_in_db_max_size,
                        uuid)],
                    log_mock.mock_calls)

                mock_get_node.assert_called_once_with(uuid)
                mock_update_node.assert_called_once_with(
                    uuid,
                    {
                        'properties': {'fake': 'property'},
                        'driver': 'fake-driver',
                        'driver_internal_info': {},
                        'version': objects.Node.VERSION,
                        'maintenance_reason':
                            maintenance_reason[
                                0:node_objects.CONF.log_in_db_max_size],
                        'last_error':
                            last_error[
                            0:node_objects.CONF.log_in_db_max_size]
                    }
                )
                self.assertEqual(self.context, n._context)
                res_updated_at = (n.updated_at).replace(tzinfo=None)
                self.assertEqual(test_time, res_updated_at)
                self.assertEqual({}, n.driver_internal_info)
示例#4
0
    def test_create(self):
        node = objects.Node(self.context, **self.fake_node)
        with mock.patch.object(self.dbapi, 'create_node',
                               autospec=True) as mock_create_node:
            mock_create_node.return_value = db_utils.get_test_node()

            node.create()

            args, _kwargs = mock_create_node.call_args
            self.assertEqual(objects.Node.VERSION, args[0]['version'])
示例#5
0
    def test_get_by_name(self):
        node_name = 'test'
        fake_node = db_utils.get_test_node(name=node_name)
        with mock.patch.object(self.dbapi, 'get_node_by_name',
                               autospec=True) as mock_get_node:
            mock_get_node.return_value = fake_node

            node = objects.Node.get_by_name(self.context, node_name)

            mock_get_node.assert_called_once_with(node_name)
            self.assertEqual(self.context, node._context)
示例#6
0
def node_post_data(**kw):
    node = utils.get_test_node(**kw)
    # These values are not part of the API object
    node.pop('conductor_affinity')
    node.pop('chassis_id')
    node.pop('tags')
    # TODO(vdrok): Remove popping network_interface when it's exposed in API
    if 'network_interface' not in kw:
        node.pop('network_interface')
    internal = node_controller.NodePatchType.internal_attrs()
    return remove_internal(node, internal)
示例#7
0
def get_test_node(ctxt, **kw):
    """Return a Node object with appropriate attributes.

    NOTE: The object leaves the attributes marked as changed, such
    that a create() could be used to commit it to the DB.
    """
    db_node = db_utils.get_test_node(**kw)
    # Let DB generate ID if it isn't specified explicitly
    if 'id' not in kw:
        del db_node['id']
    node = objects.Node(ctxt)
    for key in db_node:
        setattr(node, key, db_node[key])
    return node
示例#8
0
 def test_save_with_conductor_group_uppercase(self):
     uuid = self.fake_node['uuid']
     with mock.patch.object(self.dbapi, 'get_node_by_uuid',
                            autospec=True) as mock_get_node:
         mock_get_node.return_value = self.fake_node
         with mock.patch.object(self.dbapi, 'update_node',
                                autospec=True) as mock_update_node:
             mock_update_node.return_value = (
                 db_utils.get_test_node(conductor_group='group1'))
             n = objects.Node.get(self.context, uuid)
             n.conductor_group = 'GROUP1'
             n.save()
             mock_update_node.assert_called_once_with(
                 uuid, {'conductor_group': 'group1',
                        'version': objects.Node.VERSION})
示例#9
0
def node_post_data(**kw):
    node = db_utils.get_test_node(**kw)
    # These values are not part of the API object
    node.pop('version')
    node.pop('conductor_affinity')
    node.pop('chassis_id')
    node.pop('tags')
    node.pop('traits')
    node.pop('allocation_id')

    # NOTE(jroll): pop out fields that were introduced in later API versions,
    # unless explicitly requested. Otherwise, these will cause tests using
    # older API versions to fail.
    for field in api_utils.VERSIONED_FIELDS:
        if field not in kw:
            node.pop(field, None)

    internal = node_controller.NodePatchType.internal_attrs()
    return remove_internal(node, internal)
示例#10
0
def node_post_data(**kw):
    node = utils.get_test_node(**kw)
    # These values are not part of the API object
    node.pop('conductor_affinity')
    node.pop('chassis_id')
    node.pop('tags')

    # NOTE(jroll): pop out fields that were introduced in later API versions,
    # unless explicitly requested. Otherwise, these will cause tests using
    # older API versions to fail.
    for iface in drivers_base.ALL_INTERFACES:
        name = '%s_interface' % iface
        if name not in kw:
            node.pop(name)
    if 'resource_class' not in kw:
        node.pop('resource_class')

    internal = node_controller.NodePatchType.internal_attrs()
    return remove_internal(node, internal)
示例#11
0
 def setUp(self):
     super(TestConvertToVersion, self).setUp()
     self.ctxt = context.get_admin_context()
     self.fake_node = db_utils.get_test_node(driver='fake-hardware')
示例#12
0
 def setUp(self):
     super(TestNodeObject, self).setUp()
     self.ctxt = context.get_admin_context()
     self.fake_node = db_utils.get_test_node()
     self.node = obj_utils.get_test_node(self.ctxt, **self.fake_node)
示例#13
0
def post_get_test_port(**kw):
    port = apiutils.port_post_data(**kw)
    node = dbutils.get_test_node()
    port['node_uuid'] = kw.get('node_uuid', node['uuid'])
    return port
示例#14
0
 def setUp(self):
     super(TestNodeObject, self).setUp()
     self.fake_node = utils.get_test_node()
def post_get_test_volume_target(**kw):
    target = apiutils.volume_target_post_data(**kw)
    node = dbutils.get_test_node()
    target['node_uuid'] = kw.get('node_uuid', node['uuid'])
    return target
示例#16
0
 def setUp(self):
     super(RPCAPITestCase, self).setUp()
     self.fake_node = dbutils.get_test_node(driver='fake-driver')
     self.fake_node_obj = objects.Node._from_db_object(
         objects.Node(self.context), self.fake_node)
示例#17
0
def post_get_test_portgroup(**kw):
    """Return a Portgroup object with appropriate attributes."""
    portgroup = portgroup_post_data(**kw)
    node = utils.get_test_node()
    portgroup['node_uuid'] = kw.get('node_uuid', node['uuid'])
    return portgroup
示例#18
0
def post_get_test_volume_target(**kw):
    target = apiutils.volume_target_post_data(**kw)
    node = dbutils.get_test_node()
    target['node_uuid'] = kw.get('node_uuid', node['uuid'])
    return target
示例#19
0
 def setUp(self):
     super(TestBasicAuthMiddleware, self).setUp()
     self.environ = {'fake.cache': utils.FakeMemcache()}
     self.fake_db_node = db_utils.get_test_node(chassis_id=None)
示例#20
0
 def setUp(self):
     super(RPCAPITestCase, self).setUp()
     self.fake_node = db_utils.get_test_node(driver='fake-driver')
     self.fake_node_obj = objects.Node._from_db_object(
         self.context, objects.Node(), self.fake_node)
     self.fake_portgroup = db_utils.get_test_portgroup()
示例#21
0
def post_get_test_port(**kw):
    port = apiutils.port_post_data(**kw)
    node = dbutils.get_test_node()
    port['node_uuid'] = kw.get('node_uuid', node['uuid'])
    return port
示例#22
0
文件: utils.py 项目: pshchelo/ironic
def post_get_test_portgroup(**kw):
    """Return a Portgroup object with appropriate attributes."""
    portgroup = portgroup_post_data(**kw)
    node = db_utils.get_test_node()
    portgroup['node_uuid'] = kw.get('node_uuid', node['uuid'])
    return portgroup
示例#23
0
def post_get_test_volume_connector(**kw):
    connector = apiutils.volume_connector_post_data(**kw)
    node = dbutils.get_test_node()
    connector['node_uuid'] = kw.get('node_uuid', node['uuid'])
    return connector
示例#24
0
 def setUp(self):
     super(TestConvertToVersion, self).setUp()
     self.ctxt = context.get_admin_context()
     self.fake_node = db_utils.get_test_node(driver='fake-hardware')
示例#25
0
def post_get_test_volume_connector(**kw):
    connector = apiutils.volume_connector_post_data(**kw)
    node = dbutils.get_test_node()
    connector['node_uuid'] = kw.get('node_uuid', node['uuid'])
    return connector
示例#26
0
    def setUp(self):
        super(TestACL, self).setUp()

        self.environ = {'fake.cache': utils.FakeMemcache()}
        self.fake_db_node = db_utils.get_test_node(chassis_id=None)
        self.node_path = '/nodes/%s' % self.fake_db_node['uuid']
示例#27
0
 def setUp(self):
     super(TestNodePayloads, self).setUp()
     self.ctxt = context.get_admin_context()
     self.fake_node = db_utils.get_test_node()
     self.node = obj_utils.get_test_node(self.ctxt, **self.fake_node)