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
Xavier Thompson
slapos.toolbox
Commits
9c4df064
Commit
9c4df064
authored
Aug 06, 2021
by
Lisa Casino
Committed by
Xavier Thompson
Dec 15, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
promise/plugin: update test disk_space
parent
05ba090b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
10 deletions
+62
-10
slapos/test/promise/data/disktest.sql
slapos/test/promise/data/disktest.sql
+18
-0
slapos/test/promise/plugin/test_check_free_disk_space.py
slapos/test/promise/plugin/test_check_free_disk_space.py
+44
-10
No files found.
slapos/test/promise/data/disktest.sql
View file @
9c4df064
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-09-18'
,
'09:17:01'
,
1
);
INSERT
INTO
"disk"
VALUES
(
'/dev/sda1'
,
'159220666368'
,
'288948396032'
,
'/'
,
'2017-09-19'
,
'09:17:01'
,
1
);
INSERT
INTO
"disk"
VALUES
(
'/dev/sda1'
,
'159220666368'
,
'288948396032'
,
'/'
,
'2017-09-20'
,
'09:17:01'
,
1
);
INSERT
INTO
"disk"
VALUES
(
'/dev/sda1'
,
'159220666368'
,
'288948396032'
,
'/'
,
'2017-09-21'
,
'09:17:01'
,
1
);
INSERT
INTO
"disk"
VALUES
(
'/dev/sda1'
,
'159220666368'
,
'288948396032'
,
'/'
,
'2017-09-22'
,
'09:17:01'
,
1
);
INSERT
INTO
"disk"
VALUES
(
'/dev/sda1'
,
'159220666368'
,
'288948396032'
,
'/'
,
'2017-09-23'
,
'09:17:01'
,
1
);
INSERT
INTO
"disk"
VALUES
(
'/dev/sda1'
,
'159220666368'
,
'288948396032'
,
'/'
,
'2017-09-24'
,
'09:17:01'
,
1
);
INSERT
INTO
"disk"
VALUES
(
'/dev/sda1'
,
'159220666368'
,
'288948396032'
,
'/'
,
'2017-09-25'
,
'09:17:01'
,
1
);
INSERT
INTO
"disk"
VALUES
(
'/dev/sda1'
,
'159220666368'
,
'288948396032'
,
'/'
,
'2017-09-26'
,
'09:17:01'
,
1
);
INSERT
INTO
"disk"
VALUES
(
'/dev/sda1'
,
'159220666368'
,
'288948396032'
,
'/'
,
'2017-09-27'
,
'09:17:01'
,
1
);
INSERT
INTO
"disk"
VALUES
(
'/dev/sda1'
,
'159220666368'
,
'288948396032'
,
'/'
,
'2017-09-28'
,
'09:17:01'
,
1
);
INSERT
INTO
"disk"
VALUES
(
'/dev/sda1'
,
'159220666368'
,
'288948396032'
,
'/'
,
'2017-09-29'
,
'09:17:01'
,
1
);
INSERT
INTO
"disk"
VALUES
(
'/dev/sda1'
,
'159220666368'
,
'288948396032'
,
'/'
,
'2017-09-30'
,
'09:17:01'
,
1
);
INSERT
INTO
"disk"
VALUES
(
'/dev/sda1'
,
'159220666368'
,
'288948396032'
,
'/'
,
'2017-10-01'
,
'09:17:01'
,
1
);
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
);
...
...
@@ -14,4 +29,7 @@ INSERT INTO "disk" VALUES('/dev/sda1','159429677056','288739385344','/','2017-10
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'
,
87533020
.
0
,
'2017-10-02'
,
'09:17:00'
,
1
);
INSERT
INTO
"folder"
VALUES
(
'slapuser1'
,
21883255
.
0
,
'2017-10-02'
,
'09:17:00'
,
1
);
INSERT
INTO
"folder"
VALUES
(
'slapuser2'
,
43766510
.
0
,
'2017-10-02'
,
'09:17:00'
,
1
);
COMMIT
;
slapos/test/promise/plugin/test_check_free_disk_space.py
View file @
9c4df064
...
...
@@ -74,18 +74,19 @@ extra_config_dict = {
"""
%
{
'collectordb'
:
self
.
db_file
}
self
.
writePromise
(
self
.
promise_name
,
content
)
self
.
configureLauncher
()
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: disk check skipped"
)
def
test_disk_space_ok
(
self
):
self
.
configureLauncher
()
self
.
configureLauncher
(
timeout
=
20
)
self
.
launcher
.
run
()
result
=
self
.
getPromiseResult
(
self
.
promise_name
)
self
.
assertEqual
(
result
[
'result'
][
'failed'
],
False
)
self
.
assertEqual
(
result
[
'result'
][
'message'
],
"Disk usage: OK"
)
message
=
"Current disk usage: OK
\
n
Enable to display disk space predictions: False"
self
.
assertEqual
(
result
[
'result'
][
'message'
],
message
)
def
test_disk_space_nok
(
self
):
content
=
"""from slapos.promise.plugin.check_free_disk_space import RunPromise
...
...
@@ -98,29 +99,62 @@ extra_config_dict = {
"""
%
{
'collectordb'
:
self
.
db_file
}
self
.
writePromise
(
self
.
promise_name
,
content
)
self
.
configureLauncher
()
self
.
configureLauncher
(
timeout
=
20
)
with
self
.
assertRaises
(
PromiseError
):
self
.
launcher
.
run
()
result
=
self
.
getPromiseResult
(
self
.
promise_name
)
self
.
assertEqual
(
result
[
'result'
][
'failed'
],
True
)
self
.
assertEqual
(
result
[
'result'
][
'message'
],
"Free disk space low: remaining 269.1 G (threshold: 278.0 G)"
)
message
=
"Free disk space low: remaining 269.10 G (disk size: 417 G, threshold: 278 G)."
self
.
assertIn
(
message
,
result
[
'result'
][
'message'
]
)
self
.
configureLauncher
()
def
test_display_partition
(
self
):
content
=
"""from slapos.promise.plugin.check_free_disk_space import RunPromise
extra_config_dict = {
'collectordb': '%(collectordb)s',
'test-check-date': '2017-10-02',
'threshold': '278',
'display-partition' : '1',
}
"""
%
{
'collectordb'
:
self
.
db_file
}
self
.
writePromise
(
self
.
promise_name
,
content
)
self
.
configureLauncher
(
timeout
=
20
)
with
self
.
assertRaises
(
PromiseError
):
self
.
launcher
.
run
()
result
=
self
.
getPromiseResult
(
self
.
promise_name
)
self
.
assertEqual
(
result
[
'result'
][
'failed'
],
True
)
self
.
assertEqual
(
result
[
'result'
][
'message'
],
"Free disk space low: remaining 269.1 G (threshold: 278.0 G)"
)
message
=
"Free disk space low: remaining 269.10 G (disk size: 417 G, threshold: 278 G). "
\
"The partition slappart0 uses 83.48 G (date checked: 2017-10-02 09:17:00). "
\
"The partition slappart2 uses 41.74 G (date checked: 2017-10-02 09:17:00). "
\
"The partition slappart1 uses 20.87 G (date checked: 2017-10-02 09:17:00)."
self
.
assertIn
(
message
,
result
[
'result'
][
'message'
])
def
test_display_prediction
(
self
):
content
=
"""from slapos.promise.plugin.check_free_disk_space import RunPromise
extra_config_dict = {
'collectordb': '%(collectordb)s',
'test-check-date': '2017-10-02',
'display-prediction' : '1',
}
"""
%
{
'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
.
assertIn
(
"Prediction:"
,
result
[
'result'
][
'message'
])
def
test_check_free_disk_with_unicode_string_path
(
self
):
# set path unicode
self
.
partition_dir
=
u'%s'
%
self
.
partition_dir
self
.
configureLauncher
()
self
.
configureLauncher
(
timeout
=
20
)
self
.
launcher
.
run
()
result
=
self
.
getPromiseResult
(
self
.
promise_name
)
self
.
assertEqual
(
result
[
'result'
][
'failed'
],
False
)
self
.
assert
Equal
(
result
[
'result'
][
'message'
],
"Disk usage: OK"
)
self
.
assert
In
(
"Current disk usage: OK"
,
result
[
'result'
][
'message'
]
)
if
__name__
==
'__main__'
:
unittest
.
main
()
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