Bux fix sfi update record in order to handle user pubkey and gid update
Mohamed Larabi [Thu, 6 Dec 2012 14:43:46 +0000 (15:43 +0100)]
sfa/managers/registry_manager.py
sfa/planetlab/pldriver.py

index d4a0657..8c012ad 100644 (file)
@@ -367,7 +367,7 @@ class RegistryManager:
         # is there a change in keys ?
         new_key=None
         if type=='user':
-            if getattr(new_key,'keys',None):
+            if getattr(new_record,'keys',None):
                 new_key=new_record.keys
                 if isinstance (new_key,types.ListType):
                     new_key=new_key[0]
@@ -381,7 +381,6 @@ class RegistryManager:
             gid_object = api.auth.hierarchy.create_gid(urn, uuid, pkey)
             gid = gid_object.save_to_string(save_parents=True)
             record.gid = gid
-            dsession.commit()
         
         # xxx should do side effects from new_record to record
         # not too sure how to do that
@@ -391,12 +390,10 @@ class RegistryManager:
         if isinstance (record, RegSlice):
             researcher_hrns = getattr(new_record,'researcher',None)
             if researcher_hrns is not None: record.update_researchers (researcher_hrns)
-            dbsession.commit()
 
         elif isinstance (record, RegAuthority):
             pi_hrns = getattr(new_record,'pi',None)
             if pi_hrns is not None: record.update_pis (pi_hrns)
-            dbsession.commit()
         
         # update the PLC information that was specified with the record
         # xxx oddly enough, without this useless statement, 
@@ -404,9 +401,11 @@ class RegistryManager:
         # anyway the driver should receive an object 
         # (and then extract __dict__ itself if needed)
         print "DO NOT REMOVE ME before driver.update, record=%s"%record
-        if not self.driver.update (record.__dict__, new_record.__dict__, hrn, new_key):
-            logger.warning("driver.update failed")
-    
+        (pointer, new_key_pointer) = self.driver.update (record.__dict__, new_record.__dict__, hrn, new_key)
+        if new_key and new_key_pointer:    
+            record.reg_keys=[ RegKey (new_key, new_key_pointer)]
+
+        dbsession.commit();
         # update membership for researchers, pis, owners, operators
         self.update_driver_relations (record, new_record)
         
index abfcb92..9274f39 100644 (file)
@@ -135,6 +135,7 @@ class PlDriver (Driver):
     def update (self, old_sfa_record, new_sfa_record, hrn, new_key):
         pointer = old_sfa_record['pointer']
         type = old_sfa_record['type']
+        new_key_pointer = None
 
         # new_key implemented for users only
         if new_key and type not in [ 'user' ]:
@@ -173,20 +174,19 @@ class PlDriver (Driver):
                 keys = person['key_ids']
                 keys = self.shell.GetKeys(person['key_ids'])
                 
-                # Delete all stale keys
                 key_exists = False
                 for key in keys:
-                    if new_key != key['key']:
-                        self.shell.DeleteKey(key['key_id'])
-                    else:
+                    if new_key == key['key']:
                         key_exists = True
+                        new_key_pointer = key['key_id']
+                        break
                 if not key_exists:
-                    self.shell.AddPersonKey(pointer, {'key_type': 'ssh', 'key': new_key})
+                    new_key_pointer = self.shell.AddPersonKey(pointer, {'key_type': 'ssh', 'key': new_key})
     
         elif type == "node":
             self.shell.UpdateNode(pointer, new_sfa_record)
 
-        return True
+        return (pointer, new_key_pointer)
         
 
     ##########