[Fix Gate] Fix network segments policy test raising 503
This is to fix the gate by resolving an issue with a Neutron
segments policy test class that hardcodes the network segment
to use gre network type, which may not be supported by the
underlying network, resulting in a 503 exception being raised.
Example stacktrace: [0] and root cause: [1].
Also renames the class and file to convey that actual policy
being tested.
[0] http://logs.openstack.org/20/547820/7/check/patrole-admin/5f4e495/job-output.txt.gz#_2018-03-12_20_50_15_600175
[1] http://logs.openstack.org/20/547820/7/check/patrole-admin/5f4e495/controller/logs/screen-neutron-api.txt.gz#_Mar_12_20_50_15_698713
Change-Id: I6e3daef766f0ed5fabcc125f39471d089c9d7218
diff --git a/patrole_tempest_plugin/tests/api/network/test_networks_multiprovider_rbac.py b/patrole_tempest_plugin/tests/api/network/test_network_segments_rbac.py
similarity index 76%
rename from patrole_tempest_plugin/tests/api/network/test_networks_multiprovider_rbac.py
rename to patrole_tempest_plugin/tests/api/network/test_network_segments_rbac.py
index 9c65c14..1dee46b 100644
--- a/patrole_tempest_plugin/tests/api/network/test_networks_multiprovider_rbac.py
+++ b/patrole_tempest_plugin/tests/api/network/test_network_segments_rbac.py
@@ -14,6 +14,7 @@
# under the License.
from oslo_log import log
+
from tempest.common import utils
from tempest.lib.common.utils import data_utils
from tempest.lib.common.utils import test_utils
@@ -26,18 +27,34 @@
LOG = log.getLogger(__name__)
-class NetworksMultiProviderRbacTest(base.BaseNetworkRbacTest):
+class NetworkSegmentsRbacTest(base.BaseNetworkRbacTest):
@classmethod
def skip_checks(cls):
- super(NetworksMultiProviderRbacTest, cls).skip_checks()
+ super(NetworkSegmentsRbacTest, cls).skip_checks()
if not utils.is_extension_enabled('multi-provider', 'network'):
msg = "multi-provider extension not enabled."
raise cls.skipException(msg)
+ @classmethod
+ def resource_setup(cls):
+ super(NetworkSegmentsRbacTest, cls).resource_setup()
+ # Find the network type that is supported by the current cloud by
+ # checking which network type other networks currently have. This is
+ # done because there is no tempest.conf option enumerating supported
+ # network types.
+ networks = cls.networks_client.list_networks()['networks']
+ network_types = [n['provider:network_type'] for n in networks
+ if n['provider:network_type'] != 'flat']
+ if not network_types:
+ raise cls.skipException(
+ 'Could not find network with provider:network_type that is '
+ 'not "flat".')
+ cls.network_type = network_types[0]
+
def _create_network_segments(self):
- segments = [{"provider:network_type": "gre"},
- {"provider:network_type": "gre"}]
+ segments = [{'provider:network_type': self.network_type},
+ {'provider:network_type': self.network_type}]
body = self.networks_client.create_network(
name=data_utils.rand_name(self.__class__.__name__),
@@ -68,7 +85,7 @@
RBAC test for the neutron update_network:segments policy
"""
network = self._create_network_segments()
- new_segments = [{"provider:network_type": "gre"}]
+ new_segments = [{'provider:network_type': self.network_type}]
with self.rbac_utils.override_role(self):
self.networks_client.update_network(network['id'],
@@ -92,7 +109,7 @@
# If user does not have access to the network segments attribute,
# no NotFound or Forbidden exception are thrown. Instead,
# the response will have an empty network body only.
- if len(response_network) == 0:
+ if not response_network:
LOG.info("NotFound or Forbidden exception are not thrown when "
"role doesn't have access to the endpoint. Instead, "
"the response will have an empty network body.")