CORD-2865 add creator to CordSubscriberRoot

Change-Id: I6a021750b2f3fa0935768bd251d317778f71de40
diff --git a/xos/synchronizer/model_policies/test_model_policy_rcordsubscriber.py b/xos/synchronizer/model_policies/test_model_policy_rcordsubscriber.py
index eb89d2a..e95846f 100644
--- a/xos/synchronizer/model_policies/test_model_policy_rcordsubscriber.py
+++ b/xos/synchronizer/model_policies/test_model_policy_rcordsubscriber.py
@@ -22,22 +22,19 @@
 
 cwd=os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
 xos_dir=os.path.abspath(os.path.join(cwd, "../../../../../../orchestration/xos/xos"))
-# services_dir=os.path.join(xos_dir, "../../xos_services")
+services_dir=os.path.join(xos_dir, "../../xos_services")
 config_file = os.path.join(cwd, "test_config.yaml")
 
 # NOTE this have to start for xos_services
-# RCORD_XPROTO = "../profiles/rcord/xos/synchronizer/models/rcord.xproto"
-# OLT_XPROTO = "olt-service/xos/synchronizer/models/volt.xproto"
+RCORD_XPROTO = "../profiles/rcord/xos/synchronizer/models/rcord.xproto"
+OLT_XPROTO = "olt-service/xos/synchronizer/models/volt.xproto"
 
 Config.clear()
 Config.init(config_file, 'synchronizer-config-schema.yaml')
 
 # FIXME move the synchronizer framework into a library
 sys.path.append(xos_dir)
-# from synchronizers.new_base.mock_modelaccessor_build import build_mock_modelaccessor
-from synchronizers.new_base.modelaccessor import model_accessor
-
-from model_policy_rcordsubscriber import RCORDSubscriberPolicy
+from synchronizers.new_base.mock_modelaccessor_build import build_mock_modelaccessor
 
 class MockSubscriber:
 
@@ -74,10 +71,16 @@
 
 class TestModelPolicyRCORDSubscriber(unittest.TestCase):
     def setUp(self):
+        global model_accessor
+
         self.original_sys_path = sys.path
 
         # Generate a fake model accessor (emulate the client library)
-        # build_mock_modelaccessor(xos_dir, services_dir, [RCORD_XPROTO, OLT_XPROTO])
+        build_mock_modelaccessor(xos_dir, services_dir, [RCORD_XPROTO, OLT_XPROTO])
+
+        import synchronizers.new_base.modelaccessor
+        from synchronizers.new_base.modelaccessor import model_accessor
+        from model_policy_rcordsubscriber import RCORDSubscriberPolicy
 
         # import all class names to globals
         for (k, v) in model_accessor.all_model_classes.items():
@@ -116,4 +119,4 @@
 
 
 if __name__ == '__main__':
-    unittest.main()
\ No newline at end of file
+    unittest.main()
diff --git a/xos/synchronizer/models/models.py b/xos/synchronizer/models/models.py
index 11b0ad9..28244fa 100644
--- a/xos/synchronizer/models/models.py
+++ b/xos/synchronizer/models/models.py
@@ -44,6 +44,15 @@
         except IndexError:
             raise XOSValidationError("Service RCORD cannot be found, please make sure that the model exists.")
 
+        # VSGServiceInstance will extract the creator from the Subscriber, as it needs a creator to create its
+        # Instance.
+        if not self.creator:
+            # If we weren't passed an explicit creator, then we will assume the caller is the creator.
+            if not getattr(self, "caller", None):
+                raise XOSProgrammingError("CordSubscriberRoot's self.caller was not set")
+            self.creator = self.caller
+
+        # TODO: What is this for?
         if (not hasattr(self, 'caller') or not self.caller.is_admin):
             if (self.has_field_changed("service_specific_id")):
                 raise XOSPermissionDenied("You do not have permission to change service_specific_id")
diff --git a/xos/synchronizer/models/rcord.xproto b/xos/synchronizer/models/rcord.xproto
index 53499e9..cc2ddd3 100644
--- a/xos/synchronizer/models/rcord.xproto
+++ b/xos/synchronizer/models/rcord.xproto
@@ -20,4 +20,5 @@
     optional int32 c_tag = 12 [null = True, db_index = False, blank = False];
     required string olt_device = 13 [help_text = "VOLTDevice device_id", null = False, db_index = False, blank = False];
     required string olt_port = 14 [help_text = "VOLTDevicePort port_id", null = False, db_index = False, blank = False];
+    optional manytoone creator->User:created_rcord_subscribers = 15 [db_index = True, null = True, blank = True];
 }