'Make sure initialize_connection returns correct information.'

@mock.patch.object(cinder.volume.targets.iscsi.ISCSITarget, '_get_target_chap_auth')
@mock.patch.object(db, 'volume_admin_metadata_get')
@mock.patch.object(db.sqlalchemy.api, 'volume_get')
@mock.patch.object(db, 'volume_update')
def test_initialize_connection_qos_per_gb(self, _mock_volume_update, _mock_volume_get, _mock_volume_admin_metadata_get, mock_get_target):

    _fake_admin_meta = [{'key': 'fake-key', 'value': 'fake-value'}]
    _fake_volume = {'size': 3, 'volume_type_id': fake.VOLUME_TYPE_ID, 'name': 'fake_name', 'host': 'fake_host', 'id': fake.VOLUME_ID, 'volume_admin_metadata': _fake_admin_meta}
    fake_volume_obj = fake_volume.fake_volume_obj(self.context, **_fake_volume)
    _mock_volume_get.return_value = _fake_volume
    _mock_volume_update.return_value = _fake_volume
    _mock_volume_admin_metadata_get.return_value = {'fake-key': 'fake-value'}
    connector = {'ip': 'IP', 'initiator': 'INITIATOR'}
    qos_values = {'consumer': 'front-end', 'specs': {'write_iops_sec_per_gb': 5, 'read_iops_sec_per_gb': 7700, 'total_iops_sec_per_gb': 300000}}
    with mock.patch.object(cinder.volume.volume_types, 'get_volume_type_qos_specs') as type_qos:
        with mock.patch.object(cinder.tests.fake_driver.FakeLoggingVolumeDriver, 'initialize_connection') as driver_init:
            type_qos.return_value = dict(qos_specs=qos_values)
            driver_init.return_value = {'data': {}}
            mock_get_target.return_value = None
            qos_specs_expected = {'write_iops_sec': 15, 'read_iops_sec': 23100, 'total_iops_sec': 900000}
            conn_info = self.volume.initialize_connection(self.context, fake_volume_obj, connector)
            self.assertDictEqual(qos_specs_expected, conn_info['data']['qos_specs'])
            qos_values.update({'consumer': 'both'})
            conn_info = self.volume.initialize_connection(self.context, fake_volume_obj, connector)
            self.assertDictEqual(qos_specs_expected, conn_info['data']['qos_specs'])
