Remove duplicated MAC addresses from multi MAC field
While adding new nodes, there is possibility to paste duplicated addresses in multi MAC field. Check if this situation occurred, and remove duplication. Closes-Bug: 1437212 Change-Id: I02436ce6db1b7ce42b98dbb18c1e96b4452db222
This commit is contained in:
parent
b0494942f6
commit
6a1dba03ee
tuskar_ui
@ -97,15 +97,19 @@ class MultiMACField(forms.fields.Field):
|
||||
|
||||
def clean(self, value):
|
||||
value = super(MultiMACField, self).clean(value)
|
||||
try:
|
||||
macs = []
|
||||
for mac in SEPARATOR_RE.split(value):
|
||||
if mac:
|
||||
macs.append(normalize_MAC(mac))
|
||||
return ' '.join(macs)
|
||||
except ValueError:
|
||||
raise forms.ValidationError(
|
||||
_(u'%r is not a valid MAC address.') % mac)
|
||||
|
||||
macs = []
|
||||
for mac in SEPARATOR_RE.split(value):
|
||||
if mac:
|
||||
try:
|
||||
normalized_mac = normalize_MAC(mac)
|
||||
except ValueError:
|
||||
raise forms.ValidationError(
|
||||
_(u'%r is not a valid MAC address.') % mac)
|
||||
else:
|
||||
macs.append(normalized_mac)
|
||||
|
||||
return ' '.join(sorted(set(macs)))
|
||||
|
||||
|
||||
class NetworkField(forms.fields.Field):
|
||||
|
@ -57,3 +57,12 @@ class MultiMACFieldTests(test.TestCase):
|
||||
"DE:AD:BE:EF:CA:FC DE:AD:BE:EF:CA:FD DE:AD:BE:EF:CA:FE "
|
||||
"DE:AD:BE:EF:CA:FF",
|
||||
)
|
||||
|
||||
def test_duplicated(self):
|
||||
field = forms.MultiMACField(required=False)
|
||||
cleaned = field.clean("DE:AD:BE:EF:CA:FC DE:AD:BE:EF:CA:FC")
|
||||
|
||||
self.assertEqual(
|
||||
cleaned,
|
||||
"DE:AD:BE:EF:CA:FC",
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user