iotlab driver: wip fixing Timur's bug when a user already has an account in LDAP...
Loic Baron [Wed, 30 Jul 2014 16:16:05 +0000 (18:16 +0200)]
sfa/iotlab/LDAPapi.py
sfa/iotlab/OARrestapi.py
sfa/iotlab/iotlabdriver.py
sfa/iotlab/iotlabshell.py
sfa/iotlab/iotlabslices.py

index 7c3deb6..94565b8 100644 (file)
@@ -960,6 +960,10 @@ class LDAPapi:
             #then the login is different from the one found in its hrn
             if tmpname != hrn.split('.')[1]:
                 hrn = None
+        else:
+            hrn = None
+
+        if hrn is None:
             results = {
                 'type': 'user',
                 'pkey': ldapentry['sshPublicKey'],
@@ -974,7 +978,6 @@ class LDAPapi:
                 'authority': parent_hrn,
                 'peer_authority': peer_authority,
                 'pointer': -1,
-                'hrn': hrn,
              }
         else:
             #hrn = None
@@ -992,6 +995,7 @@ class LDAPapi:
                 'authority': parent_hrn,
                 'peer_authority': peer_authority,
                 'pointer': -1,
+                'hrn': hrn,
             }
         return results
 
index c612e47..20091e4 100644 (file)
@@ -228,7 +228,7 @@ class OARrestapi:
         #                    % (error))
             #raise ServerError("GET_OAR_SRVR : Could not reach OARserver")
         if resp.status >= 400:
-            raise ValueError ("Response Error %s, %s" %(resp.status,
+            raise ValueError ("Response Error %s, %s, %s" %(resp.status,
                 resp.reason, resp.read()))
         try:
             js_dict = json.loads(body)
@@ -286,7 +286,7 @@ class OARrestapi:
             conn.close()
 
         if resp.status >= 400:
-            raise ValueError ("Response Error %s, %s" %(resp.status,
+            raise ValueError ("Response Error %s, %s, %s" %(resp.status,
                 resp.reason, body))
 
 
index 016249b..1da81c5 100644 (file)
@@ -1493,15 +1493,18 @@ class IotlabDriver(Driver):
 
         # XXX JORDAN XXX slice_record devrait recevoir le caller_xrn...
         # LOIC maintenant c'est fait au dessus
-        logger.debug("LOIC - slice_record[user] = %s" % slice_record['user'])
+        logger.debug("IOTLABDRIVER.PY - LOIC - slice_record[user][hrn] = %s" % slice_record['user']['hrn'])
+        logger.debug("IOTLABDRIVER.PY - LOIC - slice_record[reg-researchers] = %s" % slice_record['reg-researchers'])
         persons = slices.verify_persons(xrn.hrn, slice_record, users,
                                         options=options)
         logger.debug("IOTLABDRIVER.PY  AFTER slices.verify_persons")
         logger.debug("LOIC - slice_record[user] = %s" % slice_record['user'])
+        logger.debug("IOTLABDRIVER.PY - LOIC - slice_record[reg-researchers] = %s" % slice_record['reg-researchers'])
 
         # ensure slice record exists
         current_slice = slices.verify_slice(xrn.hrn, slice_record, sfa_peer)
         logger.debug("LOIC - AFTER verify_slice - slice_record[user] = %s" % slice_record['user'])
+        logger.debug("IOTLABDRIVER.PY - LOIC - slice_record[reg-researchers] = %s" % slice_record['reg-researchers'])
         logger.debug("IOTLABDRIVER.PY \t ===============allocate \t\
                             \r\n \r\n  current_slice %s" % (current_slice))
 
index 34de4b1..830da14 100644 (file)
@@ -69,8 +69,8 @@ class IotlabShell():
         :rtype: list of dicts
 
         """
-        logger.debug("IOTLAB_API \tGetPersons person_filter %s"
-                     % (person_filter))
+        logger.debug("IOTLAB_API \tGetPersons 1st person_filter %s"
+                     % (person_filter[0]['hrn']))
         person_list = []
         if person_filter and isinstance(person_filter, list):
         #If we are looking for a list of users (list of dict records)
index bf198f6..710f613 100644 (file)
@@ -316,17 +316,18 @@ class IotlabSlices:
         sfa_slice = None
 
         # check if slice belongs to Iotlab
-        slices_list = self.driver.GetSlices(slice_filter=slicename,
-                                            slice_filter_type='slice_hrn')
-
-        if slices_list:
-            for sl in slices_list:
-
-                logger.debug("IOTLABSLICES \t verify_slice slicename %s \
-                                slices_list %s sl %s \r slice_record %s"
-                             % (slicename, slices_list, sl, slice_record))
-                sfa_slice = sl
-                sfa_slice.update(slice_record)
+        if slicename.startswith("iotlab"):
+            slices_list = self.driver.GetSlices(slice_filter=slicename,
+                                                slice_filter_type='slice_hrn')
+    
+            if slices_list:
+                for sl in slices_list:
+    
+                    logger.debug("IOTLABSLICES \t verify_slice slicename %s \
+                                    slices_list %s sl %s \r slice_record %s"
+                                 % (slicename, slices_list, sl, slice_record))
+                    sfa_slice = sl
+                    sfa_slice.update(slice_record)
 
         else:
             #Search for user in ldap based on email SA 14/11/12
@@ -389,7 +390,7 @@ class IotlabSlices:
 
 
         """
-        slice_user = slice_record['user']
+        slice_user = slice_record['user']['hrn']
 
         if options is None: options={}
         logger.debug("IOTLABSLICES \tverify_persons \tslice_hrn  %s  \
@@ -400,7 +401,9 @@ class IotlabSlices:
         #users_dict : dict whose keys can either be the user's hrn or its id.
         #Values contains only id and hrn
         users_dict = {}
-
+        
+        # XXX LOIC !!! Fix: Only 1 user per slice in iotlab
+        users = [slice_record['user']]
         #First create dicts by hrn and id for each user in the user record list:
         for info in users:
             # if 'slice_record' in info:
@@ -412,9 +415,9 @@ class IotlabSlices:
                 users_by_email[info['email']] = info
                 users_dict[info['email']] = info
 
-        logger.debug("IOTLABSLICES.PY \t verify_person  \
-                        users_dict %s \r\n user_by_email %s \r\n  "
-                     % (users_dict, users_by_email))
+        #logger.debug("IOTLABSLICES.PY \t verify_person  \
+        #                users_dict %s \r\n user_by_email %s \r\n  "
+        #             % (users_dict, users_by_email))
 
         existing_user_ids = []
         existing_user_emails = []
@@ -441,9 +444,10 @@ class IotlabSlices:
             if existing_users:
                 for user in existing_users:
                     user['login'] = user['uid']
-                    users_dict[user['email']].update(user)
-                    existing_user_emails.append(
-                        users_dict[user['email']]['email'])
+                    # XXX LOIC Fix we already have all informations comming from Allocate
+                    #users_dict[user['email']].update(user)
+                    #existing_user_emails.append(
+                    #    users_dict[user['email']]['email'])
                 logger.debug("User is in iotlab LDAP slice_record[user] = %s" % slice_user)
 
             # User from another known trusted federated site. Check
@@ -501,7 +505,8 @@ class IotlabSlices:
         # add new users
         #requested_user_email is in existing_user_emails
         if len(added_user_emails) == 0:
-            slice_record['login'] = users_dict[requested_user_emails[0]]['uid']
+            slice_record['login'] = existing_users[0]['uid']
+            #slice_record['login'] = users_dict[requested_user_emails[0]]['uid']
             logger.debug(" IOTLABSLICES  \tverify_person QUICK DIRTY %s"
                          % (slice_record))
             # XXX JORDAN uid == 'register'