'Ensure clone is cleaned up on failure.'

def test_clone_file_when_clone_fails(self):

    expected_src_path = 'fake_src_path'
    expected_dest_path = 'fake_dest_path'
    fake_volume_id = '0309c748-0d94-41f0-af46-4fbbd76686cf'
    fake_clone_op_id = 'c22ad299-ecec-4ec0-8de4-352b887bfce2'
    fake_clone_id_response = netapp_api.NaElement(etree.XML(('<results    status="passed">\n                                                                                                            <clone-id>\n                                                                                                                    <clone-id-info>\n                                                                                                                            <volume-uuid>%(volume)s</volume-uuid>\n                                                                                                                            <clone-op-id>%(clone_id)s</clone-op-id>\n                                                                                                                    </clone-id-info>\n                                                                                                            </clone-id>\n                                                                                                    </results>' % {'volume': fake_volume_id, 'clone_id': fake_clone_op_id})))
    fake_clone_list_response = netapp_api.NaElement(etree.XML(('<results>\n                                                                                                            <clone-list-status>\n                                                                                                                    <clone-id-info>\n                                                                                                                            <volume-uuid>%(volume)s</volume-uuid>\n                                                                                                                            <clone-op-id>%(clone_id)s</clone-op-id>\n                                                                                                                    </clone-id-info>\n                                                                                                                            <clone-op-id>%(clone_id)s</clone-op-id>\n                                                                                                            </clone-list-status>\n                                                                                                            <status>\n                                                                                                                    <ops-info>\n                                                                                                                            <clone-state>failed</clone-state>\n                                                                                                                    </ops-info>\n                                                                                                            </status>\n                                                                                                    </results>' % {'volume': fake_volume_id, 'clone_id': fake_clone_op_id})))
    fake_clone_clear_response = mock.Mock()
    self.connection.invoke_successfully.side_effect = [fake_clone_id_response, fake_clone_list_response, fake_clone_clear_response]
    self.assertRaises(netapp_api.NaApiError, self.client.clone_file, expected_src_path, expected_dest_path)
    (__, _args, _kwargs) = self.connection.invoke_successfully.mock_calls[0]
    actual_request = _args[0]
    enable_tunneling = _kwargs['enable_tunneling']
    actual_src_path = actual_request.get_child_by_name('source-path').get_content()
    actual_dest_path = actual_request.get_child_by_name('destination-path').get_content()
    self.assertEqual(expected_src_path, actual_src_path)
    self.assertEqual(expected_dest_path, actual_dest_path)
    self.assertIsNone(actual_request.get_child_by_name('destination-exists'))
    self.assertTrue(enable_tunneling)
    (__, _args, _kwargs) = self.connection.invoke_successfully.mock_calls[1]
    actual_request = _args[0]
    enable_tunneling = _kwargs['enable_tunneling']
    actual_clone_id = actual_request.get_child_by_name('clone-id')
    actual_clone_id_info = actual_clone_id.get_child_by_name('clone-id-info')
    actual_clone_op_id = actual_clone_id_info.get_child_by_name('clone-op-id').get_content()
    actual_volume_uuid = actual_clone_id_info.get_child_by_name('volume-uuid').get_content()
    self.assertEqual(fake_clone_op_id, actual_clone_op_id)
    self.assertEqual(fake_volume_id, actual_volume_uuid)
    self.assertTrue(enable_tunneling)
    (__, _args, _kwargs) = self.connection.invoke_successfully.mock_calls[2]
    actual_request = _args[0]
    enable_tunneling = _kwargs['enable_tunneling']
    actual_clone_id = actual_request.get_child_by_name('clone-id').get_content()
    self.assertEqual(fake_clone_op_id, actual_clone_id)
    self.assertTrue(enable_tunneling)
