Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
E
erp5_workflow
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
wenjie.zheng
erp5_workflow
Commits
2c352e90
Commit
2c352e90
authored
Feb 11, 2013
by
Sebastien Robin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleanup old logs regularly
parent
4a01afec
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
1 deletion
+37
-1
erp5/tests/testERP5TestNode.py
erp5/tests/testERP5TestNode.py
+21
-0
erp5/util/testnode/testnode.py
erp5/util/testnode/testnode.py
+16
-1
No files found.
erp5/tests/testERP5TestNode.py
View file @
2c352e90
...
@@ -564,3 +564,24 @@ branch = foo
...
@@ -564,3 +564,24 @@ branch = foo
TaskDistributionTool
.
createTestResult
=
original_createTestResult
TaskDistributionTool
.
createTestResult
=
original_createTestResult
test_node
.
_prepareSlapOS
=
original_prepareSlapOS
test_node
.
_prepareSlapOS
=
original_prepareSlapOS
test_node
.
runTestSuite
=
original_runTestSuite
test_node
.
runTestSuite
=
original_runTestSuite
def
test_16_cleanupLogDirectory
(
self
):
# Make sure that we are able to cleanup old log folders
test_node
=
self
.
getTestNode
()
def
check
(
file_list
):
log_directory_dir
=
os
.
listdir
(
self
.
log_directory
)
self
.
assertTrue
(
set
(
file_list
).
issubset
(
set
(
log_directory_dir
)),
"%r not contained by %r"
%
(
file_list
,
log_directory_dir
))
check
([])
os
.
mkdir
(
os
.
path
.
join
(
self
.
log_directory
,
'ab-llzje'
))
a_file
=
open
(
os
.
path
.
join
(
self
.
log_directory
,
'a_file'
),
'w'
)
a_file
.
close
()
check
(
set
([
'ab-llzje'
,
'a_file'
]))
# default log file time is 15 days, so nothing is going to be deleted
test_node
.
_cleanupLog
()
check
(
set
([
'ab-llzje'
,
'a_file'
]))
# then we set keep time to 0, folder will be deleted
test_node
.
max_log_time
=
0
test_node
.
_cleanupLog
()
check
(
set
([
'a_file'
]))
\ No newline at end of file
erp5/util/testnode/testnode.py
View file @
2c352e90
...
@@ -43,6 +43,8 @@ from Updater import Updater
...
@@ -43,6 +43,8 @@ from Updater import Updater
from
erp5.util
import
taskdistribution
from
erp5.util
import
taskdistribution
DEFAULT_SLEEP_TIMEOUT
=
120
# time in seconds to sleep
DEFAULT_SLEEP_TIMEOUT
=
120
# time in seconds to sleep
MAX_LOG_TIME
=
15
# time in days we should keep logs that we can see through
# httd
supervisord_pid_file
=
None
supervisord_pid_file
=
None
PROFILE_PATH_KEY
=
'profile_path'
PROFILE_PATH_KEY
=
'profile_path'
...
@@ -141,7 +143,7 @@ class NodeTestSuite(SlapOSInstance):
...
@@ -141,7 +143,7 @@ class NodeTestSuite(SlapOSInstance):
class
TestNode
(
object
):
class
TestNode
(
object
):
def
__init__
(
self
,
log
,
config
):
def
__init__
(
self
,
log
,
config
,
max_log_time
=
MAX_LOG_TIME
):
self
.
testnode_log
=
log
self
.
testnode_log
=
log
self
.
log
=
log
self
.
log
=
log
self
.
config
=
config
or
{}
self
.
config
=
config
or
{}
...
@@ -151,6 +153,7 @@ class TestNode(object):
...
@@ -151,6 +153,7 @@ class TestNode(object):
if
self
.
config
.
get
(
'working_directory'
,
''
).
endswith
(
"slapos/"
):
if
self
.
config
.
get
(
'working_directory'
,
''
).
endswith
(
"slapos/"
):
self
.
config
[
'working_directory'
]
=
self
.
config
[
self
.
config
[
'working_directory'
]
=
self
.
config
[
'working_directory'
][:
-
(
len
(
"slapos/"
))]
+
"testnode"
'working_directory'
][:
-
(
len
(
"slapos/"
))]
+
"testnode"
self
.
max_log_time
=
max_log_time
def
checkOldTestSuite
(
self
,
test_suite_data
):
def
checkOldTestSuite
(
self
,
test_suite_data
):
config
=
self
.
config
config
=
self
.
config
...
@@ -378,10 +381,22 @@ branch = %(branch)s
...
@@ -378,10 +381,22 @@ branch = %(branch)s
cwd
=
node_test_suite
.
test_suite_directory
,
cwd
=
node_test_suite
.
test_suite_directory
,
log_prefix
=
'runTestSuite'
,
get_output
=
False
)
log_prefix
=
'runTestSuite'
,
get_output
=
False
)
def
_cleanupLog
(
self
):
config
=
self
.
config
log_directory
=
self
.
config
[
'log_directory'
]
now
=
time
.
time
()
for
log_folder
in
os
.
listdir
(
log_directory
):
folder_path
=
os
.
path
.
join
(
log_directory
,
log_folder
)
if
os
.
path
.
isdir
(
folder_path
):
if
(
now
-
os
.
stat
(
folder_path
).
st_mtime
)
/
86400
>
self
.
max_log_time
:
self
.
log
(
"deleting log directory %r"
%
(
folder_path
,))
shutil
.
rmtree
(
folder_path
)
def
cleanUp
(
self
,
test_result
):
def
cleanUp
(
self
,
test_result
):
log
=
self
.
log
log
=
self
.
log
log
(
'Testnode.cleanUp'
)
log
(
'Testnode.cleanUp'
)
self
.
process_manager
.
killPreviousRun
()
self
.
process_manager
.
killPreviousRun
()
self
.
_cleanupLog
()
def
run
(
self
):
def
run
(
self
):
log
=
self
.
log
log
=
self
.
log
...
...
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