Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
envsetup
Manage
Activity
Members
Plan
Redmine
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mediaserver
envsetup
Commits
728e998a
Commit
728e998a
authored
6 years ago
by
Stéphane Diemer
Browse files
Options
Downloads
Patches
Plain Diff
Check RAM instead of swap (refs
#27150
).
parent
2f3df0f3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_partitions.py
+75
-84
75 additions, 84 deletions
tests/test_partitions.py
with
75 additions
and
84 deletions
tests/test_partitions.py
+
75
−
84
View file @
728e998a
...
@@ -9,62 +9,59 @@ import subprocess
...
@@ -9,62 +9,59 @@ import subprocess
import
sys
import
sys
import
os
import
os
BS
=
512
YELLOW
=
'
\033
[93m
'
YELLOW
=
'
\033
[93m
'
GREEN
=
'
\033
[92m
'
GREEN
=
'
\033
[92m
'
RED
=
'
\033
[91m
'
RED
=
'
\033
[91m
'
DEF
=
'
\033
[0m
'
DEF
=
'
\033
[0m
'
def
to_gbytes
(
size_bytes
):
PATHS
=
[
return
int
(
round
(
size_bytes
/
(
1024
*
1024
*
1024
)))
def
read_file
(
fname
):
with
open
(
fname
,
'
r
'
)
as
f
:
return
f
.
read
()
paths
=
[
{
{
'
mount_point
'
:
'
/
'
,
'
mount_point
'
:
'
/
'
,
'
recommended_types
'
:
(
'
ext4
'
,),
'
recommended_types
'
:
(
'
ext4
'
,
'
zfs
'
),
'
min_size_gbytes
'
:
9
,
'
min_size_gbytes
'
:
9
,
'
reco_size_gbytes
'
:
14
,
'
reco_size_gbytes
'
:
14
,
'
min_available_gbytes
'
:
4
,
'
min_available_gbytes
'
:
4
,
},
},
{
{
'
mount_point
'
:
'
/home/msuser/msinstance
'
,
'
mount_point
'
:
'
/home/msuser/msinstance
'
,
'
recommended_types
'
:
(
'
ext4
'
,
'
nfs
'
,
'
nfs4
'
,
'
zfs
'
),
'
recommended_types
'
:
(
'
ext4
'
,
'
zfs
'
,
'
nfs
'
,
'
nfs4
'
),
'
min_size_gbytes
'
:
5
,
'
min_size_gbytes
'
:
5
,
'
reco_size_gbytes
'
:
300
,
'
reco_size_gbytes
'
:
300
,
'
min_available_gbytes
'
:
5
,
'
min_available_gbytes
'
:
5
,
},
},
{
{
'
mount_point
'
:
'
/home/skyreach
'
,
'
mount_point
'
:
'
/home/skyreach
'
,
'
recommended_types
'
:
(
'
ext4
'
,
'
nfs
'
,
'
nfs4
'
,
'
zfs
'
),
'
recommended_types
'
:
(
'
ext4
'
,
'
zfs
'
,
'
nfs
'
,
'
nfs4
'
),
'
min_size_gbytes
'
:
5
,
'
min_size_gbytes
'
:
5
,
'
reco_size_gbytes
'
:
9
,
'
reco_size_gbytes
'
:
9
,
'
min_available_gbytes
'
:
2
,
'
min_available_gbytes
'
:
2
,
},
},
{
{
'
type
'
:
'
swap
'
,
'
type
'
:
'
memory
'
,
'
min_size_gbytes
'
:
1
,
'
min_size_gbytes
'
:
2
,
'
reco_size_gbytes
'
:
2
,
'
reco_size_gbytes
'
:
4
,
},
},
]
]
def
get_swap_gbytes
():
def
to_gbytes
(
size_bytes
):
d
=
read_file
(
'
/proc/meminfo
'
)
return
int
(
round
(
size_bytes
/
(
1024
*
1024
*
1024
)))
for
l
in
d
.
split
(
'
\n
'
):
if
'
SwapTotal
'
in
l
:
swap
=
l
.
split
(
'
SwapTotal:
'
)[
1
].
strip
()
def
get_memory_gbytes
():
swap_kbytes
,
unit
=
swap
.
split
(
'
'
)
memory_gbytes
=
0
if
unit
!=
'
kB
'
:
with
open
(
'
/proc/meminfo
'
,
'
r
'
)
as
f
:
print
(
'
Warning, unexpected unit %s.
'
%
unit
)
for
l
in
f
:
swap_gbytes
=
int
(
round
(
int
(
swap_kbytes
)
/
(
1024
*
1024
)))
if
'
MemTotal:
'
in
l
:
return
swap_gbytes
memory
=
l
.
split
(
'
MemTotal:
'
)[
1
].
strip
()
memory_kbytes
,
unit
=
memory
.
split
(
'
'
)
if
unit
!=
'
kB
'
:
print
(
'
Warning, unexpected unit %s.
'
%
unit
)
memory_gbytes
=
int
(
round
(
int
(
memory_kbytes
)
/
(
1024
*
1024
)))
if
not
memory_gbytes
:
print
(
'
Failed to get memory size.
'
)
return
memory_gbytes
def
get_path
(
path
):
def
get_path
(
path
):
...
@@ -82,11 +79,11 @@ def check_allocation(dev):
...
@@ -82,11 +79,11 @@ def check_allocation(dev):
root_dev
=
os
.
path
.
basename
(
dev
)[:
3
]
root_dev
=
os
.
path
.
basename
(
dev
)[:
3
]
if
not
root_dev
:
if
not
root_dev
:
return
True
return
True
d
=
read_file
(
'
/proc/partitions
'
)
dev_partitions
=
list
()
dev_partitions
=
list
()
for
l
in
d
.
split
(
'
\n
'
):
with
open
(
'
/proc/partitions
'
,
'
r
'
)
as
f
:
if
root_dev
in
l
:
for
l
in
f
:
dev_partitions
.
append
(
l
)
if
root_dev
in
l
:
dev_partitions
.
append
(
l
)
max_size
=
0
max_size
=
0
total_size
=
0
total_size
=
0
...
@@ -105,58 +102,52 @@ def check_allocation(dev):
...
@@ -105,58 +102,52 @@ def check_allocation(dev):
return
True
return
True
error
=
False
if
__name__
==
'
__main__
'
:
warning
=
False
error
=
False
warning
=
False
for
p
in
PATHS
:
def
check_path
(
p
):
psize
=
None
global
error
if
p
.
get
(
'
mount_point
'
):
global
warning
mount_point
=
p
[
'
mount_point
'
]
if
os
.
path
.
exists
(
mount_point
):
psize
=
None
mount_point
=
os
.
path
.
realpath
(
mount_point
)
mount_point
=
p
.
get
(
'
mount_point
'
)
name
=
'
Partition of %s
'
%
mount_point
if
mount_point
:
dev
,
fstype
,
psize
,
available
=
get_path
(
mount_point
)
if
os
.
path
.
exists
(
mount_point
):
if
fstype
not
in
p
.
get
(
'
recommended_types
'
):
mount_point
=
os
.
path
.
realpath
(
mount_point
)
print
(
'
Warning: %s fs type not recommended %s(current: %s, recommended: %s)%s.
'
%
(
name
,
YELLOW
,
fstype
,
p
[
'
recommended_types
'
],
DEF
))
name
=
mount_point
warning
=
True
dev
,
fstype
,
psize
,
available
=
get_path
(
mount_point
)
if
'
nfs
'
not
in
fstype
:
if
fstype
not
in
p
.
get
(
'
recommended_types
'
):
warning
=
not
check_allocation
(
dev
)
print
(
'
Warning, partition of %s fs type not recommended %s(current: %s, recommended: %s)%s.
'
%
(
name
,
YELLOW
,
fstype
,
p
[
'
recommended_types
'
],
DEF
))
min_available_gbytes
=
p
.
get
(
'
min_available_gbytes
'
)
warning
=
True
if
min_available_gbytes
and
available
<
min_available_gbytes
:
if
'
nfs
'
not
in
fstype
:
print
(
'
%s has less than %s GB available %s(%s GB available)%s.
'
%
(
name
,
min_available_gbytes
,
RED
,
available
,
DEF
))
warning
=
not
check_allocation
(
dev
)
error
=
True
min_available_gbytes
=
p
.
get
(
'
min_available_gbytes
'
)
else
:
if
min_available_gbytes
and
available
<
min_available_gbytes
:
print
(
'
%s has %s GB available.
'
%
(
name
,
available
))
print
(
'
Partition of %s has less than %s GB available %s(%s GB available)%s.
'
%
(
name
,
min_available_gbytes
,
RED
,
available
,
DEF
))
else
:
print
(
'
%s not found, cannot check.
'
%
mount_point
)
elif
p
.
get
(
'
type
'
)
==
'
memory
'
:
name
=
'
Memory
'
psize
=
get_memory_gbytes
()
if
psize
:
if
psize
<
p
[
'
min_size_gbytes
'
]:
print
(
'
%s is smaller than the minimum required size %s(%s GB < %s GB)%s.
'
%
(
name
,
RED
,
psize
,
p
[
'
min_size_gbytes
'
],
DEF
))
error
=
True
error
=
True
elif
psize
<
p
[
'
reco_size_gbytes
'
]:
print
(
'
%s is smaller than the recommended size %s(%s GB < %s GB)%s.
'
%
(
name
,
YELLOW
,
psize
,
p
[
'
reco_size_gbytes
'
],
DEF
))
warning
=
True
else
:
else
:
print
(
'
Partition of %s has %s GB available.
'
%
(
name
,
available
))
print
(
'
%s is bigger than recommended size %s(%s GB >= %s GB)%s.
'
%
(
name
,
GREEN
,
psize
,
p
[
'
reco_size_gbytes
'
],
DEF
))
else
:
print
(
'
%s not found, cannot check.
'
%
mount_point
)
if
error
:
elif
p
.
get
(
'
type
'
)
==
'
swap
'
:
print
(
'
Errors found.
'
)
name
=
'
swap
'
code
=
1
psize
=
get_swap_gbytes
()
elif
warning
:
print
(
'
Some warnings were found.
'
)
if
psize
:
code
=
3
if
psize
<
p
[
'
min_size_gbytes
'
]:
else
:
print
(
'
Partition of %s is smaller than the minimum required size %s(%s GB < %s GB)%s.
'
%
(
name
,
RED
,
psize
,
p
[
'
min_size_gbytes
'
],
DEF
))
print
(
GREEN
+
'
All OK.
'
+
DEF
)
error
=
True
code
=
0
elif
psize
<
p
[
'
reco_size_gbytes
'
]:
print
(
'
Partition of %s is smaller than the recommended size %s(%s GB < %s GB)%s.
'
%
(
name
,
YELLOW
,
psize
,
p
[
'
reco_size_gbytes
'
],
DEF
))
sys
.
exit
(
code
)
warning
=
True
for
p
in
paths
:
check_path
(
p
)
if
error
:
print
(
'
Errors found.
'
)
code
=
1
elif
warning
:
print
(
'
Some warnings were found.
'
)
code
=
3
else
:
print
(
GREEN
+
'
All OK.
'
+
DEF
)
code
=
0
sys
.
exit
(
code
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment