Only configure one interface on MAAS provider
The Zaza MAAS code selects interfaces that are attached to the provided CIDR, set up as unconfigured and has link. In the event a machine has multiple unconfigured interfaces attached to the same physical network, adding them all to the configuration might lead to undesired side effects such as network loops.
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -24,6 +24,7 @@ import tenacity
|
||||
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):
|
||||
@@ -1428,6 +1429,34 @@ class TestOpenStackUtils(ut_utils.BaseTestCase):
|
||||
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):
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user