'Test create cloned volume.'

@mock.patch.object(qnap.QnapISCSIDriver, '_get_lun_naa_from_volume_metadata')
@mock.patch.object(qnap.QnapISCSIDriver, '_gen_random_name')
@mock.patch.object(qnap.QnapISCSIDriver, '_get_volume_metadata')
@mock.patch('cinder.volume.drivers.qnap.QnapAPIExecutor')
def test_create_cloned_volume_volume_size_less_src_verf(self, mock_api_executor, mock_get_volume_metadata, mock_gen_random_name, mock_get_lun_naa_from_volume_metadata):

    fake_volume = VolumeClass('fakeDisplayName', 'fakeId', 90, 'fakeLunName')
    fake_src_vref = VolumeClass('fakeSrcVrefName', 'fakeId', 100, 'fakeSrcVref')
    mock_get_lun_naa_from_volume_metadata.return_value = 'fakeLunNaa'
    mock_api_executor.return_value.get_basic_info.return_value = ('ES1640dc    ', 'ES1640dc    ', '1.1.3')
    mock_get_volume_metadata.return_value = {}
    mock_api_executor.return_value.get_lun_info.side_effect = [self.get_lun_info_return_value(), None, self.get_lun_info_return_value()]
    mock_gen_random_name.side_effect = ['fakeSnapshot', 'fakeLun']
    mock_api_executor.return_value.get_snapshot_info.side_effect = [None, self.get_snapshot_info_return_value()]
    mock_api_executor.return_value.create_snapshot_api.return_value = 'fakeSnapshotId'
    mock_api_executor.return_value.clone_snapshot.return_value = None
    self.driver = qnap.QnapISCSIDriver(configuration=create_configuration('admin', 'qnapadmin', 'http://1.2.3.4:8080', 'Pool1', True))
    self.driver.do_setup('context')
    self.driver.create_cloned_volume(fake_volume, fake_src_vref)
    expected_call_list = [mock.call(LUNNAA='fakeLunNaa'), mock.call(LUNName='fakeLun'), mock.call(LUNName='fakeLun')]
    self.assertEqual(expected_call_list, mock_api_executor.return_value.get_lun_info.call_args_list)
    expected_call_list = [mock.call(lun_index='fakeLunIndex', snapshot_name='fakeSnapshot'), mock.call(lun_index='fakeLunIndex', snapshot_name='fakeSnapshot')]
    self.assertEqual(expected_call_list, mock_api_executor.return_value.get_snapshot_info.call_args_list)
    mock_api_return = mock_api_executor.return_value
    mock_api_return.create_snapshot_api.assert_called_once_with('fakeLunIndex', 'fakeSnapshot')
    mock_api_return.clone_snapshot.assert_called_once_with('fakeSnapshotId', 'fakeLun')
