示例#1
0
文件: utils.py 项目: pshchelo/ironic
def volume_connector_post_data(**kw):
    connector = db_utils.get_test_volume_connector(**kw)
    # These values are not part of the API object
    connector.pop('node_id')
    connector.pop('version')
    internal = vc_controller.VolumeConnectorPatchType.internal_attrs()
    return remove_internal(connector, internal)
示例#2
0
def get_test_volume_connector(ctxt, **kw):
    """Return a VolumeConnector 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_volume_connector = db_utils.get_test_volume_connector(**kw)
    # Let DB generate ID if it isn't specified explicitly
    if 'id' not in kw:
        del db_volume_connector['id']
    volume_connector = objects.VolumeConnector(ctxt)
    for key in db_volume_connector:
        setattr(volume_connector, key, db_volume_connector[key])
    return volume_connector
示例#3
0
    def test_refresh(self):
        uuid = self.volume_connector_dict['uuid']
        old_connector_id = self.volume_connector_dict['connector_id']
        returns = [self.volume_connector_dict,
                   db_utils.get_test_volume_connector(
                       connector_id="new_connector_id")]
        expected = [mock.call(uuid), mock.call(uuid)]
        with mock.patch.object(self.dbapi, 'get_volume_connector_by_uuid',
                               side_effect=returns,
                               autospec=True) as mock_get_volume_connector:
            c = objects.VolumeConnector.get_by_uuid(self.context, uuid)
            self.assertEqual(old_connector_id, c.connector_id)
            c.refresh()
            self.assertEqual('new_connector_id', c.connector_id)

            self.assertEqual(expected,
                             mock_get_volume_connector.call_args_list)
            self.assertEqual(self.context, c._context)
    def test_save(self):
        uuid = self.volume_connector_dict['uuid']
        connector_id = "new_connector_id"
        test_time = datetime.datetime(2000, 1, 1, 0, 0)
        with mock.patch.object(self.dbapi, 'get_volume_connector_by_uuid',
                               autospec=True) as mock_get_volume_connector:
            mock_get_volume_connector.return_value = self.volume_connector_dict
            with mock.patch.object(self.dbapi, 'update_volume_connector',
                                   autospec=True) as mock_update_connector:
                mock_update_connector.return_value = (
                    utils.get_test_volume_connector(connector_id=connector_id,
                                                    updated_at=test_time))
                c = objects.VolumeConnector.get_by_uuid(self.context, uuid)
                c.connector_id = connector_id
                c.save()

                mock_get_volume_connector.assert_called_once_with(uuid)
                mock_update_connector.assert_called_once_with(
                    uuid,
                    {'connector_id': connector_id})
                self.assertEqual(self.context, c._context)
                res_updated_at = (c.updated_at).replace(tzinfo=None)
                self.assertEqual(test_time, res_updated_at)
示例#5
0
 def test_update_volume_connector(self):
     fake_volume_connector = db_utils.get_test_volume_connector()
     self._test_rpcapi('update_volume_connector',
                       'call',
                       version='1.35',
                       connector=fake_volume_connector)
示例#6
0
 def test_destroy_volume_connector(self):
     fake_volume_connector = dbutils.get_test_volume_connector()
     self._test_rpcapi('destroy_volume_connector',
                       'call',
                       version='1.35',
                       connector=fake_volume_connector)
示例#7
0
 def test_update_volume_connector(self):
     fake_volume_connector = dbutils.get_test_volume_connector()
     self._test_rpcapi('update_volume_connector',
                       'call',
                       version='1.35',
                       connector=fake_volume_connector)
示例#8
0
 def setUp(self):
     super(TestVolumeConnectorObject, self).setUp()
     self.volume_connector_dict = utils.get_test_volume_connector()
示例#9
0
 def test_destroy_volume_connector(self):
     fake_volume_connector = db_utils.get_test_volume_connector()
     self._test_rpcapi('destroy_volume_connector',
                       'call',
                       version='1.35',
                       connector=fake_volume_connector)
示例#10
0
文件: utils.py 项目: Hellcatlk/ironic
def volume_connector_post_data(**kw):
    connector = db_utils.get_test_volume_connector(**kw)
    return remove_other_fields(connector,
                               vc_controller.CONNECTOR_SCHEMA['properties'])
示例#11
0
 def setUp(self):
     super(TestVolumeConnectorObject, self).setUp()
     self.volume_connector_dict = db_utils.get_test_volume_connector()