Laszlo Hornyak has uploaded a new change for review.

Change subject: fix: fix filter results aggregation
......................................................................

fix: fix filter results aggregation

In some cases the filter runner returns None, this should be tolerated
by the aggregator

Change-Id: If573af7c244056ddc6bd15eb1cc8adede4849b9f
Signed-off-by: Laszlo Hornyak <[email protected]>
---
M Makefile
M src/request_handler.py
M src/request_handler_test.py
3 files changed, 42 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-scheduler-proxy 
refs/changes/79/17879/1

diff --git a/Makefile b/Makefile
index 96b1d1f..5b9ea70 100644
--- a/Makefile
+++ b/Makefile
@@ -19,3 +19,7 @@
 
 clean:
        find -name "*.pyc" -exec rm {} \;
+
+restart:
+       $(MAKE) stop
+       $(MAKE) start
diff --git a/src/request_handler.py b/src/request_handler.py
index d836c8e..190c6ad 100644
--- a/src/request_handler.py
+++ b/src/request_handler.py
@@ -90,19 +90,20 @@
             "scores": self._scores,
             "balance": self._balancers}
 
+    def aggregate_filter_results(self, filterRunners):
+        resultSet = []
+        for runner in filterRunners:
+            if runner.getResults() is None:
+                continue
+            hosts = runner.getResults()
+            if resultSet is None:
+                resultSet = set(hosts)
+                continue
+            resultSet = resultSet.intersection(hosts)
+        return list(resultSet)
+
     def run_filters(self, filters, hostIDs, vmID, properties_map):
         #Intersects the results from the filters
-        def aggregateResults(filterRunners):
-            resultSet = None
-            for runner in filterRunners:
-                if runner.getResults() is None:
-                    continue
-                hosts = runner.getResults()
-                if resultSet is None:
-                    resultSet = set(hosts)
-                    continue
-                resultSet = resultSet.intersection(hosts)
-            return list(resultSet)
         #run each filter in a process for robustness
         filterRunners = []
         for f in filters:
@@ -122,7 +123,7 @@
         #TODO add timeout config
         self._utils.waitOnGroup(filterRunners)
 
-        return aggregateResults(filterRunners)
+        return self.aggregate_filter_results(filterRunners)
 
     def run_cost_functions(self,
                            cost_functions,
diff --git a/src/request_handler_test.py b/src/request_handler_test.py
index f36a180..33a6bd3 100644
--- a/src/request_handler_test.py
+++ b/src/request_handler_test.py
@@ -44,3 +44,28 @@
                         ('This is a simple score function that returns '
                          'all given host ID with score 50', '')}}
         pass
+
+    '''
+    Tests if the empty filterRunners array results in an None or exception
+    in such cases the xmlrpc will fail
+    '''
+    def test_aggregate_filter_results_empty(self):
+        executor = RequestHandler(os.path.join(os.getcwd(), 'plugins'),
+                                  os.path.join(os.getcwd(), 'src'))
+        filterRunners = []
+        assert executor.aggregate_filter_results(filterRunners) is not None
+
+    '''
+    Checks that the aggregate filter will not return a None or exception even
+    if the runner returns None
+    '''
+    def test_aggregate_filter_results_singleNone(self):
+        executor = RequestHandler(os.path.join(os.getcwd(), 'plugins'),
+                                  os.path.join(os.getcwd(), 'src'))
+
+        class NoneResultRunner:
+            def getResults(self):
+                return None
+
+        filterRunners = [NoneResultRunner()]
+        assert executor.aggregate_filter_results(filterRunners) is not None


-- 
To view, visit http://gerrit.ovirt.org/17879
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: If573af7c244056ddc6bd15eb1cc8adede4849b9f
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-scheduler-proxy
Gerrit-Branch: master
Gerrit-Owner: Laszlo Hornyak <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to