简体   繁体   English

Openstack Python SDK-Glance不返回图像MD5

[英]Openstack Python SDK - Glance does not return image MD5

I'm trying to download an OpenStack image from glance using only the Openstack Python SDK, but I only get this error: 我正在尝试仅使用Openstack Python SDK从一目了然下载OpenStack映像,但是我仅收到此错误:

Traceback (most recent call last):
  File "/home/openstack/discovery/discovery.py", line 222, in <module>
    main(sys.argv[1:])
  File "/home/openstack/discovery/discovery.py", line 117, in main
    image_service.download_image(image)
  File "/usr/local/lib/python2.7/dist-packages/openstack/image/v2/_proxy.py", line 72, in download_image
    return image.download(self.session)
  File "/usr/local/lib/python2.7/dist-packages/openstack/image/v2/image.py", line 166, in download
    checksum = resp.headers["Content-MD5"]
  File "/usr/local/lib/python2.7/dist-packages/requests/structures.py", line 54, in __getitem__
    return self._store[key.lower()][1]
KeyError: 'content-md5'

The weird part is that if I run the code using an IDE (PyCharm with remote debug) or as a script (python script.py -i ...) I get the error, but if I run each line using a python interpreter (ipython/python) the error does not happen! 奇怪的是,如果我使用IDE(带有远程调试的PyCharm)或作为脚本(python script.py -i ...)运行代码,则会收到错误消息,但是如果我使用python解释器运行每一行( ipython / python)不会发生错误! Have no idea why. 不知道为什么。

Here is the code I'm using: 这是我正在使用的代码:

...
image_name = node.name + "_" + time.strftime("%Y-%m-%d_%H-%M-%S")
print "Getting data from", node.name
compute_service.create_server_image(node, image_name)
image = image_service.find_image(image_name)
image_service.wait_for_status(image, 'active')
fileName = "%s.img" % image.name

with open(str(fileName), 'w+') as imgFile:
    imgFile.write(image.download(conn.image.session))
...

This code ends up calling the API in this file /usr/local/lib/python2.7/dist-packages/openstack/image/v2/image.py , with this method: 这段代码最终使用以下方法调用此文件/usr/local/lib/python2.7/dist-packages/openstack/image/v2/image.py的API:

def download(self, session):
    """Download the data contained in an image"""
    # TODO(briancurtin): This method should probably offload the get
    # operation into another thread or something of that nature.
    url = utils.urljoin(self.base_path, self.id, 'file')
    resp = session.get(url, endpoint_filter=self.service)

    checksum = resp.headers["Content-MD5"]
    digest = hashlib.md5(resp.content).hexdigest()
    if digest != checksum:
        raise exceptions.InvalidResponse("checksum mismatch")

    return resp.content

The resp.headers variable has no key "Content-MD5". resp.headers变量没有键“ Content-MD5”。 This is the value I found for it: 这是我为它找到的值:

{'Date': 'Thu, 01 Sep 2016 20:17:01 GMT', 'Transfer-Encoding': 'chunked', 
 'Connection': 'keep-alive', 'Content-Type': 'application/octet-stream', 
 'X-Openstack-Request-Id': 'req-9eb16897-1398-4ab2-9cd4-45706e92819c'}

But according to the REST API documentationm the response should return with the key Content-MD5: http://developer.openstack.org/api-ref/image/v2/?expanded=download-binary-image-data-detail 但是根据REST API文档,响应应该返回键Content-MD5: http : //developer.openstack.org/api-ref/image/v2/? expanded= download -binary-image-data-detail

If I just comment the MD5 check the download works fine, but this is inside the SDK so I can't/shouldn't change it. 如果我只是评论MD5,请检查下载是否正常,但这在SDK内,因此我不能/不应该更改它。 Anyone have any suggestion on how to achieve this using the OpenStack Python SDK? 任何人都对如何使用OpenStack Python SDK实现此建议? Is this an SDK bug? 这是SDK错误吗?

Turns out this was indeed a bug SDK/Glance. 事实证明,这确实是一个错误的SDK / Glance。 More details about it can be found here: https://bugs.launchpad.net/python-openstacksdk/+bug/1619675 可以在这里找到有关它的更多详细信息: https : //bugs.launchpad.net/python-openstacksdk/+bug/1619675

And the fix implemented can be seen here: https://github.com/openstack/python-openstacksdk/commit/759651f4a9eae2ba546f46613550a4cb10ddd964 可以在这里看到实现的修复程序: https : //github.com/openstack/python-openstacksdk/commit/759651f4a9eae2ba546f46613550a4cb10ddd964

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM