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
4c927373
Commit
4c927373
authored
Aug 21, 2020
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test wip
parent
f7a916c4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
98 additions
and
19 deletions
+98
-19
software/erp5/test/setup.py
software/erp5/test/setup.py
+1
-0
software/erp5/test/test/test_erp5.py
software/erp5/test/test/test_erp5.py
+7
-0
software/erp5/test/test/test_mariadb.py
software/erp5/test/test/test_mariadb.py
+90
-19
No files found.
software/erp5/test/setup.py
View file @
4c927373
...
...
@@ -48,6 +48,7 @@ setup(name=name,
'psutil'
,
'requests'
,
'mysqlclient'
,
'backports.lzma'
,
'cryptography'
,
'pyOpenSSL'
,
],
...
...
software/erp5/test/test/test_erp5.py
View file @
4c927373
...
...
@@ -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
...
...
software/erp5/test/test/test_mariadb.py
View file @
4c927373
...
...
@@ -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
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