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
Thomas Leymonerie
slapos.toolbox
Commits
cd0fb8f8
Commit
cd0fb8f8
authored
Jun 13, 2019
by
Łukasz Nowak
Committed by
Łukasz Nowak
Jun 13, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
promise/plugin: Convert check_url_available to requests
It will be easier to improve it soon.
parent
d5aaf706
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
23 deletions
+22
-23
slapos/promise/plugin/check_url_available.py
slapos/promise/plugin/check_url_available.py
+19
-20
slapos/test/promise/plugin/test_check_url_available.py
slapos/test/promise/plugin/test_check_url_available.py
+3
-3
No files found.
slapos/promise/plugin/check_url_available.py
View file @
cd0fb8f8
...
...
@@ -2,7 +2,7 @@ from zope import interface as zope_interface
from
slapos.grid.promise
import
interface
from
slapos.grid.promise.generic
import
GenericPromise
import
os
import
pycurl
import
requests
class
RunPromise
(
GenericPromise
):
...
...
@@ -21,33 +21,32 @@ class RunPromise(GenericPromise):
url
=
self
.
getConfig
(
'url'
)
timeout
=
int
(
self
.
getConfig
(
'timeout'
,
20
))
expected_http_code
=
int
(
self
.
getConfig
(
'http_code'
,
'200'
))
curl
=
pycurl
.
Curl
()
curl
.
setopt
(
pycurl
.
URL
,
url
)
curl
.
setopt
(
pycurl
.
TIMEOUT
,
timeout
)
curl
.
setopt
(
pycurl
.
FOLLOWLOCATION
,
True
)
curl
.
setopt
(
pycurl
.
SSL_VERIFYPEER
,
False
)
curl
.
setopt
(
pycurl
.
SSL_VERIFYHOST
,
False
)
curl
.
setopt
(
pycurl
.
WRITEFUNCTION
,
lambda
x
:
None
)
ca_cert_file
=
self
.
getConfig
(
'ca-cert-file'
)
cert_file
=
self
.
getConfig
(
'cert-file'
)
key_file
=
self
.
getConfig
(
'key-file'
)
if
key_file
and
cert_file
and
ca_cert_file
:
# set certificate configuration
curl
.
setopt
(
curl
.
CAINFO
,
ca_cert_file
)
curl
.
setopt
(
curl
.
SSLCERT
,
cert_file
)
curl
.
setopt
(
curl
.
SSLKEY
,
key_file
)
if
ca_cert_file
:
verify
=
ca_cert_file
else
:
verify
=
False
if
key_file
and
cert_file
:
cert
=
(
cert_file
,
key_file
)
else
:
cert
=
None
try
:
curl
.
perform
()
except
pycurl
.
error
,
e
:
code
,
message
=
e
self
.
logger
.
error
(
"%s: %s"
%
(
code
,
message
))
result
=
requests
.
get
(
url
,
verify
=
verify
,
allow_redirects
=
True
,
timeout
=
timeout
,
cert
=
cert
)
except
requests
.
ConnectionError
as
e
:
self
.
logger
.
error
(
"ERROR connection not possible while accessing %r"
%
(
url
,
))
return
except
Exception
,
e
:
self
.
logger
.
error
(
"ERROR: %s"
%
(
e
,))
return
http_code
=
curl
.
getinfo
(
pycurl
.
HTTP_CODE
)
http_code
=
result
.
status_code
check_secure
=
self
.
getConfig
(
'check-secure'
)
curl
.
close
()
if
http_code
==
0
:
self
.
logger
.
error
(
"%s is not available (server not reachable)."
%
url
)
...
...
slapos/test/promise/plugin/test_check_url_available.py
View file @
cd0fb8f8
...
...
@@ -59,7 +59,7 @@ extra_config_dict = {
self
.
launcher
.
run
()
result
=
self
.
getPromiseResult
(
self
.
promise_name
)
self
.
assertEqual
(
result
[
'result'
][
'failed'
],
True
)
self
.
assertEqual
(
result
[
'result'
][
'message'
],
"
3: Bad URL
"
)
self
.
assertEqual
(
result
[
'result'
][
'message'
],
"
ERROR: Invalid URL u'https://': No host supplied
"
)
def
test_check_url_malformed
(
self
):
content
=
self
.
base_content
%
{
...
...
@@ -73,7 +73,7 @@ extra_config_dict = {
self
.
launcher
.
run
()
result
=
self
.
getPromiseResult
(
self
.
promise_name
)
self
.
assertEqual
(
result
[
'result'
][
'failed'
],
True
)
self
.
assertEqual
(
result
[
'result'
][
'message'
],
"
3: <url> malformed
"
)
self
.
assertEqual
(
result
[
'result'
][
'message'
],
"
ERROR: Invalid URL '': No schema supplied. Perhaps you meant http://?
"
)
def
test_check_url_site_off
(
self
):
content
=
content
=
self
.
base_content
%
{
...
...
@@ -87,7 +87,7 @@ extra_config_dict = {
self
.
launcher
.
run
()
result
=
self
.
getPromiseResult
(
self
.
promise_name
)
self
.
assertEqual
(
result
[
'result'
][
'failed'
],
True
)
self
.
assertEqual
(
result
[
'result'
][
'message'
],
"
7: Failed to connect to localhost port 56789: Connection refused
"
)
self
.
assertEqual
(
result
[
'result'
][
'message'
],
"
ERROR connection not possible while accessing 'https://localhost:56789/site'
"
)
if
__name__
==
'__main__'
:
unittest
.
main
()
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