'A test for LP bug #781410 -- glance should fail more gracefully
on requests for images that have been removed from the fs'

def test_api_response_when_image_deleted_from_filesystem(self):

    self.cleanup()
    self.start_servers()
    image_data = ('*' * FIVE_KB)
    headers = minimal_headers('Image1')
    path = ('http://%s:%d/v1/images' % ('127.0.0.1', self.api_port))
    http = httplib2.Http()
    (response, content) = http.request(path, 'POST', headers=headers, body=image_data)
    self.assertEqual(http_client.CREATED, response.status)
    data = jsonutils.loads(content)
    self.assertEqual(hashlib.md5(image_data).hexdigest(), data['image']['checksum'])
    self.assertEqual(FIVE_KB, data['image']['size'])
    self.assertEqual('Image1', data['image']['name'])
    self.assertTrue(data['image']['is_public'])
    image_path = ('%s/images/%s' % (self.test_dir, data['image']['id']))
    os.remove(image_path)
    path = ('http://%s:%d/v1/images/%s' % ('127.0.0.1', self.api_port, data['image']['id']))
    http = httplib2.Http()
    (response, content) = http.request(path, 'HEAD')
    self.assertEqual(http_client.OK, response.status)
    self.assertEqual('Image1', response['x-image-meta-name'])
    path = ('http://%s:%d/v1/images/1' % ('127.0.0.1', self.api_port))
    http = httplib2.Http()
    (response, content) = http.request(path, 'GET')
    self.assertEqual(http_client.NOT_FOUND, response.status)
    self.stop_servers()
