From: Sandrine Avakian Date: Thu, 13 Dec 2012 12:34:57 +0000 (+0100) Subject: Modification on slabimporter to avoid creating an account when importing X-Git-Tag: sfa-2.1-24~3^2~18 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=06f76822b82796118adaefb01780bbd477ee0b72;hp=c4f80717603881b90361d31a874c077450b4e240;p=sfa.git Modification on slabimporter to avoid creating an account when importing new LDAP user to a federated user already registered in SFA db. Introducing new federation option in bash_nukem. --- diff --git a/sfa/importer/slabimporter.py b/sfa/importer/slabimporter.py index 7fd1eb57..d9e34bc9 100644 --- a/sfa/importer/slabimporter.py +++ b/sfa/importer/slabimporter.py @@ -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) diff --git a/sfa/senslab/config/bash_nukem b/sfa/senslab/config/bash_nukem index 8878dff1..70bd985a 100755 --- a/sfa/senslab/config/bash_nukem +++ b/sfa/senslab/config/bash_nukem @@ -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 ] diff --git a/sfa/senslab/slabdriver.py b/sfa/senslab/slabdriver.py index 38712808..81ac2c45 100644 --- a/sfa/senslab/slabdriver.py +++ b/sfa/senslab/slabdriver.py @@ -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: