Run auto_allocated_topology functional tests in the own project

To avoid accidental usage of the 'auto_allocate_network' which is created by
Neutron automatically when 'get_auto_allocated_topology' API is called,
by other tests those auto_allocated_topology tests are now run in own
project which is destroyed after tests are done.

Closes-Bug: #2071784
Change-Id: Ib92913204bd90c2fb56268f58b089a2d3ba45644
This commit is contained in:
Slawek Kaplonski 2024-07-03 11:58:37 +02:00 committed by Stephen Finucane
parent 10e5e20fc0
commit 3ee18eb171

View File

@ -30,40 +30,79 @@ class TestAutoAllocatedTopology(base.BaseFunctionalTest):
"required for this test"
)
projects = [o.id for o in self.operator_cloud.identity.projects()]
self.PROJECT_ID = projects[0]
project = self._create_project()
self.PROJECT_ID = project['id']
self.test_cloud = self.operator_cloud.connect_as_project(project)
def tearDown(self):
res = self.operator_cloud.network.delete_auto_allocated_topology(
res = self.test_cloud.network.delete_auto_allocated_topology(
self.PROJECT_ID
)
self.assertIsNone(res)
self._destroy_project()
super().tearDown()
def _create_project(self):
project_name = 'auto_allocated_topology_test_project'
project = self.operator_cloud.get_project(project_name)
if not project:
params = {
'name': project_name,
'description': (
'test project used only for the '
'TestAutoAllocatedTopology tests class'
),
}
if self.identity_version == '3':
params['domain_id'] = self.operator_cloud.get_domain(
'default'
)['id']
project = self.operator_cloud.create_project(**params)
user_id = self.operator_cloud.current_user_id
# Grant the current user access to the project
role_assignment = self.operator_cloud.list_role_assignments(
{'user': user_id, 'project': project['id']}
)
if not role_assignment:
self.operator_cloud.grant_role(
'member', user=user_id, project=project['id'], wait=True
)
return project
def _destroy_project(self):
self.operator_cloud.revoke_role(
'member',
user=self.operator_cloud.current_user_id,
project=self.PROJECT_ID,
)
self.operator_cloud.delete_project(self.PROJECT_ID)
def test_dry_run_option_pass(self):
# Dry run will only pass if there is a public network
networks = self.operator_cloud.network.networks()
networks = self.test_cloud.network.networks()
self._set_network_external(networks)
# Dry run option will return "dry-run=pass" in the 'id' resource
top = self.operator_cloud.network.validate_auto_allocated_topology(
top = self.test_cloud.network.validate_auto_allocated_topology(
self.PROJECT_ID
)
self.assertEqual(self.PROJECT_ID, top.project)
self.assertEqual("dry-run=pass", top.id)
def test_show_no_project_option(self):
top = self.operator_cloud.network.get_auto_allocated_topology()
project = self.conn.session.get_project_id()
network = self.operator_cloud.network.get_network(top.id)
top = self.test_cloud.network.get_auto_allocated_topology()
project = self.test_cloud.session.get_project_id()
network = self.test_cloud.network.get_network(top.id)
self.assertEqual(top.project_id, project)
self.assertEqual(top.id, network.id)
def test_show_project_option(self):
top = self.operator_cloud.network.get_auto_allocated_topology(
top = self.test_cloud.network.get_auto_allocated_topology(
self.PROJECT_ID
)
network = self.operator_cloud.network.get_network(top.id)
network = self.test_cloud.network.get_network(top.id)
self.assertEqual(top.project_id, network.project_id)
self.assertEqual(top.id, network.id)
self.assertEqual(network.name, "auto_allocated_network")
@ -71,6 +110,6 @@ class TestAutoAllocatedTopology(base.BaseFunctionalTest):
def _set_network_external(self, networks):
for network in networks:
if network.name == "public":
self.operator_cloud.network.update_network(
self.test_cloud.network.update_network(
network, is_default=True
)