openstack: Add update subnet DHCP helper

This commit is contained in:
Frode Nordahl
2022-04-13 10:44:37 +02:00
parent 85f33e8369
commit 3f711ff6da
2 changed files with 32 additions and 0 deletions

View File

@@ -1500,6 +1500,20 @@ class TestOpenStackUtils(ut_utils.BaseTestCase):
self.configure_networking_charms.assert_called_once_with(
'fakenetworkingdata', expect, use_juju_wait=False)
def test_update_subnet_dhcp(self):
neutron_client = mock.MagicMock()
openstack_utils.update_subnet_dhcp(
neutron_client, {'id': 'aId'}, True)
neutron_client.update_subnet.assert_called_once_with(
'aId',
{'subnet': {'enable_dhcp': True}})
neutron_client.reset_mock()
openstack_utils.update_subnet_dhcp(
neutron_client, {'id': 'aId'}, False)
neutron_client.update_subnet.assert_called_once_with(
'aId',
{'subnet': {'enable_dhcp': False}})
class TestAsyncOpenstackUtils(ut_utils.AioTestCase):

View File

@@ -1328,6 +1328,24 @@ def update_subnet_dns(neutron_client, subnet, dns_servers):
neutron_client.update_subnet(subnet['id'], msg)
def update_subnet_dhcp(neutron_client, subnet, enable_dhcp):
"""Update subnet DHCP status.
:param neutron_client: Authenticated neutronclient
:type neutron_client: neutronclient.Client object
:param subnet: Subnet object
:type subnet: dict
:param enable_dhcp: Whether DHCP should be enabled or not
:type enable_dhcp: bool
"""
msg = {
'subnet': {
'enable_dhcp': enable_dhcp,
}
}
neutron_client.update_subnet(subnet['id'], msg)
def create_provider_router(neutron_client, project_id):
"""Create the provider router.