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
Xavier Thompson
slapos.toolbox
Commits
b63368f4
Commit
b63368f4
authored
Sep 08, 2020
by
Kazuhiko Shiozaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
check_surykatka_json: support http-header-dict.
parent
8d50d018
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
80 additions
and
0 deletions
+80
-0
slapos/promise/plugin/check_surykatka_json.py
slapos/promise/plugin/check_surykatka_json.py
+12
-0
slapos/test/promise/plugin/test_check_surykatka_json.py
slapos/test/promise/plugin/test_check_surykatka_json.py
+68
-0
No files found.
slapos/promise/plugin/check_surykatka_json.py
View file @
b63368f4
...
...
@@ -162,6 +162,7 @@ class RunPromise(GenericPromise):
url
=
self
.
getConfig
(
'url'
)
status_code
=
self
.
getConfig
(
'status-code'
)
ip_list
=
self
.
getConfig
(
'ip-list'
,
''
).
split
()
http_header_dict
=
json
.
loads
(
self
.
getConfig
(
'http-header-dict'
,
'{}'
))
entry_list
=
[
q
for
q
in
self
.
surykatka_json
[
key
]
if
q
[
'url'
]
==
url
]
if
len
(
entry_list
)
==
0
:
...
...
@@ -181,6 +182,13 @@ class RunPromise(GenericPromise):
'IP %s got status code %s instead of %s'
%
(
entry
[
'ip'
],
status_code_explanation
,
status_code
))
error
=
True
if
http_header_dict
and
http_header_dict
!=
entry
[
'http_header_dict'
]:
appendError
(
'HTTP Header dict was %s instead of %s'
%
(
json
.
dumps
(
entry
[
'http_header_dict'
],
sort_keys
=
True
),
json
.
dumps
(
http_header_dict
,
sort_keys
=
True
),
))
error
=
True
db_ip_list
=
[
q
[
'ip'
]
for
q
in
entry_list
]
if
len
(
ip_list
):
if
set
(
ip_list
)
!=
set
(
db_ip_list
):
...
...
@@ -191,6 +199,10 @@ class RunPromise(GenericPromise):
if
error
:
return
info_message
=
'%s: OK with status code %s'
%
(
key
,
status_code
)
if
http_header_dict
:
info_message
+=
' and HTTP Header dict %s'
%
(
json
.
dumps
(
http_header_dict
,
sort_keys
=
True
),
)
if
len
(
ip_list
)
>
0
:
info_message
+=
' on IPs %s'
%
(
' '
.
join
(
ip_list
))
self
.
appendInfoMessage
(
info_message
)
...
...
slapos/test/promise/plugin/test_check_surykatka_json.py
View file @
b63368f4
...
...
@@ -519,6 +519,74 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
"127.0.0.2"
)
def
test_http_with_header_dict
(
self
):
self
.
writeSurykatkaPromise
(
{
'report'
:
'http_query'
,
'json-file'
:
self
.
json_file
,
'url'
:
'http://www.erp5.com/'
,
'status-code'
:
'200'
,
'http-header-dict'
:
'{"Vary": "Accept-Encoding", "Cache-Control": "max-age=300, public"}'
,
'test-utcnow'
:
'Fri, 27 Dec 2019 15:11:12 -0000'
}
)
self
.
writeSurykatkaJson
(
"""{
"http_query": [
{
"date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "176.31.129.213",
"http_header_dict": {"Vary": "Accept-Encoding", "Cache-Control": "max-age=300, public"},
"status_code": 200,
"url": "http://www.erp5.com/"
}
],
"ssl_certificate": [
]
}
"""
)
self
.
configureLauncher
(
enable_anomaly
=
True
)
self
.
launcher
.
run
()
self
.
assertPassedMessage
(
self
.
getPromiseResult
(
self
.
promise_name
),
"http://www.erp5.com/ : http_query: OK with status code 200 "
"and HTTP Header dict {
\
"
Cache-Control
\
"
:
\
"
max-age=300, public
\
"
,
\
"
Vary
\
"
:
\
"
Accept-Encoding
\
"
}"
)
def
test_http_with_bad_header_dict
(
self
):
self
.
writeSurykatkaPromise
(
{
'report'
:
'http_query'
,
'json-file'
:
self
.
json_file
,
'url'
:
'http://www.erp5.com/'
,
'status-code'
:
'200'
,
'http-header-dict'
:
'{"Vary": "Accept-Encoding", "Cache-Control": "max-age=300, public"}'
,
'test-utcnow'
:
'Fri, 27 Dec 2019 15:11:12 -0000'
}
)
self
.
writeSurykatkaJson
(
"""{
"http_query": [
{
"date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "176.31.129.213",
"http_header_dict": {"Vary": "Accept-Encoding,Cookie", "Cache-Control": "max-age=300, public"},
"status_code": 200,
"url": "http://www.erp5.com/"
}
],
"ssl_certificate": [
]
}
"""
)
self
.
configureLauncher
(
enable_anomaly
=
True
)
with
self
.
assertRaises
(
PromiseError
):
self
.
launcher
.
run
()
self
.
assertFailedMessage
(
self
.
getPromiseResult
(
self
.
promise_name
),
"http://www.erp5.com/ : http_query: ERROR HTTP Header dict was "
"{
\
"
Cache-Control
\
"
:
\
"
max-age=300, public
\
"
,
\
"
Vary
\
"
:
\
"
Accept-Encoding,Cookie
\
"
} "
"instead of {
\
"
Cache-Control
\
"
:
\
"
max-age=300, public
\
"
,
\
"
Vary
\
"
:
\
"
Accept-Encoding
\
"
}"
)
def
test_no_ip_list
(
self
):
self
.
writeSurykatkaPromise
(
{
...
...
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