Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.toolbox
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
Lisa Casino
slapos.toolbox
Commits
687beaae
Commit
687beaae
authored
Jan 08, 2020
by
Łukasz Nowak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
monitor: Cleanup stale history.json files
parent
c163275d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
0 deletions
+29
-0
slapos/monitor/globalstate.py
slapos/monitor/globalstate.py
+15
-0
slapos/test/monitor/testglobalstate.py
slapos/test/monitor/testglobalstate.py
+14
-0
No files found.
slapos/monitor/globalstate.py
View file @
687beaae
...
...
@@ -123,6 +123,21 @@ def generateMonitoringData(config, public_folder, private_folder, public_url,
except
ValueError
:
pass
# clean up stale history files
expected_history_json_name_list
=
[
os
.
path
.
basename
(
q
).
replace
(
'status.json'
,
'history.json'
)
for
q
in
file_list
]
cleanup_history_json_path_list
=
[]
for
history_json_name
in
[
q
for
q
in
os
.
listdir
(
public_folder
)
if
q
.
endswith
(
'history.json'
)]:
if
history_json_name
not
in
expected_history_json_name_list
:
cleanup_history_json_path_list
.
append
(
os
.
path
.
join
(
public_folder
,
history_json_name
))
for
cleanup_path
in
cleanup_history_json_path_list
:
try
:
os
.
unlink
(
cleanup_path
)
except
Exception
:
print
(
'ERROR: Failed to remove stale %s'
%
(
cleanup_path
,))
else
:
print
(
'OK: Removed stale %s'
%
(
cleanup_path
,))
for
file
in
file_list
:
try
:
with
open
(
file
,
'r'
)
as
temp_file
:
...
...
slapos/test/monitor/testglobalstate.py
View file @
687beaae
...
...
@@ -166,8 +166,22 @@ exit %(code)s
self
.
assertTrue
(
os
.
path
.
exists
(
os
.
path
.
join
(
self
.
output_dir
,
'promise_4.status.json'
)))
os
.
symlink
(
self
.
output_dir
,
'%s/public/promise'
%
self
.
base_dir
)
# create files for cleanup
must_stay_public
=
os
.
path
.
join
(
self
.
public_dir
,
'must_stay'
)
must_unlink_public
=
os
.
path
.
join
(
self
.
public_dir
,
'must_unlink.history.json'
)
for
f
in
[
must_stay_public
,
must_unlink_public
]:
with
open
(
f
,
'w'
)
as
fh
:
fh
.
write
(
'data'
)
# generate instance state files
document_list_file
=
os
.
path
.
join
(
self
.
public_dir
,
'_document_list'
)
with
open
(
document_list_file
,
'a+'
)
as
fh
:
fh
.
write
(
'must_unlink.history'
)
globalstate
.
run
(
self
.
monitor_config_file
)
with
open
(
document_list_file
)
as
fh
:
self
.
assertNotIn
(
'must_unlink.history'
,
fh
.
read
())
self
.
assertTrue
(
os
.
path
.
exists
(
must_stay_public
))
self
.
assertFalse
(
os
.
path
.
exists
(
must_unlink_public
))
self
.
assertTrue
(
os
.
path
.
exists
(
os
.
path
.
join
(
self
.
public_dir
,
'feed'
)))
self
.
assertTrue
(
os
.
path
.
exists
(
os
.
path
.
join
(
self
.
public_dir
,
'monitor.global.json'
)))
self
.
assertTrue
(
os
.
path
.
exists
(
os
.
path
.
join
(
self
.
private_dir
,
'monitor.global.json'
)))
...
...
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