Merge "Support the API for managing external gateways"

This commit is contained in:
Zuul 2024-01-30 09:31:40 +00:00 committed by Gerrit Code Review
commit 5fef752adb
4 changed files with 126 additions and 0 deletions

View File

@ -39,6 +39,8 @@ Router Operations
:members: create_router, update_router, delete_router, get_router,
find_router, routers,
add_gateway_to_router, remove_gateway_from_router,
add_external_gateways, update_external_gateways,
remove_external_gateways,
add_interface_to_router, remove_interface_from_router,
add_extra_routes_to_router, remove_extra_routes_from_router,
create_conntrack_helper, update_conntrack_helper,

View File

@ -4099,6 +4099,42 @@ class Proxy(proxy.Proxy):
router = self._get_resource(_router.Router, router)
return router.remove_gateway(self, **body)
def add_external_gateways(self, router, body):
"""Add router external gateways
:param router: Either the router ID or an instance of
:class:`~openstack.network.v2.router.Router`
:param body: Body containing the external_gateways parameter.
:returns: Router with added gateways
:rtype: :class:`~openstack.network.v2.router.Router`
"""
router = self._get_resource(_router.Router, router)
return router.add_external_gateways(self, body)
def update_external_gateways(self, router, body):
"""Update router external gateways
:param router: Either the router ID or an instance of
:class:`~openstack.network.v2.router.Router`
:param body: Body containing the external_gateways parameter.
:returns: Router with updated gateways
:rtype: :class:`~openstack.network.v2.router.Router`
"""
router = self._get_resource(_router.Router, router)
return router.update_external_gateways(self, body)
def remove_external_gateways(self, router, body):
"""Remove router external gateways
:param router: Either the router ID or an instance of
:class:`~openstack.network.v2.router.Router`
:param body: Body containing the external_gateways parameter.
:returns: Router without the removed gateways
:rtype: :class:`~openstack.network.v2.router.Router`
"""
router = self._get_resource(_router.Router, router)
return router.remove_external_gateways(self, body)
def routers_hosting_l3_agents(self, router, **query):
"""Return a generator of L3 agent hosting a router

View File

@ -177,6 +177,52 @@ class Router(_base.NetworkResource, tag.TagMixin):
resp = session.put(url, json=body)
return resp.json()
def add_external_gateways(self, session, body):
"""Add external gateways to a router.
:param session: The session to communicate through.
:type session: :class:`~keystoneauth1.adapter.Adapter`
:param dict body: The body requested to be updated on the router
:returns: The body of the response as a dictionary.
"""
url = utils.urljoin(self.base_path, self.id, 'add_external_gateways')
resp = session.put(url, json=body)
self._translate_response(resp)
return self
def update_external_gateways(self, session, body):
"""Update external gateways of a router.
:param session: The session to communicate through.
:type session: :class:`~keystoneauth1.adapter.Adapter`
:param dict body: The body requested to be updated on the router
:returns: The body of the response as a dictionary.
"""
url = utils.urljoin(
self.base_path, self.id, 'update_external_gateways'
)
resp = session.put(url, json=body)
self._translate_response(resp)
return self
def remove_external_gateways(self, session, body):
"""Remove external gateways from a router.
:param session: The session to communicate through.
:type session: :class:`~keystoneauth1.adapter.Adapter`
:param dict body: The body requested to be updated on the router
:returns: The body of the response as a dictionary.
"""
url = utils.urljoin(
self.base_path, self.id, 'remove_external_gateways'
)
resp = session.put(url, json=body)
self._translate_response(resp)
return self
class L3AgentRouter(Router):
resource_key = 'router'

View File

@ -1511,6 +1511,48 @@ class TestNetworkRouter(TestNetworkProxy):
)
mock_get.assert_called_once_with(router.Router, "FAKE_ROUTER")
@mock.patch.object(proxy_base.Proxy, '_get_resource')
@mock.patch.object(router.Router, 'add_external_gateways')
def test_add_external_gateways(self, mock_add, mock_get):
x_router = router.Router.new(id="ROUTER_ID")
mock_get.return_value = x_router
self._verify(
"openstack.network.v2.router.Router.add_external_gateways",
self.proxy.add_external_gateways,
method_args=["FAKE_ROUTER", "bar"],
expected_args=[self.proxy, "bar"],
)
mock_get.assert_called_once_with(router.Router, "FAKE_ROUTER")
@mock.patch.object(proxy_base.Proxy, '_get_resource')
@mock.patch.object(router.Router, 'update_external_gateways')
def test_update_external_gateways(self, mock_remove, mock_get):
x_router = router.Router.new(id="ROUTER_ID")
mock_get.return_value = x_router
self._verify(
"openstack.network.v2.router.Router.update_external_gateways",
self.proxy.update_external_gateways,
method_args=["FAKE_ROUTER", "bar"],
expected_args=[self.proxy, "bar"],
)
mock_get.assert_called_once_with(router.Router, "FAKE_ROUTER")
@mock.patch.object(proxy_base.Proxy, '_get_resource')
@mock.patch.object(router.Router, 'remove_external_gateways')
def test_remove_external_gateways(self, mock_remove, mock_get):
x_router = router.Router.new(id="ROUTER_ID")
mock_get.return_value = x_router
self._verify(
"openstack.network.v2.router.Router.remove_external_gateways",
self.proxy.remove_external_gateways,
method_args=["FAKE_ROUTER", "bar"],
expected_args=[self.proxy, "bar"],
)
mock_get.assert_called_once_with(router.Router, "FAKE_ROUTER")
def test_router_hosting_l3_agents_list(self):
self.verify_list(
self.proxy.routers_hosting_l3_agents,