fix urn for vini internet2 sites
[sfa.git] / sfa / plc / sfaImport.py
index a749f32..98f6b79 100644 (file)
@@ -68,18 +68,22 @@ class sfaImport:
 
 
     def create_top_level_auth_records(self, hrn):
-        # create the authority if it doesnt already exist 
         AuthHierarchy = self.AuthHierarchy
         urn = hrn_to_urn(hrn, 'authority')
-        if not AuthHierarchy.auth_exists(urn):
-            trace("Import: creating top level authorites", self.logger)
-            AuthHierarchy.create_auth(urn)
+        # make sure parent exists
         parent_hrn = get_authority(hrn)
         if not parent_hrn:
             parent_hrn = hrn
-        auth_info = AuthHierarchy.get_auth_info(parent_hrn)
+        if not parent_hrn == hrn:
+            self.create_top_level_auth_records(parent_hrn)
+
+        # create the authority if it doesnt already exist 
+        if not AuthHierarchy.auth_exists(urn):
+            trace("Import: creating top level authorites", self.logger)
+            AuthHierarchy.create_auth(urn)
         
         # create the db record if it doesnt already exist    
+        auth_info = AuthHierarchy.get_auth_info(hrn)
         table = SfaTable()
         auth_record = table.find({'type': 'authority', 'hrn': hrn})
 
@@ -196,8 +200,8 @@ class sfaImport:
         plc_auth = self.plc_auth
         sitename = site['login_base']
         sitename = cleanup_string(sitename)
+        print 'importing site %s' % sitename
         hrn = parent_hrn + "." + sitename
-        urn = hrn_to_urn(hrn, 'authority')
         # Hardcode 'internet2' into the hrn for sites hosting
         # internet2 nodes. This is a special operation for some vini
         # sites only
@@ -209,6 +213,7 @@ class sfaImport:
                 #sitename = sitename.replace("nlr", "")
                 hrn = ".".join([parent_hrn, "internet2", sitename])
 
+        urn = hrn_to_urn(hrn, 'authority')
         trace("Import: importing site " + hrn, self.logger)
 
         # create the authority