|
@@ -1328,6 +1328,43 @@ class InterfaceTestCase(TestCase):
|
|
|
self.assertEqual(lag.lag_mode, InterfaceLAGModeChoices.MODE_ACTIVE_BACKUP)
|
|
self.assertEqual(lag.lag_mode, InterfaceLAGModeChoices.MODE_ACTIVE_BACKUP)
|
|
|
self.assertIsNone(lag.lag_hash_policy)
|
|
self.assertIsNone(lag.lag_hash_policy)
|
|
|
|
|
|
|
|
|
|
+ def test_lag_attributes_cleared_when_changing_from_lag_type(self):
|
|
|
|
|
+ """Changing a LAG interface to another type clears its LAG mode and hash policy."""
|
|
|
|
|
+ lag = Interface.objects.create(
|
|
|
|
|
+ device=self.device,
|
|
|
|
|
+ name='bond0',
|
|
|
|
|
+ type=InterfaceTypeChoices.TYPE_LAG,
|
|
|
|
|
+ lag_mode=InterfaceLAGModeChoices.MODE_LACP,
|
|
|
|
|
+ lag_hash_policy=InterfaceLAGHashPolicyChoices.POLICY_LAYER3_4,
|
|
|
|
|
+ )
|
|
|
|
|
+ data = {
|
|
|
|
|
+ 'device': self.device.pk,
|
|
|
|
|
+ 'name': 'bond0',
|
|
|
|
|
+ 'type': InterfaceTypeChoices.TYPE_1GE_FIXED,
|
|
|
|
|
+ 'lag_mode': InterfaceLAGModeChoices.MODE_LACP,
|
|
|
|
|
+ 'lag_hash_policy': InterfaceLAGHashPolicyChoices.POLICY_LAYER3_4,
|
|
|
|
|
+ }
|
|
|
|
|
+ form = InterfaceForm(data, instance=lag)
|
|
|
|
|
+ self.assertTrue(form.is_valid(), form.errors)
|
|
|
|
|
+ form.save()
|
|
|
|
|
+
|
|
|
|
|
+ lag.refresh_from_db()
|
|
|
|
|
+ self.assertEqual(lag.type, InterfaceTypeChoices.TYPE_1GE_FIXED)
|
|
|
|
|
+ self.assertIsNone(lag.lag_mode)
|
|
|
|
|
+ self.assertIsNone(lag.lag_hash_policy)
|
|
|
|
|
+
|
|
|
|
|
+ def test_lag_mode_on_non_lag_interface_rejected(self):
|
|
|
|
|
+ """A LAG mode chosen for a non-LAG interface is rejected rather than silently dropped."""
|
|
|
|
|
+ data = {
|
|
|
|
|
+ 'device': self.device.pk,
|
|
|
|
|
+ 'name': 'eth9',
|
|
|
|
|
+ 'type': InterfaceTypeChoices.TYPE_1GE_FIXED,
|
|
|
|
|
+ 'lag_mode': InterfaceLAGModeChoices.MODE_LACP,
|
|
|
|
|
+ }
|
|
|
|
|
+ form = InterfaceForm(data)
|
|
|
|
|
+ self.assertFalse(form.is_valid())
|
|
|
|
|
+ self.assertIn('lag_mode', form.errors)
|
|
|
|
|
+
|
|
|
def test_child_interface_preselects_every_parent_vdc(self):
|
|
def test_child_interface_preselects_every_parent_vdc(self):
|
|
|
"""A child interface's form pre-selects every virtual device context of its parent."""
|
|
"""A child interface's form pre-selects every virtual device context of its parent."""
|
|
|
vdcs = (
|
|
vdcs = (
|