'Tests that cached images are queryable'

@skip_if_disabled
def test_cache_manage_get_cached_images(self):

    self.cleanup()
    self.start_servers(**self.__dict__.copy())
    self.verify_no_images()
    image_id = self.add_image('Image1')
    self.verify_no_cached_images()
    path = ('http://%s:%d/v1/images/%s' % ('127.0.0.1', self.api_port, image_id))
    http = httplib2.Http()
    (response, content) = http.request(path, 'GET')
    self.assertEqual(http_client.OK, response.status)
    path = ('http://%s:%d/v1/cached_images' % ('127.0.0.1', self.api_port))
    http = httplib2.Http()
    (response, content) = http.request(path, 'GET')
    self.assertEqual(http_client.OK, response.status)
    data = jsonutils.loads(content)
    self.assertIn('cached_images', data)
    for cached_image in data['cached_images']:
        for time_key in ('last_modified', 'last_accessed'):
            time_val = cached_image[time_key]
            try:
                float(time_val)
            except ValueError:
                self.fail(('%s    time    %s    for    cached    image    %s    not    a    valid    float' % (time_key, time_val, cached_image['image_id'])))
    cached_images = data['cached_images']
    self.assertEqual(1, len(cached_images))
    self.assertEqual(image_id, cached_images[0]['image_id'])
    self.assertEqual(0, cached_images[0]['hits'])
    path = ('http://%s:%d/v1/images/%s' % ('127.0.0.1', self.api_port, image_id))
    http = httplib2.Http()
    (response, content) = http.request(path, 'GET')
    self.assertEqual(http_client.OK, response.status)
    path = ('http://%s:%d/v1/cached_images' % ('127.0.0.1', self.api_port))
    http = httplib2.Http()
    (response, content) = http.request(path, 'GET')
    self.assertEqual(http_client.OK, response.status)
    data = jsonutils.loads(content)
    self.assertIn('cached_images', data)
    cached_images = data['cached_images']
    self.assertEqual(1, len(cached_images))
    self.assertEqual(image_id, cached_images[0]['image_id'])
    self.assertEqual(1, cached_images[0]['hits'])
    self.stop_servers()
