Commit 4c927373 authored by Jérome Perrin's avatar Jérome Perrin

test wip

parent f7a916c4
......@@ -48,6 +48,7 @@ setup(name=name,
'psutil',
'requests',
'mysqlclient',
'backports.lzma',
'cryptography',
'pyOpenSSL',
],
......
......@@ -78,6 +78,13 @@ class TestPublishedURLIsReachableMixin(object):
self.logger.warn("ERP5 was not available, sleeping for %ds and retrying", delay)
time.sleep(delay)
continue
if r.status_code == requests.codes.server_error:
# TODO check
delay = i * 2
self.logger.warn("ERP5 was not available, sleeping for %ds and retrying", delay)
time.sleep(delay)
continue
if r.status_code != requests.codes.ok:
r.raise_for_status()
break
......
......@@ -35,13 +35,16 @@ import time
import contextlib
import datetime
import subprocess
import gzip
from backports import lzma
import MySQLdb
from . import ERP5InstanceTestCase
from . import setUpModule
setUpModule # pyflakes
#setUpModule = None
class MariaDBTestCase(ERP5InstanceTestCase):
"""Base test case for mariadb tests.
......@@ -104,29 +107,97 @@ class TestCrontabs(MariaDBTestCase):
def test_full_backup(self):
subprocess.check_call(
self._getCrontabCommand('mariadb-backup'),
"faketime 2050-01-01 bash -o pipefail -e -c '%s'" % self._getCrontabCommand('mariadb-backup'),
shell=True,
)
self.assertTrue(
glob.glob(
os.path.join(
self.computer_partition_root_path,
'srv',
'backup',
'mariadb-full',
# TODO: this should be xz, not gz !
'*gz',
)))
# TODO: assert dump content
import pdb; pdb.set_trace()
with gzip.open(
os.path.join(
self.computer_partition_root_path,
'srv',
'backup',
'mariadb-full',
'20500101000000.sql.gz',
),
'r') as dump:
self.assertIn('CREATE TABLE `catalog`', dump.read())
def test_logrotate_and_slow_query_digest(self):
# slow query digest needs to run after logrotate, since it operates on the rotated
# file.
import pdb; pdb.set_trace()
subprocess.check_call(self._getCrontabCommand('logrotate'), shell=True)
self.assertTrue(glob.glob(
os.path.join(self.computer_partition_root_path, 'srv', 'backup',
'mariadb-full', '*gz')))
# file, so this tests both logrotate and slow query digest.
# run logrotate a first time so that it create state files
subprocess.check_call(
self._getCrontabCommand('logrotate'),
shell=True,
)
# make a slow query
cnx = self.getDatabaseConnection()
with contextlib.closing(cnx):
cnx.query("SELECT SLEEP(1.1)")
if 0:
# wait for it to be in log files.
slowquery_log = os.path.join(
self.computer_partition_root_path,
'var',
'log',
'mariadb_slowquery.log',
)
for i in range(5):
if os.path.exists(slowquery_log):
print "log exists"
with open(slowquery_log) as f:
if "SLEEP" in f.read():
break
print "no sleep !"
print "log not found, retrying"
time.sleep(i)
# crontab for log rotation executes first
subprocess.check_call(
'faketime 2050-01-01 ' + self._getCrontabCommand('logrotate'),
shell=True,
)
# this logrotate leaves the log for the day as non compressed
rotated_log_file = os.path.join(
self.computer_partition_root_path,
'srv',
'backup',
'logrotate',
'mariadb_slowquery.log-20500101',
)
self.assertTrue(os.path.exists(rotated_log_file))
# then crontab to generate slow query report executes
subprocess.check_call(
'faketime 2050-01-01 ' +
self._getCrontabCommand('generate-mariadb-slow-query-report'),
shell=True,
)
# this creates a report for the day
slow_query_report = os.path.join(
self.computer_partition_root_path,
'srv',
'monitor',
'private',
'slowquery_digest',
'slowquery_digest.txt-2050-01-01.xz',
)
with lzma.open(slow_query_report, 'r') as f:
slow_query_report_text = f.read()
self.assertIn("SLEEP(1.1)", slow_query_report_text)
# this is the hash for that slow query
self.assertIn("ID 0xF9A57DD5A41825CA", slow_query_report_text)
# next day, log files are compressed
subprocess.check_call(
'faketime 2050-01-02 ' + self._getCrontabCommand('logrotate'),
shell=True,
)
self.assertTrue(os.path.exists(rotated_log_file + '.xz'))
self.assertFalse(os.path.exists(rotated_log_file))
class TestMariaDB(MariaDBTestCase):
......@@ -300,4 +371,4 @@ class TestMroonga(MariaDBTestCase):
], list(sorted(cnx.store_result().fetch_row(maxrows=4))))
del TestMariaDB, TestMroonga, TestCrontabs
\ No newline at end of file
del TestMariaDB, TestMroonga #, TestCrontabs
\ No newline at end of file
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