[Erp5-report] r40657 luke - /erp5/trunk/utils/erp5.appliance.test/src/test.py

nobody at svn.erp5.org nobody at svn.erp5.org
Thu Nov 25 11:35:01 CET 2010


Author: luke
Date: Thu Nov 25 11:34:57 2010
New Revision: 40657

URL: http://svn.erp5.org?rev=40657&view=rev
Log:
 - support python 2.4 -- make try...finally only blocks

Modified:
    erp5/trunk/utils/erp5.appliance.test/src/test.py

Modified: erp5/trunk/utils/erp5.appliance.test/src/test.py
URL: http://svn.erp5.org/erp5/trunk/utils/erp5.appliance.test/src/test.py?rev=40657&r1=40656&r2=40657&view=diff
==============================================================================
--- erp5/trunk/utils/erp5.appliance.test/src/test.py [utf8] (original)
+++ erp5/trunk/utils/erp5.appliance.test/src/test.py [utf8] Thu Nov 25 11:34:57 2010
@@ -287,31 +287,32 @@ def callWithTimeout(command_list, config
   signal.alarm(timeout)
   command = None
   try:
-    returncode = None
-    config.logger.info(
-        'Calling %r with timeout %s\n' % (command_list, timeout))
-    command = pexpect.spawn(" ".join(command_list), timeout=timeout, cwd=cwd)
-    isalive = True
-    while isalive:
-      if input_list is not None:
-        for input in input_list:
-          command.expect(input[0])
-          command.sendline(input[1])
-          time.sleep(1)
-      line = command.readline()
-      if line:
-        line = line[:-1]
+    try:
+      returncode = None
+      config.logger.info(
+          'Calling %r with timeout %s\n' % (command_list, timeout))
+      command = pexpect.spawn(" ".join(command_list), timeout=timeout, cwd=cwd)
+      isalive = True
+      while isalive:
+        if input_list is not None:
+          for input in input_list:
+            command.expect(input[0])
+            command.sendline(input[1])
+            time.sleep(1)
+        line = command.readline()
+        if line:
+          line = line[:-1]
+          config.logger.info("%s", line.rstrip('\n').rstrip('\r'))
+        isalive = command.isalive()
+      for line in command.readlines():
         config.logger.info("%s", line.rstrip('\n').rstrip('\r'))
-      isalive = command.isalive()
-    for line in command.readlines():
-      config.logger.info("%s", line.rstrip('\n').rstrip('\r'))
-    command.close()
-    returncode = command.exitstatus
-  except TimeoutException:
-    config.logger.error(
-      'Command %r run exceeded timeout %s, killed\n' % (command_list, timeout))
-    returncode = 1
-    command.close()
+      command.close()
+      returncode = command.exitstatus
+    except TimeoutException:
+      config.logger.error(
+        'Command %r run exceeded timeout %s, killed\n' % (command_list, timeout))
+      returncode = 1
+      command.close()
   finally:
     if command is not None:
       command.kill(signal.SIGKILL)
@@ -351,34 +352,35 @@ def run_once28(config, software_path, in
     erp5_handler.revision = revision
   exc_info = None
   try:
-    # Bootstrap buildout
-    bootstrap_command = [config.python, '-S', 'bootstrap/bootstrap.py',
-                         '-v', '1.4.4']
-    callWithTimeout(bootstrap_command, config, timeout=600, cwd=software_path)
-
-    # Install software
-    buildout_command = [config.python, '-S', '%s/bin/buildout' % software_path]
-    if config.verbose is True:
-      buildout_command.append('-v')
-    callWithTimeout(buildout_command, config, timeout=14400, cwd=software_path)
-
-    # Assert software
-    assert_command = [os.path.join(software_path, 'bin', 'python2.4'),
-        os.path.join('tests', 'assertSoftware.py')]
-    callWithTimeout(assert_command, config, timeout=3600, cwd=software_path)
-
-    # Create instance place
-    if not os.path.exists(instance_path):
-      mkdir = ['mkdir', instance_path]
-      callWithTimeout(mkdir, config)
-    raise NotImplementedError
-  except SubFailed:
-    pass
-  except:
-    exc_info = sys.exc_info()
-    raise
-  else:
-    status = True
+    try:
+      # Bootstrap buildout
+      bootstrap_command = [config.python, '-S', 'bootstrap/bootstrap.py',
+                           '-v', '1.4.4']
+      callWithTimeout(bootstrap_command, config, timeout=600, cwd=software_path)
+
+      # Install software
+      buildout_command = [config.python, '-S', '%s/bin/buildout' % software_path]
+      if config.verbose is True:
+        buildout_command.append('-v')
+      callWithTimeout(buildout_command, config, timeout=14400, cwd=software_path)
+
+      # Assert software
+      assert_command = [os.path.join(software_path, 'bin', 'python2.4'),
+          os.path.join('tests', 'assertSoftware.py')]
+      callWithTimeout(assert_command, config, timeout=3600, cwd=software_path)
+
+      # Create instance place
+      if not os.path.exists(instance_path):
+        mkdir = ['mkdir', instance_path]
+        callWithTimeout(mkdir, config)
+      raise NotImplementedError
+    except SubFailed:
+      pass
+    except:
+      exc_info = sys.exc_info()
+      raise
+    else:
+      status = True
   finally:
     if exc_info is not None:
       config.logger.warning('Test stopped with exception:\n', exc_info=exc_info)
@@ -425,127 +427,128 @@ def run_once212(config, software_path, i
     erp5_handler.revision = revision
   exc_info = None
   try:
-    # Download bootstrap file
-    download_command = ['curl', '-o', 'bootstrap.py',
-      'http://svn.zope.org/*checkout*/zc.buildout/trunk/bootstrap/bootstrap.py']
-    callWithTimeout(download_command, config, cwd=software_path)
-
-    # Bootstrap buildout
-    bootstrap_command = [config.python, '-S', 'bootstrap.py',
-                         '-c', 'buildout-2.12.cfg']
-    callWithTimeout(bootstrap_command, config, timeout=600, cwd=software_path)
-
-    # Install software
-    buildout_command = ['%s/bin/buildout' % software_path]
-    if config.verbose is True:
-      buildout_command.append('-v')
-    buildout_command.extend(['-c', 'buildout-2.12.cfg'])
-    callWithTimeout(buildout_command, config, timeout=14400, cwd=software_path)
-
-    # Assert software
-    assert_command = [config.python, 'tests/assertSoftware.py']
-    callWithTimeout(assert_command, config, timeout=1800, cwd=software_path)
-
-    # Create instance place
-    if not os.path.exists(instance_path):
-      mkdir = ['mkdir', instance_path]
-      callWithTimeout(mkdir, config)
-
-    # Links
-    link_command = ['ln', '-s']
-    for link_path, destination_path in [
-        (os.path.join(software_path, 'instance-profiles'), 'instance-profiles'),
-        (os.path.join(software_path, 'profiles'), 'profiles'),
-        (os.path.join(software_path, 'software-profiles'), 'software-profiles')]:
-      if not os.path.exists(os.path.join(instance_path, destination_path)):
-        callWithTimeout(link_command + [link_path],
-                        config, cwd=instance_path)
-
-    # Create buildout profile
-    file(os.path.join(instance_path, 'buildout.cfg'), 'w').write(
-        instance_buildout_first_run)
-
-    # Bootstrap instance
-    instance_bootstrap = [os.path.join(software_path, 'bin', 'bootstrap2.6')]
-    callWithTimeout(instance_bootstrap, config, cwd=instance_path)
-
-    # Run buildout for first time
-    instance_buildout = [os.path.join(instance_path, 'bin', 'buildout')]
-    callWithTimeout(instance_buildout, config, cwd=instance_path)
-
-    # Start supervisor in foreground mode and have control over its process
-    # as in the end it have to be cleanly shutdown
-    supervisord_command = [os.path.join(instance_path, 'bin', 'supervisord'),
-        '-n']
-    supervisord_popen = subprocess.Popen(supervisord_command, cwd=instance_path)
-    supervisord_popen.poll()
-    # Wait 10 seconds, to give supervisord chance to start required services
-    time.sleep(10)
     try:
-      # Populate mysql database
-      mysql_command = [os.path.join(instance_path, 'var', 'bin', 'mysql'),
-          '-h', '127.0.0.1', '-u', 'root']
-      callWithTimeout(mysql_command,
-          config, cwd=instance_path, input_list=[
-            ("mysql> ", "create database development_site;"),
-            ("mysql> ", "grant all privileges on development_site.* to "
-              "'development_user'@'localhost' identified by "
-              "'development_password';"),
-            ("mysql> ", "grant all privileges on development_site.* to "
-              "'development_user'@'127.0.0.1' identified by "
-              "'development_password';"),
-            ("mysql> ", "create database test212;"),
-            ("mysql> ", "grant all privileges on test212.* to "
-              "'test'@'localhost';"),
-            ("mysql> ", "grant all privileges on test212.* to "
-              "'test'@'127.0.0.1';"),
-            ("mysql> ", "exit")])
-      # Update profile
+      # Download bootstrap file
+      download_command = ['curl', '-o', 'bootstrap.py',
+        'http://svn.zope.org/*checkout*/zc.buildout/trunk/bootstrap/bootstrap.py']
+      callWithTimeout(download_command, config, cwd=software_path)
+
+      # Bootstrap buildout
+      bootstrap_command = [config.python, '-S', 'bootstrap.py',
+                           '-c', 'buildout-2.12.cfg']
+      callWithTimeout(bootstrap_command, config, timeout=600, cwd=software_path)
+
+      # Install software
+      buildout_command = ['%s/bin/buildout' % software_path]
+      if config.verbose is True:
+        buildout_command.append('-v')
+      buildout_command.extend(['-c', 'buildout-2.12.cfg'])
+      callWithTimeout(buildout_command, config, timeout=14400, cwd=software_path)
+
+      # Assert software
+      assert_command = [config.python, 'tests/assertSoftware.py']
+      callWithTimeout(assert_command, config, timeout=1800, cwd=software_path)
+
+      # Create instance place
+      if not os.path.exists(instance_path):
+        mkdir = ['mkdir', instance_path]
+        callWithTimeout(mkdir, config)
+
+      # Links
+      link_command = ['ln', '-s']
+      for link_path, destination_path in [
+          (os.path.join(software_path, 'instance-profiles'), 'instance-profiles'),
+          (os.path.join(software_path, 'profiles'), 'profiles'),
+          (os.path.join(software_path, 'software-profiles'), 'software-profiles')]:
+        if not os.path.exists(os.path.join(instance_path, destination_path)):
+          callWithTimeout(link_command + [link_path],
+                          config, cwd=instance_path)
+
+      # Create buildout profile
       file(os.path.join(instance_path, 'buildout.cfg'), 'w').write(
-        instance_buildout_complete)
-      # Re run buildout
-      callWithTimeout(instance_buildout, config, timeout=600, cwd=instance_path)
-      # Run a test from readme
-      test_run_command = [os.path.join(instance_path, 'bin', 'runUnitTest'),
-          'testClassTool']
-      callWithTimeout(test_run_command, config, timeout=1200, cwd=instance_path)
-      # check basic functionality of test -- catalog and dms
-      bt5_directory = os.path.join(instance_path, 'bt5')
+          instance_buildout_first_run)
+
+      # Bootstrap instance
+      instance_bootstrap = [os.path.join(software_path, 'bin', 'bootstrap2.6')]
+      callWithTimeout(instance_bootstrap, config, cwd=instance_path)
+
+      # Run buildout for first time
+      instance_buildout = [os.path.join(instance_path, 'bin', 'buildout')]
+      callWithTimeout(instance_buildout, config, cwd=instance_path)
+
+      # Start supervisor in foreground mode and have control over its process
+      # as in the end it have to be cleanly shutdown
+      supervisord_command = [os.path.join(instance_path, 'bin', 'supervisord'),
+          '-n']
+      supervisord_popen = subprocess.Popen(supervisord_command, cwd=instance_path)
+      supervisord_popen.poll()
+      # Wait 10 seconds, to give supervisord chance to start required services
+      time.sleep(10)
       try:
-        if not os.path.exists(bt5_directory):
-          os.mkdir(bt5_directory)
-        # Get needed business template
-        for bt5 in ['erp5_base', 'erp5_ingestion', 'erp5_ingestion_mysql_'
-            'innodb_catalog', 'erp5_web', 'erp5_dms']:
-          callWithTimeout(['svn', 'export', '--non-interactive',
-            '--trust-server-cert',
-            'https://svn.erp5.org/repos/public/erp5/trunk/bt5/' + bt5,
-            os.path.join(bt5_directory, bt5)], config, timeout=600)
-        # Check that catalog is working
-        for test in ['testERP5Catalog.TestERP5Catalog.'
-            'test_04_SearchFolderWithDeletedObjects', 'testDms.TestDocument.'
-            'testOOoDocument_get_size']:
-          test_run_command = [os.path.join(instance_path, 'bin', 'runUnitTest'),
-            '--bt5_path=%s/bt5' % instance_path, test]
-          callWithTimeout(test_run_command, config, timeout=1200,
-              cwd=instance_path)
+        # Populate mysql database
+        mysql_command = [os.path.join(instance_path, 'var', 'bin', 'mysql'),
+            '-h', '127.0.0.1', '-u', 'root']
+        callWithTimeout(mysql_command,
+            config, cwd=instance_path, input_list=[
+              ("mysql> ", "create database development_site;"),
+              ("mysql> ", "grant all privileges on development_site.* to "
+                "'development_user'@'localhost' identified by "
+                "'development_password';"),
+              ("mysql> ", "grant all privileges on development_site.* to "
+                "'development_user'@'127.0.0.1' identified by "
+                "'development_password';"),
+              ("mysql> ", "create database test212;"),
+              ("mysql> ", "grant all privileges on test212.* to "
+                "'test'@'localhost';"),
+              ("mysql> ", "grant all privileges on test212.* to "
+                "'test'@'127.0.0.1';"),
+              ("mysql> ", "exit")])
+        # Update profile
+        file(os.path.join(instance_path, 'buildout.cfg'), 'w').write(
+          instance_buildout_complete)
+        # Re run buildout
+        callWithTimeout(instance_buildout, config, timeout=600, cwd=instance_path)
+        # Run a test from readme
+        test_run_command = [os.path.join(instance_path, 'bin', 'runUnitTest'),
+            'testClassTool']
+        callWithTimeout(test_run_command, config, timeout=1200, cwd=instance_path)
+        # check basic functionality of test -- catalog and dms
+        bt5_directory = os.path.join(instance_path, 'bt5')
+        try:
+          if not os.path.exists(bt5_directory):
+            os.mkdir(bt5_directory)
+          # Get needed business template
+          for bt5 in ['erp5_base', 'erp5_ingestion', 'erp5_ingestion_mysql_'
+              'innodb_catalog', 'erp5_web', 'erp5_dms']:
+            callWithTimeout(['svn', 'export', '--non-interactive',
+              '--trust-server-cert',
+              'https://svn.erp5.org/repos/public/erp5/trunk/bt5/' + bt5,
+              os.path.join(bt5_directory, bt5)], config, timeout=600)
+          # Check that catalog is working
+          for test in ['testERP5Catalog.TestERP5Catalog.'
+              'test_04_SearchFolderWithDeletedObjects', 'testDms.TestDocument.'
+              'testOOoDocument_get_size']:
+            test_run_command = [os.path.join(instance_path, 'bin', 'runUnitTest'),
+              '--bt5_path=%s/bt5' % instance_path, test]
+            callWithTimeout(test_run_command, config, timeout=1200,
+                cwd=instance_path)
+        finally:
+          if os.path.exists(bt5_directory):
+            shutil.rmtree(bt5_directory)
       finally:
-        if os.path.exists(bt5_directory):
-          shutil.rmtree(bt5_directory)
-    finally:
-      # Stop supervisor
-      while supervisord_popen.poll() is None:
-        # send SIGKILL
-        supervisord_popen.terminate()
-        # give some time to terminate services
-        time.sleep(5)
-  except SubFailed:
-    pass
-  except:
-    exc_info = sys.exc_info()
-    raise
-  else:
-    status = True
+        # Stop supervisor
+        while supervisord_popen.poll() is None:
+          # send SIGKILL
+          supervisord_popen.terminate()
+          # give some time to terminate services
+          time.sleep(5)
+    except SubFailed:
+      pass
+    except:
+      exc_info = sys.exc_info()
+      raise
+    else:
+      status = True
   finally:
     if exc_info is not None:
       config.logger.warning('Test stopped with exception:\n', exc_info=exc_info)




More information about the Erp5-report mailing list