diff --git a/ironic_tempest_plugin/manager.py b/ironic_tempest_plugin/manager.py index 5344f93c40..130eff9550 100644 --- a/ironic_tempest_plugin/manager.py +++ b/ironic_tempest_plugin/manager.py @@ -418,6 +418,50 @@ class ScenarioTest(tempest.test.BaseTestCase): else: raise lib_exc.InvalidConfiguration() + def _get_router(self, client=None, tenant_id=None): + """Retrieve a router for the given tenant id. + + If a public router has been configured, it will be returned. + + If a public router has not been configured, but a public + network has, a tenant router will be created and returned that + routes traffic to the public network. + """ + if not client: + client = self.routers_client + if not tenant_id: + tenant_id = client.tenant_id + router_id = CONF.network.public_router_id + network_id = CONF.network.public_network_id + if router_id: + body = client.show_router(router_id) + return body['router'] + elif network_id: + router = self._create_router(client, tenant_id) + kwargs = {'external_gateway_info': dict(network_id=network_id)} + router = client.update_router(router['id'], **kwargs)['router'] + return router + else: + raise Exception("Neither of 'public_router_id' or " + "'public_network_id' has been defined.") + + def _create_router(self, client=None, tenant_id=None, + namestart='router-smoke'): + if not client: + client = self.routers_client + if not tenant_id: + tenant_id = client.tenant_id + name = data_utils.rand_name(namestart) + result = client.create_router(name=name, + admin_state_up=True, + tenant_id=tenant_id) + router = result['router'] + self.assertEqual(router['name'], name) + self.addCleanup(test_utils.call_and_ignore_notfound_exc, + client.delete_router, + router['id']) + return router + class NetworkScenarioTest(ScenarioTest): """Base class for network scenario tests.