Remove skip exception from virtual interfaces test
Currently, test_list_virtual_interfaces in the virtual interfaces
rbac test file throws a skip exception in the event that a BadRequest
is thrown -- which happens if neutron is enabled. This is because
listing virtual interfaces is only available for nova-network, in nova.
However, skipping the test is not necessary, because policy enforcement
is always performed [0]: the API always performs policy enforcement
first followed by everything else, so a 403 is always thrown before a 400.
So, this patch gets rid of the unnecessary raising of skipException.
It also adds a assertRaisesRegexp with the expected error message:
"Listing virtual interfaces is not supported by this cloud" and
expected BadRequest error. By checking for a specific regex (error
message), there is certainty that the expected BadRequest is indeed
thrown; if any other BadRequest is thrown, an AssertionError will be
raised.
In short: this patch removes the skipException because policy
enforcement is always performed and ensures that the correct
BadRequest is thrown.
[0] https://github.com/openstack/nova/blob/master/nova/api/openstack/compute/virtual_interfaces.py
Change-Id: Ia5bd4feb2708095bbab9eb2a377f336da84103fc
diff --git a/patrole_tempest_plugin/tests/api/compute/test_server_virtual_interfaces_rbac.py b/patrole_tempest_plugin/tests/api/compute/test_server_virtual_interfaces_rbac.py
index 3e74a01..a0a000c 100644
--- a/patrole_tempest_plugin/tests/api/compute/test_server_virtual_interfaces_rbac.py
+++ b/patrole_tempest_plugin/tests/api/compute/test_server_virtual_interfaces_rbac.py
@@ -14,11 +14,9 @@
# under the License.
from tempest import config
-
from tempest.lib import decorators
from tempest.lib import exceptions
-from patrole_tempest_plugin import rbac_exceptions
from patrole_tempest_plugin import rbac_rule_validation
from patrole_tempest_plugin.tests.api.compute import rbac_base as base
@@ -39,13 +37,10 @@
def test_list_virtual_interfaces(self):
server = self.create_test_server(wait_until='ACTIVE')
self.rbac_utils.switch_role(self, toggle_rbac_role=True)
- try:
- self.client.list_virtual_interfaces(server['id'])
- except exceptions.ServerFault as e:
- raise rbac_exceptions.RbacActionFailed(e)
- except exceptions.BadRequest as e:
+
+ if CONF.service_available.neutron:
msg = "Listing virtual interfaces is not supported by this cloud."
- if msg == str(e.resp_body['message']):
- raise self.skipException(msg)
- else:
- raise e
+ with self.assertRaisesRegex(exceptions.BadRequest, msg):
+ self.client.list_virtual_interfaces(server['id'])
+ else:
+ self.client.list_virtual_interfaces(server['id'])