Commit 76e8a196 authored by Łukasz Nowak's avatar Łukasz Nowak Committed by Łukasz Nowak

promise/plugin: Implement enhancements to check_url_available

Enhancements:

 * implement ignore-code
 * cover http_code
 * cover timeout
 * implement verify
 * correctly cover ca-cert-file
 * use SLAPOS_TEST_IPV4
parent c7c26219
...@@ -66,6 +66,7 @@ setup(name=name, ...@@ -66,6 +66,7 @@ setup(name=name,
}, },
tests_require = [ tests_require = [
'mock', 'mock',
'cryptography',
], ],
zip_safe=False, # proxy depends on Flask, which has issues with zip_safe=False, # proxy depends on Flask, which has issues with
# accessing templates # accessing templates
......
...@@ -25,9 +25,12 @@ class RunPromise(GenericPromise): ...@@ -25,9 +25,12 @@ class RunPromise(GenericPromise):
ca_cert_file = self.getConfig('ca-cert-file') ca_cert_file = self.getConfig('ca-cert-file')
cert_file = self.getConfig('cert-file') cert_file = self.getConfig('cert-file')
key_file = self.getConfig('key-file') key_file = self.getConfig('key-file')
verify = int(self.getConfig('verify', 0))
if ca_cert_file: if ca_cert_file:
verify = ca_cert_file verify = ca_cert_file
elif verify:
verify = True
else: else:
verify = False verify = False
...@@ -39,6 +42,14 @@ class RunPromise(GenericPromise): ...@@ -39,6 +42,14 @@ class RunPromise(GenericPromise):
try: try:
result = requests.get( result = requests.get(
url, verify=verify, allow_redirects=True, timeout=timeout, cert=cert) url, verify=verify, allow_redirects=True, timeout=timeout, cert=cert)
except requests.exceptions.SSLError as e:
if 'certificate verify failed' in str(e.message):
self.logger.error(
"ERROR SSL verify failed while accessing %r" % (url,))
else:
self.logger.error(
"ERROR Unknown SSL error %r while accessing %r" % (e, url))
return
except requests.ConnectionError as e: except requests.ConnectionError as e:
self.logger.error( self.logger.error(
"ERROR connection not possible while accessing %r" % (url, )) "ERROR connection not possible while accessing %r" % (url, ))
...@@ -49,13 +60,11 @@ class RunPromise(GenericPromise): ...@@ -49,13 +60,11 @@ class RunPromise(GenericPromise):
http_code = result.status_code http_code = result.status_code
check_secure = int(self.getConfig('check-secure', 0)) check_secure = int(self.getConfig('check-secure', 0))
ignore_code = int(self.getConfig('ignore-code', 0))
if http_code == 0: if http_code == 401 and check_secure == 1:
self.logger.error("%s is not available (server not reachable)." % url)
elif http_code == 401 and check_secure == 1:
self.logger.info("%r is protected (returned %s)." % (url, http_code)) self.logger.info("%r is protected (returned %s)." % (url, http_code))
elif not ignore_code and http_code != expected_http_code:
elif http_code != expected_http_code:
self.logger.error("%r is not available (returned %s, expected %s)." % ( self.logger.error("%r is not available (returned %s, expected %s)." % (
url, http_code, expected_http_code)) url, http_code, expected_http_code))
else: else:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment