Modification on slabimporter to avoid creating an account when importing
authorSandrine Avakian <sandrine.avakian@inria.fr>
Thu, 13 Dec 2012 12:34:57 +0000 (13:34 +0100)
committerSandrine Avakian <sandrine.avakian@inria.fr>
Thu, 13 Dec 2012 12:34:57 +0000 (13:34 +0100)
new LDAP user to a federated user already registered in SFA db.
Introducing new federation option in bash_nukem.

sfa/importer/slabimporter.py
sfa/senslab/config/bash_nukem
sfa/senslab/slabdriver.py

index 7fd1eb5..d9e34bc 100644 (file)
@@ -75,6 +75,7 @@ class SlabImporter:
        
         self.records_by_type_hrn = \
             dict ( [ ( (record.type,record.hrn) , record ) for record in all_records ] )
+        print>>sys.stderr,"\r\n SLABIMPORT \t all_records[0] %s all_records[0].email %s \r\n" %(all_records[0].type, all_records[0])
         self.users_rec_by_email = \
             dict ( [ (record.email, record) for record in all_records if record.type == 'user' ] )
             
@@ -169,6 +170,8 @@ class SlabImporter:
                     
         # import persons
         for person in ldap_person_listdict : 
+            
+
             print>>sys.stderr,"SlabImporter: person: %s" %(person['hrn'])
             if 'ssh-rsa' not in person['pkey']:
                 #people with invalid ssh key (ssh-dss, empty, bullshit keys...)
@@ -181,9 +184,20 @@ class SlabImporter:
             if len(person_hrn) > 64: person_hrn = person_hrn[:64]
             person_urn = hrn_to_urn(person_hrn, 'user')
             
-            user_record = self.users_rec_by_email[person['email']]
-            print>>sys.stderr,"SlabImporter: user_record " , user_record
-            #user_record = self.find_record_by_type_hrn('user', person_hrn)
+            
+            print>>sys.stderr," \r\n SlabImporter:  HEYYYYYYYYYY" , self.users_rec_by_email
+            
+            #Check if user using person['email'] form LDAP is already registered
+            #in SFA. One email = one person. Inb this case, do not create another
+            #record for this person
+            #person_hrn  returned by GetPErson based on senslab root auth + uid ldap
+            user_record = self.find_record_by_type_hrn('user', person_hrn)
+            if not user_record and  person['email'] in self.users_rec_by_email:
+                user_record = self.users_rec_by_email[person['email']]
+                person_hrn = user_record.hrn
+                person_urn = hrn_to_urn(person_hrn, 'user')
+                
+            
             slice_record = self.find_record_by_type_hrn ('slice', slice_hrn)
             
             # return a tuple pubkey (a plc key object) and pkey (a Keypair object)
index 8878dff..70bd985 100755 (executable)
@@ -3,9 +3,10 @@
 # Configuration first : set the local repository
 # where the code can be found
 # Test number of arguments 
-if (( ! $# == 2 ))
+if (( ! $# == 3 ))
 then
-    echo " Usage : bash_nukem repository_directory vm (should be senslab or senslab2)"
+    echo " Usage : bash_nukem repository_directory vm (should be senslab or senslab2) and \
+    federation option (0 (not federated),1(other senslab) , 2(ple) 3 (senslab and ple))"
     echo  $#
     exit
 fi
@@ -28,6 +29,13 @@ else
     exit 
 fi
 
+if [ $vm = "senslab" ]
+then
+    federation_commented_line_nb=2
+else
+    federation_commented_line_nb=3
+fi
+
 # First restart sfa (prevents stalling when connecting
 # to the DB and dropping tables)
 sudo service sfa restart
@@ -70,6 +78,38 @@ sudo cp $git_local_repo/sfa/senslab/config/$vm/default_config.xml /etc/sfa/defau
 # sudo cp $git_local_repo/sfa/senslab/config/$vm/site.xml  /etc/sfa/site.xml
 # sudo cp $git_local_repo/sfa/senslab/config/$vm/site_config  /etc/sfa/configs/site_config
 # sudo ln -s ldap_config.py  /etc/sfa/ldap_config.py
+sudo cp $git_local_repo/sfa/senslab/config/registries.xml /etc/sfa/registries.xml
+sudo cp $git_local_repo/sfa/senslab/config/aggregates.xml /etc/sfa/aggregates.xml
+
+
+case "$3" in
+    0) echo "No federation at all"
+        #Insert a # on every beginning of line except if there is 'aggregates'
+        sed -i '/aggregates/!s/^/#/g' /etc/sfa/aggregates.xml 
+        sed -i '/aggregates/!s/^/#/g' /etc/sfa/registries.xml   
+        ;;
+    1) echo "Setting up federation with other senslab "
+        #  Commenting out senslab and ple, lines 2 and 4 OR
+        #  Commenting out senslab2 and ple, lines 3 and 4
+        sed -i "${federation_commented_line_nb} s/^/#/" /etc/sfa/aggregates.xml 
+        sed -i "${federation_commented_line_nb} s/^/#/" /etc/sfa/registries.xml 
+        sed -i '4 s/^/#/' /etc/sfa/aggregates.xml 
+        sed -i '4 s/^/#/' /etc/sfa/registries.xml 
+        ;;
+
+    2) echo "Setting up federation with  ple " 
+        sed -i '2 s/^/#/' /etc/sfa/aggregates.xml 
+        sed -i '2 s/^/#/' /etc/sfa/registries.xml 
+        sed -i '3 s/^/#/' /etc/sfa/aggregates.xml 
+        sed -i '3 s/^/#/' /etc/sfa/registries.xml 
+        ;;  
+
+    3) echo "setting federation with other senslab and ple"
+        # Commenting out senslab or senslab2
+        sed -i "${federation_commented_line_nb} s/^/#/" /etc/sfa/aggregates.xml 
+        sed -i "${federation_commented_line_nb} s/^/#/" /etc/sfa/registries.xml 
+        ;;
+esac
 
 #Senslab LDAP and OAR access config files
 if [ ! -f /etc/sfa/ldap_config.py ] 
index 3871280..81ac2c4 100644 (file)
@@ -1491,7 +1491,7 @@ class SlabDriver(Driver):
                         for rec in recslice_list: 
                             logger.debug("SLABDRIVER\r\n  \t \t fill_record_info oar_job_id %s " %(rec['oar_job_id']))
                             #record['oar_job_id'].append(rec['oar_job_id'])
-                            del record['_sa_instance_state']
+                            #del record['_sa_instance_state']
                             del record['reg_researchers']
                             record['node_ids'] = [ self.root_auth + hostname for hostname in rec['node_ids']]
                     except KeyError: