[ARVADOS] created: 2d74226c43ec6eb6f4f9b6f7957755785802b680
Git user
git at public.curoverse.com
Mon May 2 17:06:34 EDT 2016
at 2d74226c43ec6eb6f4f9b6f7957755785802b680 (commit)
commit 2d74226c43ec6eb6f4f9b6f7957755785802b680
Author: Brett Smith <brett at curoverse.com>
Date: Mon May 2 17:06:09 2016 -0400
9120: search_for_now falls back to real driver methods when needed.
This fixes a regression introduced in 32eb510594.
diff --git a/services/nodemanager/arvnodeman/computenode/driver/__init__.py b/services/nodemanager/arvnodeman/computenode/driver/__init__.py
index 1bf2493..fa9cfff 100644
--- a/services/nodemanager/arvnodeman/computenode/driver/__init__.py
+++ b/services/nodemanager/arvnodeman/computenode/driver/__init__.py
@@ -92,7 +92,11 @@ class BaseComputeNodeDriver(RetryMixin):
value search for a `term` match on each item. Returns the
object's 'id' attribute by default.
"""
- items = getattr(self, list_method)(**kwargs)
+ try:
+ list_func = getattr(self, list_method)
+ except AttributeError:
+ list_func = getattr(self.real, list_method)
+ items = list_func(**kwargs)
results = [item for item in items if key(item) == term]
count = len(results)
if count != 1:
diff --git a/services/nodemanager/tests/test_computenode_driver.py b/services/nodemanager/tests/test_computenode_driver.py
index 221f3cc..71a39a6 100644
--- a/services/nodemanager/tests/test_computenode_driver.py
+++ b/services/nodemanager/tests/test_computenode_driver.py
@@ -22,6 +22,13 @@ class ComputeNodeDriverTestCase(unittest.TestCase):
self.assertIs(image, driver.search_for_now('id_1', 'list_images'))
self.assertEqual(1, self.driver_mock().list_images.call_count)
+ def test_search_for_now_uses_private_method(self):
+ net = testutil.cloud_object_mock(1)
+ self.driver_mock().ex_list_networks.return_value = [net]
+ driver = driver_base.BaseComputeNodeDriver({}, {}, {}, self.driver_mock)
+ self.assertIs(net, driver.search_for_now('id_1', 'ex_list_networks'))
+ self.assertEqual(1, self.driver_mock().ex_list_networks.call_count)
+
def test_search_for_now_raises_ValueError_on_zero_results(self):
self.driver_mock().list_images.return_value = []
driver = driver_base.BaseComputeNodeDriver({}, {}, {}, self.driver_mock)
commit 85cf81ec3693485088a09a0a1367e21cf7011fad
Author: Brett Smith <brett at curoverse.com>
Date: Mon May 2 16:59:21 2016 -0400
9120: Add tests for BaseComputeNodeDriver's search_for methods.
diff --git a/services/nodemanager/tests/test_computenode_driver.py b/services/nodemanager/tests/test_computenode_driver.py
new file mode 100644
index 0000000..221f3cc
--- /dev/null
+++ b/services/nodemanager/tests/test_computenode_driver.py
@@ -0,0 +1,54 @@
+#!/usr/bin/env python
+
+from __future__ import absolute_import, print_function
+
+import unittest
+
+import libcloud.common.types as cloud_types
+import mock
+
+import arvnodeman.computenode.driver as driver_base
+from . import testutil
+
+class ComputeNodeDriverTestCase(unittest.TestCase):
+ def setUp(self):
+ self.driver_mock = mock.MagicMock(name='driver_mock')
+ driver_base.BaseComputeNodeDriver.SEARCH_CACHE = {}
+
+ def test_search_for_now_uses_public_method(self):
+ image = testutil.cloud_object_mock(1)
+ self.driver_mock().list_images.return_value = [image]
+ driver = driver_base.BaseComputeNodeDriver({}, {}, {}, self.driver_mock)
+ self.assertIs(image, driver.search_for_now('id_1', 'list_images'))
+ self.assertEqual(1, self.driver_mock().list_images.call_count)
+
+ def test_search_for_now_raises_ValueError_on_zero_results(self):
+ self.driver_mock().list_images.return_value = []
+ driver = driver_base.BaseComputeNodeDriver({}, {}, {}, self.driver_mock)
+ with self.assertRaises(ValueError) as test:
+ driver.search_for_now('id_1', 'list_images')
+
+ def test_search_for_now_raises_ValueError_on_extra_results(self):
+ image = testutil.cloud_object_mock(1)
+ self.driver_mock().list_images.return_value = [image, image]
+ driver = driver_base.BaseComputeNodeDriver({}, {}, {}, self.driver_mock)
+ with self.assertRaises(ValueError) as test:
+ driver.search_for_now('id_1', 'list_images')
+
+ def test_search_for_now_does_not_cache_results(self):
+ image1 = testutil.cloud_object_mock(1)
+ image2 = testutil.cloud_object_mock(1)
+ self.driver_mock().list_images.side_effect = [[image1], [image2]]
+ driver = driver_base.BaseComputeNodeDriver({}, {}, {}, self.driver_mock)
+ self.assertIsNot(driver.search_for_now('id_1', 'list_images'),
+ driver.search_for_now('id_1', 'list_images'))
+ self.assertEqual(2, self.driver_mock().list_images.call_count)
+
+ def test_search_for_returns_cached_results(self):
+ image1 = testutil.cloud_object_mock(1)
+ image2 = testutil.cloud_object_mock(1)
+ self.driver_mock().list_images.side_effect = [[image1], [image2]]
+ driver = driver_base.BaseComputeNodeDriver({}, {}, {}, self.driver_mock)
+ self.assertIs(driver.search_for('id_1', 'list_images'),
+ driver.search_for('id_1', 'list_images'))
+ self.assertEqual(1, self.driver_mock().list_images.call_count)
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list