Migrate to override_role for network tests-2

Now that override_role has supplanted switch_role (which has
been deprecated) in [0], the RBAC tests need to switch to use
override_role.

This PS switches to override_role for the network module
for 3 modules.

[0] I670fba358bf321eae0d22d18cea6d2f530f00716

Partially Implements: blueprint rbac-utils-contextmanager

Change-Id: Ie4bd14b5cb9520381c25d1a3df0973a038680fdf
diff --git a/patrole_tempest_plugin/tests/api/network/test_agents_rbac.py b/patrole_tempest_plugin/tests/api/network/test_agents_rbac.py
index fb747d6..6b03ebe 100644
--- a/patrole_tempest_plugin/tests/api/network/test_agents_rbac.py
+++ b/patrole_tempest_plugin/tests/api/network/test_agents_rbac.py
@@ -45,8 +45,8 @@
 
         RBAC test for the neutron get_agent policy
         """
-        self.rbac_utils.switch_role(self, toggle_rbac_role=True)
-        self.agents_client.show_agent(self.agent['id'])
+        with self.rbac_utils.override_role(self):
+            self.agents_client.show_agent(self.agent['id'])
 
     @decorators.idempotent_id('8ca68fdb-eaf6-4880-af82-ba0982949dec')
     @rbac_rule_validation.action(service="neutron",
@@ -60,9 +60,9 @@
         original_status = self.agent['admin_state_up']
         agent_status = {'admin_state_up': original_status}
 
-        self.rbac_utils.switch_role(self, toggle_rbac_role=True)
-        self.agents_client.update_agent(agent_id=self.agent['id'],
-                                        agent=agent_status)
+        with self.rbac_utils.override_role(self):
+            self.agents_client.update_agent(agent_id=self.agent['id'],
+                                            agent=agent_status)
 
 
 class L3AgentSchedulerRbacTest(base.BaseNetworkRbacTest):
@@ -105,8 +105,8 @@
 
         RBAC test for the neutron get_l3-routers policy
         """
-        self.rbac_utils.switch_role(self, toggle_rbac_role=True)
-        self.agents_client.list_routers_on_l3_agent(self.agent['id'])
+        with self.rbac_utils.override_role(self):
+            self.agents_client.list_routers_on_l3_agent(self.agent['id'])
 
     @decorators.idempotent_id('466b2a10-8747-4c09-855a-bd90a1c86ce7')
     @rbac_rule_validation.action(service="neutron",
@@ -116,9 +116,9 @@
 
         RBAC test for the neutron create_l3-router policy
         """
-        self.rbac_utils.switch_role(self, toggle_rbac_role=True)
-        self.agents_client.create_router_on_l3_agent(
-            self.agent['id'], router_id=self.router['id'])
+        with self.rbac_utils.override_role(self):
+            self.agents_client.create_router_on_l3_agent(
+                self.agent['id'], router_id=self.router['id'])
         self.addCleanup(
             test_utils.call_and_ignore_notfound_exc,
             self.agents_client.delete_router_from_l3_agent,
@@ -139,9 +139,9 @@
             self.agents_client.delete_router_from_l3_agent,
             self.agent['id'], router_id=self.router['id'])
 
-        self.rbac_utils.switch_role(self, toggle_rbac_role=True)
-        self.agents_client.delete_router_from_l3_agent(
-            self.agent['id'], router_id=self.router['id'])
+        with self.rbac_utils.override_role(self):
+            self.agents_client.delete_router_from_l3_agent(
+                self.agent['id'], router_id=self.router['id'])
 
 
 class DHCPAgentSchedulersRbacTest(base.BaseNetworkRbacTest):
@@ -198,9 +198,9 @@
 
         RBAC test for the neutron get_dhcp-networks policy
         """
-        self.rbac_utils.switch_role(self, toggle_rbac_role=True)
-        self.agents_client.list_networks_hosted_by_one_dhcp_agent(
-            self.agent['id'])
+        with self.rbac_utils.override_role(self):
+            self.agents_client.list_networks_hosted_by_one_dhcp_agent(
+                self.agent['id'])
 
     @decorators.idempotent_id('14e014ac-f355-46d3-b6d8-98f2c9ec1610')
     @rbac_rule_validation.action(service="neutron",
@@ -213,9 +213,9 @@
         network_id = self._create_and_prepare_network_for_agent(
             self.agent['id'])
 
-        self.rbac_utils.switch_role(self, toggle_rbac_role=True)
-        self.agents_client.add_dhcp_agent_to_network(
-            self.agent['id'], network_id=network_id)
+        with self.rbac_utils.override_role(self):
+            self.agents_client.add_dhcp_agent_to_network(
+                self.agent['id'], network_id=network_id)
         # Clean up is not necessary and might result in 409 being raised.
 
     @decorators.idempotent_id('937a4302-4b49-407d-9980-5843d7badc38')
@@ -232,6 +232,6 @@
             self.agent['id'], network_id=network_id)
         # Clean up is not necessary and might result in 409 being raised.
 
-        self.rbac_utils.switch_role(self, toggle_rbac_role=True)
-        self.agents_client.delete_network_from_dhcp_agent(
-            self.agent['id'], network_id=network_id)
+        with self.rbac_utils.override_role(self):
+            self.agents_client.delete_network_from_dhcp_agent(
+                self.agent['id'], network_id=network_id)
diff --git a/patrole_tempest_plugin/tests/api/network/test_floating_ips_rbac.py b/patrole_tempest_plugin/tests/api/network/test_floating_ips_rbac.py
index dc674d1..20e4aa7 100644
--- a/patrole_tempest_plugin/tests/api/network/test_floating_ips_rbac.py
+++ b/patrole_tempest_plugin/tests/api/network/test_floating_ips_rbac.py
@@ -70,8 +70,8 @@
 
         RBAC test for the neutron create_floatingip policy
         """
-        self.rbac_utils.switch_role(self, toggle_rbac_role=True)
-        self._create_floatingip()
+        with self.rbac_utils.override_role(self):
+            self._create_floatingip()
 
     @rbac_rule_validation.action(service="neutron",
                                  rule="create_floatingip:floating_ip_address")
@@ -83,8 +83,8 @@
         """
         fip = str(netaddr.IPAddress(self.cidr) + 10)
 
-        self.rbac_utils.switch_role(self, toggle_rbac_role=True)
-        self._create_floatingip(floating_ip_address=fip)
+        with self.rbac_utils.override_role(self):
+            self._create_floatingip(floating_ip_address=fip)
 
     @rbac_rule_validation.action(service="neutron",
                                  rule="update_floatingip")
@@ -95,11 +95,10 @@
         RBAC test for the neutron update_floatingip policy
         """
         floating_ip = self._create_floatingip()
-        self.rbac_utils.switch_role(self, toggle_rbac_role=True)
-
-        # Associate floating IP to the other port
-        self.floating_ips_client.update_floatingip(
-            floating_ip['id'], port_id=None)
+        with self.rbac_utils.override_role(self):
+            # Associate floating IP to the other port
+            self.floating_ips_client.update_floatingip(
+                floating_ip['id'], port_id=None)
 
     @rbac_rule_validation.action(service="neutron",
                                  rule="get_floatingip",
@@ -111,9 +110,9 @@
         RBAC test for the neutron get_floatingip policy
         """
         floating_ip = self._create_floatingip()
-        self.rbac_utils.switch_role(self, toggle_rbac_role=True)
-        # Show floating IP
-        self.floating_ips_client.show_floatingip(floating_ip['id'])
+        with self.rbac_utils.override_role(self):
+            # Show floating IP
+            self.floating_ips_client.show_floatingip(floating_ip['id'])
 
     @rbac_rule_validation.action(service="neutron",
                                  rule="delete_floatingip",
@@ -125,6 +124,6 @@
         RBAC test for the neutron delete_floatingip policy
         """
         floating_ip = self._create_floatingip()
-        self.rbac_utils.switch_role(self, toggle_rbac_role=True)
-        # Delete the floating IP
-        self.floating_ips_client.delete_floatingip(floating_ip['id'])
+        with self.rbac_utils.override_role(self):
+            # Delete the floating IP
+            self.floating_ips_client.delete_floatingip(floating_ip['id'])
diff --git a/patrole_tempest_plugin/tests/api/network/test_subnetpools_rbac.py b/patrole_tempest_plugin/tests/api/network/test_subnetpools_rbac.py
index 9231c15..fe14c92 100644
--- a/patrole_tempest_plugin/tests/api/network/test_subnetpools_rbac.py
+++ b/patrole_tempest_plugin/tests/api/network/test_subnetpools_rbac.py
@@ -60,8 +60,8 @@
 
         RBAC test for the neutron create_subnetpool policy
         """
-        self.rbac_utils.switch_role(self, toggle_rbac_role=True)
-        self._create_subnetpool()
+        with self.rbac_utils.override_role(self):
+            self._create_subnetpool()
 
     @rbac_rule_validation.action(service="neutron",
                                  rule="create_subnetpool:shared")
@@ -71,8 +71,8 @@
 
         RBAC test for the neutron create_subnetpool:shared policy
         """
-        self.rbac_utils.switch_role(self, toggle_rbac_role=True)
-        self._create_subnetpool(shared=True)
+        with self.rbac_utils.override_role(self):
+            self._create_subnetpool(shared=True)
 
     @rbac_rule_validation.action(service="neutron",
                                  rule="get_subnetpool",
@@ -84,8 +84,8 @@
         RBAC test for the neutron get_subnetpool policy
         """
         subnetpool = self._create_subnetpool()
-        self.rbac_utils.switch_role(self, toggle_rbac_role=True)
-        self.subnetpools_client.show_subnetpool(subnetpool['id'])
+        with self.rbac_utils.override_role(self):
+            self.subnetpools_client.show_subnetpool(subnetpool['id'])
 
     @rbac_rule_validation.action(service="neutron",
                                  rule="update_subnetpool")
@@ -96,9 +96,9 @@
         RBAC test for the neutron update_subnetpool policy
         """
         subnetpool = self._create_subnetpool()
-        self.rbac_utils.switch_role(self, toggle_rbac_role=True)
-        self.subnetpools_client.update_subnetpool(subnetpool['id'],
-                                                  min_prefixlen=24)
+        with self.rbac_utils.override_role(self):
+            self.subnetpools_client.update_subnetpool(subnetpool['id'],
+                                                      min_prefixlen=24)
 
     @decorators.idempotent_id('a16f4e5c-0675-415f-b636-00af00638693')
     @rbac_rule_validation.action(service="neutron",
@@ -117,9 +117,9 @@
             default_pool = self._create_subnetpool(is_default=True)
         original_desc = default_pool['description']
 
-        self.rbac_utils.switch_role(self, toggle_rbac_role=True)
-        self.subnetpools_client.update_subnetpool(
-            default_pool['id'], description=original_desc, is_default=True)
+        with self.rbac_utils.override_role(self):
+            self.subnetpools_client.update_subnetpool(
+                default_pool['id'], description=original_desc, is_default=True)
 
     @rbac_rule_validation.action(service="neutron",
                                  rule="delete_subnetpool")
@@ -130,5 +130,5 @@
         RBAC test for the neutron delete_subnetpool policy
         """
         subnetpool = self._create_subnetpool()
-        self.rbac_utils.switch_role(self, toggle_rbac_role=True)
-        self.subnetpools_client.delete_subnetpool(subnetpool['id'])
+        with self.rbac_utils.override_role(self):
+            self.subnetpools_client.delete_subnetpool(subnetpool['id'])