i'm trying download openstack image glance using openstack python sdk, error:
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 if run code using ide (pycharm remote debug) or script (python script.py -i ...) error, if run each line using python interpreter (ipython/python) error not happen! have no idea why.
here 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 open(str(filename), 'w+') imgfile: imgfile.write(image.download(conn.image.session)) ...
this code ends calling api in file /usr/local/lib/python2.7/dist-packages/openstack/image/v2/image.py
, method:
def download(self, session): """download data contained in image""" # todo(briancurtin): method should offload # operation thread or of 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". value found 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 rest api documentationm response should return key content-md5: http://developer.openstack.org/api-ref/image/v2/?expanded=download-binary-image-data-detail
if comment md5 check download works fine, inside sdk can't/shouldn't change it. have suggestion on how achieve using openstack python sdk? sdk bug?
turns out indeed bug sdk/glance. more details can found here: https://bugs.launchpad.net/python-openstacksdk/+bug/1619675
and fix implemented can seen here: https://github.com/openstack/python-openstacksdk/commit/759651f4a9eae2ba546f46613550a4cb10ddd964
Comments
Post a Comment