Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.toolbox
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
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Lisa Casino
slapos.toolbox
Commits
36675caa
Commit
36675caa
authored
Aug 06, 2021
by
Lisa Casino
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
promise/plugin: test monitor_partition_space
parent
cd4f5c59
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
184 additions
and
0 deletions
+184
-0
slapos/test/promise/data/folder_disk_test.sql
slapos/test/promise/data/folder_disk_test.sql
+33
-0
slapos/test/promise/plugin/test_monitor_partition_space.py
slapos/test/promise/plugin/test_monitor_partition_space.py
+151
-0
No files found.
slapos/test/promise/data/folder_disk_test.sql
0 → 100644
View file @
36675caa
BEGIN
TRANSACTION
;
CREATE
TABLE
disk
(
partition
text
,
used
text
,
free
text
,
mountpoint
text
,
date
text
,
time
text
,
reported
integer
NULL
DEFAULT
0
);
CREATE
TABLE
folder
(
partition
text
,
disk_used
real
,
date
text
,
time
text
,
reported
integer
NULL
DEFAULT
0
);
INSERT
INTO
"disk"
VALUES
(
'/dev/sda1'
,
'159220666368'
,
'288948396032'
,
'/'
,
'2017-10-02'
,
'09:17:01'
,
1
);
INSERT
INTO
"disk"
VALUES
(
'/dev/sda1'
,
'159237537792'
,
'288931524608'
,
'/'
,
'2017-10-02'
,
'09:18:01'
,
1
);
INSERT
INTO
"disk"
VALUES
(
'/dev/sda1'
,
'159238090752'
,
'288930971648'
,
'/'
,
'2017-10-02'
,
'09:19:02'
,
1
);
INSERT
INTO
"disk"
VALUES
(
'/dev/sda1'
,
'159241568256'
,
'288927494144'
,
'/'
,
'2017-10-02'
,
'09:20:02'
,
1
);
INSERT
INTO
"disk"
VALUES
(
'/dev/sda1'
,
'159242719232'
,
'288926343168'
,
'/'
,
'2017-10-02'
,
'09:21:02'
,
1
);
INSERT
INTO
"disk"
VALUES
(
'/dev/sda1'
,
'159196176384'
,
'288972886016'
,
'/'
,
'2017-10-02'
,
'09:22:03'
,
1
);
INSERT
INTO
"disk"
VALUES
(
'/dev/sda1'
,
'159300747264'
,
'288868315136'
,
'/'
,
'2017-10-02'
,
'09:23:03'
,
1
);
INSERT
INTO
"disk"
VALUES
(
'/dev/sda1'
,
'159294308352'
,
'288874754048'
,
'/'
,
'2017-10-02'
,
'09:24:02'
,
1
);
INSERT
INTO
"disk"
VALUES
(
'/dev/sda1'
,
'159328468992'
,
'288840593408'
,
'/'
,
'2017-10-02'
,
'09:25:03'
,
1
);
INSERT
INTO
"disk"
VALUES
(
'/dev/sda1'
,
'159384883200'
,
'288784179200'
,
'/'
,
'2017-10-02'
,
'09:26:03'
,
1
);
INSERT
INTO
"disk"
VALUES
(
'/dev/sda1'
,
'159429677056'
,
'288739385344'
,
'/'
,
'2017-10-02'
,
'09:27:02'
,
1
);
INSERT
INTO
"disk"
VALUES
(
'/dev/sda1'
,
'159444549632'
,
'288724512768'
,
'/'
,
'2017-10-02'
,
'09:28:03'
,
1
);
INSERT
INTO
"disk"
VALUES
(
'/dev/sda1'
,
'159472902144'
,
'288696160256'
,
'/'
,
'2017-10-02'
,
'09:29:02'
,
1
);
INSERT
INTO
"disk"
VALUES
(
'/dev/sda1'
,
'159476805632'
,
'288692256768'
,
'/'
,
'2017-10-02'
,
'09:30:03'
,
1
);
INSERT
INTO
"folder"
VALUES
(
'slapuser0'
,
21883255
.
0
,
'2017-09-18'
,
'09:30:20'
,
1
);
INSERT
INTO
"folder"
VALUES
(
'slapuser0'
,
24071580
.
5
,
'2017-09-19'
,
'09:30:11'
,
1
);
INSERT
INTO
"folder"
VALUES
(
'slapuser0'
,
23196250
.
3
,
'2017-09-20'
,
'09:30:08'
,
1
);
INSERT
INTO
"folder"
VALUES
(
'slapuser0'
,
23415082
.
8
,
'2017-09-21'
,
'09:30:21'
,
1
);
INSERT
INTO
"folder"
VALUES
(
'slapuser0'
,
23633915
.
4
,
'2017-09-22'
,
'09:30:09'
,
1
);
INSERT
INTO
"folder"
VALUES
(
'slapuser0'
,
30636557
.
0
,
'2017-09-23'
,
'09:30:06'
,
1
);
INSERT
INTO
"folder"
VALUES
(
'slapuser0'
,
28448231
.
5
,
'2017-09-24'
,
'09:30:19'
,
1
);
INSERT
INTO
"folder"
VALUES
(
'slapuser0'
,
27572901
.
3
,
'2017-09-25'
,
'09:30:13'
,
1
);
INSERT
INTO
"folder"
VALUES
(
'slapuser0'
,
29761226
.
8
,
'2017-09-26'
,
'09:30:15'
,
1
);
INSERT
INTO
"folder"
VALUES
(
'slapuser0'
,
30855389
.
5
,
'2017-09-27'
,
'09:30:06'
,
1
);
INSERT
INTO
"folder"
VALUES
(
'slapuser0'
,
30636557
.
0
,
'2017-09-28'
,
'09:30:11'
,
1
);
INSERT
INTO
"folder"
VALUES
(
'slapuser0'
,
31074222
.
0
,
'2017-09-29'
,
'09:30:08'
,
1
);
INSERT
INTO
"folder"
VALUES
(
'slapuser0'
,
31096105
.
3
,
'2017-09-30'
,
'09:30:05'
,
1
);
INSERT
INTO
"folder"
VALUES
(
'slapuser0'
,
31949552
.
2
,
'2017-10-01'
,
'09:30:10'
,
1
);
INSERT
INTO
"folder"
VALUES
(
'slapuser0'
,
87533020
.
0
,
'2017-10-02'
,
'09:30:02'
,
1
);
COMMIT
;
\ No newline at end of file
slapos/test/promise/plugin/test_monitor_partition_space.py
0 → 100644
View file @
36675caa
##############################################################################
#
# Copyright (c) 2018 Vifib SARL and Contributors. All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from
slapos.test.promise.plugin
import
TestPromisePluginMixin
from
slapos.grid.promise
import
PromiseError
import
os
import
sqlite3
from
slapos.grid.promise
import
PromiseError
class
TestMonitorPartitionSpace
(
TestPromisePluginMixin
):
def
setUp
(
self
):
TestPromisePluginMixin
.
setUp
(
self
)
log_folder
=
os
.
path
.
join
(
self
.
partition_dir
,
'var/log'
)
os
.
makedirs
(
log_folder
)
self
.
db_file
=
'/tmp/collector.db'
# populate db
self
.
conn
=
sqlite3
.
connect
(
self
.
db_file
)
f
=
open
(
self
.
base_path
+
"/folder_disk_test.sql"
)
sql
=
f
.
read
()
self
.
conn
.
executescript
(
sql
)
self
.
conn
.
close
()
self
.
promise_name
=
"monitor-partition-space.py"
content
=
"""from slapos.promise.plugin.monitor_partition_space import RunPromise
extra_config_dict = {
'collectordb': '%(collectordb)s',
'test-check-date': '2017-10-02',
}
"""
%
{
'collectordb'
:
self
.
db_file
}
self
.
writePromise
(
self
.
promise_name
,
content
)
def
tearDown
(
self
):
TestPromisePluginMixin
.
tearDown
(
self
)
if
os
.
path
.
exists
(
self
.
db_file
):
os
.
remove
(
self
.
db_file
)
def
test_no_data_for_a_partition
(
self
):
content
=
"""from slapos.promise.plugin.monitor_partition_space import RunPromise
extra_config_dict = {
'collectordb': '%(collectordb)s',
'test-check-date': '2017-10-02',
'test-partition': 'slapuser1'
}
"""
%
{
'collectordb'
:
self
.
db_file
}
self
.
writePromise
(
self
.
promise_name
,
content
)
self
.
configureLauncher
(
timeout
=
20
)
self
.
launcher
.
run
()
result
=
self
.
getPromiseResult
(
self
.
promise_name
)
self
.
assertEqual
(
result
[
'result'
][
'failed'
],
False
)
self
.
assertEqual
(
result
[
'result'
][
'message'
],
"No result from collector database in partition slapuser1: skipped"
)
def
test_no_recent_data
(
self
):
content
=
"""from slapos.promise.plugin.monitor_partition_space import RunPromise
extra_config_dict = {
'collectordb': '%(collectordb)s',
'test-check-date': '2017-10-04'
}
"""
%
{
'collectordb'
:
self
.
db_file
}
self
.
writePromise
(
self
.
promise_name
,
content
)
self
.
configureLauncher
(
timeout
=
20
)
self
.
launcher
.
run
()
result
=
self
.
getPromiseResult
(
self
.
promise_name
)
self
.
assertEqual
(
result
[
'result'
][
'failed'
],
False
)
self
.
assertEqual
(
result
[
'result'
][
'message'
],
"Not enough recent data to detect anomalies: skipped"
)
def
test_no_enough_data
(
self
):
content
=
"""from slapos.promise.plugin.monitor_partition_space import RunPromise
extra_config_dict = {
'collectordb': '%(collectordb)s',
'test-check-date': '2017-09-24'
}
"""
%
{
'collectordb'
:
self
.
db_file
}
self
.
writePromise
(
self
.
promise_name
,
content
)
self
.
configureLauncher
(
timeout
=
20
)
self
.
launcher
.
run
()
result
=
self
.
getPromiseResult
(
self
.
promise_name
)
self
.
assertEqual
(
result
[
'result'
][
'failed'
],
False
)
self
.
assertEqual
(
result
[
'result'
][
'message'
],
"Not enough data to detect anomalies: skipped"
)
def
test_no_anomalies
(
self
):
content
=
"""from slapos.promise.plugin.monitor_partition_space import RunPromise
extra_config_dict = {
'collectordb': '%(collectordb)s',
'test-check-date': '2017-10-02',
'threshold_ratio': '0.70'
}
"""
%
{
'collectordb'
:
self
.
db_file
}
self
.
writePromise
(
self
.
promise_name
,
content
)
self
.
configureLauncher
(
timeout
=
20
)
self
.
launcher
.
run
()
result
=
self
.
getPromiseResult
(
self
.
promise_name
)
self
.
assertEqual
(
result
[
'result'
][
'failed'
],
False
)
self
.
assertEqual
(
result
[
'result'
][
'message'
],
"No anomaly detected (last date checked: 2017-10-02 09:30:00)"
)
def
test_presence_of_anomalies
(
self
):
self
.
configureLauncher
(
timeout
=
20
)
with
self
.
assertRaises
(
PromiseError
):
self
.
launcher
.
run
()
result
=
self
.
getPromiseResult
(
self
.
promise_name
)
self
.
assertEqual
(
result
[
'result'
][
'failed'
],
True
)
msg
=
"Anomaly detected on 2017-10-02 09:30:00. Space used by slapuser0: %.2f G."
self
.
assertEqual
(
result
[
'result'
][
'message'
],
msg
%
(
87533020.0
/
(
1024
*
1024
*
1024
)))
if
__name__
==
'__main__'
:
unittest
.
main
()
\ 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