Upgrade bind function to use murano actions

Bind call in murano service broker didn't use MuranoPL actions to get
credentials from the applications, and was barely a stub. Now it expects
action getCredentials and operate with it.

Change-Id: I60ee7410781c5f9e5438efec0c06fce5d11ab3ee
Closes-Bug: #1558242
This commit is contained in:
Nikolay Starodubtsev 2016-03-16 22:30:35 +03:00
parent d911efe7a9
commit db9ea80608
4 changed files with 52 additions and 14 deletions

View File

@ -18,6 +18,7 @@ import uuid
import muranoclient.client as client
from oslo_config import cfg
from oslo_log import log as logging
from oslo_service import loopingcall
import six
from webob import response
@ -187,7 +188,6 @@ class Controller(object):
return response.Response(status=202, json_body={})
def bind(self, req, body, instance_id, app_id):
filtered = [u'?', u'instance']
db_service = db_cf.get_service_for_instance(instance_id)
if not db_service:
return {}
@ -202,12 +202,42 @@ class Controller(object):
LOG.debug('Got environment {0}'.format(env))
service = self._get_service(env, service_id)
LOG.debug('Got service {0}'.format(service))
credentials = {}
for k, v in six.iteritems(service):
if k not in filtered:
credentials[k] = v
return {'credentials': credentials}
# NOTE(starodubcevna): Here we need to find an action which will return
# us needed credentials. By default we will looking for getCredentials
# action.
result = {}
try:
actions = service['?']['_actions']
for action_id in list(actions):
if 'getCredentials' in action_id:
@loopingcall.RetryDecorator(max_retry_count=10,
inc_sleep_time=2,
max_sleep_time=60,
exceptions=(TypeError))
def _get_creds(client, task_id, environment_id):
result = m_cli.actions.get_result(environment_id,
task_id)['result']
return result
task_id = m_cli.actions.call(environment_id, action_id)
result = _get_creds(m_cli, task_id, environment_id)
if not result:
LOG.warning(_LW("This application doesn't have action "
"getCredentials"))
return response.Response(status=500)
except KeyError:
# NOTE(starodubcevna): In CF service broker API spec return
# code for failed bind is not present, so we will return 500.
LOG.warning(_LW("This application doesn't have actions at all"))
return response.Response(status=500)
if 'credentials' in list(result):
return result
else:
return {'credentials': result}
def unbind(self, req, instance_id, app_id):
"""Unsupported functionality

View File

@ -136,13 +136,17 @@ class TestController(base.MuranoTestCase):
mock_get_si.return_value = service
services = [{'id': 'xxx-xxx-xxx',
'?': {'id': '111-111'},
'instance': {},
'smthg': 'nothing'}]
'?': {'id': '111-111',
'_actions': {
'dafsa_getCredentials': {
'name': 'getCredentials'}}},
'instance': {}}]
mock_client.return_value.environments.get =\
mock.MagicMock(return_value=mock.MagicMock(services=services))
nice_resp = {'credentials': {'smthg': 'nothing', 'id': 'xxx-xxx-xxx'}}
mock_client.return_value.actions.get_result =\
mock.MagicMock(return_value={'result': {'smthg': 'nothing'}})
nice_resp = {'credentials': {'smthg': 'nothing'}}
resp = self.controller.bind(self.request, {}, '555-555', '666-666')
self.assertEqual(nice_resp, resp)

View File

@ -16,6 +16,12 @@ Methods:
Usage: Action
Body:
- $this.find(std:Environment).reporter.report($this, 'Completed')
getCredentials:
Usage: Action
Body:
- Return:
credentials:
uri: localhost
deploy:
Body:
- $this.find(std:Environment).reporter.report($this, 'Follow the white rabbit')

View File

@ -67,9 +67,7 @@ class ServiceBrokerActionsTest(base.BaseServiceBrokerAdminTest):
app_list = self.service_broker_client.get_applications_list()
app = self.service_broker_client.get_application(application_name,
app_list)
post_json = {
"userName": application_name
}
post_json = {}
instance_id = utils.generate_uuid()
space_id = utils.generate_uuid()
service = self.service_broker_client.provision(
@ -80,7 +78,7 @@ class ServiceBrokerActionsTest(base.BaseServiceBrokerAdminTest):
self.assertIsInstance(json.loads(service), dict)
binding = self.service_broker_client.create_binding(instance_id)
self.assertIsInstance(binding, dict)
self.assertEqual(application_name, binding['userName'])
self.assertEqual({'uri': 'localhost'}, binding)
@test.attr(type=["smoke", "gate"])
def test_provision_with_incorrect_input(self):