Commit 9de598f2 authored by Bryton Lacquement's avatar Bryton Lacquement 🚪

wip

parent d1e941b3
......@@ -149,8 +149,8 @@ def _generateSlaposNodeConfigurationFile(slapos_node_config_path, args):
slapos_node_configuration_content = re.sub(
'(key_file|cert_file|certificate_repository_path).*=.*\n',
'', slapos_node_configuration_content)
with open(slapos_node_config_path, 'wb') as fout:
fout.write(slapos_node_configuration_content.encode('utf8'))
with open(slapos_node_config_path, 'w') as fout:
fout.write(slapos_node_configuration_content)
def _generateSlaposProxyConfigurationFile(conf):
template_arg_list = (__name__, '../../slapos-proxy.cfg.example')
......@@ -172,8 +172,8 @@ def _generateSlaposProxyConfigurationFile(conf):
slapos_proxy_configuration_content = _replaceParameterValue(
slapos_proxy_configuration_template, to_replace)
with open(slapos_proxy_configuration_path, 'wb') as fout:
fout.write(slapos_proxy_configuration_content.encode('utf8'))
with open(slapos_proxy_configuration_path, 'w') as fout:
fout.write(slapos_proxy_configuration_content)
return slapos_proxy_configuration_path
......
......@@ -28,7 +28,7 @@
##############################################################################
import atexit
import six.moves.configparser
from six.moves import configparser
import os
import sys
......@@ -52,7 +52,7 @@ class ClientConfig(object):
# Merges the arguments and configuration
try:
configuration_dict = dict(configp.items('slapconsole'))
except ConfigParser.NoSectionError:
except configparser.NoSectionError:
pass
else:
for key in configuration_dict:
......
......@@ -74,19 +74,15 @@ class User(object):
time_cycle = self.disk_snapshot_params.get('time_cycle', 0)
database.connect()
if time_cycle:
order = 'date DESC, time DESC'
limit = 1
query = database.select(table="folder", columns="date, time",
order=order, limit=limit,
where="partition='%s'" % self.name)
query_result = zip(*query)
if len(query_result):
date, time = (query_result[0][0], query_result[1][0])
latest_date = datetime.strptime('%s %s' % (date, time),
"%Y-%m-%d %H:%M:%S")
for date_time in database.select(table="folder", columns="date, time",
order='date DESC, time DESC', limit=1,
where="partition='%s'" % self.name):
latest_date = datetime.strptime('%s %s' % date_time,
"%Y-%m-%d %H:%M:%S")
if (datetime.now() - latest_date).seconds < time_cycle:
# wait the time cycle
return
break
pid_file = self.disk_snapshot_params.get('pid_folder', None)
if pid_file is not None:
pid_file = os.path.join(pid_file, '%s_disk_size.pid' % self.name)
......
......@@ -40,6 +40,8 @@ import tarfile
import time
import psutil
import six
log_file = False
class Dumper(object):
......@@ -59,10 +61,10 @@ class SystemReporter(Dumper):
""" Dump data """
_date = time.strftime("%Y-%m-%d")
self.db.connect()
for item, collected_item_list in self.db.exportSystemAsDict(_date).iteritems():
for item, collected_item_list in six.iteritems(self.db.exportSystemAsDict(_date)):
self.writeFile(item, folder, collected_item_list)
for partition, collected_item_list in self.db.exportDiskAsDict(_date).iteritems():
for partition, collected_item_list in six.iteritems(self.db.exportDiskAsDict(_date)):
partition_id = "_".join(partition.split("-")[:-1]).replace("/", "_")
item = "memory_%s" % partition.split("-")[-1]
self.writeFile("disk_%s_%s" % (item, partition_id), folder, collected_item_list)
......
......@@ -36,6 +36,8 @@ from .temperature import collectComputerTemperature, \
from .temperature.heating import get_contribution_ratio
import six
MEASURE_INTERVAL = 5
class _Snapshot(object):
......@@ -242,6 +244,6 @@ class ComputerSnapshot(_Snapshot):
DiskPartitionSnapshot(partition.device,
partition.mountpoint))
return [(k, v) for k, v in partition_dict.iteritems()]
return [(k, v) for k, v in six.iteritems(partition_dict)]
......@@ -18,7 +18,8 @@ def collectComputerTemperature(sensor_bin="sensors"):
cmd = ["%s -u" % sensor_bin]
sp = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, shell=True)
stderr=subprocess.PIPE, shell=True,
universal_newlines=True)
stdout, stderr = sp.communicate()
......
......@@ -161,8 +161,8 @@ class GenericPromise(object):
self.logger.removeHandler(handler)
if self.__log_folder is None:
# configure logger with StringIO
import cStringIO
self.__logger_buffer = cStringIO.StringIO()
from six.moves import cStringIO
self.__logger_buffer = cStringIO()
logger_handler = logging.StreamHandler(self.__logger_buffer)
self.__log_file = None
else:
......
......@@ -6,7 +6,7 @@ import os
from .interface import IManager
from six.moves import filter
from zope import interface
from zope.interface import implementer
logger = logging.getLogger(__name__)
......@@ -22,9 +22,8 @@ def which(exename):
return full_path
return None
@implementer(IManager)
class Manager(object):
interface.implements(IManager)
port_redirect_filename = '.slapos-port-redirect'
def __init__(self, config):
......
......@@ -3,5 +3,5 @@
import pkg_resources
from slapos.util import bytes2str
DB_VERSION = bytes2str(pkg_resources.resource_stream('slapos.proxy', 'schema.sql').readline().strip().split(b':')[1])
DB_VERSION = bytes2str(pkg_resources.resource_stream('slapos.proxy', 'schema.sql').readline()).strip().split(':')[1]
......@@ -298,7 +298,7 @@ def useComputer():
@app.route('/loadComputerConfigurationFromXML', methods=['POST'])
def loadComputerConfigurationFromXML():
xml = request.form['xml']
computer_dict = xml_marshaller.xml_marshaller.loads(str(xml).encode('utf-8'))
computer_dict = xml_marshaller.xml_marshaller.loads(xml.encode('utf-8'))
execute_db('computer', 'INSERT OR REPLACE INTO %s values(:reference, :address, :netmask)',
computer_dict)
for partition in computer_dict['partition_list']:
......@@ -622,7 +622,7 @@ def requestNotSlave(software_release, software_type, partition_reference, partit
execute_db('partition', q, args)
args = []
partition = execute_db('partition', 'SELECT * FROM %s WHERE reference=? and computer_reference=?',
[partition['reference'].encode(), partition['computer_reference'].encode()], one=True)
[partition['reference'], partition['computer_reference']], one=True)
address_list = []
for address in execute_db('partition_network', 'SELECT * FROM %s WHERE partition_reference=?', [partition['reference']]):
address_list.append((address['reference'], address['address']))
......
......@@ -873,12 +873,12 @@ class slap:
# XXX-Cedric: should raise something smarter than NotFound
raise NotFoundError
xml = bytes(self._connection_helper.GET('registerComputerPartition',
xml = self._connection_helper.GET('registerComputerPartition',
params = {
'computer_reference': computer_guid,
'computer_partition_reference': partition_id,
}
))
)
result = xml_marshaller.loads(xml)
# XXX: dirty hack to make computer partition usable. xml_marshaller is too
# low-level for our needs here.
......@@ -913,7 +913,7 @@ class slap:
'software_release_url parameters are specified.')
params['software_release_url'] = software_release_url
xml = bytes(self._connection_helper.GET(url, params=params))
xml = self._connection_helper.GET(url, params=params)
result = xml_marshaller.loads(xml)
assert(type(result) == list)
return result
......
......@@ -364,7 +364,7 @@ class TestCollectReport(unittest.TestCase):
with tarfile.open("%s.tar.gz" % dump_folder) as tf:
self.assertEquals(tf.getmembers()[0].name, "1990-01-01")
self.assertEquals(tf.getmembers()[1].name, "1990-01-01/test.txt")
self.assertEquals(tf.extractfile(tf.getmembers()[1]).read(), 'hi')
self.assertEquals(tf.extractfile(tf.getmembers()[1]).read(), b'hi')
class TestCollectSnapshot(unittest.TestCase):
......@@ -482,10 +482,10 @@ class TestCollectEntity(unittest.TestCase):
config.set('slapos', 'instance_root', self.instance_root)
user_dict = entity.get_user_list(config)
username_list = ['slapuser0', 'slapuser1', 'slapuser2']
self.assertEquals(username_list, user_dict.keys())
username_set = {'slapuser0', 'slapuser1', 'slapuser2'}
self.assertEquals(username_set, set(user_dict))
for name in username_list:
for name in username_set:
self.assertEquals(user_dict[name].name, name)
self.assertEquals(user_dict[name].snapshot_list, [])
expected_path = "%s/slappart%s" % (self.instance_root, name.strip("slapuser"))
......@@ -508,11 +508,11 @@ class TestCollectEntity(unittest.TestCase):
self.assertEquals(database.invoked_method_list[1][0], "insertUserSnapshot")
self.assertEquals(database.invoked_method_list[1][1][0], ("fakeuser0",))
self.assertEquals(database.invoked_method_list[1][1][1].keys(),
['cpu_time', 'cpu_percent', 'process',
self.assertEquals(set(database.invoked_method_list[1][1][1]),
{'cpu_time', 'cpu_percent', 'process',
'memory_rss', 'pid', 'memory_percent',
'io_rw_counter', 'insertion_date', 'insertion_time',
'io_cycles_counter', 'cpu_num_threads'])
'io_cycles_counter', 'cpu_num_threads'})
self.assertEquals(database.invoked_method_list[2], ("commit", ""))
self.assertEquals(database.invoked_method_list[3], ("close", ""))
......@@ -527,19 +527,19 @@ class TestCollectEntity(unittest.TestCase):
self.assertEquals(database.invoked_method_list[1][0], "insertUserSnapshot")
self.assertEquals(database.invoked_method_list[1][1][0], ("fakeuser0",))
self.assertEquals(database.invoked_method_list[1][1][1].keys(),
['cpu_time', 'cpu_percent', 'process',
self.assertEquals(set(database.invoked_method_list[1][1][1]),
{'cpu_time', 'cpu_percent', 'process',
'memory_rss', 'pid', 'memory_percent',
'io_rw_counter', 'insertion_date', 'insertion_time',
'io_cycles_counter', 'cpu_num_threads'])
'io_cycles_counter', 'cpu_num_threads'})
self.assertEquals(database.invoked_method_list[2], ("commit", ""))
self.assertEquals(database.invoked_method_list[3], ("close", ""))
self.assertEquals(database.invoked_method_list[4], ("connect", ""))
self.assertEquals(database.invoked_method_list[5][0], "inserFolderSnapshot")
self.assertEquals(database.invoked_method_list[5][1][0], ("fakeuser0",))
self.assertEquals(database.invoked_method_list[5][1][1].keys(),
['insertion_date', 'disk_usage', 'insertion_time'])
self.assertEquals(set(database.invoked_method_list[5][1][1]),
{'insertion_date', 'disk_usage', 'insertion_time'})
self.assertEquals(database.invoked_method_list[6], ("commit", ""))
self.assertEquals(database.invoked_method_list[7], ("close", ""))
......@@ -554,23 +554,23 @@ class TestCollectEntity(unittest.TestCase):
self.assertEquals(database.invoked_method_list[1][0], "insertUserSnapshot")
self.assertEquals(database.invoked_method_list[1][1][0], ("fakeuser0",))
self.assertEquals(database.invoked_method_list[1][1][1].keys(),
['cpu_time', 'cpu_percent', 'process',
self.assertEquals(set(database.invoked_method_list[1][1][1]),
{'cpu_time', 'cpu_percent', 'process',
'memory_rss', 'pid', 'memory_percent',
'io_rw_counter', 'insertion_date', 'insertion_time',
'io_cycles_counter', 'cpu_num_threads'])
'io_cycles_counter', 'cpu_num_threads'})
self.assertEquals(database.invoked_method_list[2], ("commit", ""))
self.assertEquals(database.invoked_method_list[3], ("close", ""))
self.assertEquals(database.invoked_method_list[4], ("connect", ""))
self.assertEquals(database.invoked_method_list[5][0], "select")
self.assertEquals(database.invoked_method_list[5][1][0], ())
self.assertEquals(database.invoked_method_list[5][1][1].keys(),
['table', 'where', 'limit', 'order', 'columns'])
self.assertEquals(set(database.invoked_method_list[5][1][1]),
{'table', 'where', 'limit', 'order', 'columns'})
self.assertEquals(database.invoked_method_list[6][0], "inserFolderSnapshot")
self.assertEquals(database.invoked_method_list[6][1][0], ("fakeuser0",))
self.assertEquals(database.invoked_method_list[6][1][1].keys(),
['insertion_date', 'disk_usage', 'insertion_time'])
self.assertEquals(set(database.invoked_method_list[6][1][1]),
{'insertion_date', 'disk_usage', 'insertion_time'})
self.assertEquals(database.invoked_method_list[7], ("commit", ""))
self.assertEquals(database.invoked_method_list[8], ("close", ""))
......@@ -583,14 +583,14 @@ class TestCollectEntity(unittest.TestCase):
self.assertEquals(database.invoked_method_list[1][0], "insertComputerSnapshot")
self.assertEquals(database.invoked_method_list[1][1][0], ())
self.assertEquals(database.invoked_method_list[1][1][1].keys(),
['insertion_time', 'insertion_date', 'cpu_num_core',
self.assertEquals(set(database.invoked_method_list[1][1][1]),
{'insertion_time', 'insertion_date', 'cpu_num_core',
'partition_list', 'cpu_frequency', 'memory_size',
'cpu_type', 'memory_type'])
'cpu_type', 'memory_type'})
self.assertEquals(database.invoked_method_list[2][0], "insertSystemSnapshot")
self.assertEquals(database.invoked_method_list[2][1][0], ())
self.assertEquals(set(database.invoked_method_list[2][1][1].keys()),
self.assertEquals(set(database.invoked_method_list[2][1][1]),
set([ 'memory_used', 'cpu_percent', 'insertion_date', 'insertion_time',
'loadavg', 'memory_free', 'net_in_bytes', 'net_in_dropped',
'net_in_errors', 'net_out_bytes', 'net_out_dropped',
......@@ -598,7 +598,7 @@ class TestCollectEntity(unittest.TestCase):
self.assertEquals(database.invoked_method_list[3][0], "insertDiskPartitionSnapshot")
self.assertEquals(database.invoked_method_list[3][1][0], ())
self.assertEquals(set(database.invoked_method_list[3][1][1].keys()),
self.assertEquals(set(database.invoked_method_list[3][1][1]),
set([ 'used', 'insertion_date', 'partition', 'free',
'mountpoint', 'insertion_time' ]))
......
......@@ -290,9 +290,9 @@ class RunPromise(GenericPromise):
promise_module = promise_process._loadPromiseModule()
promise = promise_module.RunPromise(promise_process.argument_dict)
self.assertEqual(promise.getConfig('foo'), 'bar')
self.assertEqual(promise.getConfig('my-config'), 4522111)
self.assertEqual(promise.getConfig('text'), config_dict['text'])
self.assertEquals(promise.getConfig('foo'), 'bar')
self.assertEquals(promise.getConfig('my-config'), 4522111)
self.assertEquals(promise.getConfig('text'), config_dict['text'])
def test_promise_extra_config_reserved_name(self):
promise_name = 'my_promise_extra.py'
......@@ -347,7 +347,7 @@ class RunPromise(GenericPromise):
with open(state_file) as f:
result_dict = json.loads(f.read())
result_dict['result'].pop('date')
self.assertEqual(json.loads(expected_result), result_dict)
self.assertEquals(json.loads(expected_result), result_dict)
def test_runpromise_multiple(self):
promise_name = 'my_promise.py'
......@@ -381,7 +381,7 @@ class RunPromise(GenericPromise):
result_dict = json.loads(f.read())
result_dict['result'].pop('date')
expected_dict = expected_result % {'promise_dir': self.plugin_dir, 'name': 'my_promise'}
self.assertEqual(json.loads(expected_dict), result_dict)
self.assertEquals(json.loads(expected_dict), result_dict)
# second promise
state_file = os.path.join(self.partition_dir, PROMISE_RESULT_FOLDER_NAME, 'my_second_promise.status.json')
......@@ -390,7 +390,7 @@ class RunPromise(GenericPromise):
result_dict = json.loads(f.read())
result_dict['result'].pop('date')
expected_dict = expected_result % {'promise_dir': self.plugin_dir, 'name': 'my_second_promise'}
self.assertEqual(json.loads(expected_dict), result_dict)
self.assertEquals(json.loads(expected_dict), result_dict)
def test_runpromise_no_logdir(self):
promise_name = 'my_promise.py'
......@@ -410,11 +410,11 @@ class RunPromise(GenericPromise):
self.assertTrue(isinstance(result, PromiseQueueResult))
self.assertTrue(isinstance(result.item, TestResult))
self.assertTrue(result.execution_time != 0)
self.assertEqual(result.title, 'my_promise')
self.assertEqual(result.name, promise_name)
self.assertEqual(result.path, os.path.join(self.plugin_dir, promise_name))
self.assertEqual(result.item.message, "success")
self.assertEqual(result.item.hasFailed(), False)
self.assertEquals(result.title, 'my_promise')
self.assertEquals(result.name, promise_name)
self.assertEquals(result.path, os.path.join(self.plugin_dir, promise_name))
self.assertEquals(result.item.message, "success")
self.assertEquals(result.item.hasFailed(), False)
self.assertTrue(isinstance(result.item.date, datetime))
self.configureLauncher(save_method=test_method)
......@@ -432,11 +432,11 @@ class RunPromise(GenericPromise):
self.assertTrue(isinstance(result, PromiseQueueResult))
self.assertTrue(isinstance(result.item, TestResult))
self.assertTrue(result.execution_time != 0)
self.assertEqual(result.title, 'my_promise')
self.assertEqual(result.name, promise_name)
self.assertEqual(result.path, os.path.join(self.plugin_dir, promise_name))
self.assertEqual(result.item.message, "success")
self.assertEqual(result.item.hasFailed(), False)
self.assertEquals(result.title, 'my_promise')
self.assertEquals(result.name, promise_name)
self.assertEquals(result.path, os.path.join(self.plugin_dir, promise_name))
self.assertEquals(result.item.message, "success")
self.assertEquals(result.item.hasFailed(), False)
self.assertTrue(isinstance(result.item.date, datetime))
# no promise log output dir
......@@ -455,11 +455,11 @@ class RunPromise(GenericPromise):
self.assertTrue(isinstance(result, PromiseQueueResult))
self.assertTrue(isinstance(result.item, AnomalyResult))
self.assertTrue(result.execution_time != 0)
self.assertEqual(result.title, 'my_promise')
self.assertEqual(result.name, promise_name)
self.assertEqual(result.path, os.path.join(self.plugin_dir, promise_name))
self.assertEqual(result.item.message, "success")
self.assertEqual(result.item.hasFailed(), False)
self.assertEquals(result.title, 'my_promise')
self.assertEquals(result.name, promise_name)
self.assertEquals(result.path, os.path.join(self.plugin_dir, promise_name))
self.assertEquals(result.item.message, "success")
self.assertEquals(result.item.hasFailed(), False)
self.assertTrue(isinstance(result.item.date, datetime))
self.configureLauncher(save_method=test_method, enable_anomaly=True)
......@@ -480,11 +480,11 @@ class RunPromise(GenericPromise):
self.assertTrue(isinstance(result.item, TestResult))
self.assertTrue(result.name in [promise_failed, promise_name])
if result.name == promise_failed:
self.assertEqual(result.item.hasFailed(), True)
self.assertEqual(result.item.message, "failed")
self.assertEquals(result.item.hasFailed(), True)
self.assertEquals(result.item.message, "failed")
else:
self.assertEqual(result.item.hasFailed(), False)
self.assertEqual(result.item.message, "success")
self.assertEquals(result.item.hasFailed(), False)
self.assertEquals(result.item.message, "success")
self.counter += 1
self.configureLauncher(save_method=test_method)
......@@ -494,7 +494,7 @@ class RunPromise(GenericPromise):
with self.assertRaises(PromiseError):
self.launcher.run()
self.assertEqual(self.counter, 2)
self.assertEquals(self.counter, 2)
self.assertTrue(os.path.exists(state_file))
self.assertTrue(os.path.exists(os.path.join(self.log_dir, 'my_promise.log')))
self.assertTrue(os.path.exists(os.path.join(self.log_dir, 'my_failed_promise.log')))
......@@ -508,8 +508,8 @@ class RunPromise(GenericPromise):
self.assertTrue(isinstance(result, PromiseQueueResult))
self.assertTrue(isinstance(result.item, TestResult))
self.assertTrue(result.name in [first_promise, second_promise, third_promise])
self.assertEqual(result.item.hasFailed(), False)
self.assertEqual(result.item.message, "success")
self.assertEquals(result.item.hasFailed(), False)
self.assertEquals(result.item.message, "success")
self.counter += 1
self.configureLauncher(save_method=test_method)
......@@ -520,7 +520,7 @@ class RunPromise(GenericPromise):
# run promise will not fail
self.launcher.run()
self.assertEqual(self.counter, 3)
self.assertEquals(self.counter, 3)
self.assertTrue(os.path.exists(state_file))
self.assertTrue(os.path.exists(os.path.join(self.log_dir, 'my_first_promise.log')))
self.assertTrue(os.path.exists(os.path.join(self.log_dir, 'my_second_promise.log')))
......@@ -562,15 +562,15 @@ class RunPromise(GenericPromise):
def test_method_first(result):
self.assertTrue(result.name in [first_promise, second_promise])
self.assertEqual(result.item.hasFailed(), False)
self.assertEqual(result.item.message, "success")
self.assertEquals(result.item.hasFailed(), False)
self.assertEquals(result.item.message, "success")
self.counter += 1
def test_method_one(result):
self.counter += 1
self.assertEqual(result.name, first_promise)
self.assertEqual(result.item.hasFailed(), False)
self.assertEqual(result.item.message, "success")
self.assertEquals(result.name, first_promise)
self.assertEquals(result.item.hasFailed(), False)
self.assertEquals(result.item.message, "success")
self.configureLauncher(save_method=test_method_first)
# ~2 seconds
......@@ -579,19 +579,19 @@ class RunPromise(GenericPromise):
self.generatePromiseScript(second_promise, success=True, periodicity=0.05)
self.launcher.run()
self.assertEqual(self.counter, 2)
self.assertEquals(self.counter, 2)
self.configureLauncher(save_method=test_method_one)
time.sleep(2)
self.counter = 0
self.launcher.run() # only my_first_promise will run
self.assertEqual(self.counter, 1)
self.assertEquals(self.counter, 1)
time.sleep(3)
self.counter = 0
self.configureLauncher(save_method=test_method_first)
self.launcher.run()
self.assertEqual(self.counter, 2)
self.assertEquals(self.counter, 2)
def test_runpromise_with_periodicity_same(self):
first_promise = 'my_first_promise.py'
......@@ -600,8 +600,8 @@ class RunPromise(GenericPromise):
def test_method(result):
self.assertTrue(result.name in [first_promise, second_promise])
self.assertEqual(result.item.hasFailed(), False)
self.assertEqual(result.item.message, "success")
self.assertEquals(result.item.hasFailed(), False)
self.assertEquals(result.item.message, "success")
self.counter += 1
self.configureLauncher(save_method=test_method)
......@@ -610,19 +610,19 @@ class RunPromise(GenericPromise):
self.generatePromiseScript(second_promise, success=True, periodicity=0.03)
self.launcher.run()
self.assertEqual(self.counter, 2)
self.assertEquals(self.counter, 2)
self.configureLauncher(save_method=test_method)
time.sleep(1)
self.counter = 0
self.launcher.run() # run nothing
self.assertEqual(self.counter, 0)
self.assertEquals(self.counter, 0)
time.sleep(1)
self.counter = 0
self.configureLauncher(save_method=test_method)
self.launcher.run()
self.assertEqual(self.counter, 2)
self.assertEquals(self.counter, 2)
def test_runpromise_with_periodicity_result_failed(self):
first_promise = 'my_first_promise.py'
......@@ -640,14 +640,14 @@ class RunPromise(GenericPromise):
with self.assertRaises(PromiseError) as exc:
self.launcher.run()
self.assertEqual(exc.exception.message, 'Promise %r failed.' % second_promise)
self.assertEqual(str(exc.exception), 'Promise %r failed.' % second_promise)
self.assertTrue(os.path.exists(first_state_file))
self.assertTrue(os.path.exists(second_state_file))
first_result = json.load(open(first_state_file))
second_result = json.load(open(second_state_file))
self.assertEqual(first_result['name'], first_promise)
self.assertEqual(second_result['name'], second_promise)
self.assertEquals(first_result['name'], first_promise)
self.assertEquals(second_result['name'], second_promise)
first_date = first_result['result']['date']
second_date = second_result['result']['date']
......@@ -655,19 +655,19 @@ class RunPromise(GenericPromise):
time.sleep(2)
with self.assertRaises(PromiseError) as exc:
self.launcher.run() # only my_first_promise will run but second_promise still failing
self.assertEqual(exc.exception.message, 'Promise %r failed.' % second_promise)
self.assertEqual(str(exc.exception), 'Promise %r failed.' % second_promise)
first_result = json.load(open(first_state_file))
second_result = json.load(open(second_state_file))
self.assertNotEquals(first_result['result']['date'], first_date)
self.assertEqual(second_result['result']['date'], second_date)
self.assertEquals(second_result['result']['date'], second_date)
first_date = first_result['result']['date']
time.sleep(3)
self.configureLauncher()
with self.assertRaises(PromiseError) as exc:
self.launcher.run()
self.assertEqual(exc.exception.message, 'Promise %r failed.' % second_promise)
self.assertEqual(str(exc.exception), 'Promise %r failed.' % second_promise)
first_result = json.load(open(first_state_file))
second_result = json.load(open(second_state_file))
......@@ -696,8 +696,8 @@ class RunPromise(GenericPromise):
self.assertTrue(os.path.exists(second_state_file))
first_result = json.load(open(first_state_file))
second_result = json.load(open(second_state_file))
self.assertEqual(first_result['name'], first_promise)
self.assertEqual(second_result['name'], second_promise)
self.assertEquals(first_result['name'], first_promise)
self.assertEquals(second_result['name'], second_promise)
first_date = first_result['result']['date']
second_date = second_result['result']['date']
......@@ -710,7 +710,7 @@ class RunPromise(GenericPromise):
first_result = json.load(open(first_state_file))
second_result = json.load(open(second_state_file))
self.assertNotEquals(first_result['result']['date'], first_date)
self.assertEqual(second_result['result']['date'], second_date)
self.assertEquals(second_result['result']['date'], second_date)
first_date = first_result['result']['date']
second_date = second_result['result']['date']
......@@ -735,8 +735,8 @@ class RunPromise(GenericPromise):
def test_method(result):
self.assertTrue(result.name in [first_promise, second_promise])
self.assertEqual(result.item.hasFailed(), False)
self.assertEqual(result.item.message, "success")
self.assertEquals(result.item.hasFailed(), False)
self.assertEquals(result.item.message, "success")
self.counter += 1
self.configureLauncher(save_method=test_method)
......@@ -745,30 +745,30 @@ class RunPromise(GenericPromise):
self.generatePromiseScript(second_promise, success=True, periodicity=0.03)
self.launcher.run()
self.assertEqual(self.counter, 2)
self.assertEquals(self.counter, 2)
self.configureLauncher(save_method=test_method)
time.sleep(1)
self.counter = 0
self.launcher.run() # run nothing
self.assertEqual(self.counter, 0)
self.assertEquals(self.counter, 0)
self.configureLauncher(save_method=test_method, force=True)
self.counter = 0
self.launcher.run() # will run all as force is True
self.assertEqual(self.counter, 2)
self.assertEquals(self.counter, 2)
self.configureLauncher(save_method=test_method)
time.sleep(1)
self.counter = 0
self.launcher.run() # run nothing
self.assertEqual(self.counter, 0)
self.assertEquals(self.counter, 0)
time.sleep(1)
self.counter = 0
self.configureLauncher(save_method=test_method)
self.launcher.run() # after 2 seconds will run all
self.assertEqual(self.counter, 2)
self.assertEquals(self.counter, 2)
def test_runpromise_wrapped(self):
promise_name = "my_bash_promise"
......@@ -785,11 +785,11 @@ echo "success"
self.assertTrue(isinstance(result, PromiseQueueResult))
self.assertTrue(isinstance(result.item, TestResult))
self.assertTrue(result.execution_time != 0)
self.assertEqual(result.title, promise_name)
self.assertEqual(result.name, promise_name)
self.assertEqual(result.path, os.path.join(self.legacy_promise_dir, promise_name))
self.assertEqual(result.item.message, "success")
self.assertEqual(result.item.hasFailed(), False)
self.assertEquals(result.title, promise_name)
self.assertEquals(result.name, promise_name)
self.assertEquals(result.path, os.path.join(self.legacy_promise_dir, promise_name))
self.assertEquals(result.item.message, "success")
self.assertEquals(result.item.hasFailed(), False)
self.assertTrue(isinstance(result.item.date, datetime))
self.configureLauncher(save_method=test_method)
......@@ -822,12 +822,12 @@ exit 1
self.called += 1
result_dict.pop(result.name)
if result.title == "first_promise" or result.title == "second_promise":
self.assertEqual(result.item.message, "success")
self.assertEquals(result.item.message, "success")
if result.title == "my_bash_promise":
self.assertEqual(result.item.message, "promise 1 succeeded")
self.assertEquals(result.item.message, "promise 1 succeeded")
if result.title == "my_bash_promise2":
self.assertEqual(result.item.message, "promise 2 succeeded")
self.assertEqual(result.item.hasFailed(), False)
self.assertEquals(result.item.message, "promise 2 succeeded")
self.assertEquals(result.item.hasFailed(), False)
promise_name = "my_bash_promise"
promise_path = os.path.join(self.legacy_promise_dir, promise_name)
......@@ -850,7 +850,7 @@ exit 0
self.configureLauncher(save_method=test_method)
self.launcher.run()
self.assertEqual(self.called, 4)
self.assertEquals(self.called, 4)
def test_runpromise_run_only(self):
......@@ -861,8 +861,8 @@ exit 0
self.check_list = [first_promise, second_promise, third_promise]
def test_method(result):
self.assertTrue(result.name in self.check_list)
self.assertEqual(result.item.hasFailed(), False)
self.assertEqual(result.item.message, "success")
self.assertEquals(result.item.hasFailed(), False)
self.assertEquals(result.item.message, "success")
self.counter += 1
self.configureLauncher(save_method=test_method)
......@@ -872,14 +872,14 @@ exit 0
# run promise will not fail
self.launcher.run()
self.assertEqual(self.counter, 3)
self.assertEquals(self.counter, 3)
self.counter = 0
self.check_list = [second_promise]
self.configureLauncher(save_method=test_method, run_list=[second_promise], force=True)
time.sleep(1)
self.launcher.run()
self.assertEqual(self.counter, 1)
self.assertEquals(self.counter, 1)
def test_runpromise_run_only_multiple(self):
first_promise = 'my_first_promise.py'
......@@ -889,8 +889,8 @@ exit 0
self.check_list = [first_promise, second_promise, third_promise]
def test_method(result):
self.assertTrue(result.name in self.check_list)
self.assertEqual(result.item.hasFailed(), False)
self.assertEqual(result.item.message, "success")
self.assertEquals(result.item.hasFailed(), False)
self.assertEquals(result.item.message, "success")
self.counter += 1
self.configureLauncher(save_method=test_method)
......@@ -900,14 +900,14 @@ exit 0
# run promise will not fail
self.launcher.run()
self.assertEqual(self.counter, 3)
self.assertEquals(self.counter, 3)
self.counter = 0
self.check_list = [third_promise, second_promise]
self.configureLauncher(save_method=test_method, run_list=self.check_list, force=True)
time.sleep(1)
self.launcher.run()
self.assertEqual(self.counter, 2)
self.assertEquals(self.counter, 2)
def writeLatestPromiseResult(self):
state_file = os.path.join(self.partition_dir, PROMISE_RESULT_FOLDER_NAME, 'my_promise.status.json')
......@@ -962,10 +962,10 @@ exit 0
self.assertTrue(isinstance(result, PromiseQueueResult))
self.assertTrue(isinstance(result.item, AnomalyResult))
self.assertTrue(result.execution_time >= 1)
self.assertEqual(result.title, 'my_promise')
self.assertEqual(result.name, promise_name)
self.assertEquals(result.title, 'my_promise')
self.assertEquals(result.name, promise_name)
self.assertTrue("Promise timed out after" in result.item.message)
self.assertEqual(result.item.hasFailed(), True)
self.assertEquals(result.item.hasFailed(), True)
self.configureLauncher(save_method=test_method, enable_anomaly=True, timeout=1)
self.generatePromiseScript(promise_name, success=True, content="""import time
......@@ -993,11 +993,11 @@ echo "success"
self.assertTrue(isinstance(result, PromiseQueueResult))
self.assertTrue(isinstance(result.item, TestResult))
self.assertTrue(result.execution_time >= 1)
self.assertEqual(result.title, promise_name)
self.assertEqual(result.name, promise_name)
self.assertEqual(result.path, promise_path)
self.assertEquals(result.title, promise_name)
self.assertEquals(result.name, promise_name)
self.assertEquals(result.path, promise_path)
self.assertTrue("Promise timed out after" in result.item.message)
self.assertEqual(result.item.hasFailed(), True)
self.assertEquals(result.item.hasFailed(), True)
self.assertTrue(isinstance(result.item.date, datetime))
self.configureLauncher(save_method=test_method, timeout=1)
......@@ -1105,16 +1105,16 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
promise_process = self.createPromiseProcess()
promise_module = promise_process._loadPromiseModule()
promise = promise_module.RunPromise(self.promise_config)
self.assertEqual(promise.getPeriodicity(), 1)
self.assertEqual(promise.getName(), self.promise_name)
self.assertEqual(promise.getTitle(), 'my_promise')
self.assertEqual(promise.getPartitionFolder(), self.partition_dir)
self.assertEqual(promise.getPromiseFile(), self.promise_path)
self.assertEqual(promise.getLogFolder(), self.log_dir)
self.assertEqual(promise.getLogFile(), os.path.join(self.log_dir, 'my_promise.log'))
self.assertEquals(promise.getPeriodicity(), 1)
self.assertEquals(promise.getName(), self.promise_name)
self.assertEquals(promise.getTitle(), 'my_promise')
self.assertEquals(promise.getPartitionFolder(), self.partition_dir)
self.assertEquals(promise.getPromiseFile(), self.promise_path)
self.assertEquals(promise.getLogFolder(), self.log_dir)
self.assertEquals(promise.getLogFile(), os.path.join(self.log_dir, 'my_promise.log'))
promise.setPeriodicity(2)
self.assertEqual(promise.getPeriodicity(), 2)
self.assertEquals(promise.getPeriodicity(), 2)
with self.assertRaises(ValueError):
promise.setPeriodicity(0)
......@@ -1122,11 +1122,11 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
result = self.queue.get(True, 1)
self.assertTrue(isinstance(result, PromiseQueueResult))
self.assertTrue(isinstance(result.item, AnomalyResult))
self.assertEqual(result.title, 'my_promise')
self.assertEqual(result.name, self.promise_name)
self.assertEqual(result.path, os.path.join(self.plugin_dir, self.promise_name))
self.assertEqual(result.item.message, "success")
self.assertEqual(result.item.hasFailed(), False)
self.assertEquals(result.title, 'my_promise')
self.assertEquals(result.name, self.promise_name)
self.assertEquals(result.path, os.path.join(self.plugin_dir, self.promise_name))
self.assertEquals(result.item.message, "success")
self.assertEquals(result.item.hasFailed(), False)
self.assertTrue(isinstance(result.item.date, datetime))
def test_promise_anomaly_disabled(self):
......@@ -1139,11 +1139,11 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
result = self.queue.get(True, 1)
self.assertTrue(isinstance(result, PromiseQueueResult))
self.assertTrue(isinstance(result.item, TestResult))
self.assertEqual(result.title, 'my_promise')
self.assertEqual(result.name, self.promise_name)
self.assertEqual(result.path, os.path.join(self.plugin_dir, self.promise_name))
self.assertEqual(result.item.message, "success")
self.assertEqual(result.item.hasFailed(), False)
self.assertEquals(result.title, 'my_promise')
self.assertEquals(result.name, self.promise_name)
self.assertEquals(result.path, os.path.join(self.plugin_dir, self.promise_name))
self.assertEquals(result.item.message, "success")
self.assertEquals(result.item.hasFailed(), False)
self.assertTrue(isinstance(result.item.date, datetime))
def test_promise_with_raise(self):
......@@ -1156,10 +1156,10 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
# no raise
promise.run()
result = self.queue.get(True, 1)
self.assertEqual(result.title, 'my_promise')
self.assertEqual(result.name, self.promise_name)
self.assertEqual(result.item.message, "Bad Promise raised")
self.assertEqual(result.item.hasFailed(), True)
self.assertEquals(result.title, 'my_promise')
self.assertEquals(result.name, self.promise_name)
self.assertEquals(result.item.message, "Bad Promise raised")
self.assertEquals(result.item.hasFailed(), True)
def test_promise_no_return(self):
promise_content = "return"
......@@ -1171,10 +1171,10 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
# no raise
promise.run()
result = self.queue.get(True, 1)
self.assertEqual(result.title, 'my_promise')
self.assertEqual(result.name, self.promise_name)
self.assertEqual(result.item.message, "No result found!")
self.assertEqual(result.item.hasFailed(), False)
self.assertEquals(result.title, 'my_promise')
self.assertEquals(result.name, self.promise_name)
self.assertEquals(result.item.message, "No result found!")
self.assertEquals(result.item.hasFailed(), False)
def test_promise_resultfromlog(self):
promise_content = "self.logger.info('Promise is running...')"
......@@ -1188,11 +1188,11 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
# get all messages during the latest minute
latest_message_list = promise.getLastPromiseResultList(result_count=1)
date = datetime.strptime(date.strftime('%Y-%m-%d %H:%M:%S'), '%Y-%m-%d %H:%M:%S')
self.assertEqual(len(latest_message_list), 1)
self.assertEqual(
self.assertEquals(len(latest_message_list), 1)
self.assertEquals(
latest_message_list[0][0],
{'date': date, 'status': 'INFO', 'message': 'Promise is running...'})
self.assertEqual(
self.assertEquals(
latest_message_list[0][1],
{'date': date, 'status': 'INFO', 'message': 'success'})
......@@ -1208,12 +1208,12 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
# get all messages during the latest minute
latest_message_list = promise.getLastPromiseResultList(result_count=1)
date = datetime.strptime(date.strftime('%Y-%m-%d %H:%M:%S'), '%Y-%m-%d %H:%M:%S')
self.assertEqual(len(latest_message_list), 1)
self.assertEqual(
self.assertEquals(len(latest_message_list), 1)
self.assertEquals(
latest_message_list[0][0],
{'date': date, 'status': 'ERROR',
'message': 'Promise is running...\nmessage in new line'})
self.assertEqual(
self.assertEquals(
latest_message_list[0][1],
{'date': date, 'status': 'INFO', 'message': 'success'})
......@@ -1227,17 +1227,17 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
date = datetime.now()
promise.sense()
self.assertEqual(promise.getLogFolder(), None)
self.assertEqual(promise.getLogFile(), None)
self.assertEquals(promise.getLogFolder(), None)
self.assertEquals(promise.getLogFile(), None)
# get all messages during the latest minute
latest_message_list = promise.getLastPromiseResultList(result_count=1)
date = datetime.strptime(date.strftime('%Y-%m-%d %H:%M:%S'), '%Y-%m-%d %H:%M:%S')
self.assertEqual(len(latest_message_list), 1)
self.assertEqual(
self.assertEquals(len(latest_message_list), 1)
self.assertEquals(
latest_message_list[0][0],
{'date': date, 'status': 'INFO', 'message': 'Promise is running...'})
self.assertEqual(
self.assertEquals(
latest_message_list[0][1],
{'date': date, 'status': 'INFO', 'message': 'success'})
......@@ -1264,13 +1264,13 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
start_date = datetime.strptime(start_date.strftime('%Y-%m-%d %H:%M:%S'), '%Y-%m-%d %H:%M:%S')
end_date_string = (start_date - timedelta(minutes=9)).strftime('%Y-%m-%d %H:%M:%S')
end_date = datetime.strptime(end_date_string, '%Y-%m-%d %H:%M:%S')
self.assertEqual(len(latest_message_list), 10)
self.assertEquals(len(latest_message_list), 10)
for message in latest_message_list:
self.assertEqual(len(message), 1)
self.assertEqual(
self.assertEquals(len(message), 1)
self.assertEquals(
latest_message_list[0][0],
{'date': start_date, 'status': 'INFO', 'message': 'Promise result 49'})
self.assertEqual(
self.assertEquals(
latest_message_list[-1][0],
{'date': end_date, 'status': 'INFO', 'message': 'Promise result 40'})
......@@ -1309,13 +1309,13 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
end_date_string = (start_date - timedelta(seconds=30*19)).strftime('%Y-%m-%d %H:%M:%S')
end_date = datetime.strptime(end_date_string, '%Y-%m-%d %H:%M:%S')
# there is 2 result line per minutes
self.assertEqual(len(latest_message_list), 10)
self.assertEquals(len(latest_message_list), 10)
for message in latest_message_list:
self.assertEqual(len(message), 2)
self.assertEqual(
self.assertEquals(len(message), 2)
self.assertEquals(
latest_message_list[0][1],
{'date': start_date, 'status': 'INFO', 'message': 'Promise result 0'})
self.assertEqual(
self.assertEquals(
latest_message_list[-1][0],
{'date': end_date, 'status': 'INFO', 'message': 'Promise result 19'})
......@@ -1353,11 +1353,11 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
end_date_string = (start_date - timedelta(seconds=30)).strftime('%Y-%m-%d %H:%M:%S')
end_date = datetime.strptime(end_date_string, '%Y-%m-%d %H:%M:%S')
# there is 2 result line per minutes
self.assertEqual(len(latest_message_list), 1)
self.assertEqual(
self.assertEquals(len(latest_message_list), 1)
self.assertEquals(
latest_message_list[0][0],
{'date': end_date, 'status': 'INFO', 'message': 'Promise result 1'})
self.assertEqual(
self.assertEquals(
latest_message_list[0][1],
{'date': start_date, 'status': 'INFO', 'message': 'Promise result 0'})
......@@ -1395,19 +1395,19 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
end_date_string = (start_date - timedelta(seconds=30*3)).strftime('%Y-%m-%d %H:%M:%S')
end_date = datetime.strptime(end_date_string, '%Y-%m-%d %H:%M:%S')
# there is 2 result line per minutes
self.assertEqual(len(latest_message_list), 2)
self.assertEquals(len(latest_message_list), 2)
for message in latest_message_list:
self.assertEqual(len(message), 2)
self.assertEqual(
self.assertEquals(len(message), 2)
self.assertEquals(
latest_message_list[0][1],
{'date': start_date, 'status': 'INFO', 'message': 'Promise result 0'})
self.assertEqual(
self.assertEquals(
latest_message_list[-1][0],
{'date': end_date, 'status': 'INFO', 'message': 'Promise result 3'})
latest_message_list = promise.getLastPromiseResultList(result_count=100)
# all results
self.assertEqual(len(latest_message_list), 25)
self.assertEquals(len(latest_message_list), 25)
def test_promise_defaulttest(self):
promise_content = 'self.logger.info("Promise is running...\\nmessage in new line")'
......@@ -1420,8 +1420,8 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
result = promise._test(result_count=1, failure_amount=1)
self.assertTrue(isinstance(result, TestResult))
self.assertEqual(result.message, 'Promise is running...\nmessage in new line\nsuccess')
self.assertEqual(result.hasFailed(), False)
self.assertEquals(result.message, 'Promise is running...\nmessage in new line\nsuccess')
self.assertEquals(result.hasFailed(), False)
def test_promise_defaulttest_failure(self):
self.initialisePromise(success=False)
......@@ -1433,8 +1433,8 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
result = promise._test(result_count=1, failure_amount=1)
self.assertTrue(isinstance(result, TestResult))
self.assertEqual(result.message, 'failed')
self.assertEqual(result.hasFailed(), True)
self.assertEquals(result.message, 'failed')
self.assertEquals(result.hasFailed(), True)
def test_promise_defaulttest_error_if_two_fail(self):
self.initialisePromise(success=False, timeout=1)
......@@ -1447,8 +1447,8 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
# fail if 2 errors found
result = promise._test(result_count=2, failure_amount=2)
self.assertTrue(isinstance(result, TestResult))
self.assertEqual(result.message, 'failed')
self.assertEqual(result.hasFailed(), False)
self.assertEquals(result.message, 'failed')
self.assertEquals(result.hasFailed(), False)
self.initialisePromise(success=False, timeout=1)
promise_process = self.createPromiseProcess()
......@@ -1456,8 +1456,8 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
promise = promise_module.RunPromise(self.promise_config)
promise.sense()
result = promise._test(result_count=2, failure_amount=2)
self.assertEqual(result.message, 'failed')
self.assertEqual(result.hasFailed(), True)
self.assertEquals(result.message, 'failed')
self.assertEquals(result.hasFailed(), True)
# will continue to fail
self.initialisePromise(success=False, timeout=1)
......@@ -1466,8 +1466,8 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
promise = promise_module.RunPromise(self.promise_config)
promise.sense()
result = promise._test(result_count=2, failure_amount=2)
self.assertEqual(result.message, 'failed')
self.assertEqual(result.hasFailed(), True)
self.assertEquals(result.message, 'failed')
self.assertEquals(result.hasFailed(), True)
def test_promise_defaulttest_anomaly(self):
promise_content = 'self.logger.info("Promise is running...\\nmessage in new line")'
......@@ -1480,8 +1480,8 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
result = promise._anomaly(result_count=1, failure_amount=1)
self.assertTrue(isinstance(result, AnomalyResult))
self.assertEqual(result.message, 'Promise is running...\nmessage in new line\nsuccess')
self.assertEqual(result.hasFailed(), False)
self.assertEquals(result.message, 'Promise is running...\nmessage in new line\nsuccess')
self.assertEquals(result.hasFailed(), False)
if __name__ == '__main__':
......
......@@ -84,8 +84,6 @@ def string_to_boolean(string):
The parser is completely arbitrary, see code for actual implementation.
"""
if isinstance(string, bytes):
string = string.decode('utf-8')
try:
return ('false', 'true').index(string.lower())
except Exception:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment