Martin Sivák has uploaded a new change for review. Change subject: When all filters fail, return all hosts ......................................................................
When all filters fail, return all hosts Change-Id: I3e88e22795d17dbd6c9dd03e7cc84da31feb483e Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1002444 Signed-off-by: Martin Sivak <msi...@redhat.com> --- A plugins/test_failing_plugin.py M src/ovirtscheduler/request_handler.py M src/ovirtscheduler/request_handler_test.py M tests/java/src/test/java/org/ovirt/schedulerproxy/SchedulerProxyTest.java 4 files changed, 54 insertions(+), 19 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-scheduler-proxy refs/changes/41/22241/1 diff --git a/plugins/test_failing_plugin.py b/plugins/test_failing_plugin.py new file mode 100644 index 0000000..ef9a311 --- /dev/null +++ b/plugins/test_failing_plugin.py @@ -0,0 +1,9 @@ +class test_failing_plugin(object): + def do_filter(self, hosts, vm, args): + """This filter is expected to fail and should be used only in tests.""" + raise Exception("Expected fail") + + def do_score(self, hosts, vm, args): + """This function is expected to fail and should be used only in tests.""" + + raise Exception("Expected fail") diff --git a/src/ovirtscheduler/request_handler.py b/src/ovirtscheduler/request_handler.py index af44d60..8e6616a 100644 --- a/src/ovirtscheduler/request_handler.py +++ b/src/ovirtscheduler/request_handler.py @@ -146,9 +146,7 @@ else: resultSet = resultSet.intersection(hosts) - if resultSet is None: - resultSet = [] - else: + if resultSet is not None: resultSet = list(resultSet) return resultSet @@ -192,6 +190,9 @@ log_adapter.debug("Aggregating results") results = self.aggregate_filter_results(filterRunners, request_id) + if results is None: + log_adapter.info('All filters failed, return the full list') + results = hostIDs log_adapter.info('returning: %s' % str(results)) return results diff --git a/src/ovirtscheduler/request_handler_test.py b/src/ovirtscheduler/request_handler_test.py index 4a95104..a0e3468 100644 --- a/src/ovirtscheduler/request_handler_test.py +++ b/src/ovirtscheduler/request_handler_test.py @@ -29,34 +29,33 @@ ret = executor.discover() print ret assert ret == {'balance': - {'test_plugin': - ('This is a fake balance function that always ' - 'return the guid ' - '33333333-3333-3333-3333-333333333333', '')}, + {'test_plugin': + ('This is a fake balance function that always return the guid 33333333-3333-3333-3333-333333333333', '')}, 'filters': - {'test_plugin': - ('This is a simple filter that ' - 'returns all given host ID', '')}, + {'test_plugin': + ('This is a simple filter that returns all given host ID', ''), + 'test_failing_plugin': + ('This filter is expected to fail and should be used only in tests.', '')}, 'scores': - {'test_plugin': - ('This is a simple score function that returns ' - 'all given host ID with score 50', '')}} + {'test_plugin': + ('This is a simple score function that returns all given host ID with score 50', ''), + 'test_failing_plugin': + ('This function is expected to fail and should be used only in tests.', '')}} pass def test_aggregate_filter_results_empty(self): """ - Tests if the empty filterRunners array results in an None or exception - in such cases the xmlrpc will fail + Tests if the empty filterRunners array results in None. """ executor = RequestHandler(os.path.join(os.getcwd(), 'plugins'), os.path.join(os.getcwd(), 'src')) filterRunners = [] - assert executor.aggregate_filter_results(filterRunners, '') is not None + assert executor.aggregate_filter_results(filterRunners, '') is None def test_aggregate_filter_results_singleNone(self): """ - Checks that the aggregate filter will not return a None or exception - even if the runner returns None + Checks that the aggregate filter will return None when + all runners fail. """ executor = RequestHandler(os.path.join(os.getcwd(), 'plugins'), os.path.join(os.getcwd(), 'src')) @@ -75,4 +74,4 @@ return None filterRunners = [NoneResultRunner()] - assert executor.aggregate_filter_results(filterRunners, '') is not None + assert executor.aggregate_filter_results(filterRunners, '') is None diff --git a/tests/java/src/test/java/org/ovirt/schedulerproxy/SchedulerProxyTest.java b/tests/java/src/test/java/org/ovirt/schedulerproxy/SchedulerProxyTest.java index bc92642..2a2372e 100644 --- a/tests/java/src/test/java/org/ovirt/schedulerproxy/SchedulerProxyTest.java +++ b/tests/java/src/test/java/org/ovirt/schedulerproxy/SchedulerProxyTest.java @@ -12,6 +12,7 @@ public class SchedulerProxyTest { static String CLASS_NAME = "test_plugin"; + static String FAILING_CLASS_NAME = "test_failing_plugin"; static String HOST_ID1 = "11111111-1111-1111-1111-111111111111"; static String HOST_ID2 = "22222222-2222-2222-2222-222222222222"; static String[] HOST_ARRAY = new String[] { HOST_ID1, HOST_ID2 }; @@ -57,6 +58,22 @@ } @Test + public void testFilterWithOnlyFailingPlugin() throws XmlRpcException { + List<String> result = proxy.filter(new String[]{ FAILING_CLASS_NAME }, HOST_ARRAY, VM_ID, ""); + assertTrue(result.size() == HOST_ARRAY.length); + assertTrue(result.contains(HOST_ID1)); + assertTrue(result.contains(HOST_ID2)); + } + + @Test + public void testFilterWithFailingPlugin() throws XmlRpcException { + List<String> result = proxy.filter(new String[]{ CLASS_NAME, FAILING_CLASS_NAME }, HOST_ARRAY, VM_ID, ""); + assertTrue(result.size() == HOST_ARRAY.length); + assertTrue(result.contains(HOST_ID1)); + assertTrue(result.contains(HOST_ID2)); + } + + @Test public void testScore() throws XmlRpcException { HashMap<String, Integer> result = proxy.score(new String[] { CLASS_NAME }, new Integer[] { 2 }, HOST_ARRAY, VM_ID, ""); @@ -66,6 +83,15 @@ } @Test + public void testScoreWithFailingPlugin() throws XmlRpcException { + HashMap<String, Integer> result = + proxy.score(new String[]{ FAILING_CLASS_NAME, CLASS_NAME }, new Integer[]{ 1, 2 }, HOST_ARRAY, VM_ID, ""); + assertTrue(result.size() == 2); + assertTrue(result.get(HOST_ID1) == 100); + assertTrue(result.get(HOST_ID2) == 100); + } + + @Test public void testBalance() throws XmlRpcException { HashMap<String, List<String>> result = proxy.balance(CLASS_NAME, HOST_ARRAY, ""); assertTrue(result.containsKey(VM_ID)); -- To view, visit http://gerrit.ovirt.org/22241 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I3e88e22795d17dbd6c9dd03e7cc84da31feb483e Gerrit-PatchSet: 1 Gerrit-Project: ovirt-scheduler-proxy Gerrit-Branch: master Gerrit-Owner: Martin Sivák <msi...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches