From 4fd5acb9cad3ea4003649b69bde961979403220c Mon Sep 17 00:00:00 2001
From: Julien Muchembled <jm@nexedi.com>
Date: Thu, 20 Apr 2017 11:54:16 +0200
Subject: [PATCH] erp5.util.testnode: fix values of --firefox_bin and
 --xvfb_bin

Firefox and Xvfb aren not provided by the tested SR,
but rather by a separate SR that is installed by the testnode.
---
 erp5/tests/testERP5TestNode.py       | 12 +++++++++---
 erp5/util/testnode/UnitTestRunner.py | 22 +++++++++++++---------
 2 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/erp5/tests/testERP5TestNode.py b/erp5/tests/testERP5TestNode.py
index bf76136d64..9a4402219e 100644
--- a/erp5/tests/testERP5TestNode.py
+++ b/erp5/tests/testERP5TestNode.py
@@ -89,6 +89,7 @@ class ERP5TestNode(TestCase):
     config["httpd_ip"] = "ff:ff:ff:ff:ff:ff:ff:ff"
     config["httpd_software_access_port"] = "9080"
     config["frontend_url"] = "http://frontend/"
+    config["software_list"] = ["foo", "bar"]
 
     return TestNode(self.log, config)
 
@@ -515,12 +516,17 @@ shared = true
 
     checkRunTestSuiteParameters()
 
-    parts = slapos_controler.instance_root + '/a/software_release/parts/'
+    def part(path): # in "bar" SR
+      path = test_node.config['slapos_directory'] \
+        + '/soft/37b51d194a7513e45b56f6524f2d51f2/parts/' + path
+      os.makedirs(os.path.dirname(path))
+      os.close(os.open(path, os.O_CREAT))
+      return path
     for option in (
-        ('--firefox_bin', parts + 'firefox/firefox-slapos'),
+        ('--firefox_bin', part('firefox/firefox-slapos')),
         ('--frontend_url', 'http://frontend/'),
         ('--node_quantity', 3),
-        ('--xvfb_bin', parts + 'xserver/bin/Xvfb'),
+        ('--xvfb_bin', part('xserver/bin/Xvfb')),
       ):
       parser.add_argument(option[0])
       expected_parameter_list += option
diff --git a/erp5/util/testnode/UnitTestRunner.py b/erp5/util/testnode/UnitTestRunner.py
index 1eeb2abac0..c1a3fff63e 100644
--- a/erp5/util/testnode/UnitTestRunner.py
+++ b/erp5/util/testnode/UnitTestRunner.py
@@ -43,6 +43,7 @@ from NodeTestSuite import SlapOSInstance
 from Updater import Updater
 from Utils import dealShebang
 from erp5.util import taskdistribution
+from slapos.grid.utils import md5digest
 
 class UnitTestRunner():
   def __init__(self, testnode):
@@ -147,16 +148,19 @@ class UnitTestRunner():
       '--test_suite_title', node_test_suite.test_suite_title)
     supported_parameter_set = set(self.testnode.process_manager
       .getSupportedParameterList(run_test_suite_path))
-    parts = os.path.dirname(os.path.dirname(run_test_suite_path))
-    parts += '/software_release/parts/'
-    for option in (
-        ('--firefox_bin', parts + 'firefox/firefox-slapos'),
-        ('--frontend_url', config['frontend_url']),
-        ('--node_quantity', config['node_quantity']),
-        ('--xvfb_bin', parts + 'xserver/bin/Xvfb'),
+    def part(path):
+        path = config['slapos_directory'] + '/soft/%s/parts/' + path
+        path, = filter(os.path.exists, (path % md5digest(software)
+            for software in config['software_list']))
+        return path
+    for option, value in (
+        ('--firefox_bin', lambda: part('firefox/firefox-slapos')),
+        ('--frontend_url', lambda: config['frontend_url']),
+        ('--node_quantity', lambda: config['node_quantity']),
+        ('--xvfb_bin', lambda: part('xserver/bin/Xvfb')),
         ):
-      if option[0] in supported_parameter_set:
-        invocation_list += option
+      if option in supported_parameter_set:
+        invocation_list += option, value()
 
     # TODO : include testnode correction ( b111682f14890bf )
     if hasattr(node_test_suite,'additional_bt5_repository_id'):
-- 
2.30.9