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
wangjie
OpenXG-RAN
Commits
dda388e6
Commit
dda388e6
authored
Jun 16, 2021
by
hardy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix and improve log mgt
parent
6897bfc1
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
21 deletions
+35
-21
ci-scripts/cls_log_mgt.py
ci-scripts/cls_log_mgt.py
+35
-21
No files found.
ci-scripts/cls_log_mgt.py
View file @
dda388e6
...
...
@@ -24,17 +24,24 @@
#
#---------------------------------------------------------------------
#import sys
#USAGE:
# log=Log_Mgt(IPAddress,Password,Path)
# log.LogRotation()
import
re
import
subprocess
import
logging
import
math
class
Log_Mgt
:
def
__init__
(
self
,
IPAddress
,
Password
,
path
,
filesize
):
def
__init__
(
self
,
IPAddress
,
Password
,
Path
):
self
.
IPAddress
=
IPAddress
self
.
Password
=
"oaicicd"
self
.
path
=
path
self
.
filesize
=
filesize
self
.
Password
=
Password
self
.
path
=
Path
#-----------------$
#PRIVATE# Methods$
...
...
@@ -46,42 +53,49 @@ class Log_Mgt:
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
()
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
tmp
[
3
]
#return avail space from the line
def
__GetOldestFile
(
self
):
HOST
=
self
.
IPAddress
COMMAND
=
"ls -rtl "
+
self
.
path
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
tmp
[
8
]
#return filename from the line
#-----------------$
#PUBLIC Methods$
#-----------------$
def
AvgSize
(
self
):
HOST
=
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
()
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
def
LogRotation
(
self
):
avail_space
=
self
.
__CheckAvailSpace
()
print
(
"Avail Space : "
+
avail_space
+
" / Artifact Size : "
+
self
.
filesize
)
if
filesize
>
avail_space
:
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
<
2
*
avg_size
:
#reserved space is 2x artifact file ; oldest file will be deleted
oldestfile
=
self
.
__GetOldestFile
()
HOST
=
self
.
IPAddress
COMMAND
=
"echo "
+
self
.
Password
+
" | sudo -S rm "
+
self
.
path
+
"/"
+
oldestfile
print
(
COMMAND
)
logging
.
debug
(
COMMAND
)
ssh
=
subprocess
.
Popen
([
"ssh"
,
"%s"
%
HOST
,
COMMAND
],
shell
=
False
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
else
:
print
(
"Still some space left for artifacts storage"
)
logging
.
debug
(
"Still some space left for artifacts storage"
)
#if __name__ == "__main__":
# IPAddress=sys.argv[1]
# Password=sys.argv[2]
# path=sys.argv[3]
# filesize=sys.argv[4]
# log=Log_Mgt(IPAddress,Password,path,filesize)
# log.LogRotation()
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