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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Rafael Monnerat
slapos.toolbox
Commits
58eface4
Commit
58eface4
authored
Aug 28, 2018
by
Alain Takoudjou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixup: move check_free_disk_space promise to promise.plugin
parent
2b5d1afa
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
32 deletions
+31
-32
slapos/promise/plugin/check_free_disk_space.py
slapos/promise/plugin/check_free_disk_space.py
+30
-31
slapos/test/promise/plugin/test_check_free_disk_space.py
slapos/test/promise/plugin/test_check_free_disk_space.py
+1
-1
No files found.
slapos/promise/plugin/check_free_disk_space.py
View file @
58eface4
...
...
@@ -12,6 +12,33 @@ import psutil
from
slapos.collect.db
import
Database
def
getFreeSpace
(
disk_partition
,
database
,
date
,
time
,
logger
=
None
):
database
=
Database
(
database
,
create
=
False
,
timeout
=
10
)
try
:
# fetch free disk space
database
.
connect
()
where_query
=
"time between '%s:00' and '%s:30' and partition='%s'"
%
(
time
,
time
,
disk_partition
)
query_result
=
database
.
select
(
"disk"
,
date
,
"free"
,
where
=
where_query
)
result
=
zip
(
*
query_result
)
if
not
result
or
not
result
[
0
][
0
]:
if
logger
is
not
None
:
logger
.
info
(
"No result from collector database: disk check skipped"
)
return
0
disk_free
=
result
[
0
][
0
]
except
sqlite3
.
OperationalError
,
e
:
# if database is still locked after timeout expiration (another process is using it)
# we print warning message and try the promise at next run until max warn msg
locked_message
=
"database is locked"
if
locked_message
in
str
(
e
)
and
\
not
self
.
raiseOnDatabaseLocked
(
locked_message
):
return
0
raise
finally
:
database
.
close
()
pass
return
int
(
disk_free
)
class
RunPromise
(
GenericPromise
):
zope_interface
.
implements
(
interface
.
IPromise
)
...
...
@@ -48,35 +75,6 @@ class RunPromise(GenericPromise):
self
.
logger
.
warn
(
"collector database is locked by another process: %s %s"
%
(
warning_count
,
len
(
latest_result_list
)))
return
False
def
functio
(
self
):
raise
sqlite3
.
OperationalError
(
"database is locked"
)
def
getFreeSpace
(
self
,
disk_partition
,
database
,
date
,
time
):
database
=
Database
(
database
,
create
=
False
,
timeout
=
10
)
try
:
# fetch free disk space
database
.
connect
()
where_query
=
"time between '%s:00' and '%s:30' and partition='%s'"
%
(
time
,
time
,
disk_partition
)
query_result
=
database
.
select
(
"disk"
,
date
,
"free"
,
where
=
where_query
)
result
=
zip
(
*
query_result
)
if
not
result
or
not
result
[
0
][
0
]:
self
.
logger
.
info
(
"No result from collector database: disk check skipped"
)
return
0
disk_free
=
result
[
0
][
0
]
except
sqlite3
.
OperationalError
,
e
:
# if database is still locked after timeout expiration (another process is using it)
# we print warning message and try the promise at next run until max warn msg
locked_message
=
"database is locked"
if
locked_message
in
str
(
e
)
and
\
not
self
.
raiseOnDatabaseLocked
(
locked_message
):
return
0
raise
finally
:
database
.
close
()
pass
return
int
(
disk_free
)
def
getInodeUsage
(
self
,
path
):
max_inode_usage
=
97.99
# < 98% usage
...
...
@@ -151,7 +149,8 @@ class RunPromise(GenericPromise):
if
db_path
.
endswith
(
"collector.db"
):
db_path
=
db_path
[:
-
len
(
"collector.db"
)]
free_space
=
self
.
getFreeSpace
(
disk_partition
,
db_path
,
currentdate
,
currenttime
)
free_space
=
getFreeSpace
(
disk_partition
,
db_path
,
currentdate
,
currenttime
,
self
.
logger
)
if
free_space
==
0
:
return
elif
free_space
>
min_free_size
:
...
...
slapos/test/promise/plugin/test_check_free_disk_space.py
View file @
58eface4
...
...
@@ -30,7 +30,7 @@ from slapos.grid.promise import PromiseError
import
os
import
sqlite3
from
slapos.test.promise
import
data
from
slapos.promise.
check_free_disk
import
getFreeSpace
from
slapos.promise.
plugin.check_free_disk_space
import
getFreeSpace
from
slapos.grid.promise
import
PromiseError
class
TestCheckFreeDiskSpace
(
TestPromisePluginMixin
):
...
...
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