Support ssl cert verification on outgoing https

Added the verify parameter to HttpAction class so that a ca bundle
 can be used to verify ssl certs when making outgoing https calls
 via HttpAction
Modified unit tests to expect added parameter
Corrected name of test_inspect_utils.py as it was under the knife
 in any case

Change-Id: I444b22eabf7c48db62f29a59421aaa290b5f0cd7
Closes-Bug: #1421167
This commit is contained in:
David C Kennedy 2015-02-12 11:22:46 +00:00
parent 568dd2cebb
commit 65a9d16a60
6 changed files with 27 additions and 14 deletions

View File

@ -118,6 +118,8 @@ class HTTPAction(base.Action):
redirect following is allowed. redirect following is allowed.
:param proxies: (optional) Dictionary mapping protocol to the URL of :param proxies: (optional) Dictionary mapping protocol to the URL of
the proxy. the proxy.
:param verify: (optional) if ``True``, the SSL cert will be verified.
A CA_BUNDLE path can also be provided.
""" """
def __init__(self, def __init__(self,
@ -130,7 +132,8 @@ class HTTPAction(base.Action):
auth=None, auth=None,
timeout=None, timeout=None,
allow_redirects=None, allow_redirects=None,
proxies=None): proxies=None,
verify=None):
if auth and len(auth.split(':')) == 2: if auth and len(auth.split(':')) == 2:
self.auth = (auth.split(':')[0], auth.split(':')[1]) self.auth = (auth.split(':')[0], auth.split(':')[1])
@ -146,12 +149,13 @@ class HTTPAction(base.Action):
self.timeout = timeout self.timeout = timeout
self.allow_redirects = allow_redirects self.allow_redirects = allow_redirects
self.proxies = proxies self.proxies = proxies
self.verify = verify
def run(self): def run(self):
LOG.info("Running HTTP action " LOG.info("Running HTTP action "
"[url=%s, method=%s, params=%s, body=%s, headers=%s," "[url=%s, method=%s, params=%s, body=%s, headers=%s,"
" cookies=%s, auth=%s, timeout=%s, allow_redirects=%s," " cookies=%s, auth=%s, timeout=%s, allow_redirects=%s,"
" proxies=%s]" % " proxies=%s, verify=%s]" %
(self.url, (self.url,
self.method, self.method,
self.params, self.params,
@ -161,7 +165,8 @@ class HTTPAction(base.Action):
self.auth, self.auth,
self.timeout, self.timeout,
self.allow_redirects, self.allow_redirects,
self.proxies)) self.proxies,
self.verify))
try: try:
resp = requests.request( resp = requests.request(
@ -174,7 +179,8 @@ class HTTPAction(base.Action):
auth=self.auth, auth=self.auth,
timeout=self.timeout, timeout=self.timeout,
allow_redirects=self.allow_redirects, allow_redirects=self.allow_redirects,
proxies=self.proxies proxies=self.proxies,
verify=self.verify
) )
except Exception as e: except Exception as e:
raise exc.ActionException("Failed to send HTTP request: %s" % e) raise exc.ActionException("Failed to send HTTP request: %s" % e)
@ -216,7 +222,8 @@ class MistralHTTPAction(HTTPAction):
auth=None, auth=None,
timeout=None, timeout=None,
allow_redirects=None, allow_redirects=None,
proxies=None): proxies=None,
verify=None):
headers = headers or {} headers = headers or {}
headers.update({ headers.update({
'Mistral-Workflow-Name': action_context.get('workflow_name'), 'Mistral-Workflow-Name': action_context.get('workflow_name'),
@ -235,6 +242,7 @@ class MistralHTTPAction(HTTPAction):
timeout, timeout,
allow_redirects, allow_redirects,
proxies, proxies,
verify,
) )
def is_sync(self): def is_sync(self):

View File

@ -80,7 +80,8 @@ class HTTPActionTest(base.BaseTest):
timeout=20, timeout=20,
auth=None, auth=None,
allow_redirects=True, allow_redirects=True,
proxies=None proxies=None,
verify=None
) )
@mock.patch.object(requests, "request") @mock.patch.object(requests, "request")
@ -115,5 +116,6 @@ class HTTPActionTest(base.BaseTest):
timeout=None, timeout=None,
auth=('user', 'password'), auth=('user', 'password'),
allow_redirects=None, allow_redirects=None,
proxies=None proxies=None,
verify=None
) )

View File

@ -92,4 +92,4 @@ class ActionContextTest(base.EngineTestCase):
requests.request.assert_called_with( requests.request.assert_called_with(
'GET', 'https://wiki.openstack.org/wiki/mistral', 'GET', 'https://wiki.openstack.org/wiki/mistral',
params=None, data=None, headers=headers, cookies=None, auth=None, params=None, data=None, headers=headers, cookies=None, auth=None,
timeout=None, allow_redirects=None, proxies=None) timeout=None, allow_redirects=None, proxies=None, verify=None)

View File

@ -134,7 +134,8 @@ class ActionDefaultTest(base.EngineTestCase):
requests.request.assert_called_with( requests.request.assert_called_with(
'GET', 'https://api.library.org/books', 'GET', 'https://api.library.org/books',
params=None, data=None, headers=None, cookies=None, params=None, data=None, headers=None, cookies=None,
allow_redirects=None, proxies=None, auth=EXPECTED_ENV_AUTH, allow_redirects=None, proxies=None, verify=None,
auth=EXPECTED_ENV_AUTH,
timeout=ENV['__actions']['std.http']['timeout']) timeout=ENV['__actions']['std.http']['timeout'])
@mock.patch.object( @mock.patch.object(
@ -158,7 +159,8 @@ class ActionDefaultTest(base.EngineTestCase):
requests.request.assert_called_with( requests.request.assert_called_with(
'GET', 'https://api.library.org/books', 'GET', 'https://api.library.org/books',
params=None, data=None, headers=None, cookies=None, params=None, data=None, headers=None, cookies=None,
allow_redirects=None, proxies=None, auth=EXPECTED_ENV_AUTH, allow_redirects=None, proxies=None, verify=None,
auth=EXPECTED_ENV_AUTH,
timeout=60) timeout=60)
@mock.patch.object( @mock.patch.object(
@ -191,7 +193,7 @@ class ActionDefaultTest(base.EngineTestCase):
calls = [mock.call('GET', url, params=None, data=None, calls = [mock.call('GET', url, params=None, data=None,
headers=None, cookies=None, headers=None, cookies=None,
allow_redirects=None, proxies=None, allow_redirects=None, proxies=None,
auth=EXPECTED_ENV_AUTH, auth=EXPECTED_ENV_AUTH, verify=None,
timeout=ENV['__actions']['std.http']['timeout']) timeout=ENV['__actions']['std.http']['timeout'])
for url in wf_input['links']] for url in wf_input['links']]
@ -227,7 +229,8 @@ class ActionDefaultTest(base.EngineTestCase):
calls = [mock.call('GET', url, params=None, data=None, calls = [mock.call('GET', url, params=None, data=None,
headers=None, cookies=None, headers=None, cookies=None,
allow_redirects=None, proxies=None, allow_redirects=None, proxies=None,
auth=EXPECTED_ENV_AUTH, timeout=60) auth=EXPECTED_ENV_AUTH, verify=None,
timeout=60)
for url in wf_input['links']] for url in wf_input['links']]
requests.request.assert_has_calls(calls, any_order=True) requests.request.assert_has_calls(calls, any_order=True)

View File

@ -25,7 +25,7 @@ class ActionManagerTest(base.DbTestCase):
"url, method=GET, params=None, body=None, " "url, method=GET, params=None, body=None, "
"headers=None, cookies=None, auth=None, " "headers=None, cookies=None, auth=None, "
"timeout=None, allow_redirects=None, " "timeout=None, allow_redirects=None, "
"proxies=None" "proxies=None, verify=None"
) )
self.assertEqual(http_action_input, std_http.input) self.assertEqual(http_action_input, std_http.input)

View File

@ -26,7 +26,7 @@ class InspectUtilsTest(base.BaseTest):
"url, method=GET, params=None, body=None, " "url, method=GET, params=None, body=None, "
"headers=None, cookies=None, auth=None, " "headers=None, cookies=None, auth=None, "
"timeout=None, allow_redirects=None, " "timeout=None, allow_redirects=None, "
"proxies=None" "proxies=None, verify=None"
) )
self.assertEqual(http_action_params, parameters_str) self.assertEqual(http_action_params, parameters_str)