Comment 12 for bug 1525259

Revision history for this message
Abhishek Kekane (abhishek-kekane) wrote : Re: Add request_ids attribute to v2 schemas

Hi Stuart, Erno,

A potential issue with the current approach:

Let’s take an example here: images.get() API call

Here we are making two 'requests': First the http_client.get() as a part of images.Contoller.get() itself
and second in schemas.Controller.get() via the images.Controller.model() to fetch glance schema for creating warlock model object.

Inserting 'hook' into the first request is straight forward.

To insert hook in second case we need to pass request ids list to schemas.Controller.get() from model()
and model() will inturn get this list from images.Controller.get() API method.

Now here we have a problem, we cannot pass extra arguements to model() like:

self.model(request_ids=request_ids, **body)

Alternative way: If we cannot pass request ids list to model() let’s try returning one:

diff --git a/glanceclient/v2/images.py b/glanceclient/v2/images.py
index c065535..b090c02 100644
--- a/glanceclient/v2/images.py
+++ b/glanceclient/v2/images.py
@@ -38,10 +38,11 @@ class Controller(object):

     @utils.memoized_property
     def model(self):
- schema = self.schema_client.get('image')
+ request_ids = []
+ schema = self.schema_client.get('image', request_ids=request_ids)
         warlock_model = warlock.model_factory(schema.raw(),
                                               schemas.SchemaBasedModel)
- return warlock_model
+ return warlock_model, request_ids

     @utils.memoized_property
     def unvalidated_model(self):
@@ -183,7 +184,9 @@ class Controller(object):
         # NOTE(bcwaldon): remove 'self' for now until we have an elegant
         # way to pass it into the model constructor without conflict
         body.pop('self', None)
- return self.model(**body)
+ model, req_ids = self.model(**body)
+ request_ids.extend(req_ids)
+ return model

But again this approach is also giving problem:
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "glanceclient/v2/images.py", line 188, in get
    model, req_ids = self.model(**body)
TypeError: 'tuple' object is not callable
>>>
Also this means we need to make lot of changes to every method that uses model().

This is only required if we want the request id for fetching schema from glance. If we do not want to retrieve this particular request id then there will be no issue so please suggest whether
we should exclude this request id or not.