iotlab driver: applying Jordan's fixes to the driver
Loic Baron [Wed, 30 Jul 2014 13:47:32 +0000 (15:47 +0200)]
sfa/iotlab/iotlabaggregate.py
sfa/iotlab/iotlabdriver.py
sfa/iotlab/iotlabslices.py

index 56e40e4..e113d8e 100644 (file)
@@ -405,7 +405,8 @@ class IotlabAggregate:
         if options is None: options={}
         filter={}
         if slice:
-           filter.update({'name':slice['slice_name']})
+           filter.update({'slice_hrn':slice['slice_hrn']}) # JORDAN: this is = "upmc" !!!
+           #filter.update({'name':slice['slice_name']})
         #return_fields = ['lease_id', 'hostname', 'site_id', 'name', 't_from', 't_until']
         leases = self.driver.GetLeases(lease_filter_dict=filter)
         grain = self.driver.testbed_shell.GetLeaseGranularity()
@@ -614,7 +615,8 @@ class IotlabAggregate:
 
         .. seealso:: http://groups.geni.net/geni/wiki/GAPI_AM_API_V3/CommonConcepts#urns
         """
-
+        # JORDAN using SLICE_KEY for slice_hrn
+        SLICE_KEY = 'slice_hrn' # slice_hrn
         if options is None: options={}
         slice_ids = set()
         node_ids = []
@@ -641,18 +643,19 @@ class IotlabAggregate:
                        \r\n" % (xrn, slice_names))
         filter_sliver = {}
         if slice_names:
-            filter_sliver['slice_hrn'] = list(slice_names)
-            slice_hrn = filter_sliver['slice_hrn'][0]
+            filter_sliver[SLICE_KEY] = list(slice_names)
+            slice_hrn = filter_sliver[SLICE_KEY][0]
 
-            slice_filter_type = 'slice_hrn'
+            slice_filter_type = SLICE_KEY
 
         # if slice_ids:
         #     filter['slice_id'] = list(slice_ids)
         # # get slices
         if slice_hrn:
+            #logger.debug("JORDAN SLICE_HRN=%r" % slice_hrn)
             slices = self.driver.GetSlices(slice_hrn,
                 slice_filter_type)
-            leases = self.driver.GetLeases({'slice_hrn':slice_hrn})
+            leases = self.driver.GetLeases({SLICE_KEY:slice_hrn})
         logger.debug("IotlabAggregate \t get_slivers \
                        slices %s leases %s\r\n" % (slices, leases ))
         if not slices:
@@ -660,6 +663,13 @@ class IotlabAggregate:
 
         single_slice = slices[0]
         # get sliver users
+        # XXX LOIC !!! XXX QUICK AND DIRTY - Let's try...
+        logger.debug("LOIC Number of reg_researchers = %s" % len(single_slice['reg_researchers']))
+        if 'reg_researchers' in single_slice and len(single_slice['reg_researchers'])==0:
+            user = {'uid':single_slice['user']}
+        else:
+            user = single_slice['reg_researchers'][0].__dict__
+
         user = single_slice['reg_researchers'][0].__dict__
         logger.debug("IotlabAggregate \t get_slivers user %s \
                        \r\n" % (user))
@@ -670,14 +680,18 @@ class IotlabAggregate:
                        \r\n" % (person))
         # name = person['last_name']
         user['login'] = person['uid']
-        user['user_urn'] = hrn_to_urn(user['hrn'], 'user')
-        user['keys'] = person['pkey']
+        # XXX LOIC !!! if we have more info, let's fill user
+        if 'hrn' in user:
+            user['user_urn'] = hrn_to_urn(user['hrn'], 'user')
+        if 'keys' in user:
+            user['keys'] = person['pkey']
 
 
         try:
             node_ids = single_slice['node_ids']
-            node_list = self.driver.testbed_shell.GetNodes(
-                    {'hostname':single_slice['node_ids']})
+            node_list = self.driver.testbed_shell.GetNodes()
+# JORDAN REMOVED FILTER so that next check always succeed
+#                    {'hostname':single_slice['node_ids']})
             node_by_hostname = dict([(node['hostname'], node)
                                         for node in node_list])
         except KeyError:
@@ -697,11 +711,16 @@ class IotlabAggregate:
                 node_id = current_lease['resource_ids'][index]
                 # node['slice_name'] = user['login']
                 # node.update(single_slice)
+                # JORDAN XXX This fails sometimes when hostname not in the list
+                #if hostname in node_by_hostname:
                 more_info = node_by_hostname[hostname]
                 node.update(more_info)
+                #else:
+                #    # This can happen when specifying a lease without the resource, then all subsequent calls will fail
+                #    logger.debug("Ignored missing hostname for now one")
                 # oar_job_id is the slice_id (lease_id)
                 sliver_hrn = '%s.%s-%s' % (self.driver.hrn,
-                            current_lease['lease_id'], node_id)
+                             current_lease['lease_id'], node_id)
                 node['node_id'] = node_id
                 node['expires'] = current_lease['t_until']
                 node['sliver_id'] = Xrn(sliver_hrn, type='sliver').urn
@@ -824,7 +843,10 @@ class IotlabAggregate:
             geni_urn = sliver_allocation.slice_urn
             sliver_allocation_dict[sliver_allocation.sliver_id] = \
                                                             sliver_allocation
-        if not options.get('list_leases') or options['list_leases'] != 'leases':                                                    
+        # JORDAN get the option list_leases if we want to have the leases in describe 
+        show_leases = options.get('list_leases')
+        if show_leases in ['resources', 'all']:
+        #if not options.get('list_leases') or options['list_leases'] != 'leases': 
             # add slivers
             nodes_dict = {}
             for sliver in slivers:
@@ -839,9 +861,11 @@ class IotlabAggregate:
                 geni_slivers.append(geni_sliver)
             rspec.version.add_nodes(rspec_nodes)
 
-        if not options.get('list_leases') or options['list_leases'] == 'resources':
+        if show_leases in ['leases', 'all']:
+        #if not options.get('list_leases') or options['list_leases'] == 'resources':
             if slivers:
-                leases = self.get_leases(slivers[0])
+                leases = self.get_leases(slice=slivers[0])
+                logger.debug("JORDAN: getting leases from slice: %r" % slivers[0])
                 rspec.version.add_leases(leases)
 
         return {'geni_urn': geni_urn,
index adcf8a1..016249b 100644 (file)
@@ -1490,6 +1490,9 @@ class IotlabDriver(Driver):
         # dans la methode avec les infos du user, els infos sont propagees
         # dans verify_slice_leases
         logger.debug("IOTLABDRIVER.PY  BEFORE slices.verify_persons")
+
+        # 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'])
         persons = slices.verify_persons(xrn.hrn, slice_record, users,
                                         options=options)
@@ -1507,6 +1510,7 @@ class IotlabDriver(Driver):
                                     # options=options)
 
         # add/remove slice from nodes
+        # XXX JORDAN ensure requested_xp_dict returns a dict with all new leases
         requested_xp_dict = self._process_requested_xp_dict(rspec)
 
         logger.debug("IOTLABDRIVER.PY \tallocate  requested_xp_dict %s "
@@ -1529,10 +1533,14 @@ class IotlabDriver(Driver):
         rspec_requested_leases = rspec.version.get_leases()
         leases = slices.verify_slice_leases(slice_record,
                                                 requested_xp_dict, peer)
+        # JORDAN: 
+        #   leases = already in slice
+        #   rspec_requested_leases = newly requested
         logger.debug("IOTLABDRIVER.PY \tallocate leases  %s \
                         rspec_requested_leases %s" % (leases,
                         rspec_requested_leases))
-         # update sliver allocations
+        # update sliver allocations
+        # JORDAN Here we loop over newly allocated nodes
         for hostname in nodes_list:
             client_id = hostname
             node_urn = xrn_object(self.testbed_shell.root_auth, hostname).urn
@@ -1560,7 +1568,7 @@ class IotlabDriver(Driver):
             'geni_slice_urn': urn,
             'list_leases': 'all',
         }
-        return aggregate.describe([xrn.get_urn()], version=rspec.version)
+        return aggregate.describe([xrn.get_urn()], version=rspec.version, options=describe_options)
 
     def provision(self, urns, options=None):
         if options is None: options={}
@@ -1589,4 +1597,4 @@ class IotlabDriver(Driver):
             'geni_slice_urn': current_slice['urn'],
             'list_leases': 'all',
         }
-        return self.describe(urns, rspec_version, options=options)
+        return self.describe(urns, rspec_version, options=describe_options)
index 05a8e03..2a1b3bc 100644 (file)
@@ -2,7 +2,7 @@
 This file defines the IotlabSlices class by which all the slice checkings
 upon lease creation are done.
 """
-from sfa.util.xrn import get_authority, urn_to_hrn
+from sfa.util.xrn import get_authority, urn_to_hrn, hrn_to_urn
 from sfa.util.sfalogging import logger
 
 MAXINT = 2L**31-1
@@ -212,11 +212,13 @@ class IotlabSlices:
                     job['hostname'],
                     sfa_slice, int(job['start_time']),
                     int(job['duration']))
-                if job_id is not None:
-                    new_leases = self.driver.GetLeases(login=
-                        sfa_slice['login'])
-                    for new_lease in new_leases:
-                        leases.append(new_lease)
+
+                # Removed by jordan
+                #if job_id is not None:
+                #    new_leases = self.driver.GetLeases(login=
+                #        sfa_slice['login'])
+                #    for new_lease in new_leases:
+                #        leases.append(new_lease)
 
         #Deleted leases are the ones with lease id not declared in the Rspec
         if deleted_leases:
@@ -235,7 +237,10 @@ class IotlabSlices:
                     job['hostname'],
                     sfa_slice, int(job['start_time']),
                     int(job['duration']))
-        return leases
+
+        # Added by Jordan: until we find a better solution, always update the list of leases
+        return self.driver.GetLeases(login= sfa_slice['login'])
+        #return leases
 
     def verify_slice_nodes(self, sfa_slice, requested_slivers, peer):
         """Check for wanted and unwanted nodes in the slice.