[ARVADOS] updated: ceb9156a30ec638e768524c1b6725a8c30054f21

Git user git at public.curoverse.com
Thu Apr 7 17:28:42 EDT 2016


Summary of changes:
 .../arvnodeman/computenode/driver/__init__.py      | 39 ++++++++++++++--------
 .../arvnodeman/computenode/driver/azure.py         |  7 ++--
 .../arvnodeman/computenode/driver/ec2.py           |  4 ++-
 .../arvnodeman/computenode/driver/gce.py           |  7 ++--
 .../tests/test_computenode_driver_azure.py         |  4 ---
 .../tests/test_computenode_driver_ec2.py           |  3 --
 .../tests/test_computenode_driver_gce.py           |  4 ---
 services/nodemanager/tests/testutil.py             |  6 ++--
 8 files changed, 42 insertions(+), 32 deletions(-)

       via  ceb9156a30ec638e768524c1b6725a8c30054f21 (commit)
      from  12b18d9bbed9d604fb5f2a17ee0744bba1cc79e9 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit ceb9156a30ec638e768524c1b6725a8c30054f21
Author: Brett Smith <brett at curoverse.com>
Date:   Thu Apr 7 17:28:26 2016 -0400

    8872: Fixups from code review.

diff --git a/services/nodemanager/arvnodeman/computenode/driver/__init__.py b/services/nodemanager/arvnodeman/computenode/driver/__init__.py
index d46b4b6..95b6fa8 100644
--- a/services/nodemanager/arvnodeman/computenode/driver/__init__.py
+++ b/services/nodemanager/arvnodeman/computenode/driver/__init__.py
@@ -80,10 +80,17 @@ class BaseComputeNodeDriver(RetryMixin):
         return 'auth', key
 
     def search_for_now(self, term, list_method, key=attrgetter('id'), **kwargs):
-        """Call a cloud list API method and return one matching item.
+        """Return one matching item from a list of cloud objects.
+
+        Raises ValueError if the number of matching objects is not exactly 1.
 
-        See search_for() for details of arguments and exceptions.
-        This method does not cache results.
+        Arguments:
+        * term: The value that identifies a matching item.
+        * list_method: A string that names the method to call on this
+          instance's libcloud driver for a list of objects.
+        * key: A function that accepts a cloud object and returns a
+          value search for a `term` match on each item.  Returns the
+          object's 'id' attribute by default.
         """
         items = getattr(self.real, list_method)(**kwargs)
         results = [item for item in items if key(item) == term]
@@ -94,17 +101,11 @@ class BaseComputeNodeDriver(RetryMixin):
         return results[0]
 
     def search_for(self, term, list_method, key=attrgetter('id'), **kwargs):
-        """Return one matching item from a list of cloud objects.
-
-        Raises ValueError if the number of matching objects is not exactly 1.
+        """Return one cached matching item from a list of cloud objects.
 
-        Arguments:
-        * term: The value that identifies a matching item.
-        * list_method: A string that names the method to call on this
-          instance's libcloud driver for a list of objects.
-        * key: A function that accepts a cloud object and returns a
-          value search for a `term` match on each item.  Returns the
-          object's 'id' attribute by default.
+        See search_for_now() for details of arguments and exceptions.
+        This method caches results, so it's good to find static cloud objects
+        like node sizes, regions, etc.
         """
         cache_key = (list_method, term)
         if cache_key not in self.SEARCH_CACHE:
@@ -117,6 +118,18 @@ class BaseComputeNodeDriver(RetryMixin):
         l.update(kwargs)
         return self.real.list_nodes(**l)
 
+    def create_cloud_name(self, arvados_node):
+        """Return a cloud node name for the given Arvados node record.
+
+        Subclasses must override this method.  It should return a string
+        that can be used as the name for a newly-created cloud node,
+        based on identifying information in the Arvados node record.
+
+        Arguments:
+        * arvados_node: This Arvados node record to seed the new cloud node.
+        """
+        raise NotImplementedError("BaseComputeNodeDriver.create_cloud_name")
+
     def arvados_create_kwargs(self, size, arvados_node):
         """Return dynamic keyword arguments for create_node.
 
diff --git a/services/nodemanager/arvnodeman/computenode/driver/azure.py b/services/nodemanager/arvnodeman/computenode/driver/azure.py
index 167d8b3..e293d1b 100644
--- a/services/nodemanager/arvnodeman/computenode/driver/azure.py
+++ b/services/nodemanager/arvnodeman/computenode/driver/azure.py
@@ -38,15 +38,18 @@ class ComputeNodeDriver(BaseComputeNodeDriver):
             auth_kwargs, list_kwargs, create_kwargs,
             driver_class)
 
+    def create_cloud_name(self, arvados_node):
+        uuid_parts = arvados_node['uuid'].split('-', 2)
+        return 'compute-{parts[2]}-{parts[0]}'.format(parts=uuid_parts)
+
     def arvados_create_kwargs(self, size, arvados_node):
-        cluster_id, _, node_id = arvados_node['uuid'].split('-')
-        name = 'compute-{}-{}'.format(node_id, cluster_id)
         tags = {
             'booted_at': time.strftime(ARVADOS_TIMEFMT, time.gmtime()),
             'arv-ping-url': self._make_ping_url(arvados_node)
         }
         tags.update(self.tags)
 
+        name = self.create_cloud_name(arvados_node)
         customdata = """#!/bin/sh
 mkdir -p    /var/tmp/arv-node-data/meta-data
 echo %s > /var/tmp/arv-node-data/arv-ping-url
diff --git a/services/nodemanager/arvnodeman/computenode/driver/ec2.py b/services/nodemanager/arvnodeman/computenode/driver/ec2.py
index d314d38..8deabbd 100644
--- a/services/nodemanager/arvnodeman/computenode/driver/ec2.py
+++ b/services/nodemanager/arvnodeman/computenode/driver/ec2.py
@@ -64,8 +64,10 @@ class ComputeNodeDriver(BaseComputeNodeDriver):
     def _init_subnet_id(self, subnet_id):
         return 'ex_subnet', self.search_for(subnet_id, 'ex_list_subnets')
 
+    create_cloud_name = staticmethod(arvados_node_fqdn)
+
     def arvados_create_kwargs(self, size, arvados_node):
-        return {'name': arvados_node_fqdn(arvados_node),
+        return {'name': self.create_cloud_name(arvados_node),
                 'ex_userdata': self._make_ping_url(arvados_node)}
 
     def post_create_node(self, cloud_node):
diff --git a/services/nodemanager/arvnodeman/computenode/driver/gce.py b/services/nodemanager/arvnodeman/computenode/driver/gce.py
index be99883..b853f00 100644
--- a/services/nodemanager/arvnodeman/computenode/driver/gce.py
+++ b/services/nodemanager/arvnodeman/computenode/driver/gce.py
@@ -60,9 +60,12 @@ class ComputeNodeDriver(BaseComputeNodeDriver):
             self.create_kwargs['ex_metadata']['sshKeys'] = (
                 'root:' + ssh_file.read().strip())
 
+    def create_cloud_name(self, arvados_node):
+        uuid_parts = arvados_node['uuid'].split('-', 2)
+        return 'compute-{parts[2]}-{parts[0]}'.format(parts=uuid_parts)
+
     def arvados_create_kwargs(self, size, arvados_node):
-        cluster_id, _, node_id = arvados_node['uuid'].split('-')
-        name = 'compute-{}-{}'.format(node_id, cluster_id)
+        name = self.create_cloud_name(arvados_node)
         disks = [
             {'autoDelete': True,
              'boot': True,
diff --git a/services/nodemanager/tests/test_computenode_driver_azure.py b/services/nodemanager/tests/test_computenode_driver_azure.py
index 0b99e9c..8e701b9 100644
--- a/services/nodemanager/tests/test_computenode_driver_azure.py
+++ b/services/nodemanager/tests/test_computenode_driver_azure.py
@@ -19,10 +19,6 @@ class AzureComputeNodeDriverTestCase(testutil.DriverTestMixin, unittest.TestCase
         list_kwargs.setdefault("ex_resource_group", "TestResourceGroup")
         return super(AzureComputeNodeDriverTestCase, self).new_driver(auth_kwargs, list_kwargs, create_kwargs)
 
-    def cloud_name_from_arv_node(self, arv_node):
-        uuid_parts = arv_node['uuid'].split('-', 2)
-        return 'compute-{parts[2]}-{parts[0]}'.format(parts=uuid_parts)
-
     def test_driver_instantiation(self):
         kwargs = {'key': 'testkey'}
         driver = self.new_driver(auth_kwargs=kwargs)
diff --git a/services/nodemanager/tests/test_computenode_driver_ec2.py b/services/nodemanager/tests/test_computenode_driver_ec2.py
index 7f1b38e..a778cd5 100644
--- a/services/nodemanager/tests/test_computenode_driver_ec2.py
+++ b/services/nodemanager/tests/test_computenode_driver_ec2.py
@@ -15,9 +15,6 @@ from . import testutil
 class EC2ComputeNodeDriverTestCase(testutil.DriverTestMixin, unittest.TestCase):
     TEST_CLASS = ec2.ComputeNodeDriver
 
-    def cloud_name_from_arv_node(self, arv_node):
-        return '{n[hostname]}.{n[domain]}'.format(n=arv_node)
-
     def test_driver_instantiation(self):
         kwargs = {'key': 'testkey'}
         driver = self.new_driver(auth_kwargs=kwargs)
diff --git a/services/nodemanager/tests/test_computenode_driver_gce.py b/services/nodemanager/tests/test_computenode_driver_gce.py
index 15d94a5..e8b2fa3 100644
--- a/services/nodemanager/tests/test_computenode_driver_gce.py
+++ b/services/nodemanager/tests/test_computenode_driver_gce.py
@@ -28,10 +28,6 @@ class GCEComputeNodeDriverTestCase(testutil.DriverTestMixin, unittest.TestCase):
         return super(GCEComputeNodeDriverTestCase, self).new_driver(
             auth_kwargs, list_kwargs, create_kwargs)
 
-    def cloud_name_from_arv_node(self, arv_node):
-        uuid_parts = arv_node['uuid'].split('-', 2)
-        return 'compute-{parts[2]}-{parts[0]}'.format(parts=uuid_parts)
-
     def test_driver_instantiation(self):
         kwargs = {'user_id': 'foo'}
         driver = self.new_driver(auth_kwargs=kwargs)
diff --git a/services/nodemanager/tests/testutil.py b/services/nodemanager/tests/testutil.py
index 35716ab..b376ca7 100644
--- a/services/nodemanager/tests/testutil.py
+++ b/services/nodemanager/tests/testutil.py
@@ -144,10 +144,10 @@ class DriverTestMixin(object):
             self.assertIs(driver.real, driver_mock2)
 
     def test_create_can_find_node_after_timeout(self):
+        driver = self.new_driver()
         arv_node = arvados_node_mock()
         cloud_node = cloud_node_mock()
-        cloud_node.name = self.cloud_name_from_arv_node(arv_node)
-        driver = self.new_driver()
+        cloud_node.name = driver.create_cloud_name(arv_node)
         create_method = self.driver_mock().create_node
         create_method.side_effect = cloud_types.LibcloudError("fake timeout")
         list_method = self.driver_mock().list_nodes
@@ -156,8 +156,8 @@ class DriverTestMixin(object):
         self.assertIs(cloud_node, actual)
 
     def test_create_can_raise_exception_after_timeout(self):
-        arv_node = arvados_node_mock()
         driver = self.new_driver()
+        arv_node = arvados_node_mock()
         create_method = self.driver_mock().create_node
         create_method.side_effect = cloud_types.LibcloudError("fake timeout")
         list_method = self.driver_mock().list_nodes

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list