Skip to content

Commit

Permalink
openstack: Add update subnet DHCP helper
Browse files Browse the repository at this point in the history
(cherry picked from commit 3f711ff)
  • Loading branch information
fnordahl committed Jul 20, 2023
1 parent 0b69b8d commit 552066c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
14 changes: 14 additions & 0 deletions unit_tests/utilities/test_zaza_utilities_openstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -1500,6 +1500,20 @@ def test_configure_charmed_openstack_on_maas(self):
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):

Expand Down
18 changes: 18 additions & 0 deletions zaza/openstack/utilities/openstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -1332,6 +1332,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.
Expand Down

0 comments on commit 552066c

Please sign in to comment.