Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
OpenXG-RAN
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
littleBu
OpenXG-RAN
Commits
9ea4b3cd
Commit
9ea4b3cd
authored
3 years ago
by
Robert Schmidt
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/ci_fix_log_rotation' into integration_2022_wk09_b
parents
a45bbd40
ce9229a1
Branches unavailable
2025.w08
2025.w07
2025.w06
2025.w05
2025.w04
2025.w03
2025.w02
2024.w51
2024.w50
2024.w49
2024.w48
2024.w47
2024.w46
2024.w45
2024.w44
2024.w43
2024.w42
2024.w41
2024.w40
2024.w39
2024.w38
2024.w36
2024.w35
2024.w34
2024.w33
2024.w32
2024.w31
2024.w30
2024.w29
2024.w28
2024.w27
2024.w26
2024.w25
2024.w24
2024.w23
2024.w22
2024.w21
2024.w18
2024.w17
2024.w16
2024.w15
2024.w14
2024.w13
2024.w12
2024.w11
2024.w10
2024.w09
2024.w08
2024.w06
2024.w05
2024.w04
2024.w03
2024.w02
2024.w01
2023.w51
2023.w50
2023.w49
2023.w48
2023.w47
2023.w45
2023.w43
2023.w42
2023.w41
2023.w40
2023.w39
2023.w38
2023.w37
2023.w36
2023.w34
2023.w33
2023.w32
2023.w31
2023.w30
2023.w29
2023.w28
2023.w27
2023.w26
2023.w25
2023.w24
2023.w23
2023.w22
2023.w21
2023.w20
2023.w19
2023.w18
2023.w18b
2023.w16
2023.w15
2023.w14
2023.w13
2023.w12
2023.w11
2023.w11b
2023.w10
2023.w10b
2023.w09
2023.w08
2023.w08b
2023.w07
2023.w06
2023.w05
2023.w03
2023.w02
2022.42
2022.41
2022.w51
2022.w50
2022.w49
2022.w48
2022.w47
2022.w46
2022.w45
2022.w43
2022.w42
2022.w42b
2022.w41
2022.w40
2022.w39
2022.w38
2022.w37
2022.w37b
2022.w36
2022.w35
2022.w33
2022.w32
2022.w31
2022.w31b
2022.w30
2022.w29
2022.w26
2022.w25
2022.w24
2022.w24b
2022.w23
2022.w22
2022.w21
2022.w20
2022.w19
2022.w18
2022.w17
2022.w15
2022.w15b
2022.w14a
2022.w13
2022.w13b
2022.w13a
2022.w12
2022.w10
2022.w09b
v2.2.0
v2.1.0
v2.0.0
setparam
flexran-eol
ARC_1.3
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
39 deletions
+26
-39
ci-scripts/cls_log_mgt.py
ci-scripts/cls_log_mgt.py
+26
-39
No files found.
ci-scripts/cls_log_mgt.py
View file @
9ea4b3cd
...
...
@@ -30,11 +30,15 @@
import
logging
import
re
import
subprocess
import
logging
import
math
import
sshconnection
logging
.
basicConfig
(
level
=
logging
.
DEBUG
,
format
=
"[%(asctime)s] %(name)s:%(levelname)s: %(message)s"
)
class
Log_Mgt
:
...
...
@@ -49,40 +53,25 @@ class Log_Mgt:
#-----------------$
def
__Check
Avail
Space
(
self
):
def
__Check
Used
Space
(
self
):
HOST
=
self
.
Username
+
'@'
+
self
.
IPAddress
COMMAND
=
"df "
+
self
.
path
ssh
=
subprocess
.
Popen
([
"ssh"
,
"%s"
%
HOST
,
COMMAND
],
shell
=
False
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
result
=
ssh
.
stdout
.
readlines
()
s
=
result
[
1
].
decode
(
'utf-8'
).
rstrip
()
#result[1] is the second line with the results we are looking for
tmp
=
s
.
split
()
return
tmp
[
3
]
#return avail space from the line
used
=
s
.
split
()[
4
]
#get 4th field ex: 70%
m
=
re
.
match
(
'^(\d+)\%'
,
used
)
if
m
is
not
None
:
return
int
(
m
.
group
(
1
))
def
__GetOldestFile
(
self
):
HOST
=
self
.
Username
+
'@'
+
self
.
IPAddress
COMMAND
=
"ls -rtl "
+
self
.
path
#-rtl will bring oldest file on top
ssh
=
subprocess
.
Popen
([
"ssh"
,
"%s"
%
HOST
,
COMMAND
],
shell
=
False
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
result
=
ssh
.
stdout
.
readlines
()
s
=
result
[
1
].
decode
(
'utf-8'
).
rstrip
()
tmp
=
s
.
split
()
return
tmp
[
8
]
#return filename from the line
def
__RemoveOldest
(
self
):
mySSH
=
sshconnection
.
SSHConnection
()
mySSH
.
open
(
self
.
IPAddress
,
self
.
Username
,
self
.
Password
)
COMMAND
=
'echo '
+
self
.
Password
+
' | sudo -S find '
+
self
.
path
+
' -type f -mtime +14 -delete'
mySSH
.
command
(
COMMAND
,
'\$'
,
20
)
mySSH
.
close
()
def
__AvgSize
(
self
):
HOST
=
self
.
Username
+
'@'
+
self
.
IPAddress
COMMAND
=
"ls -rtl "
+
self
.
path
ssh
=
subprocess
.
Popen
([
"ssh"
,
"%s"
%
HOST
,
COMMAND
],
shell
=
False
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
result
=
ssh
.
stdout
.
readlines
()
if
len
(
result
)
>
1
:
#at least 1 file present
total_size
=
0
for
i
in
range
(
1
,
len
(
result
)):
s
=
result
[
i
].
decode
(
'utf-8'
).
rstrip
()
tmp
=
s
.
split
()
total_size
+=
int
(
tmp
[
4
])
#get filesize
return
math
.
floor
(
total_size
/
(
len
(
result
)
-
1
))
#compute average file/artifact size
else
:
#empty,no files
return
0
#-----------------$
#PUBLIC Methods$
...
...
@@ -90,17 +79,15 @@ class Log_Mgt:
def
LogRotation
(
self
):
avail_space
=
int
(
self
.
__CheckAvailSpace
())
*
1000
#avail space in target folder, initially displayed in Gb
avg_size
=
self
.
__AvgSize
()
#average size of artifacts in the target folder
logging
.
debug
(
"Avail Space : "
+
str
(
avail_space
)
+
" / Artifact Avg Size : "
+
str
(
avg_size
))
if
avail_space
<
50
*
avg_size
:
#reserved space is 50x artifact file ; oldest file will be deleted
oldestfile
=
self
.
__GetOldestFile
()
HOST
=
self
.
Username
+
'@'
+
self
.
IPAddress
COMMAND
=
"echo "
+
self
.
Password
+
" | sudo -S rm "
+
self
.
path
+
"/"
+
oldestfile
logging
.
debug
(
COMMAND
)
ssh
=
subprocess
.
Popen
([
"ssh"
,
"%s"
%
HOST
,
COMMAND
],
shell
=
False
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
used_space
=
self
.
__CheckUsedSpace
()
#avail space in target folder
if
used_space
>
80
:
logging
.
debug
(
'
\u001B
[1;37;41m Used Disk > 80%, on '
+
self
.
Username
+
'@'
+
self
.
IPAddress
+
'
\u001B
[0m'
)
logging
.
debug
(
'
\u001B
[1;37;41m Removing Artifacts older than 14 days
\u001B
[0m'
)
self
.
__RemoveOldest
()
else
:
logging
.
debug
(
"Still some space left for artifacts storage"
)
logging
.
debug
(
'Used Disk < 80%, on '
+
self
.
Username
+
'@'
+
self
.
IPAddress
+
', no cleaning required'
)
...
...
This diff is collapsed.
Click to expand it.
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