From 923dc6770b0a5110d83d3dc2126a09456283cffa Mon Sep 17 00:00:00 2001
From: Sebastien Robin <seb@nexedi.com>
Date: Wed, 11 May 2011 16:20:34 +0200
Subject: [PATCH] allow to test a particular branch

---
 slapos/recipe/erp5.recipe.testnode/setup.py   |  2 +-
 .../erp5/recipe/testnode/SlapOSControler.py   |  3 +-
 .../src/erp5/recipe/testnode/__init__.py      |  2 ++
 .../src/erp5/recipe/testnode/testnode.py      | 33 +++++++++++--------
 4 files changed, 25 insertions(+), 15 deletions(-)

diff --git a/slapos/recipe/erp5.recipe.testnode/setup.py b/slapos/recipe/erp5.recipe.testnode/setup.py
index ae9ba344e1..b8b5837abc 100644
--- a/slapos/recipe/erp5.recipe.testnode/setup.py
+++ b/slapos/recipe/erp5.recipe.testnode/setup.py
@@ -1,7 +1,7 @@
 from setuptools import setup, find_packages
 
 name = "erp5.recipe.testnode"
-version = '1.0'
+version = '1.0.5'
 
 def read(name):
   return open(name).read()
diff --git a/slapos/recipe/erp5.recipe.testnode/src/erp5/recipe/testnode/SlapOSControler.py b/slapos/recipe/erp5.recipe.testnode/src/erp5/recipe/testnode/SlapOSControler.py
index b3a47262a4..e86f33abdd 100644
--- a/slapos/recipe/erp5.recipe.testnode/src/erp5/recipe/testnode/SlapOSControler.py
+++ b/slapos/recipe/erp5.recipe.testnode/src/erp5/recipe/testnode/SlapOSControler.py
@@ -47,11 +47,12 @@ class SlapOSControler(object):
  'reference': config['computer_id'],
  'software_root': config['software_root']}))
 
-  def runSoftwareRelease(self, config, process_group_pid_list=None):
+  def runSoftwareRelease(self, config, environment, process_group_pid_list=None):
     print "SlapOSControler.runSoftwareRelease"
     while True:
       cpu_count = os.sysconf("SC_NPROCESSORS_ONLN")
       os.putenv('MAKEFLAGS', '-j%s' % cpu_count)
+      os.environ['PATH'] = environment['PATH']
       slapgrid = subprocess.Popen([config['slapgrid_software_binary'], '-v', '-c',
         #'--buildout-parameter',"'-U -N' -o",
         config['slapos_config']],
diff --git a/slapos/recipe/erp5.recipe.testnode/src/erp5/recipe/testnode/__init__.py b/slapos/recipe/erp5.recipe.testnode/src/erp5/recipe/testnode/__init__.py
index ad7494418c..a6ba8dd01c 100644
--- a/slapos/recipe/erp5.recipe.testnode/src/erp5/recipe/testnode/__init__.py
+++ b/slapos/recipe/erp5.recipe.testnode/src/erp5/recipe/testnode/__init__.py
@@ -85,6 +85,7 @@ class Recipe(BaseSlapRecipe):
               working_directory=CONFIG['working_directory'],
               vcs_repository=self.parameter_dict.get('vcs_repository'),
               node_quantity=self.parameter_dict.get('node_quantity', '1'),
+              branch=self.parameter_dict.get('branch', None),
               test_suite_master_url=self.parameter_dict.get(
                                 'test_suite_master_url', None),
               test_suite_name=self.parameter_dict.get('test_suite_name'),
@@ -96,6 +97,7 @@ class Recipe(BaseSlapRecipe):
               # environment of running bot
               bot_environment=self.parameter_dict.get('bot_environment', ''),
               partition_reference=CONFIG['partition_reference'],
+              environment=dict(PATH=os.environ['PATH']),
             )
           ]))
 
diff --git a/slapos/recipe/erp5.recipe.testnode/src/erp5/recipe/testnode/testnode.py b/slapos/recipe/erp5.recipe.testnode/src/erp5/recipe/testnode/testnode.py
index 8ca8d518ea..8b02f64ac8 100644
--- a/slapos/recipe/erp5.recipe.testnode/src/erp5/recipe/testnode/testnode.py
+++ b/slapos/recipe/erp5.recipe.testnode/src/erp5/recipe/testnode/testnode.py
@@ -59,6 +59,7 @@ slapos_controler = None
 def run(args):
   config = args[0]
   slapgrid = None
+  branch = config.get('branch', None)
   supervisord_pid_file = os.path.join(config['instance_root'], 'var', 'run',
         'supervisord.pid')
   subprocess.check_call([config['git_binary'],
@@ -74,27 +75,33 @@ def run(args):
   # Write our own software.cfg to use the local repository
   custom_profile_path = os.path.join(config['working_directory'], 'software.cfg')
   config['custom_profile_path'] = custom_profile_path
-  if not os.path.exists(custom_profile_path):
-    # create a profile in order to use the repository we already have
-    custom_profile = open(custom_profile_path, 'w')
-    profile_content = """
+  
+  # create a profile in order to use the repository we already have
+  custom_profile = open(custom_profile_path, 'w')
+  profile_content = """
 [buildout]
 extends = %(software_config_path)s
 
-[%(repository_name)s_repository]
+[%(repository_name)s]
 repository = %(repository_path)s
 """ %     {'software_config_path': os.path.join(repository_path,
-                                            config['profile_url']),
-      'repository_name': repository_name,
-      'repository_path' : repository_path}
-    custom_profile.write(profile_content)
-    custom_profile.close()
+                                          config['profile_url']),
+    'repository_name': repository_name,
+    'repository_path' : repository_path}
+  if branch is not None:
+    profile_content += "\nbranch = %s" % branch
+  custom_profile.write(profile_content)
+  custom_profile.close()
   try:
     while True:
       # Make sure we have local repository
       if not os.path.exists(repository_path):
-        subprocess.check_call([config['git_binary'],
-                'clone', config['vcs_repository'], repository_path])
+        parameter_list = [config['git_binary'], 'clone',
+                          config['vcs_repository']]
+        if branch is not None:
+          parameter_list.extend(['-b',branch])
+        parameter_list.append(repository_path)
+        subprocess.check_call(parameter_list)
         # XXX this looks like to not wait the end of the command
       # Make sure we have local repository
       updater = Updater(repository_path, git_binary=config['git_binary'])
@@ -105,7 +112,6 @@ repository = %(repository_path)s
         continue
       previous_revision = revision
 
-
       print config
       portal_url = config['test_suite_master_url']
       test_result_path = None
@@ -137,6 +143,7 @@ repository = %(repository_path)s
         if run_software:
           # this should be always true later, but it is too slow for now
           slapos_controler.runSoftwareRelease(config,
+            environment=config['environment'],
             process_group_pid_list=process_group_pid_list,
             )
           run_software = False
-- 
2.30.9