Persist project_id and user_id for baymodel object

Implements part of bp multi-tenant

Change-Id: Ief01572eeda39e2ea6aa19839d12f1a14feeae4d
This commit is contained in:
Jay Lau (Guangya Liu) 2015-01-27 02:26:38 -05:00
parent 576e81c882
commit 7d5baf384a
2 changed files with 16 additions and 2 deletions

View File

@ -229,8 +229,12 @@ class BayModelsController(rest.RestController):
if self.from_baymodels: if self.from_baymodels:
raise exception.OperationNotPermitted raise exception.OperationNotPermitted
new_baymodel = objects.BayModel(pecan.request.context, baymodel_dict = baymodel.as_dict()
**baymodel.as_dict()) ctxt = pecan.request.context
auth_token = ctxt.auth_token_info['token']
baymodel_dict['project_id'] = auth_token['project']['id']
baymodel_dict['user_id'] = auth_token['user']['id']
new_baymodel = objects.BayModel(ctxt, **baymodel_dict)
new_baymodel.create() new_baymodel.create()
# Set the HTTP Location Header # Set the HTTP Location Header
pecan.response.location = link.build_url('baymodels', pecan.response.location = link.build_url('baymodels',

View File

@ -19,6 +19,7 @@ from six.moves.urllib import parse as urlparse
from wsme import types as wtypes from wsme import types as wtypes
from magnum.api.controllers.v1 import baymodel as api_baymodel from magnum.api.controllers.v1 import baymodel as api_baymodel
from magnum.common import context
from magnum.common import utils from magnum.common import utils
from magnum.tests.api import base as api_base from magnum.tests.api import base as api_base
from magnum.tests.api import utils as apiutils from magnum.tests.api import utils as apiutils
@ -246,6 +247,15 @@ class TestPatch(api_base.FunctionalTest):
class TestPost(api_base.FunctionalTest): class TestPost(api_base.FunctionalTest):
def setUp(self):
super(TestPost, self).setUp()
p = mock.patch.object(context, 'RequestContext')
self.mock_request_context = p.start()
mock_auth_token = self.mock_request_context.auth_token_info['token']
mock_auth_token['project']['id'].return_value = 'fake_project'
mock_auth_token['user']['id'].return_value = 'fake_user'
self.addCleanup(p.stop)
@mock.patch.object(timeutils, 'utcnow') @mock.patch.object(timeutils, 'utcnow')
def test_create_baymodel(self, mock_utcnow): def test_create_baymodel(self, mock_utcnow):
cdict = apiutils.baymodel_post_data() cdict = apiutils.baymodel_post_data()