ovo - switch credential calls

This switches the Credential DB calls to use Credential objects.

Change-Id: I202e71965faf0cf2126e2bfb8d049253b3168cd1
This commit is contained in:
tengqm 2016-05-27 00:50:37 -04:00 committed by Qiming Teng
parent b1501cd0a7
commit a76e43fc83
9 changed files with 36 additions and 35 deletions

View File

@ -144,7 +144,7 @@ pygments_style = 'sphinx'
# using the given strftime format.
# html_last_updated_fmt = '%b %d, %Y'
git_cmd = ["git", "log", "--pretty=format:'%ad, commit %h'", "--date=local",
"-n1"]
"-n1"]
html_last_updated_fmt = subprocess.Popen(
git_cmd, stdout=subprocess.PIPE).communicate()[0]

View File

@ -18,7 +18,7 @@ from six.moves.urllib import parse
from senlin.common import consts
from senlin.common import exception
from senlin.common import utils
from senlin.db import api as db_api
from senlin.objects import credential as co
from senlin.objects import receiver as ro
CONF = cfg.CONF
@ -94,7 +94,7 @@ class Receiver(object):
cdata = dict()
if context.is_admin:
# use object owner if request is from admin
cred = db_api.cred_get(context, cluster.user, cluster.project)
cred = co.Credential.get(context, cluster.user, cluster.project)
trust_id = cred['cred']['openstack']['trust']
cdata['trust_id'] = trust_id
else:

View File

@ -43,6 +43,7 @@ from senlin.engine import health_manager
from senlin.engine import node as node_mod
from senlin.engine import receiver as receiver_mod
from senlin.engine import scheduler
from senlin.objects import credential as cred_obj
from senlin.objects import event as event_obj
from senlin.objects import node as node_obj
from senlin.objects import policy as policy_obj
@ -205,7 +206,7 @@ class EngineService(service.Service):
}
}
}
db_api.cred_create_update(context, values)
cred_obj.Credential.update_or_create(context, values)
return {'cred': cred}
@request_context
@ -221,7 +222,7 @@ class EngineService(service.Service):
:return: A dictionary containing the persistent credential, or None
if no matching credential is found.
"""
res = db_api.cred_get(context, context.user, context.project)
res = cred_obj.Credential.get(context, context.user, context.project)
if res is None:
return None
return res.cred.get('openstack', None)
@ -239,8 +240,8 @@ class EngineService(service.Service):
the credential.
:return: A dictionary containing the updated credential.
"""
db_api.cred_update(context, context.user, context.project,
{'cred': {'openstack': {'trust': cred}}})
cred_obj.Credential.update(context, context.user, context.project,
{'cred': {'openstack': {'trust': cred}}})
return {'cred': cred}
@request_context

View File

@ -25,8 +25,8 @@ class Credential(senlin_base.SenlinObject, base.VersionedObjectDictCompat):
fields = {
'user': fields.StringField(),
'project': fields.StringField(),
'cred': fields.DictOfStringField(),
'data': fields.DictOfStringField(),
'cred': fields.DictOfStringsField(),
'data': fields.DictOfStringsField(),
}
@staticmethod

View File

@ -19,8 +19,8 @@ from senlin.common import exception
from senlin.common.i18n import _
from senlin.common import schema
from senlin.common import utils
from senlin.db import api as db_api
from senlin.engine import environment
from senlin.objects import credential as co
from senlin.objects import policy as po
CHECK_RESULTS = (
@ -289,8 +289,8 @@ class Policy(object):
'user_domain_name': service_creds.get('user_domain_name')
}
cred = db_api.cred_get(oslo_context.get_current(),
cluster.user, cluster.project)
cred = co.Credential.get(oslo_context.get_current(),
cluster.user, cluster.project)
if cred is None:
raise exception.TrustNotFound(trustor=cluster.user)
params['trust_id'] = cred.cred['openstack']['trust']

View File

@ -23,9 +23,9 @@ from senlin.common.i18n import _
from senlin.common.i18n import _LE
from senlin.common import schema
from senlin.common import utils
from senlin.db import api as db_api
from senlin.engine import environment
from senlin.objects import profile as profile_obj
from senlin.objects import credential as co
from senlin.objects import profile as po
LOG = logging.getLogger(__name__)
@ -135,8 +135,8 @@ class Profile(object):
def load(cls, ctx, profile=None, profile_id=None, project_safe=True):
'''Retrieve a profile object from database.'''
if profile is None:
profile = profile_obj.Profile.get(ctx, profile_id,
project_safe=project_safe)
profile = po.Profile.get(ctx, profile_id,
project_safe=project_safe)
if profile is None:
raise exception.ProfileNotFound(profile=profile_id)
@ -147,16 +147,16 @@ class Profile(object):
project_safe=True):
"""Retrieve all profiles from database."""
records = profile_obj.Profile.get_all(ctx, limit=limit, marker=marker,
sort=sort, filters=filters,
project_safe=project_safe)
records = po.Profile.get_all(ctx, limit=limit, marker=marker,
sort=sort, filters=filters,
project_safe=project_safe)
for record in records:
yield cls.from_object(record)
@classmethod
def delete(cls, ctx, profile_id):
profile_obj.Profile.delete(ctx, profile_id)
po.Profile.delete(ctx, profile_id)
def store(self, ctx):
'''Store the profile into database and return its ID.'''
@ -176,11 +176,11 @@ class Profile(object):
if self.id:
self.updated_at = timestamp
values['updated_at'] = timestamp
profile_obj.Profile.update(ctx, self.id, values)
po.Profile.update(ctx, self.id, values)
else:
self.created_at = timestamp
values['created_at'] = timestamp
profile = profile_obj.Profile.create(ctx, values)
profile = po.Profile.create(ctx, values)
self.id = profile.id
return self.id
@ -261,7 +261,7 @@ class Profile(object):
:returns: A dict containing the required parameters for connection
creation.
"""
cred = db_api.cred_get(oslo_context.get_current(), user, project)
cred = co.Credential.get(oslo_context.get_current(), user, project)
if cred is None:
raise exception.TrustNotFound(trustor=user)

View File

@ -12,8 +12,8 @@
import mock
from senlin.db.sqlalchemy import api as db_api
from senlin.engine import service
from senlin.objects import credential as co
from senlin.tests.unit.common import base
from senlin.tests.unit.common import utils
@ -26,7 +26,7 @@ class CredentialTest(base.SenlinTestCase):
project='fake_project_id')
self.eng = service.EngineService('host-a', 'topic-a')
@mock.patch.object(db_api, 'cred_create')
@mock.patch.object(co.Credential, 'update_or_create')
def test_credential_create(self, mock_create):
x_cred = 'fake_cred'
@ -46,7 +46,7 @@ class CredentialTest(base.SenlinTestCase):
}
)
@mock.patch.object(db_api, 'cred_get')
@mock.patch.object(co.Credential, 'get')
def test_credential_get(self, mock_get):
x_data = {'openstack': {'foo': 'bar'}}
x_cred = mock.Mock(cred=x_data)
@ -58,7 +58,7 @@ class CredentialTest(base.SenlinTestCase):
mock_get.assert_called_once_with(
self.ctx, 'fake_user_id', 'fake_project_id')
@mock.patch.object(db_api, 'cred_get')
@mock.patch.object(co.Credential, 'get')
def test_credential_get_not_found(self, mock_get):
mock_get.return_value = None
@ -68,7 +68,7 @@ class CredentialTest(base.SenlinTestCase):
mock_get.assert_called_once_with(
self.ctx, 'fake_user_id', 'fake_project_id')
@mock.patch.object(db_api, 'cred_get')
@mock.patch.object(co.Credential, 'get')
def test_credential_data_not_match(self, mock_get):
x_cred = mock.Mock(cred={'bogkey': 'bogval'})
mock_get.return_value = x_cred
@ -79,7 +79,7 @@ class CredentialTest(base.SenlinTestCase):
mock_get.assert_called_once_with(
self.ctx, 'fake_user_id', 'fake_project_id')
@mock.patch.object(db_api, 'cred_update')
@mock.patch.object(co.Credential, 'update')
def test_credential_update(self, mock_update):
x_cred = 'fake_credential'

View File

@ -19,9 +19,9 @@ from senlin.common import context as senlin_ctx
from senlin.common import exception
from senlin.common import schema
from senlin.common import utils as common_utils
from senlin.db import api as db_api
from senlin.engine import environment
from senlin.engine import parser
from senlin.objects import credential as co
from senlin.objects import policy as po
from senlin.policies import base as pb
from senlin.tests.unit.common import base
@ -405,7 +405,7 @@ class TestPolicyBase(base.SenlinTestCase):
res = policy.detach(cluster)
self.assertEqual((True, None), res)
@mock.patch.object(db_api, 'cred_get')
@mock.patch.object(co.Credential, 'get')
@mock.patch.object(senlin_ctx, 'get_service_context')
@mock.patch.object(oslo_ctx, 'get_current')
def test_build_conn_params(self, mock_get_current, mock_get_service_ctx,
@ -450,7 +450,7 @@ class TestPolicyBase(base.SenlinTestCase):
mock_get_service_ctx.assert_called_once_with()
mock_cred_get.assert_called_once_with(current_ctx, 'user1', 'project1')
@mock.patch.object(db_api, 'cred_get')
@mock.patch.object(co.Credential, 'get')
@mock.patch.object(senlin_ctx, 'get_service_context')
@mock.patch.object(oslo_ctx, 'get_current')
def test_build_conn_params_trust_not_found(

View File

@ -21,9 +21,9 @@ from senlin.common import context as senlin_ctx
from senlin.common import exception
from senlin.common import schema
from senlin.common import utils as common_utils
from senlin.db import api as db_api
from senlin.engine import environment
from senlin.engine import parser
from senlin.objects import credential as co
from senlin.objects import profile as po
from senlin.profiles import base as pb
from senlin.tests.unit.common import base
@ -565,7 +565,7 @@ class TestProfileBase(base.SenlinTestCase):
}
self.assertEqual(expected, profile.context)
@mock.patch.object(db_api, 'cred_get')
@mock.patch.object(co.Credential, 'get')
@mock.patch.object(oslo_ctx, 'get_current')
def test__build_conn_params(self, mock_current, mock_get):
profile = self._create_profile('test-profile')
@ -587,7 +587,7 @@ class TestProfileBase(base.SenlinTestCase):
mock_current.assert_called_once_with()
mock_get.assert_called_once_with(fake_ctx, 'FAKE_USER', 'FAKE_PROJECT')
@mock.patch.object(db_api, 'cred_get')
@mock.patch.object(co.Credential, 'get')
@mock.patch.object(oslo_ctx, 'get_current')
def test__build_conn_params_trust_not_found(self, mock_current, mock_get):
profile = self._create_profile('test-profile')