Commit 0920b1c7 authored by Łukasz Nowak's avatar Łukasz Nowak

promise/plugin: check_url_available implement ignore-code

For ignore-code=1 any HTTP status code is ok.
parent 7f411df4
...@@ -49,13 +49,11 @@ class RunPromise(GenericPromise): ...@@ -49,13 +49,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:
......
...@@ -81,6 +81,7 @@ extra_config_dict = { ...@@ -81,6 +81,7 @@ extra_config_dict = {
'url': '%(url)s', 'url': '%(url)s',
'timeout': %(timeout)s, 'timeout': %(timeout)s,
'check-secure': %(check_secure)s, 'check-secure': %(check_secure)s,
'ignore-code': %(ignore_code)s,
} }
""" """
...@@ -91,7 +92,8 @@ extra_config_dict = { ...@@ -91,7 +92,8 @@ extra_config_dict = {
content = self.base_content % { content = self.base_content % {
'url': 'https://', 'url': 'https://',
'timeout': 10, 'timeout': 10,
'check_secure': 0 'check_secure': 0,
'ignore_code': 0,
} }
self.writePromise(self.promise_name, content) self.writePromise(self.promise_name, content)
self.configureLauncher() self.configureLauncher()
...@@ -108,7 +110,8 @@ extra_config_dict = { ...@@ -108,7 +110,8 @@ extra_config_dict = {
content = self.base_content % { content = self.base_content % {
'url': '', 'url': '',
'timeout': 10, 'timeout': 10,
'check_secure': 0 'check_secure': 0,
'ignore_code': 0,
} }
self.writePromise(self.promise_name, content) self.writePromise(self.promise_name, content)
self.configureLauncher() self.configureLauncher()
...@@ -125,7 +128,8 @@ extra_config_dict = { ...@@ -125,7 +128,8 @@ extra_config_dict = {
content = content = self.base_content % { content = content = self.base_content % {
'url': 'https://localhost:56789/site', 'url': 'https://localhost:56789/site',
'timeout': 10, 'timeout': 10,
'check_secure': 0 'check_secure': 0,
'ignore_code': 0,
} }
self.writePromise(self.promise_name, content) self.writePromise(self.promise_name, content)
self.configureLauncher() self.configureLauncher()
...@@ -144,7 +148,8 @@ extra_config_dict = { ...@@ -144,7 +148,8 @@ extra_config_dict = {
content = content = self.base_content % { content = content = self.base_content % {
'url': url, 'url': url,
'timeout': 10, 'timeout': 10,
'check_secure': 0 'check_secure': 0,
'ignore_code': 0,
} }
self.writePromise(self.promise_name, content) self.writePromise(self.promise_name, content)
self.configureLauncher() self.configureLauncher()
...@@ -161,7 +166,8 @@ extra_config_dict = { ...@@ -161,7 +166,8 @@ extra_config_dict = {
content = content = self.base_content % { content = content = self.base_content % {
'url': url, 'url': url,
'timeout': 10, 'timeout': 10,
'check_secure': 0 'check_secure': 0,
'ignore_code': 0,
} }
self.writePromise(self.promise_name, content) self.writePromise(self.promise_name, content)
self.configureLauncher() self.configureLauncher()
...@@ -174,12 +180,31 @@ extra_config_dict = { ...@@ -174,12 +180,31 @@ extra_config_dict = {
"%r is not available (returned 401, expected 200)." % (url,) "%r is not available (returned 401, expected 200)." % (url,)
) )
def test_check_401_secure(self): def test_check_401_ignore_code(self):
url = HTTPS_ENDPOINT + '401' url = HTTPS_ENDPOINT + '401'
content = content = self.base_content % { content = content = self.base_content % {
'url': url, 'url': url,
'timeout': 10, 'timeout': 10,
'check_secure': 1 'check_secure': 0,
'ignore_code': 1,
}
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'],
"%r is available" % (url,)
)
def test_check_401_check_secure(self):
url = HTTPS_ENDPOINT + '401'
content = content = self.base_content % {
'url': url,
'timeout': 10,
'check_secure': 1,
'ignore_code': 0,
} }
self.writePromise(self.promise_name, content) self.writePromise(self.promise_name, content)
self.configureLauncher() self.configureLauncher()
......
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