From ff05f123b01daf5f9320982054ccf2f5ab16beba Mon Sep 17 00:00:00 2001
From: Benjamin Blanc <benjamin.blanc@tiolive.com>
Date: Tue, 25 Jun 2013 15:50:13 +0200
Subject: [PATCH] util: resolve test_result problems

---
 erp5/util/benchmark/scalability_launcher.py | 46 +++++++++++++++------
 erp5/util/taskdistribution/__init__.py      | 10 ++++-
 2 files changed, 42 insertions(+), 14 deletions(-)

diff --git a/erp5/util/benchmark/scalability_launcher.py b/erp5/util/benchmark/scalability_launcher.py
index d11f938212..4128828ba4 100644
--- a/erp5/util/benchmark/scalability_launcher.py
+++ b/erp5/util/benchmark/scalability_launcher.py
@@ -8,6 +8,8 @@ import sys
 import multiprocessing
 import errno
 
+import logging
+import logging.handlers
 from .argument import ArgumentType
 from .performance_tester import PerformanceTester
 from erp5.util import taskdistribution
@@ -23,18 +25,30 @@ class ScalabilityTest(object):
     print 'self.count: %s' %(str(self.count))
     
 class ScalabilityLauncher(object):
-  def __init__(self, namespace=None):
-    if not namespace:
-      self.__argumentNamespace = self._parseArguments(argparse.ArgumentParser(
+  def __init__(self):
+    # Parse arguments
+    self.__argumentNamespace = self._parseArguments(argparse.ArgumentParser(
           description='Run ERP5 benchmarking scalability suites.'))
-    else:
-      self.__argumentNamespace = namespace
+    # Create Logger
+    logger_format = '%(asctime)s %(name)-13s: %(levelname)-8s %(message)s'
+    formatter = logging.Formatter(logger_format)
+    logging.basicConfig(level=logging.INFO,
+                     format=logger_format)
+    logger = logging.getLogger('scalability_launcher')
+    logger.addHandler(logging.NullHandler())
+    file_handler = logging.handlers.RotatingFileHandler(
+        filename=self.__argumentNamespace.log_path,
+        maxBytes=20000000, backupCount=4)
+    file_handler.setFormatter(formatter)
+    logger.addHandler(file_handler)
+    self.log = logger.info
 
-    # Here make a connection with erp5 master
-    portal_url = __argumentNamespace.test_result_url
-    result = taskdistribution.TestResultProxyProxy(portal_url, 1.0,
-                self._logger, __argumentNamespace.test_result_url,
-                __argumentNamespace.node_title, __argumentNamespace.revision)      
+
+    
+    # Proxy to with erp5 master test_result
+    result = taskdistribution.TestResultProxyProxy(self.__argumentNamespace.portal_url,
+              1.0, logger, self.__argumentNamespace.test_result_url,
+              self.__argumentNamespace.node_title, self.__argumentNamespace.revision)  
 
   @staticmethod
   def _addParserArguments(parser):
@@ -43,7 +57,7 @@ class ScalabilityLauncher(object):
                         metavar='ERP5_URL',
                         help='Main url of ERP5 instance to test')
 
-    parser.add_argument('--erp5-test-result-url',
+    parser.add_argument('--test-result-url',
                         metavar='ERP5_TEST_RESULT_URL',
                         help='ERP5 URL to find test results corresponding '
                              'to the current running test_suite')
@@ -56,6 +70,14 @@ class ScalabilityLauncher(object):
                         metavar='NODE_TITLE',
                         help='Title of the testnode which is running this'
                               'launcher')
+                              
+    parser.add_argument('--portal-url',
+                        metavar='PORTAL_URL',
+                        help='Url to connect to ERP5 Master portal')
+                        
+    parser.add_argument('--log-path',
+                        metavar='LOG_PATH',
+                        help='Log Path')
    
   @staticmethod
   def _checkParsedArguments(namespace):
@@ -94,7 +116,7 @@ class ScalabilityLauncher(object):
     start_time = time.time()
     error_message_set, exit_status = set(), 0
     
-    print self.__argumentNamespace.erp5_test_result_url
+    print self.__argumentNamespace.test_result_url
     print self.__argumentNamespace.erp5_url
     print self.__argumentNamespace.revision
     print self.__argumentNamespace.node_title
diff --git a/erp5/util/taskdistribution/__init__.py b/erp5/util/taskdistribution/__init__.py
index 241e7916a0..878e236781 100644
--- a/erp5/util/taskdistribution/__init__.py
+++ b/erp5/util/taskdistribution/__init__.py
@@ -356,8 +356,14 @@ class TestResultProxyProxy(TestResultProxy):
     """
     def __init__(self, portal_url, retry_time, logger, test_result_path,
                 node_title, revision):
-      proxy = ServerProxy(portal_url, allow_none=True)
-      TestResultProxy.__init__(proxy, retry_time, logger, test_result_path,
+      try:
+        proxy = ServerProxy(
+                portal_url,
+                allow_none=True,
+            ).portal_task_distribution
+      except:
+        raise ValueError("Cannot instanciate ServerProxy")
+      TestResultProxy(proxy, retry_time, logger, test_result_path,
                 node_title, revision)
 
 
-- 
2.30.9