Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Romain Courteaud
erp5
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
Show 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
TaskDistributionTool
.
createTestResult
=
original_createTestResult
test_node
.
_prepareSlapOS
=
original_prepareSlapOS
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
from
erp5.util
import
taskdistribution
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
PROFILE_PATH_KEY
=
'profile_path'
...
...
@@ -141,7 +143,7 @@ class NodeTestSuite(SlapOSInstance):
class
TestNode
(
object
):
def
__init__
(
self
,
log
,
config
):
def
__init__
(
self
,
log
,
config
,
max_log_time
=
MAX_LOG_TIME
):
self
.
testnode_log
=
log
self
.
log
=
log
self
.
config
=
config
or
{}
...
...
@@ -151,6 +153,7 @@ class TestNode(object):
if
self
.
config
.
get
(
'working_directory'
,
''
).
endswith
(
"slapos/"
):
self
.
config
[
'working_directory'
]
=
self
.
config
[
'working_directory'
][:
-
(
len
(
"slapos/"
))]
+
"testnode"
self
.
max_log_time
=
max_log_time
def
checkOldTestSuite
(
self
,
test_suite_data
):
config
=
self
.
config
...
...
@@ -378,10 +381,22 @@ branch = %(branch)s
cwd
=
node_test_suite
.
test_suite_directory
,
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
):
log
=
self
.
log
log
(
'Testnode.cleanUp'
)
self
.
process_manager
.
killPreviousRun
()
self
.
_cleanupLog
()
def
run
(
self
):
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