neutron/policyd: Use `create_network` for test

At present the neutron policyd test assumes a network visible to
the demo user has already been created at the time of the test
being executed.

This may not always be the case, so let's manage the resource we
use for the test.
This commit is contained in:
Frode Nordahl
2020-04-17 15:26:41 +02:00
parent 82928825fd
commit e93fa0b571
+11 -8
View File
@@ -514,7 +514,7 @@ class KeystoneTests(BasePolicydSpecialization):
class NeutronApiTests(BasePolicydSpecialization):
"""Test the policyd override using the neutron client."""
_rule = {'rule.yaml': "{'get_network': '!'}"}
_rule = {'rule.yaml': "{'create_network': '!'}"}
@classmethod
def setUpClass(cls, application_name=None):
@@ -541,13 +541,16 @@ class NeutronApiTests(BasePolicydSpecialization):
neutron_client = openstack_utils.get_neutron_session_client(
self.get_keystone_session_demo_user(ip))
try:
# If we are allowed to list networks, this will return something.
# if the policyd override is present, then no error is generated,
# but no networks are returned.
networks = neutron_client.list_networks()
logging.debug("networks: {}".format(networks))
if len(networks['networks']) == 0:
raise PolicydOperationFailedException()
# If we are allowed to create networks, this will return something.
# if the policyd override is present, an exception will be raised
created_network = neutron_client.create_network(
{
'network': {
'name': 'zaza-policyd-test',
},
})
logging.debug("networks: {}".format(created_network))
neutron_client.delete_network(created_network['network']['id'])
except Exception:
raise PolicydOperationFailedException()