code duplication : tenant checked twice for resource creation

Bug #1513825 reported by Mathieu Rohon
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
neutron
Fix Released
Low
Mathieu Rohon

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/

tags: added: low-hanging-fruit
Henry Gessau (gessau)
Changed in neutron:
importance: Undecided → Low
status: New → Confirmed
Hong Hui Xiao (xiaohhui)
Changed in neutron:
assignee: nobody → Hong Hui Xiao (xiaohhui)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to neutron (master)

Fix proposed to branch: master
Review: https://review.openstack.org/242841

Changed in neutron:
assignee: Hong Hui Xiao (xiaohhui) → Mathieu Rohon (mathieu-rohon)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Change abandoned on neutron (master)

Change abandoned by Hong Hui Xiao (<email address hidden>) on branch: master
Review: https://review.openstack.org/242841
Reason: Abandon the change based on the discussion.

Changed in neutron:
assignee: Mathieu Rohon (mathieu-rohon) → nobody
status: Confirmed → Incomplete
Revision history for this message
Henry Gessau (gessau) wrote :

Mathieu is still working on this, via https://review.openstack.org/241984

Changed in neutron:
assignee: nobody → Mathieu Rohon (mathieu-rohon)
tags: added: lbaas
Changed in neutron:
status: Incomplete → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to neutron-lbaas (master)

Fix proposed to branch: master
Review: https://review.openstack.org/256298

tags: added: vpnaas
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to neutron-vpnaas (master)

Fix proposed to branch: master
Review: https://review.openstack.org/256573

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to neutron-lbaas (master)

Fix proposed to branch: master
Review: https://review.openstack.org/256574

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Change abandoned on neutron-lbaas (master)

Change abandoned by Mathieu Rohon (<email address hidden>) on branch: master
Review: https://review.openstack.org/256298
Reason: the correct patch with a unified change-id for every change related to this bug is here :

https://review.openstack.org/#/c/256574/

tags: added: fwaas
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to neutron-fwaas (master)

Fix proposed to branch: master
Review: https://review.openstack.org/256582

Revision history for this message
OpenStack Infra (hudson-openstack) wrote :

Fix proposed to branch: master
Review: https://review.openstack.org/259064

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Change abandoned on neutron-fwaas (master)

Change abandoned by Mathieu Rohon (<email address hidden>) on branch: master
Review: https://review.openstack.org/256582

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to neutron-lbaas (master)

Fix proposed to branch: master
Review: https://review.openstack.org/259068

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Change abandoned on neutron-lbaas (master)

Change abandoned by Mathieu Rohon (<email address hidden>) on branch: master
Review: https://review.openstack.org/256574
Reason: modifying change-id so that I can add a depends-on in the change https://review.openstack.org/#/c/241984/

the new change ID is : Iea3f014ef17a1e1b755cd2efe99afd1a36ebbc6a

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to neutron-vpnaas (master)

Fix proposed to branch: master
Review: https://review.openstack.org/259079

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Change abandoned on neutron-vpnaas (master)

Change abandoned by Mathieu Rohon (<email address hidden>) on branch: master
Review: https://review.openstack.org/256573
Reason: modifying change-id so that I can add a depends-on in the change https://review.openstack.org/#/c/241984/

the new change ID is : I604602d023e0cbf7f6591149f914d73217d7a574

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to neutron-vpnaas (master)

Reviewed: https://review.openstack.org/259079
Committed: https://git.openstack.org/cgit/openstack/neutron-vpnaas/commit/?id=7e8b817173cfdbf6ea953eead15787a2f2d83fee
Submitter: Jenkins
Branch: master

commit 7e8b817173cfdbf6ea953eead15787a2f2d83fee
Author: Mathieu Rohon <email address hidden>
Date: Fri Dec 11 16:36:09 2015 +0000

    Avoid duplicating tenant check when creating resources

    When the Neutron Controller processes a "create" request, it
    will check that the tenant_id is valid and add it to the
    resource dict. Hence, the _get_tenant_id_for_create() can be removed,
    as proposed in Neutron.

    Change-Id: I604602d023e0cbf7f6591149f914d73217d7a574
    Partial-Bug: 1513825

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to neutron-fwaas (master)

Reviewed: https://review.openstack.org/259064
Committed: https://git.openstack.org/cgit/openstack/neutron-fwaas/commit/?id=c89adc708d8becd23bb3a41785dc5765362441ae
Submitter: Jenkins
Branch: master

commit c89adc708d8becd23bb3a41785dc5765362441ae
Author: Mathieu Rohon <email address hidden>
Date: Fri Dec 11 16:54:29 2015 +0000

    Avoid duplicating tenant check when creating resources

    When the Neutron Controller processes a "create" request, it
    will check that the tenant_id is valid and add it to the
    resource dict. Hence, the _get_tenant_id_for_create() can be removed,
    as proposed in Neutron.

    Change-Id: I31022e9230fc5404c6a94edabbb08d2b079c3a09
    Partial-Bug: 1513825

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to neutron-lbaas (master)

Reviewed: https://review.openstack.org/259068
Committed: https://git.openstack.org/cgit/openstack/neutron-lbaas/commit/?id=d0973af3fd97f7c5d5e618993f60df6b14953ebd
Submitter: Jenkins
Branch: master

commit d0973af3fd97f7c5d5e618993f60df6b14953ebd
Author: Mathieu Rohon <email address hidden>
Date: Fri Dec 11 09:08:52 2015 +0000

    Avoid duplicating tenant check when creating resources

    When the Neutron Controller processes a "create" request, it
    will check that the tenant_id is valid and add it to the
    resource dict. Hence, the _get_tenant_id_for_create() can be removed,
    as proposed in Neutron.

    Change-Id: Iea3f014ef17a1e1b755cd2efe99afd1a36ebbc6a
    Partial-Bug: 1513825

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to neutron (master)

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 <email address hidden>
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 <email address hidden>
    Closes-Bug: #1513825
    Change-Id: Icea06dc81344e1120bdf986a97a6b1094bbb765e
    Depends-On: I31022e9230fc5404c6a94edabbb08d2b079c3a09
    Depends-On: Iea3f014ef17a1e1b755cd2efe99afd1a36ebbc6a
    Depends-On: I604602d023e0cbf7f6591149f914d73217d7a574

Changed in neutron:
status: In Progress → Fix Released
Revision history for this message
Thierry Carrez (ttx) wrote : Fix included in openstack/neutron 8.0.0.0b2

This issue was fixed in the openstack/neutron 8.0.0.0b2 development milestone.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.