'Test that the ETag header matches the x-image-meta-checksum'

def test_etag_equals_checksum_header(self):

    fixture_headers = {'x-image-meta-store': 'file', 'x-image-meta-disk-format': 'vhd', 'x-image-meta-container-format': 'ovf', 'x-image-meta-name': 'fake    image    #3'}
    image_contents = 'chunk00000remainder'
    image_checksum = hashlib.md5(image_contents).hexdigest()
    req = webob.Request.blank('/images')
    req.method = 'POST'
    for (k, v) in six.iteritems(fixture_headers):
        req.headers[k] = v
    req.headers['Content-Type'] = 'application/octet-stream'
    req.body = image_contents
    res = req.get_response(self.api)
    self.assertEqual(http_client.CREATED, res.status_int)
    image = jsonutils.loads(res.body)['image']
    expected_headers = {'x-image-meta-checksum': image_checksum, 'etag': image_checksum}
    req = webob.Request.blank(('/images/%s' % image['id']))
    req.method = 'HEAD'
    res = req.get_response(self.api)
    self.assertEqual(http_client.OK, res.status_int)
    for key in expected_headers.keys():
        self.assertIn(key, res.headers, ("required    header    '%s'    missing    from    returned    headers" % key))
    for (key, value) in six.iteritems(expected_headers):
        self.assertEqual(value, res.headers[key])
