Commit 31804f68 authored by Bryton Lacquement's avatar Bryton Lacquement 🚪 Committed by Julien Muchembled

erp5.util: add support for Python 3

/reviewed-on !830
parent 5abb074d
......@@ -23,7 +23,6 @@ import sys
import tempfile
import json
import time
import types
import re
@contextmanager
......@@ -144,7 +143,8 @@ class ERP5TestNode(TestCase):
self.__dict__.update(**kw)
def __call__(self, command):
return subprocess.check_output(command, **self.__dict__)
return subprocess.check_output(command, universal_newlines=True,
**self.__dict__)
return Caller(**kw)
def generateTestRepositoryList(self, add_third_repository=False):
......@@ -172,10 +172,10 @@ class ERP5TestNode(TestCase):
output = call(['git', 'log', '--format=%H %s'])
output = output.strip()
output_line_list = output.split("\n")
self.assertEquals(2, len(output_line_list))
self.assertEqual(2, len(output_line_list))
expected_commit_subject_list = ["next_commit", "first_commit"]
commit_subject_list = [x.split()[1] for x in output_line_list]
self.assertEquals(expected_commit_subject_list, commit_subject_list)
self.assertEqual(expected_commit_subject_list, commit_subject_list)
commit_dict['rep%i' % i] = [x.split() for x in output_line_list]
if repository_path == self.remote_repository2:
output = call('git checkout master -b foo'.split())
......@@ -192,13 +192,13 @@ class ERP5TestNode(TestCase):
"""
test_node = self.getTestNode()
node_test_suite = test_node.getNodeTestSuite('foo')
self.assertEquals(0, node_test_suite.retry_software_count)
self.assertEqual(0, node_test_suite.retry_software_count)
node_test_suite.retry_software_count = 2
self.assertIs(node_test_suite, test_node.getNodeTestSuite('foo'))
self.assertEquals(2, node_test_suite.retry_software_count)
self.assertEqual(2, node_test_suite.retry_software_count)
del test_node.node_test_suite_dict['foo']
node_test_suite = test_node.getNodeTestSuite('foo')
self.assertEquals(0, node_test_suite.retry_software_count)
self.assertEqual(0, node_test_suite.retry_software_count)
def test_02_NodeTestSuiteWorkingDirectory(self):
"""
......@@ -206,9 +206,9 @@ class ERP5TestNode(TestCase):
"""
test_node = self.getTestNode()
node_test_suite = test_node.getNodeTestSuite('foo')
self.assertEquals("%s/foo" % self.working_directory,
self.assertEqual("%s/foo" % self.working_directory,
node_test_suite.working_directory)
self.assertEquals("%s/foo/test_suite" % self.working_directory,
self.assertEqual("%s/foo/test_suite" % self.working_directory,
node_test_suite.test_suite_directory)
def test_03_NodeTestSuiteCheckDataAfterEdit(self):
......@@ -219,13 +219,13 @@ class ERP5TestNode(TestCase):
test_node = self.getTestNode()
node_test_suite = test_node.getNodeTestSuite('foo')
self.updateNodeTestSuiteData(node_test_suite)
self.assertEquals(2, len(node_test_suite.vcs_repository_list))
self.assertEqual(2, len(node_test_suite.vcs_repository_list))
repository_path_list = []
for vcs_repository in node_test_suite.vcs_repository_list:
repository_path_list.append(vcs_repository['repository_path'])
expected_list = ["%s/rep0" % node_test_suite.working_directory,
"%s/rep1" % node_test_suite.working_directory]
self.assertEquals(expected_list, repository_path_list)
self.assertEqual(expected_list, repository_path_list)
def test_04_constructProfile(self, my_test_type='UnitTest'):
"""
......@@ -239,7 +239,7 @@ class ERP5TestNode(TestCase):
node_test_suite.revision_list = (('rep1', (1234, 'azerty')),
('rep2', (3456, 'qwerty')))
test_node.constructProfile(node_test_suite,my_test_type)
self.assertEquals("%s/software.cfg" % (node_test_suite.working_directory,),
self.assertEqual("%s/software.cfg" % (node_test_suite.working_directory,),
node_test_suite.custom_profile_path)
profile = open(node_test_suite.custom_profile_path, 'r')
if my_test_type=='UnitTest':
......@@ -282,7 +282,7 @@ ignore-ssl-certificate = true
develop = false
shared = true
""" % {'temp_dir': self._temp_dir, 'revision1': revision1, 'revision2': revision2}
self.assertEquals(expected_profile, profile.read())
self.assertEqual(expected_profile, profile.read())
profile.close()
def getAndUpdateFullRevisionList(self, test_node, node_test_suite):
......@@ -298,9 +298,9 @@ shared = true
node_test_suite = test_node.getNodeTestSuite('foo')
self.updateNodeTestSuiteData(node_test_suite)
rev_list = self.getAndUpdateFullRevisionList(test_node, node_test_suite)
self.assertEquals(2, len(rev_list))
self.assertEquals(rev_list[0], 'rep0=2-%s' % commit_dict['rep0'][0][0])
self.assertEquals(rev_list[1], 'rep1=2-%s' % commit_dict['rep1'][0][0])
self.assertEqual(2, len(rev_list))
self.assertEqual(rev_list[0], 'rep0=2-%s' % commit_dict['rep0'][0][0])
self.assertEqual(rev_list[1], 'rep1=2-%s' % commit_dict['rep1'][0][0])
my_file = open(os.path.join(self.remote_repository1, 'first_file'), 'w')
my_file.write("next_content")
my_file.close()
......@@ -309,7 +309,7 @@ shared = true
rev_list = self.getAndUpdateFullRevisionList(test_node, node_test_suite)
self.assertTrue(rev_list[0].startswith('rep0=2-'))
self.assertTrue(rev_list[1].startswith('rep1=3-'))
self.assertEquals(2, len(node_test_suite.vcs_repository_list))
self.assertEqual(2, len(node_test_suite.vcs_repository_list))
for vcs_repository in node_test_suite.vcs_repository_list:
self.assertTrue(os.path.exists(vcs_repository['repository_path']))
......@@ -323,8 +323,8 @@ shared = true
node_test_suite = test_node.getNodeTestSuite('foo')
self.updateNodeTestSuiteData(node_test_suite, add_third_repository=True)
rev_list = self.getAndUpdateFullRevisionList(test_node, node_test_suite)
self.assertEquals(3, len(rev_list))
self.assertEquals(3, len(node_test_suite.vcs_repository_list))
self.assertEqual(3, len(rev_list))
self.assertEqual(3, len(node_test_suite.vcs_repository_list))
rep2_clone_path = [x['repository_path'] for x in \
node_test_suite.vcs_repository_list \
if x['repository_path'].endswith("rep2")][0]
......@@ -332,13 +332,13 @@ shared = true
output = call("git branch".split()).strip()
self.assertTrue("* foo" in output.split('\n'))
vcs_repository_info = node_test_suite.vcs_repository_list[0]
self.assertEquals(vcs_repository_info['repository_id'], 'rep2')
self.assertEquals(vcs_repository_info['branch'], 'foo')
self.assertEqual(vcs_repository_info['repository_id'], 'rep2')
self.assertEqual(vcs_repository_info['branch'], 'foo')
# change it to master
vcs_repository_info['branch'] = 'master'
rev_list = self.getAndUpdateFullRevisionList(test_node, node_test_suite)
output = call("git branch".split()).strip()
print output
print(output)
self.assertTrue("* master" in output.split('\n'))
# Add a third branch on remote, make sure we could switch to it
remote_call = self.getCaller(cwd=self.remote_repository2)
......@@ -368,8 +368,8 @@ shared = true
node_test_suite = test_node.getNodeTestSuite('foo')
self.updateNodeTestSuiteData(node_test_suite)
rev_list = self.getAndUpdateFullRevisionList(test_node, node_test_suite)
self.assertEquals(2, len(rev_list))
self.assertEquals(2, len(node_test_suite.vcs_repository_list))
self.assertEqual(2, len(rev_list))
self.assertEqual(2, len(node_test_suite.vcs_repository_list))
# patch deleteRepository to make sure it will be called once for the wrong
# repos, and not for the repos which has not changed
deleted_repository_path_list = []
......@@ -386,12 +386,12 @@ shared = true
node_test_suite.vcs_repository_list \
if x['repository_path'].endswith("rep0")][0]
call = self.getCaller(cwd=rep0_clone_path)
self.assertEquals(call("git config --get remote.origin.url".split()).strip(),
self.assertEqual(call("git config --get remote.origin.url".split()).strip(),
self.remote_repository0)
rev_list = self.getAndUpdateFullRevisionList(test_node, node_test_suite)
self.assertEquals(call("git config --get remote.origin.url".split()).strip(),
self.assertEqual(call("git config --get remote.origin.url".split()).strip(),
self.remote_repository2)
self.assertEquals([rep0_clone_path], deleted_repository_path_list)
self.assertEqual([rep0_clone_path], deleted_repository_path_list)
finally:
Updater.deleteRepository = original_deleteRepository
......@@ -407,8 +407,8 @@ shared = true
node_test_suite = test_node.getNodeTestSuite('foo')
self.updateNodeTestSuiteData(node_test_suite)
rev_list = self.getAndUpdateFullRevisionList(test_node, node_test_suite)
self.assertEquals(2, len(rev_list))
self.assertEquals(2, len(node_test_suite.vcs_repository_list))
self.assertEqual(2, len(rev_list))
self.assertEqual(2, len(node_test_suite.vcs_repository_list))
rep0_clone_path = [x['repository_path'] for x in \
node_test_suite.vcs_repository_list \
if x['repository_path'].endswith("rep0")][0]
......@@ -457,10 +457,9 @@ shared = true
node_test_suite.vcs_repository_list \
if x['repository_path'].endswith("rep0")][0]
# simulate a data corruption on rep0's index
index_file = open(os.path.join(rep0_clone_path, '.git', 'index'), 'a')
index_file.seek(10, os.SEEK_END)
index_file.truncate()
index_file.close()
with open(os.path.join(rep0_clone_path, '.git', 'index'), 'ab') as index_file:
index_file.seek(10, os.SEEK_END)
index_file.truncate()
# we get rev list with corrupted repository, we get None, but in the same
# time the bad repository is deleted
rev_list = self.getAndUpdateFullRevisionList(test_node, node_test_suite)
......@@ -490,8 +489,8 @@ shared = true
info_list.append(
call("git log -n1 --format=%H".split()).strip())
return info_list
self.assertEquals(['2', '2'], getRepInfo(count=1))
self.assertEquals([commit_dict['rep0'][0][0],commit_dict['rep1'][0][0]],
self.assertEqual(['2', '2'], getRepInfo(count=1))
self.assertEqual([commit_dict['rep0'][0][0],commit_dict['rep1'][0][0]],
getRepInfo(hash=1))
class TestResult(object):
revision = NodeTestSuite.revision
......@@ -501,25 +500,25 @@ shared = true
test_result.revision_list = (('rep0', (2, commit_dict['rep0'][0][0])),
('rep1', (1, commit_dict['rep1'][1][0])))
test_node.checkRevision(test_result, node_test_suite)
self.assertEquals(['2', '1'], getRepInfo(count=1))
self.assertEquals([commit_dict['rep0'][0][0],commit_dict['rep1'][1][0]],
self.assertEqual(['2', '1'], getRepInfo(count=1))
self.assertEqual([commit_dict['rep0'][0][0],commit_dict['rep1'][1][0]],
getRepInfo(hash=1))
def test_07_checkExistingTestSuite(self):
test_node = self.getTestNode()
test_suite_data = self.getTestSuiteData(add_third_repository=True)
self.assertEquals([], os.listdir(self.working_directory))
self.assertEqual([], os.listdir(self.working_directory))
test_node.purgeOldTestSuite(test_suite_data)
self.assertEquals([], os.listdir(self.working_directory))
self.assertEqual([], os.listdir(self.working_directory))
os.mkdir(os.path.join(self.working_directory, 'foo'))
self.assertEquals(['foo'], os.listdir(self.working_directory))
self.assertEqual(['foo'], os.listdir(self.working_directory))
test_node.purgeOldTestSuite(test_suite_data)
self.assertEquals(['foo'], os.listdir(self.working_directory))
self.assertEqual(['foo'], os.listdir(self.working_directory))
os.mkdir(os.path.join(self.working_directory, 'bar'))
self.assertEquals(set(['bar','foo']),
self.assertEqual(set(['bar','foo']),
set(os.listdir(self.working_directory)))
test_node.purgeOldTestSuite(test_suite_data)
self.assertEquals(['foo'], os.listdir(self.working_directory))
self.assertEqual(['foo'], os.listdir(self.working_directory))
def test_purgeOldTestSuiteChmodNonWriteable(self):
"""Old test suites can be deleted even when some files/directories have
......@@ -633,11 +632,11 @@ shared = true
method_list_for_prepareSlapOSForTestSuite = ["initializeSlapOSControler",
"runSoftwareRelease", "runComputerPartition"]
runner.prepareSlapOSForTestNode(test_node_slapos)
self.assertEquals(method_list_for_prepareSlapOSForTestNode,
self.assertEqual(method_list_for_prepareSlapOSForTestNode,
[x["method_name"] for x in call_list])
call_list = []
runner.prepareSlapOSForTestSuite(node_test_suite)
self.assertEquals(method_list_for_prepareSlapOSForTestSuite,
self.assertEqual(method_list_for_prepareSlapOSForTestSuite,
[x["method_name"] for x in call_list])
call_list = []
SlapOSControler.runSoftwareRelease = Patch("runSoftwareRelease", status_code=1)
......@@ -681,7 +680,7 @@ shared = true
return json.dumps([])
def _checkExistingTestSuite(reference_set):
test_self.assertEquals(set(reference_set),
test_self.assertEqual(set(reference_set),
set(os.listdir(test_node.working_directory)))
for x in reference_set:
test_self.assertTrue(os.path.exists(os.path.join(
......@@ -761,7 +760,7 @@ shared = true
SlapOSControler.initializeSlapOSControler = doNothing
# Inside test_node a runner is created using new UnitTestRunner methods
test_node.run()
self.assertEquals(5, counter)
self.assertEqual(5, counter)
time.sleep = original_sleep
# Restore old class methods
if my_test_type == "ScalabilityTest":
......@@ -797,23 +796,23 @@ shared = true
file_name = 'AC_Ra\xc3\xadzertic\xc3\xa1ma'
non_ascii_file = open(os.path.join(controler.software_root, file_name), 'w')
non_ascii_file.close()
self.assertEquals([file_name], os.listdir(controler.software_root))
self.assertEqual([file_name], os.listdir(controler.software_root))
controler._resetSoftware()
self.assertEquals([], os.listdir(controler.software_root))
self.assertEqual([], os.listdir(controler.software_root))
def test_14_createFolder(self):
test_node = self.getTestNode()
node_test_suite = test_node.getNodeTestSuite('foo')
folder = node_test_suite.test_suite_directory
self.assertEquals(False, os.path.exists(folder))
self.assertFalse(os.path.exists(folder))
createFolder(folder)
self.assertEquals(True, os.path.exists(folder))
self.assertTrue(os.path.exists(folder))
to_drop_path = os.path.join(folder, 'drop')
to_drop = open(to_drop_path, 'w')
to_drop.close()
self.assertEquals(True, os.path.exists(to_drop_path))
self.assertTrue(os.path.exists(to_drop_path))
createFolder(folder, clean=True)
self.assertEquals(False, os.path.exists(to_drop_path))
self.assertFalse(os.path.exists(to_drop_path))
def test_15_suite_log_directory(self, my_test_type='UnitTest', grade='master'):
def doNothing(self, *args, **kw):
......@@ -861,7 +860,7 @@ shared = true
def checkTestSuite(test_node):
test_node.node_test_suite_dict
rand_part_set = set()
self.assertEquals(2, len(test_node.node_test_suite_dict))
self.assertEqual(2, len(test_node.node_test_suite_dict))
for ref, suite in test_node.node_test_suite_dict.items():
self.assertTrue('var/log/testnode/%s' % suite.reference in \
suite.suite_log_path,
......@@ -925,7 +924,7 @@ shared = true
RunnerClass._prepareSlapOS = patch_prepareSlapOS
SlapOSControler.initializeSlapOSControler = doNothing
test_node.run()
self.assertEquals(counter, 3)
self.assertEqual(counter, 3)
checkTestSuite(test_node)
time.sleep = original_sleep
# Restore old class methods
......@@ -1021,18 +1020,18 @@ shared = true
def callRaisingPrepareSlapos():
self.assertRaises(SubprocessError, callPrepareSlapOS)
self.assertEquals(node_test_suite.retry_software_count, 0)
for x in xrange(0,11):
self.assertEqual(node_test_suite.retry_software_count, 0)
for x in range(11):
callRaisingPrepareSlapos()
self.assertEquals(len(init_call_kw_list), 11)
self.assertEquals(init_call_kw_list[-1]['reset_software'], False)
self.assertEquals(node_test_suite.retry_software_count, 11)
self.assertEqual(len(init_call_kw_list), 11)
self.assertEqual(init_call_kw_list[-1]['reset_software'], False)
self.assertEqual(node_test_suite.retry_software_count, 11)
callRaisingPrepareSlapos()
self.assertEquals(init_call_kw_list[-1]['reset_software'], True)
self.assertEquals(node_test_suite.retry_software_count, 1)
self.assertEqual(init_call_kw_list[-1]['reset_software'], True)
self.assertEqual(node_test_suite.retry_software_count, 1)
callRaisingPrepareSlapos()
self.assertEquals(init_call_kw_list[-1]['reset_software'], False)
self.assertEquals(node_test_suite.retry_software_count, 2)
self.assertEqual(init_call_kw_list[-1]['reset_software'], False)
self.assertEqual(node_test_suite.retry_software_count, 2)
SlapOSControler.initializeSlapOSControler = \
initial_initializeSlapOSControler
SlapOSControler.runSoftwareRelease = initial_runSoftwareRelease
......
......@@ -28,6 +28,7 @@
#
##############################################################################
from __future__ import print_function
import argparse
import os
import sys
......@@ -264,7 +265,7 @@ class PerformanceTester(object):
error_message = exit_msg_queue.get()
except KeyboardInterrupt, e:
print >>sys.stderr, "\nInterrupted by user, stopping gracefully..."
print("\nInterrupted by user, stopping gracefully...", file=sys.stderr)
exit_status = 2
# An IOError may be raised when receiving a SIGINT which interrupts the
......@@ -337,7 +338,7 @@ class PerformanceTester(object):
def main():
error_message_set, exit_status = PerformanceTester().run()
for error_message in error_message_set:
print >>sys.stderr, "ERROR: %s" % error_message
print("ERROR: %s" % error_message, file=sys.stderr)
sys.exit(exit_status)
......
......@@ -31,6 +31,7 @@
#
##############################################################################
from __future__ import print_function
import argparse
import re
......@@ -537,7 +538,7 @@ def generateReport():
for filename in filename_iter:
# There may be no results at all in case of errors
if not os.stat(filename).st_size:
print >>sys.stderr, "Ignoring empty file %s" % filename
print("Ignoring empty file %s" % filename, file=sys.stderr)
continue
report_dict = per_nb_users_report_dict.setdefault(
......@@ -546,10 +547,8 @@ def generateReport():
report_dict['filename'].append(filename)
if not per_nb_users_report_dict:
print >>sys.stderr, "ERROR: No result file found, perhaps "\
"``--filename-prefix'' should be specified?"
sys.exit(1)
sys.exit("ERROR: No result file found, perhaps ``--filename-prefix'' should"
"be specified?")
pdf = PdfPages(argument_namespace.output_filename)
......
......@@ -28,6 +28,7 @@
#
##############################################################################
from __future__ import print_function
from .result import CSVBenchmarkResult, NothingFlushedException
class CSVScalabilityBenchmarkResult(CSVBenchmarkResult):
......@@ -60,7 +61,7 @@ class ScalabilityTester(PerformanceTester):
urllib.urlencode({'error_message_set': '|'.join(error_message_set)})).close()
except:
print >>sys.stderr, "ERROR: %s" % Formatter().formatException(sys.exc_info())
print("ERROR: %s" % Formatter().formatException(sys.exc_info()), file=sys.stderr)
def getResultClass(self):
if not self._argument_namespace.erp5_publish_url:
......
......@@ -27,7 +27,7 @@ def main():
if error_message_set:
exit_status = 1
for error in error_message_set:
print error
print(error)
elif result:
print result
print(result)
sys.exit(exit_status)
......@@ -5,23 +5,15 @@ import os
import shutil
import time
import sys
import multiprocessing
import signal
import errno
import json
import logging
import logging.handlers
import glob
import urlparse
import httplib
import base64
import threading
from erp5.util.benchmark.argument import ArgumentType
from erp5.util.benchmark.performance_tester import PerformanceTester
from erp5.util.benchmark.thread import TestThread, TestMetricThread
from erp5.util import taskdistribution
from erp5.util.testnode import Utils
from erp5.util.testnode.ProcessManager import SubprocessError, ProcessManager, CancellationError
from erp5.util.testnode.ProcessManager import ProcessManager
import datetime
MAX_INSTALLATION_TIME = 60*50
......@@ -179,31 +171,28 @@ class ScalabilityLauncher(object):
"""
data_array = self.__argumentNamespace.current_test_data.split(',')
data = json.dumps({"count": data_array[0], "title": data_array[1], "relative_path": data_array[2]})
decoded_data = Utils.deunicodeData(json.loads(data))
return ScalabilityTest(decoded_data, self.test_result)
encoded_data = Utils.deunicodeData(json.loads(data))
return ScalabilityTest(encoded_data, self.test_result)
def clearUsersFile(self, user_file_path):
self.log("Clearing users file: %s" % user_file_path)
os.remove(user_file_path)
users_file = open(user_file_path, "w")
for line in self.users_file_original_content:
users_file.write(line)
users_file.close()
with open(user_file_path, "w") as users_file:
for line in self.users_file_original_content:
users_file.write(line)
def updateUsersFile(self, user_quantity, password, user_file_path):
self.log("Updating users file: %s" % user_file_path)
users_file = open(user_file_path, "r")
file_content = users_file.readlines()
with open(user_file_path, "r") as users_file:
file_content = users_file.readlines()
self.users_file_original_content = file_content
new_file_content = []
for line in file_content:
new_file_content.append(line.replace('<password>', password).replace('<user_quantity>', str(user_quantity)))
users_file.close()
os.remove(user_file_path)
users_file = open(user_file_path, "w")
for line in new_file_content:
users_file.write(line)
users_file.close()
with open(user_file_path, "w") as users_file:
for line in new_file_content:
users_file.write(line)
def run(self):
self.log("Scalability Launcher started, with:")
......
......@@ -40,11 +40,15 @@ Example use:
test_line.stop()
"""
from __future__ import print_function
import httplib
import six
from six.moves import (
map,
http_client as httplib,
xmlrpc_client as xmlrpclib,
)
import socket
import threading
import time
import xmlrpclib
__all__ = ['TaskDistributor', 'TestResultProxy', 'TestResultLineProxy', 'patchRPCParser']
......@@ -89,11 +93,17 @@ def patchRPCParser(error_handler):
def verbose_feed(self, data):
try:
return original_feed(self, data)
except Exception, exc:
except Exception as exc:
if not error_handler(data, exc):
raise
parser_klass.feed = verbose_feed
try: # PY3
basestring
except NameError:
basestring = bytes, str
unicode = str
def binarize_args(arg):
# Converts recursively basestring arg into xmlrpclib.Binary, as they can
# contain non-XML allowed characters
......@@ -102,9 +112,9 @@ def binarize_args(arg):
arg = arg.encode('utf-8')
return xmlrpclib.Binary(arg)
if isinstance(arg, (list, tuple, set)):
return map(binarize_args, arg)
return list(map(binarize_args, arg))
if isinstance(arg, dict):
return {k: binarize_args(v) for k, v in arg.iteritems()}
return {k: binarize_args(v) for k, v in six.iteritems(arg)}
return arg
class RPCRetry(object):
......@@ -350,7 +360,7 @@ class TestResultProxy(RPCRetry):
caption_list = []
append = caption_list.append
for name, (stream, max_history_bytes) in \
self._watcher_dict.iteritems():
six.iteritems(self._watcher_dict):
append('==> %s <==' % (name, ))
start = stream.tell()
stream.seek(0, 2)
......
......@@ -8,6 +8,7 @@
#
# TODO: There must be a better way than the code below to do that though...
from __future__ import print_function
import sys
from erp5.util.testbrowser.browser import Browser
......@@ -19,11 +20,8 @@ try:
user_nbr = int(user_nbr)
except ValueError:
print >>sys.stderr, "ERROR: Missing arguments: %s URL USERNAME " \
"PASSWORD NUMBER_OF_USERS NEW_USERNAME_PREFIX NEW_USERS_PASSWORD" % \
sys.argv[0]
sys.exit(1)
sys.exit("ERROR: Missing arguments: %s URL USERNAME PASSWORD NUMBER_OF_USERS "
"NEW_USERNAME_PREFIX NEW_USERS_PASSWORD" % sys.argv[0])
# Create a browser instance
browser = Browser(url, username, password)
......
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import division, print_function
from erp5.util.testbrowser.browser import Browser
ITERATION = 20
......@@ -89,4 +90,4 @@ if __name__ == '__main__':
counter += 1
for title, time_list in result_dict.iteritems():
print "%s: %.4fs" % (title, float(sum(time_list)) / ITERATION)
print("%s: %.4fs" % (title, sum(time_list) / ITERATION))
......@@ -32,6 +32,8 @@ import string
import random
from .Utils import createFolder
from six.moves import range
class SlapOSInstance(object):
"""
Base of an software instance,
......@@ -69,14 +71,14 @@ class NodeTestSuite(SlapOSInstance):
def createSuiteLog(self):
# /srv/slapgrid/slappartXX/srv/var/log/testnode/az-D27KqX7FxJ/suite.log
alphabets = string.digits + string.letters
alphabets = string.digits + string.ascii_letters
while 1:
log_folder_name = '%s-%s' % (self.reference,
''.join(random.choice(alphabets) for i in xrange(10)))
''.join(random.choice(alphabets) for i in range(10)))
log_folder_path = os.path.join(self.log_directory, log_folder_name)
try:
os.makedirs(log_folder_path)
except OSError, e:
except OSError as e:
if e.errno != errno.EEXIST:
raise
else:
......
......@@ -79,7 +79,8 @@ def subprocess_capture(p, log_prefix, get_output=True):
break
if get_output:
buffer.append(data)
log(log_prefix + data.rstrip('\n'))
log(log_prefix + (data if str is bytes else
data.decode('utf-8', errors='replace')).rstrip('\n'))
if p.stdout:
stdout = []
stdout_thread = threading.Thread(target=readerthread,
......@@ -97,8 +98,8 @@ def subprocess_capture(p, log_prefix, get_output=True):
stdout_thread.join()
if p.stderr:
stderr_thread.join()
return (p.stdout and ''.join(stdout),
p.stderr and ''.join(stderr))
return (p.stdout and b''.join(stdout),
p.stderr and b''.join(stderr))
def killCommand(pid):
"""
......@@ -109,7 +110,7 @@ def killCommand(pid):
try:
process = psutil.Process(pid)
process.suspend()
except psutil.Error, e:
except psutil.Error as e:
return
process_list = [process]
new_list = process.children(recursive=True)
......@@ -118,19 +119,19 @@ def killCommand(pid):
for child in new_list:
try:
child.suspend()
except psutil.Error, e:
except psutil.Error as e:
logger.debug("killCommand/suspend: %s", e)
time.sleep(1)
new_list = set(process.children(recursive=True)).difference(process_list)
for process in process_list:
try:
process.kill()
except psutil.Error, e:
except psutil.Error as e:
logger.debug("killCommand/kill: %s", e)
class ProcessManager(object):
stdin = file(os.devnull)
stdin = open(os.devnull)
def __init__(self, max_timeout=MAX_TIMEOUT):
self.process_pid_set = set()
......
......@@ -30,30 +30,31 @@ import subprocess
import sys
import time
import glob
import SlapOSControler
import SlapOSMasterCommunicator
from . import SlapOSControler, SlapOSMasterCommunicator
import json
import time
import shutil
import logging
import string
import random
import urlparse
from six.moves.urllib.parse import urlparse
import base64
import httplib
import Utils
from six.moves import http_client as httplib
from . import Utils
import requests
import slapos.slap
import cPickle as pickle
from ProcessManager import SubprocessError, ProcessManager, CancellationError
from six.moves import cPickle as pickle
from .ProcessManager import SubprocessError, ProcessManager, CancellationError
from subprocess import CalledProcessError
from Updater import Updater
from .Updater import Updater
from erp5.util import taskdistribution
from erp5.util.benchmark.thread import TestThread
# for dummy slapos answer