← Back to team overview

yahoo-eng-team team mailing list archive

[Bug 1513825] Re: code duplication : tenant checked twice for resource creation

 

Reviewed:  https://review.openstack.org/241984
Committed: https://git.openstack.org/cgit/openstack/neutron/commit/?id=5d53dfb8d64186b5b1d2f356fbff8f222e15d1b2
Submitter: Jenkins
Branch:    master

commit 5d53dfb8d64186b5b1d2f356fbff8f222e15d1b2
Author: Mathieu Rohon <mathieu.rohon@xxxxxxxxx>
Date:   Wed Nov 4 17:49:40 2015 +0000

    Avoid duplicating tenant check when creating resources
    
    The check of the tenant done in the method _get_tenant_id_for_create()
    is already did by the Neutron Controller in prepare_request_body(),
    with a call to attributes.populate_tenant_id().
    Moreover, when the Controller processes a "create" requests, it
    will add the 'tenant_id' to the resource dict.
    Thus, _get_tenant_id_for_create() can be deleted.
    Calls to this method are replaced by the res['tenant_id'].
    
    Changes have to be done in UT to explicitly add the tenant_id while
    creating resources, since the UT framework is bypassing the controller code
    that automatically adds the tenant_id to the resource.
    
    Co-Authored-By: Hong Hui Xiao <xiaohhui@xxxxxxxxxx>
    Closes-Bug: #1513825
    Change-Id: Icea06dc81344e1120bdf986a97a6b1094bbb765e
    Depends-On: I31022e9230fc5404c6a94edabbb08d2b079c3a09
    Depends-On: Iea3f014ef17a1e1b755cd2efe99afd1a36ebbc6a
    Depends-On: I604602d023e0cbf7f6591149f914d73217d7a574


** Changed in: neutron
       Status: In Progress => Fix Released

-- 
You received this bug notification because you are a member of Yahoo!
Engineering Team, which is subscribed to neutron.
https://bugs.launchpad.net/bugs/1513825

Title:
  code duplication : tenant checked twice for resource creation

Status in neutron:
  Fix Released

Bug description:
  The check of the tenant done in neutron/db/common_db_mixin._get_tenant_id_for_create() is already did by the
  Neutron Controller in prepare_request_body(), with a call to attibutes.populate_tenant_id().
  Moreover, when the Controller processes a "create" requests, it will add the 'tenant_id' to the resource dict.

  So instead of calling the _get_tenant_id_for_create(), modules can
  directly get the tenant_id in the resource dict.

  A firsts patch has been submitted to avoid duplicated code [1], but it
  requires a bigger effort to add the tenant_id in requests used during
  UTs. Indeed, UT framework seems to bypass the controller. Thus, the
  tenant_id is not automatically added by the controller during UTs. The
  _get_tenant_id_for_create() was convenient for UTs, since it retrieves
  the tenant_id from the context, if it is not in the resource dict.

  [1]https://review.openstack.org/#/c/241984/

To manage notifications about this bug go to:
https://bugs.launchpad.net/neutron/+bug/1513825/+subscriptions


References