From 0e50837a374958d2863deef890879c960a05d8aa Mon Sep 17 00:00:00 2001
From: Abhishek Kekane <abhishek.kekane@nttdata.com>
Date: Wed, 16 Aug 2017 15:49:47 +0530
Subject: [PATCH] stage call fails with TypeError

image-stage call fails with TypeError saying 'stage() takes exactly
3 arguments (4 given). The reason is stage() also accepts image_size
as a argument which is not provided.

Further it raises 'NoneType' object has no attribute 'headers'. The
reason is stage() internally calls upload method which
returns a object of RequestIdWrapper on body (which is None) and
response. In stage call it again tries to add request id which requires
response object but instead it has a RequestIdWrapper which fails to
retrieve headers.

Change-Id: I4de4be7a55f35c3533b53acd48042c7c95b4bdc0
Closes-bug: #1711090
---
 glanceclient/v2/images.py | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/glanceclient/v2/images.py b/glanceclient/v2/images.py
index d95ebca5..6d456ebd 100644
--- a/glanceclient/v2/images.py
+++ b/glanceclient/v2/images.py
@@ -240,16 +240,18 @@ class Controller(object):
         return body, resp
 
     @utils.add_req_id_to_object()
-    def stage(self, image_id, image_data):
+    def stage(self, image_id, image_data, image_size=None):
         """Upload the data to image staging.
 
         :param image_id: ID of the image to upload data for.
         :param image_data: File-like object supplying the data to upload.
+        :param image_size: Unused - present for backwards compatibility
         """
         url = '/v2/images/%s/stage' % image_id
-        return self.upload(image_id,
-                           image_data,
-                           u_url=url)
+        resp, body = self.upload(image_id,
+                                 image_data,
+                                 u_url=url)
+        return body, resp
 
     @utils.add_req_id_to_object()
     def image_import(self, image_id, method='glance-direct'):