Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
5
Merge Requests
5
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jérome Perrin
slapos
Commits
0360412b
Commit
0360412b
authored
Aug 21, 2020
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test ok
parent
fbed19ae
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
64 additions
and
50 deletions
+64
-50
software/erp5/test/test/test_mariadb.py
software/erp5/test/test/test_mariadb.py
+64
-50
No files found.
software/erp5/test/test/test_mariadb.py
View file @
0360412b
...
...
@@ -31,6 +31,7 @@ import json
import
glob
import
urlparse
import
socket
import
sys
import
time
import
contextlib
import
datetime
...
...
@@ -60,8 +61,8 @@ class MariaDBTestCase(ERP5InstanceTestCase):
return
{
'tcpv4-port'
:
3306
,
'max-connection-count'
:
5
,
'max-slowqueries-threshold'
:
5
,
'slowest-query-threshold'
:
10
,
'max-slowqueries-threshold'
:
1
,
'slowest-query-threshold'
:
0.1
,
# XXX what is this ? should probably not be needed here
'name'
:
cls
.
__name__
,
'monitor-passwd'
:
'secret'
,
...
...
@@ -90,6 +91,26 @@ class MariaDBTestCase(ERP5InstanceTestCase):
)
def
getPluginParameterDict
(
filepath
):
"""Load the slapos monitor plugin and returns the configuration used by this plugin.
This allow to check that monitoring plugin are using a proper config.
"""
extra_config_dict_json
=
subprocess
.
check_output
([
sys
.
executable
,
"-c"
,
"""
import json, sys
with open(sys.argv[1]) as f:
exec(f.read())
print(json.dumps(extra_config_dict))
"""
,
filepath
,
])
return
json
.
loads
(
extra_config_dict_json
)
class
TestCrontabs
(
MariaDBTestCase
):
def
_getCrontabCommand
(
self
,
crontab_name
):
...
...
@@ -105,12 +126,17 @@ class TestCrontabs(MariaDBTestCase):
crontab_spec
=
f
.
read
()
return
" "
.
join
(
crontab_spec
.
split
()[
5
:])
def
test_full_backup
(
self
):
def
_executeCrontabAtDate
(
self
,
crontab_name
,
date
):
"""Executes a crontab at a given date.
"""
crontab_command
=
self
.
_getCrontabCommand
(
crontab_name
)
subprocess
.
check_call
(
"faketime
2050-01-01 bash -o pipefail -e -c '%s'"
%
self
.
_getCrontabCommand
(
'mariadb-backup'
),
"faketime
{date} bash -o pipefail -e -c '{crontab_command}'"
.
format
(
**
locals
()
),
shell
=
True
,
)
import
pdb
;
pdb
.
set_trace
()
def
test_full_backup
(
self
):
self
.
_executeCrontabAtDate
(
'mariadb-backup'
,
'2050-01-01'
)
with
gzip
.
open
(
os
.
path
.
join
(
self
.
computer_partition_root_path
,
...
...
@@ -120,46 +146,25 @@ class TestCrontabs(MariaDBTestCase):
'20500101000000.sql.gz'
,
),
'r'
)
as
dump
:
self
.
assertIn
(
'CREATE TABLE
`catalog`
'
,
dump
.
read
())
self
.
assertIn
(
'CREATE TABLE'
,
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, 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
,
)
self
.
_executeCrontabAtDate
(
'logrotate'
,
'2000-01-01'
)
# make
a slow query
# make
two slow queries
cnx
=
self
.
getDatabaseConnection
()
with
contextlib
.
closing
(
cnx
):
cnx
.
query
(
"SELECT SLEEP(1.1)"
)
cnx
.
store_result
()
cnx
.
query
(
"SELECT SLEEP(1.2)"
)
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
,
)
# slow query crontab depends on crontab for log rotation
# to be executed first.
self
.
_executeCrontabAtDate
(
'logrotate'
,
'2050-01-01'
)
# this logrotate leaves the log for the day as non compressed
rotated_log_file
=
os
.
path
.
join
(
self
.
computer_partition_root_path
,
...
...
@@ -170,13 +175,9 @@ class TestCrontabs(MariaDBTestCase):
)
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
# then crontab to generate slow query report is executed
self
.
_executeCrontabAtDate
(
'generate-mariadb-slow-query-report'
,
'2050-01-01'
)
# and it creates a report for the day
slow_query_report
=
os
.
path
.
join
(
self
.
computer_partition_root_path
,
'srv'
,
...
...
@@ -186,19 +187,32 @@ class TestCrontabs(MariaDBTestCase):
'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
)
# this is the hash for our "select sleep(n)" slow query
self
.
assertIn
(
"ID 0xF9A57DD5A41825CA"
,
f
.
read
())
# next day, log files are compressed
subprocess
.
check_call
(
'faketime 2050-01-02 '
+
self
.
_getCrontabCommand
(
'logrotate'
),
shell
=
True
,
)
# on next day execution of logrotate, log files are compressed
self
.
_executeCrontabAtDate
(
'logrotate'
,
'2050-01-02'
)
self
.
assertTrue
(
os
.
path
.
exists
(
rotated_log_file
+
'.xz'
))
self
.
assertFalse
(
os
.
path
.
exists
(
rotated_log_file
))
# there's a promise checking that the threshold is not exceeded
# and it reports a problem since we set a threshold of 1 slow query
check_slow_query_promise_plugin
=
getPluginParameterDict
(
os
.
path
.
join
(
self
.
computer_partition_root_path
,
'etc'
,
'plugin'
,
'check-slow-query-pt-digest-result.py'
,
))
with
self
.
assertRaises
(
subprocess
.
CalledProcessError
)
as
error_context
:
subprocess
.
check_output
(
'faketime 2050-01-01 %s'
%
check_slow_query_promise_plugin
[
'command'
],
shell
=
True
)
self
.
assertEqual
(
error_context
.
exception
.
output
,
"""
\
Threshold is lower than expected:
Expected total queries : 1.0 and current is: 2
Expected slowest query : 0.1 and current is: 1
"""
)
class
TestMariaDB
(
MariaDBTestCase
):
def
test_utf8_collation
(
self
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment