From 7c598c245634588b6393b2d16dab213b71d38f8f Mon Sep 17 00:00:00 2001
From: Benjamin Blanc <benjamin.blanc@tiolive.com>
Date: Tue, 27 Aug 2013 17:07:26 +0200
Subject: [PATCH] testnode: change way to reach repository in scalability case

---
 erp5/tests/testERP5TestNode.py              |  4 +-
 erp5/util/testnode/ScalabilityTestRunner.py | 44 ++++++++++++++-------
 erp5/util/testnode/Updater.py               |  3 ++
 erp5/util/testnode/testnode.py              |  7 ++--
 4 files changed, 38 insertions(+), 20 deletions(-)

diff --git a/erp5/tests/testERP5TestNode.py b/erp5/tests/testERP5TestNode.py
index d525b76cdd..556ed29d3b 100644
--- a/erp5/tests/testERP5TestNode.py
+++ b/erp5/tests/testERP5TestNode.py
@@ -243,10 +243,10 @@ branch = foo
 extends = %(temp_dir)s/testnode/foo/rep0/software.cfg
 
 [rep1]
-revision = %(revision1)s
+repository = <obfuscated_url>/rep1
 
 [rep2]
-revision = %(revision2)s
+repository = <obfuscated_url>/rep2
 """ % {'temp_dir': self._temp_dir, 'revision1': revision1, 'revision2': revision2}
     self.assertEquals(expected_profile, profile.read())
     profile.close()
diff --git a/erp5/util/testnode/ScalabilityTestRunner.py b/erp5/util/testnode/ScalabilityTestRunner.py
index 1b17f992e9..4abbf1c1ad 100644
--- a/erp5/util/testnode/ScalabilityTestRunner.py
+++ b/erp5/util/testnode/ScalabilityTestRunner.py
@@ -160,8 +160,6 @@ ces or already launched.")
     if self.testnode.test_suite_portal.isMasterTestnode(
                            self.testnode.config['test_node_title']):
       pass
-#      software_path_list = []
-#      software_path_list.append(self.testnode.config.get("software_list"))
     return {'status_code' : 0} 
 
   # Dummy slapos answering
@@ -276,7 +274,13 @@ late a SlapOS (positive) answer." %(str(os.getpid()),str(os.getpid()),))
         self.log("ERP5 Master indicates : %s" %(self.error_message,))
         # error : wich code to return ?
         return {'status_code' : 1}
-      # create an obfuscated link to the testsuite directory
+
+      involved_nodes_computer_guid = test_configuration['involved_nodes_computer_guid']
+      configuration_list = test_configuration['configuration_list']
+      node_test_suite.edit(configuration_list=configuration_list)
+      self.launcher_nodes_computer_guid = test_configuration['launcher_nodes_computer_guid']
+      
+      # Create an obfuscated link to the testsuite directory
       path_to_suite = os.path.join(
                       self.testnode.config['working_directory'],
                       node_test_suite.reference)
@@ -293,22 +297,32 @@ late a SlapOS (positive) answer." %(str(os.getpid()),str(os.getpid()),))
           self.log("testnode, Unable to create symbolic link to the testsuite.")
           raise ValueError("testnode, Unable to create symbolic link to the testsuite.")
       self.log("Sym link : %s %s" %(path_to_suite, self.obfuscated_link_path))
-      involved_nodes_computer_guid = test_configuration['involved_nodes_computer_guid']
-      configuration_list = test_configuration['configuration_list']
-      node_test_suite.edit(configuration_list=configuration_list)
-      self.launcher_nodes_computer_guid = test_configuration['launcher_nodes_computer_guid']
-      software_path_list = []
+      
       # Construct the ipv6 obfuscated url of the software profile reachable from outside
-      self.reachable_profile = os.path.join(
+      self.reachable_address = os.path.join(
         "https://","["+self.testnode.config['httpd_ip']+"]"+":"+self.testnode.config['httpd_software_access_port'],
-        self.randomized_path, "software.cfg")
+        self.randomized_path)
+      self.reachable_profile = os.path.join(self.reachable_address, "software.cfg")
+
+      # Write the reachable address in the software.cfg file,
+      # by replacing <obfuscated_url> occurences by the current reachable address.
+      software_file = open(node_test_suite.custom_profile_path, "r")
+      file_content = software_file.readlines()
+      new_file_content = []
+      for line in file_content:
+        new_file_content.append(line.replace('<obfuscated_url>', self.reachable_address))
+      software_file.close()
+      os.remove(node_test_suite.custom_profile_path)
+      software_file = open(node_test_suite.custom_profile_path, "w")
+      for line in new_file_content:
+        software_file.write(line)
+      software_file.close()
       self.log("Software reachable profile path is : %s "
                               %(self.reachable_profile,))
-      software_path_list.append(self.reachable_profile)
-      # Ask for softwares installation
-      for software_path in software_path_list:
-        for computer_guid in self.involved_nodes_computer_guid:
-          self._prepareSlapOS(software_path, computer_guid) 
+
+      # Ask for SR installation
+      for computer_guid in self.involved_nodes_computer_guid:
+        self._prepareSlapOS(self.reachable_profile, computer_guid) 
       # From the line below we would not supply any more softwares
       self.authorize_supply = False
       # TODO : remove the line below wich simulate an answer from slapos master
diff --git a/erp5/util/testnode/Updater.py b/erp5/util/testnode/Updater.py
index c19d46462a..72eabc2617 100644
--- a/erp5/util/testnode/Updater.py
+++ b/erp5/util/testnode/Updater.py
@@ -96,6 +96,9 @@ class Updater(object):
   def _git(self, *args, **kw):
     return self.spawn(self.git_binary, *args, **kw)['stdout'].strip()
 
+  def git_update_server_info(self):
+    return self._git('update-server-info')
+
   def _git_find_rev(self, ref):
     try:
       return self._git_cache[ref]
diff --git a/erp5/util/testnode/testnode.py b/erp5/util/testnode/testnode.py
index 0bc6c6f813..c62c7f3e7c 100644
--- a/erp5/util/testnode/testnode.py
+++ b/erp5/util/testnode/testnode.py
@@ -163,11 +163,11 @@ extends = %(software_config_path)s
           revision_list = [ [x.split('=')[0],x.split('=')[1].split('-')[1]] for x in all_revision.split(',') ]
           # from [[sec1,azer],[sec2,qwer],..] to {sec1:azer,sec2:qwer,..}
           revision_dict = {branch:revision for branch,revision in revision_list}
+          # <obfuscated_url> word is modified by in runner.prepareSlapOSForTestSuite()
           profile_content_list.append("""
 [%(buildout_section_id)s]
-revision = %(revision)s
-""" %  {'buildout_section_id': buildout_section_id,
-   'revision' : revision_dict[buildout_section_id]})
+repository = <obfuscated_url>/%(buildout_section_id)s
+""" %  {'buildout_section_id': buildout_section_id})
         else:
           profile_content_list.append("""
 [%(buildout_section_id)s]
@@ -261,6 +261,7 @@ branch = %(branch)s
                         revision=revision, log=log,
                         process_manager=self.process_manager)
       updater.checkout()
+      updater.git_update_server_info()
       node_test_suite.revision = test_result.revision
 
   def _cleanupLog(self):
-- 
2.30.9