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
Xiaowu Zhang
slapos.toolbox
Commits
1352e00d
Commit
1352e00d
authored
Jun 09, 2022
by
Xiaowu Zhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add site check promise
parent
ca3341d5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
0 deletions
+45
-0
slapos/promise/plugin/check_site_state.py
slapos/promise/plugin/check_site_state.py
+45
-0
No files found.
slapos/promise/plugin/check_site_state.py
0 → 100644
View file @
1352e00d
from
zope.interface
import
implementer
from
slapos.grid.promise
import
interface
from
slapos.grid.promise.generic
import
GenericPromise
import
time
import
xml.etree.ElementTree
as
ET
import
sys
from
os.path
import
exists
@
implementer
(
interface
.
IPromise
)
class
RunPromise
(
GenericPromise
):
def
__init__
(
self
,
config
):
super
(
RunPromise
,
self
).
__init__
(
config
)
self
.
setPeriodicity
(
minute
=
10
)
def
sense
(
self
):
log_file
=
self
.
getConfig
(
'site-state-file'
)
file_exists
=
exists
(
log_file
)
if
not
file_exists
:
self
.
logger
.
info
(
'wait for crawler'
)
return
tree
=
ET
.
parse
(
log_file
)
root
=
tree
.
getroot
()
error
=
False
for
url
in
root
.
findall
(
'url'
):
loc
=
url
.
find
(
'loc'
).
text
referrer_tag
=
url
.
find
(
'referrer'
)
cache_control_tag
=
url
.
find
(
'stateData/headers/cache-control'
)
if
not
getattr
(
cache_control_tag
,
'text'
,
None
):
error
=
True
referrer
=
getattr
(
referrer_tag
,
'text'
,
None
)
if
referrer
:
message
=
"***%s has no cache defined in %s ---
\
n
"
%
(
loc
,
referrer
)
else
:
message
=
"***%s has no cache defined ---
\
n
"
%
loc
self
.
logger
.
error
(
message
)
if
not
error
:
self
.
logger
.
info
(
"Site is ok"
)
def
test
(
self
):
return
self
.
_test
(
result_count
=
1
,
failure_amount
=
1
)
def
anomaly
(
self
):
return
self
.
_test
(
result_count
=
3
,
failure_amount
=
3
)
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