[CORD-3156] Adding support for mac_address in olt-service
Change-Id: I945257416f527b2d019231c9abc4cdf44a5a6a58
diff --git a/xos/synchronizer/models/models.py b/xos/synchronizer/models/models.py
index ed1e062..3dcefae 100644
--- a/xos/synchronizer/models/models.py
+++ b/xos/synchronizer/models/models.py
@@ -46,6 +46,13 @@
def get_volt_si(self):
return VOLTServiceInstance.objects.all()
+ def save(self, *args, **kwargs):
+
+ if (self.host or self.port) and self.mac_address:
+ raise XOSValidationError("You can't specify both host/port and mac_address for OLTDevice [host=%s, port=%s, mac_address=%s]" % (self.host, self.port, self.mac_address))
+
+ super(OLTDevice, self).save(*args, **kwargs)
+
def delete(self, *args, **kwargs):
onus = []
diff --git a/xos/synchronizer/models/test_oltdevice_model.py b/xos/synchronizer/models/test_oltdevice_model.py
index 34bf200..5da9583 100644
--- a/xos/synchronizer/models/test_oltdevice_model.py
+++ b/xos/synchronizer/models/test_oltdevice_model.py
@@ -40,13 +40,24 @@
from models import OLTDevice
- print OLTDevice
-
self.olt_device = OLTDevice()
self.olt_device.id = None # this is a new model
self.olt_device.is_new = True
self.olt_device.device_id = 1234
+ def test_create_mac_address(self):
+ from models import OLTDevice
+ olt = OLTDevice()
+
+ olt.host = "1.1.1.1"
+ olt.port = "9101"
+ olt.mac_address = "00:0c:d5:00:05:40"
+
+ with self.assertRaises(Exception) as e:
+ olt.save()
+
+ self.assertEqual(e.exception.message,
+ "You can't specify both host/port and mac_address for OLTDevice [host=%s, port=%s, mac_address=%s]" % (olt.host, olt.port, olt.mac_address))
def test_delete(self):
self.olt_device.delete()
diff --git a/xos/synchronizer/models/volt.xproto b/xos/synchronizer/models/volt.xproto
index 39383f4..3106210 100644
--- a/xos/synchronizer/models/volt.xproto
+++ b/xos/synchronizer/models/volt.xproto
@@ -23,8 +23,9 @@
required manytoone volt_service->VOLTService:volt_devices = 1 [db_index = True, null = False, blank = False];
optional string name = 2 [help_text = "name of device", max_length = 254, null = True, db_index = False, blank = True, unique = True];
required string device_type = 3 [help_text = "Device Type", default = "asfvolt16_olt", max_length = 254, null = False, db_index = False, blank = False, tosca_key=True];
- required string host = 4 [help_text = "Host", max_length = 254, null = False, db_index = False, blank = False, tosca_key=True];
- required int32 port = 5 [help_text = "Fabric port", null = False, db_index = False, blank = False, tosca_key=True];
+ optional string host = 4 [help_text = "Device IP", max_length = 254, null = True, db_index = False, blank = True];
+ optional int32 port = 5 [help_text = "Device port", null = True, db_index = False, blank = True, tosca_key_one_of=host];
+ optional string mac_address = 6 [help_text = "Device mac address", null = True, db_index = False, blank = True, tosca_key_one_of=host];
optional string device_id = 10 [help_text = "Device ID", null = True, db_index = False, blank = False, feedback_state = True];
optional string admin_state = 11 [help_text = "admin_state", null = True, db_index = False, blank = False, feedback_state = True];