<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jun 23, 2015 at 5:48 AM, John Garbutt <span dir="ltr"><<a href="mailto:john@johngarbutt.com" target="_blank">john@johngarbutt.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 23 June 2015 at 03:30, Adam Young <<a href="mailto:ayoung@redhat.com">ayoung@redhat.com</a>> wrote:<br>
> On 06/22/2015 10:13 PM, Sajeesh Cimson Sasi wrote:<br>
> ________________________________<br>
> From: Adam Young [<a href="mailto:ayoung@redhat.com">ayoung@redhat.com</a>]<br>
> Sent: 23 June 2015 00:01:48<br>
> To: <a href="mailto:openstack-dev@lists.openstack.org">openstack-dev@lists.openstack.org</a><br>
> Subject: Re: [openstack-dev] [nova][keystone] Nova calls to Keystone<br>
><br>
> On 06/20/2015 02:46 PM, Sajeesh Cimson Sasi wrote:<br>
><br>
> Hi All,<br>
>    I need your advice for the implementation of the following blueprint.<br>
> <a href="https://review.openstack.org/#/c/160605" rel="noreferrer" target="_blank">https://review.openstack.org/#/c/160605</a> .<br>
>    All the use cases mentioned in the blueprint have  been implemented and<br>
> the complete code is up for review.<br>
>   <a href="https://review.openstack.org/#/c/149828/" rel="noreferrer" target="_blank">https://review.openstack.org/#/c/149828/</a><br>
>   However, we have an issue on which we need your input. In the nova quota<br>
> api call, keystone calls are made to<br>
>   get the parent_id and the child project or sub project list. This is<br>
> required because nova doesn't store any information<br>
>   regarding the hierarchy.<br>
<br>
</span>This is maybe a dumb question, but...<br>
<br>
Could this information not come from the keystone middleware at the<br>
same time we get all the other identity information, and just live in<br>
the context?<br>
<div><div class="h5"><br></div></div></blockquote><div><br></div><div>Unfortunately no, the project hierarchy information is only available in the GET /projects API - having this in the token so it could live in the context could be a nice improvement (although this would need to feasible for all types of tokens).<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">
>Hierarchy Information is  taken during run time,<br>
> from keystone. Since the keystone calls are<br>
>   made inside the api call, it is not possible to give any dummy or  fake<br>
> values while writing the unit tests. If the keystone<br>
>   call was made outside the api call, we could have given fake values in the<br>
> test cases. However,  the keystone calls for<br>
>    parent_id and child projects are made inside the api call.<br>
>   Can anyone suggest an elegant solution to this problem? What is the proper<br>
> way to implement this ?<br>
>     Did anybody encounter and solve a  similar  problem ? Many thanks for<br>
> any suggestions!<br>
>          best regards<br>
>            sajeesh<br>
><br>
><br>
> __________________________________________________________________________<br>
> OpenStack Development Mailing List (not for usage questions)<br>
> Unsubscribe: <a href="http://OpenStack-dev-request@lists.openstack.org?subject:unsubscribe" rel="noreferrer" target="_blank">OpenStack-dev-request@lists.openstack.org?subject:unsubscribe</a><br>
> <a href="http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev" rel="noreferrer" target="_blank">http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev</a><br>
><br>
> If you are talking to a live Keystone server, make sure you are using valid<br>
> data.<br>
><br>
> If you are not talking to a live keystone server in a unit test, use<br>
> RequestsMock or equivalent (varied by project)  to handle the HTTP request<br>
> and response.<br>
><br>
> A worst case approach is to monkey patch the Keystoneclient.  Please don't<br>
> do that if you can avoid it;  better to provide a mock alternative.<br>
><br>
><br>
> Hi Adam,<br>
>                Thanks a lot. I am not planning to talk to the live keystone<br>
> server in the unit test.<br>
>                I don't think that I need to monkey patch the KeystoneClient.<br>
> In the nova api code, there are two methods (get_parent_project and<br>
> get_immediate_child_list),which uses keystoneclient.I can monkey patch those<br>
> two methods to return fixed data according to a fake hierarchy. Am I right ?<br>
><br>
><br>
> Its not great, but not horrible.  It seems to match the scope of what you<br>
> are testing.  However, you might want to consider doing a mock for the whole<br>
> Keystoneclient call, as that really should beo utside of the unit test for<br>
> the Nova code.<br>
><br>
<br>
</div></div>Please use mock to do that for you, following the pattern of the<br>
existing Nova unit tests. I think you will find that easier.<br></blockquote><div><br></div><div>Maybe point out where he can find similar tests?<br><br></div><div>Thanks!<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Thanks,<br>
John<br>
<div class="HOEnZb"><div class="h5"><br>
__________________________________________________________________________<br>
OpenStack Development Mailing List (not for usage questions)<br>
Unsubscribe: <a href="http://OpenStack-dev-request@lists.openstack.org?subject:unsubscribe" rel="noreferrer" target="_blank">OpenStack-dev-request@lists.openstack.org?subject:unsubscribe</a><br>
<a href="http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev" rel="noreferrer" target="_blank">http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><font color="#666666">Rodrigo Duarte Sousa</font><div><font color="#666666">Senior Software Engineer at Advanced OpenStack Brazil<br></font><div><font color="#666666">Distributed Systems Laboratory<br></font><span style="color:rgb(102,102,102)">MSc</span><span style="color:rgb(102,102,102)"></span><span style="color:rgb(102,102,102)"> in Computer Science</span><font color="#666666"><br></font></div><div><font color="#666666">Federal University of Campina Grande<br>Campina Grande, PB - Brazil</font><br><font color="#3333ff"><a href="http://lsd.ufcg.edu.br/%7Erodrigods" target="_blank">http://<font color="#3333ff">rodrigods.com</font></a></font></div></div></div></div></div></div>
</div></div>