Commit 2699c3bd authored by Jérome Perrin's avatar Jérome Perrin

Fix random test failures

"test_networkbench: increase resolution time tolerance" addresses [this](https://erp5.nexedi.net/test_result_module/20200911-8C18D791/14):

```
======================================================================
FAIL: test_dnsbench_fail (slapos.test.test_networkbench.TestDNSBench)
Test dns failure resolution
----------------------------------------------------------------------
Traceback (most recent call last):
File "/srv/slapgrid/slappart20/srv/testnode/cum/inst/test0-0/parts/slapos.toolbox/slapos/test/test_networkbench.py", line 66, in test_dnsbench_fail
self.assertLess(info[3], 1)
AssertionError: 2.0736539363861084 not less than 1
```

"cpu load plugin: fix test and minor cleanups" addresses [this](https://erp5.nexedi.net/test_result_module/20200911-C444DB47/13):

```
======================================================================
ERROR: test_check_cpu_load_run (slapos.test.promise.plugin.test_check_server_cpu_load.TestCheckServerCPULoad)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/srv/slapgrid/slappart9/srv/testnode/bvi/inst/test0-0/parts/slapos.toolbox/slapos/test/promise/plugin/test_check_server_cpu_load.py", line 48, in test_check_cpu_load_run
    self.launcher.run()
  File "/srv/slapgrid/slappart9/srv/testnode/bvi/soft/65dbbd3d11daa99cf78c9566a0a4798e/parts/slapos.core-repository/slapos/grid/promise/__init__.py", line 884, in run
    failed_promise_output))
PromiseError: Promise 'server-cpu-load-promise.py' failed with output: Error: Promise timed out after 0.5 seconds
```
Some more fixes are in nexedi/slapos!809

See merge request nexedi/slapos.toolbox!85
parents ca67bbc0 35b56408
......@@ -4,6 +4,7 @@ from slapos.grid.promise.generic import GenericPromise
import subprocess
import os
import psutil
@implementer(interface.IPromise)
class RunPromise(GenericPromise):
......@@ -14,13 +15,9 @@ class RunPromise(GenericPromise):
self.setPeriodicity(minute=3)
def checkCPULoad(self, tolerance=2.2):
# tolerance=1.5 => accept CPU load up to 1.5 =150%
uptime_result = subprocess.check_output('uptime', universal_newlines=True)
line = uptime_result.strip().split(' ')
load, load5, long_load = line[-3:]
long_load = float(long_load.replace(',', '.'))
core_count = int(subprocess.check_output('nproc').strip())
load, load5, long_load = psutil.getloadavg()
core_count = psutil.cpu_count()
max_load = core_count * tolerance
if long_load > max_load:
# display top statistics
......@@ -51,9 +48,9 @@ class RunPromise(GenericPromise):
self.checkCPULoad(threshold or 2.2)
def test(self):
# fail if load is high than the threshold for more than 30 minutes
# fail if load is higher than the threshold for more than 30 minutes
return self._test(result_count=10, failure_amount=10)
def anomaly(self):
# fail if load is high than the threshold for more than 30 minutes
# fail if load is higher than the threshold for more than 30 minutes
return self._test(result_count=10, failure_amount=10)
......@@ -32,7 +32,7 @@ import os
class TestCheckServerCPULoad(TestPromisePluginMixin):
def setUp(self):
TestPromisePluginMixin.setUp(self)
super(TestCheckServerCPULoad, self).setUp()
self.promise_name = "server-cpu-load-promise.py"
content = """from slapos.promise.plugin.check_server_cpu_load import RunPromise
......@@ -44,13 +44,10 @@ extra_config_dict = {
self.writePromise(self.promise_name, content)
def test_check_cpu_load_run(self):
self.configureLauncher()
self.configureLauncher(timeout=5)
self.launcher.run()
result = self.getPromiseResult(self.promise_name)
if result['result']['failed']:
self.assertTrue("CPU load is high" in result['result']['message'])
else:
self.assertEqual("CPU load is OK", result['result']['message'].strip())
if __name__ == '__main__':
unittest.main()
......@@ -47,7 +47,7 @@ class TestDNSBench(unittest.TestCase):
self.assertEqual(info[1], 'eu.web.vifib.com')
self.assertEqual(info[2], 200)
self.assertLess(info[3], 1)
self.assertLess(info[3], 30)
self.assertEqual(info[4], 'OK',
"%s != OK, full info: %s" % (info[4], info) )
self.assertEqual(set(info[5]), set([u'85.118.38.162', u'176.31.129.213']),
......@@ -63,7 +63,7 @@ class TestDNSBench(unittest.TestCase):
self.assertEqual(info[1], 'thisdomaindontexist.erp5.com')
self.assertEqual(info[2], 600)
self.assertLess(info[3], 1)
self.assertLess(info[3], 30)
self.assertEqual(info[4], 'Cannot resolve the hostname')
self.assertEqual(info[5], [])
......@@ -77,7 +77,7 @@ class TestDNSBench(unittest.TestCase):
self.assertEqual(info[1], 'www.erp5.com')
self.assertEqual(info[2], 200)
self.assertLess(info[3], 1)
self.assertLess(info[3], 30)
self.assertEqual(info[4], 'UNEXPECTED')
self.assertTrue(info[5].startswith("['85.118.38.162'] (expected) != "))
......@@ -207,37 +207,3 @@ class TestHTTPBench(unittest.TestCase):
self.assertEqual(info[2], 200)
self.assertEqual(len(info[3].split(';')), 5 )
self.assertEqual(info[4], "UNEXPECTED (COUSCOUS not in page content)")
#def request(url, expected_dict):
#
# rendering_time = "%s;%s;%s;%s;%s" % \
# (curl.getinfo(curl.NAMELOOKUP_TIME),
# curl.getinfo(curl.CONNECT_TIME),
# curl.getinfo(curl.PRETRANSFER_TIME),
# curl.getinfo(curl.STARTTRANSFER_TIME),
# curl.getinfo(curl.TOTAL_TIME))
#
# response_code = curl.getinfo(pycurl.HTTP_CODE)
#
# expected_response = expected_dict.get("expected_response", None)
# if expected_response is not None and \
# expected_response != response_code:
# result = "UNEXPECTED (%s != %s)" % (expected_response, response_code)
#
# expected_text = expected_dict.get("expected_text", None)
# if expected_text is not None and \
# str(expected_text) not in str(body):
# result = "UNEXPECTED (%s not in page content)" % (expected_text)
#
#
# info_list = ('GET', url, response_code, rendering_time, result)
#
# return info_list
#
if __name__ == '__main__':
unittest.main()
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