'Test that the scrubber handles the case where an
exception occurs when _delete() is called. The scrubber
should not write out queue files in this case.'

def test_scrubber_delete_handles_exception(self):

    self.cleanup()
    self.start_servers(delayed_delete=True, daemon=False, default_store='file')
    self.assertEqual(self.api_server.default_store, 'file')
    path = ('http://%s:%d/v1/images' % ('127.0.0.1', self.api_port))
    (response, content) = self._send_http_request(path, 'POST', body='XXX')
    self.assertEqual(http_client.CREATED, response.status)
    image = jsonutils.loads(content)['image']
    self.assertEqual('active', image['status'])
    path = ('http://%s:%d/v1/images/%s' % ('127.0.0.1', self.api_port, image['id']))
    (response, content) = self._send_http_request(path, 'DELETE')
    self.assertEqual(http_client.OK, response.status)
    (response, content) = self._send_http_request(path, 'HEAD')
    self.assertEqual(http_client.OK, response.status)
    self.assertEqual('pending_delete', response['x-image-meta-status'])
    file_path = os.path.join(self.api_server.image_dir, image['id'])
    os.remove(file_path)
    time.sleep(self.api_server.scrub_time)
    exe_cmd = ('%s    -m    glance.cmd.scrubber' % sys.executable)
    cmd = ('%s    --config-file    %s' % (exe_cmd, self.scrubber_daemon.conf_file_name))
    (exitcode, out, err) = execute(cmd, raise_error=False)
    self.assertEqual(0, exitcode)
    self.wait_for_scrub(path)
    self.stop_servers()
