Move switch roles in teardown to base rbac classes

Registered by Felipe Monteiro

There is no need to add switch_role(switch_to_rbac_role=False) in the tearDown method of every single Patrole test class. It is more sensible and more maintainable to move switch_role(switch_to_rbac_role=False) to every base Patrole test class, e.g. to rbac_base.py in compute, identity, image, network and volume project folders.

The only edge case can be illustrated by the following example:

    def tearDown(self):
        rbac_utils.switch_role(self, switchToRbacRole=False)

        # Guarantee that the server is active during each test run.
        vm_state = self.client.show_server(self.server['id'])['server'][
            'OS-EXT-STS:vm_state'].upper()
        if vm_state != 'ACTIVE':
            self.client.resume_server(self.server['id'])
            waiters.wait_for_server_status(self.client, self.server['id'],
                                           'ACTIVE')

In this case, the call to rbac_utils.switch_role() should be removed; instead, super(...).tearDown() will be called before any test-specific clean up.

Blueprint information

Status:
Complete
Approver:
Samantha Blanco
Priority:
Undefined
Drafter:
Felipe Monteiro
Direction:
Needs approval
Assignee:
Mh Raies
Definition:
Approved
Series goal:
None
Implementation:
Implemented
Milestone target:
None
Started by
Felipe Monteiro
Completed by
Felipe Monteiro

Related branches

Sprints

Whiteboard

I have a one more idea on this.
Instead of using role switching in tearDown, we can move this completely feature to rule validation decorator. Thus completely removing tearDown method. And it is possible and I have verified it on my setup.
By doing this, we can remove tearDown method completely thus saving hundreds of lines of code.
During rule validation one every task is done, it will take the reference of testcase class and wiill switch the role back to admin. If this idea seems fine to you all, I can start working on this -- Mh Raies

Gerrit topic: https://review.openstack.org/#q,topic:bp/decrease-tempest-gate-runtime,n,z

Addressed by: https://review.openstack.org/438203
    Add role validation/run time efficiency to Patrole framework.

Gerrit topic: https://review.openstack.org/#q,topic:bp/refactor-teardown-switch-roles,n,z

Addressed by: https://review.openstack.org/444994
    Move switch roles in tearDown to base rbac classes.

Addressed by: https://review.openstack.org/444963
    Make user to group test in test_groups_rbac atomic so it passes.

Addressed by: https://review.openstack.org/445474
    Removal of re-switching of rbac-role from tearDown

@Felipe, kindly mark is as completed.

(?)

Work Items

This blueprint contains Public information 
Everyone can see this information.

Subscribers

No subscribers.