patch for dealing with clients that don't set a component_id
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Wed, 24 Apr 2019 08:07:35 +0000 (10:07 +0200)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Wed, 24 Apr 2019 08:07:35 +0000 (10:07 +0200)
when talking to a single-node testbed like R2lab

sfa/planetlab/plslices.py

index e868acd..d0cd2cb 100644 (file)
@@ -220,17 +220,32 @@ class PlSlices:
     def verify_slice_nodes(self, slice_urn, slice, rspec_nodes):
 
         slivers = {}
-        for node in rspec_nodes:
-            hostname = node.get('component_name')
-            client_id = node.get('client_id')
-            component_id = node.get('component_id').strip()
-            if hostname:
-                hostname = hostname.strip()
-            elif component_id:
-                hostname = xrn_to_hostname(component_id)
-            if hostname:
-                slivers[hostname] = {
-                    'client_id': client_id, 'component_id': component_id}
+        try:
+            for node in rspec_nodes:
+                hostname = node.get('component_name')
+                client_id = node.get('client_id')
+                component_id = node.get('component_id').strip()
+                if hostname:
+                    hostname = hostname.strip()
+                elif component_id:
+                    hostname = xrn_to_hostname(component_id)
+                if hostname:
+                    slivers[hostname] = {
+                        'client_id': client_id, 'component_id': component_id}
+        # for r2lab and similar use cases
+        # the incoming rspec has no component_id, and
+        # since there's only one node in the whole testbed
+        # we can assume that's the one
+        # admittedly quite hacky, but this is intended temporary
+        # in an attempt to make progress on the fed4fire-r2lab federation link
+        except AttributeError:
+            all_nodes = self.driver.shell.GetNodes({},['hostname'])
+            if len(all_nodes) == 1:
+                hostname = all_nodes[0]['hostname']
+                component_id = Xrn(xrn=hostname).get_urn()
+                slivers[hostname] = dict(
+                    client_id=client_id,
+                    component_id=component_id)
 
         nodes = self.driver.shell.GetNodes(
             slice['node_ids'], ['node_id', 'hostname', 'interface_ids'])