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
Joanne Hugé
slapos.toolbox
Commits
2c955c9a
Commit
2c955c9a
authored
Sep 22, 2023
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Plain Diff
check_url_available: new allow-redirects option
See merge request
!119
parents
268a82ae
90d828ae
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
64 additions
and
12 deletions
+64
-12
setup.py
setup.py
+1
-3
slapos/promise/check_slow_queries_digest_result/__init__.py
slapos/promise/check_slow_queries_digest_result/__init__.py
+1
-3
slapos/promise/plugin/check_url_available.py
slapos/promise/plugin/check_url_available.py
+4
-1
slapos/test/promise/plugin/test_check_url_available.py
slapos/test/promise/plugin/test_check_url_available.py
+57
-3
slapos/test/promise/test_check_slow_queries_digest_result.py
slapos/test/promise/test_check_slow_queries_digest_result.py
+1
-2
No files found.
setup.py
View file @
2c955c9a
...
...
@@ -44,7 +44,6 @@ setup(name=name,
'croniter'
,
# needed to know cron schedule
'pytz'
,
# needed to manipulate timezone
'tzlocal'
,
# needed to manipulate timezone
'backports.lzma'
,
'netifaces'
,
'erp5.util'
,
'PyRSS2Gen'
,
...
...
@@ -56,8 +55,7 @@ setup(name=name,
'six'
,
'cryptography'
,
'click'
,
'websocket-client; python_version>="3"'
,
'ipaddress; python_version<"3"'
,
'websocket-client'
,
),
extras_require
=
{
'lampconfigure'
:
[
"mysqlclient"
],
#needed for MySQL Database access
...
...
slapos/promise/check_slow_queries_digest_result/__init__.py
View file @
2c955c9a
...
...
@@ -4,8 +4,6 @@
Check if a mariadb result matches the desired threshold or raises an error.
"""
from
__future__
import
print_function
import
json
import
os
import
re
...
...
@@ -13,7 +11,7 @@ import sys
import
time
import
datetime
import
argparse
from
backports
import
lzma
import
lzma
def
checkMariadbDigestResult
(
mariadbdex_path
,
mariadbdex_report_status_file
,
max_query_threshold
,
slowest_query_threshold
):
...
...
slapos/promise/plugin/check_url_available.py
View file @
2c955c9a
...
...
@@ -11,6 +11,9 @@ Some notable parameters:
(default 200) The expected response HTTP code.
ignore-code:
(default 0) If set to 1, ignore the response HTTP code.
allow-redirects:
(default 1) If set to 1, follow Location header on HTTP redirect status code.
If set to 0, does not follow and use the redirect response.
username, password:
If supplied, enables basic HTTP authentication.
"""
...
...
@@ -72,7 +75,7 @@ class RunPromise(GenericPromise):
request_type
=
"non-authenticated"
request_options
=
{
'allow_redirects'
:
True
,
'allow_redirects'
:
bool
(
int
(
self
.
getConfig
(
'allow-redirects'
,
1
)))
,
'timeout'
:
int
(
self
.
getConfig
(
'timeout'
,
default_timeout
)),
'verify'
:
verify
,
'cert'
:
cert
,
...
...
slapos/test/promise/plugin/test_check_url_available.py
View file @
2c955c9a
...
...
@@ -191,6 +191,7 @@ class TestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
class
CheckUrlAvailableMixin
(
TestPromisePluginMixin
):
RequestHandler
=
TestHandler
@
classmethod
def
setUpClass
(
cls
):
cls
.
another_server_ca
=
CertificateAuthority
(
u"Another Server Root CA"
)
...
...
@@ -221,7 +222,7 @@ class CheckUrlAvailableMixin(TestPromisePluginMixin):
def
server
():
server
=
BaseHTTPServer
.
HTTPServer
(
(
SLAPOS_TEST_IPV4
,
SLAPOS_TEST_IPV4_PORT
),
T
estHandler
)
cls
.
Requ
estHandler
)
server
.
socket
=
ssl
.
wrap_socket
(
server
.
socket
,
certfile
=
cls
.
test_server_certificate_file
.
name
,
...
...
@@ -313,9 +314,11 @@ class TestCheckUrlAvailable(CheckUrlAvailableMixin):
self
.
launcher
.
run
()
result
=
self
.
getPromiseResult
(
self
.
promise_name
)
self
.
assertEqual
(
result
[
'result'
][
'failed'
],
True
)
self
.
assert
Equal
(
self
.
assert
In
(
result
[
'result'
][
'message'
],
"ERROR: Invalid URL '': No scheme supplied. Perhaps you meant http://?"
(
"ERROR: Invalid URL '': No scheme supplied. Perhaps you meant https://?"
,
# BBB requests < 2.28.2
"ERROR: Invalid URL '': No scheme supplied. Perhaps you meant http://?"
)
)
def
test_check_url_site_off
(
self
):
...
...
@@ -628,5 +631,56 @@ class TestCheckUrlAvailableTimeout(CheckUrlAvailableMixin):
)
class
TestCheckUrlAvailableRedirect
(
CheckUrlAvailableMixin
):
class
RequestHandler
(
BaseHTTPServer
.
BaseHTTPRequestHandler
):
def
do_GET
(
self
):
if
self
.
path
==
'/'
:
self
.
send_response
(
302
)
self
.
send_header
(
'Location'
,
'/redirected'
)
self
.
end_headers
()
self
.
wfile
.
write
(
b'see /redirected'
)
elif
self
.
path
==
'/redirected'
:
self
.
send_response
(
200
)
self
.
end_headers
()
self
.
wfile
.
write
(
b'OK'
)
else
:
self
.
send_response
(
400
)
self
.
end_headers
()
self
.
wfile
.
write
(
b'Unexepected path: '
+
self
.
path
.
encode
())
def
test_check_redirected_follow_redirect
(
self
):
url
=
HTTPS_ENDPOINT
content
=
self
.
make_content
({
'url'
:
url
,
'http-code'
:
'200'
,
})
self
.
writePromise
(
self
.
promise_name
,
content
)
self
.
configureLauncher
()
self
.
launcher
.
run
()
result
=
self
.
getPromiseResult
(
self
.
promise_name
)
self
.
assertEqual
(
result
[
'result'
][
'failed'
],
False
)
self
.
assertEqual
(
result
[
'result'
][
'message'
],
self
.
success_template
%
(
url
,
200
)
)
def
test_check_redirected_not_follow_redirect
(
self
):
url
=
HTTPS_ENDPOINT
content
=
self
.
make_content
({
'url'
:
url
,
'allow-redirects'
:
'0'
,
'http-code'
:
'302'
,
})
self
.
writePromise
(
self
.
promise_name
,
content
)
self
.
configureLauncher
()
self
.
launcher
.
run
()
result
=
self
.
getPromiseResult
(
self
.
promise_name
)
self
.
assertEqual
(
result
[
'result'
][
'failed'
],
False
)
self
.
assertEqual
(
result
[
'result'
][
'message'
],
self
.
success_template
%
(
url
,
302
)
)
if
__name__
==
'__main__'
:
unittest
.
main
()
slapos/test/promise/test_check_slow_queries_digest_result.py
View file @
2c955c9a
...
...
@@ -24,7 +24,6 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from
__future__
import
unicode_literals
import
unittest
import
os
import
time
...
...
@@ -32,7 +31,7 @@ import tempfile
import
datetime
import
shutil
import
codecs
from
backports
import
lzma
import
lzma
from
.
import
data
from
slapos.promise.check_slow_queries_digest_result
import
checkMariadbDigestResult
...
...
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