[SEBA-742] Tech-profile-id as a mandatory field in RCORDSubscriber

Change-Id: I3f7f1e816d7cac457e1e286d809fd2728fb6f0ee
diff --git a/xos/synchronizer/models/models.py b/xos/synchronizer/models/models.py
index 5a42ce5..c80cb63 100755
--- a/xos/synchronizer/models/models.py
+++ b/xos/synchronizer/models/models.py
@@ -15,7 +15,7 @@
 import re
 import socket
 import random
-
+from django.core.exceptions import ObjectDoesNotExist
 from xos.exceptions import XOSValidationError, XOSProgrammingError, XOSPermissionDenied, XOSConfigurationError
 from models_decl import RCORDService_decl, RCORDSubscriber_decl, RCORDIpAddress_decl, BandwidthProfile_decl
 
@@ -82,7 +82,6 @@
         else:
             return tag
 
-
     def generate_c_tag(self):
 
         # unused_c_tags_for_s_tag() this function will return a list of unused c_tags for the given s_tag
@@ -165,6 +164,26 @@
         else:
             return None 
 
+    def validate_tech_profile_id(self):
+        if self.owner.leaf_model.access != "voltha":
+            # if we're not using VOLTHA we don't need to validate this
+            return True
+
+        volt = None
+        for ps in self.owner.provider_services:
+            provider_service = ps.leaf_model
+            if provider_service.name.lower() == "volt":
+                volt = provider_service
+
+        technology = volt.get_olt_technology_from_unu_sn(self.onu_device)
+
+        try:
+            tp = volt.get_tech_profile(technology, self.tech_profile_id)
+            return True
+        except ObjectDoesNotExist:
+            return False
+
+
     def save(self, *args, **kwargs):
         self.validate_unique_service_specific_id(none_okay=True)
 
@@ -232,6 +251,10 @@
             if not volt_service.has_access_device(self.onu_device):
                 raise XOSValidationError("The onu_device you specified (%s) does not exists" % self.onu_device)
 
+        # validate that the tech_profile_id actually exists
+        if not self.validate_tech_profile_id():
+            raise XOSValidationError("The technology profile you specified [%s] does not exist" % self.tech_profile_id)
+
         super(RCORDSubscriber, self).save(*args, **kwargs)
         self.invalidate_related_objects()
         return