Skip to content

Commit

Permalink
Merge pull request openstack-charmers#620 from fnordahl/maas-configur…
Browse files Browse the repository at this point in the history
…e-one-interface

Maas configure one interface
  • Loading branch information
coreycb authored Aug 17, 2021
2 parents 3813a53 + 6e8201f commit fa5f314
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 10 deletions.
5 changes: 0 additions & 5 deletions unit_tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,3 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import sys
import unittest.mock as mock

sys.modules['zaza.utilities.maas'] = mock.MagicMock()
29 changes: 29 additions & 0 deletions unit_tests/utilities/test_zaza_utilities_openstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import unit_tests.utils as ut_utils
from zaza.openstack.utilities import openstack as openstack_utils
from zaza.openstack.utilities import exceptions
from zaza.utilities.maas import LinkMode, MachineInterfaceMac


class TestOpenStackUtils(ut_utils.BaseTestCase):
Expand Down Expand Up @@ -1428,6 +1429,34 @@ def test_get_remote_ca_cert_file(self):
self.move.assert_called_once_with(
'tempfilename', '/tmp/default/ca1.cert')

def test_configure_charmed_openstack_on_maas(self):
self.patch_object(openstack_utils, 'get_charm_networking_data')
self.patch_object(openstack_utils.zaza.utilities.maas,
'get_macs_from_cidr')
self.patch_object(openstack_utils.zaza.utilities.maas,
'get_maas_client_from_juju_cloud_data')
self.patch_object(openstack_utils.zaza.model, 'get_cloud_data')
self.patch_object(openstack_utils, 'configure_networking_charms')
self.get_charm_networking_data.return_value = 'fakenetworkingdata'
self.get_macs_from_cidr.return_value = [
MachineInterfaceMac('id_a', 'ens6', '00:53:00:00:00:01',
'192.0.2.0/24', LinkMode.LINK_UP),
MachineInterfaceMac('id_a', 'ens7', '00:53:00:00:00:02',
'192.0.2.0/24', LinkMode.LINK_UP),
MachineInterfaceMac('id_b', 'ens6', '00:53:00:00:01:01',
'192.0.2.0/24', LinkMode.LINK_UP),

]
network_config = {'external_net_cidr': '192.0.2.0/24'}
expect = [
'00:53:00:00:00:01',
'00:53:00:00:01:01',
]
openstack_utils.configure_charmed_openstack_on_maas(
network_config)
self.configure_networking_charms.assert_called_once_with(
'fakenetworkingdata', expect, use_juju_wait=False)


class TestAsyncOpenstackUtils(ut_utils.AioTestCase):

Expand Down
19 changes: 14 additions & 5 deletions zaza/openstack/utilities/openstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -1056,14 +1056,23 @@ def configure_charmed_openstack_on_maas(network_config, limit_gws=None):
:type limit_gws: Optional[int]
"""
networking_data = get_charm_networking_data(limit_gws=limit_gws)
macs = [
mim.mac
for mim in zaza.utilities.maas.get_macs_from_cidr(
macs = []
machines = set()
for mim in zaza.utilities.maas.get_macs_from_cidr(
zaza.utilities.maas.get_maas_client_from_juju_cloud_data(
zaza.model.get_cloud_data()),
network_config['external_net_cidr'],
link_mode=zaza.utilities.maas.LinkMode.LINK_UP)
]
link_mode=zaza.utilities.maas.LinkMode.LINK_UP):
if mim.machine_id in machines:
logging.warning("Machine {} has multiple unconfigured interfaces, "
"ignoring interface {} ({})."
.format(mim.machine_id, mim.ifname, mim.mac))
continue
logging.info("Machine {} selected {} ({}) for external networking."
.format(mim.machine_id, mim.ifname, mim.mac))
machines.add(mim.machine_id)
macs.append(mim.mac)

if macs:
configure_networking_charms(
networking_data, macs, use_juju_wait=False)
Expand Down

0 comments on commit fa5f314

Please sign in to comment.