Persist project_id and user_id
This patch persists project_id and user_id for the following objects: 1) bay 2) node 3) container Implements part of bp multi-tenant Change-Id: Iab2c1c8b1b97dde0827050cba34baab581a75f0c
This commit is contained in:
parent
5f26f671cd
commit
075581b132
|
@ -236,7 +236,12 @@ class BaysController(rest.RestController):
|
|||
if self.from_bays:
|
||||
raise exception.OperationNotPermitted
|
||||
|
||||
new_bay = objects.Bay(pecan.request.context, **bay.as_dict())
|
||||
bay_dict = bay.as_dict()
|
||||
ctxt = pecan.request.context
|
||||
auth_token = ctxt.auth_token_info['token']
|
||||
bay_dict['project_id'] = auth_token['project']['id']
|
||||
bay_dict['user_id'] = auth_token['user']['id']
|
||||
new_bay = objects.Bay(ctxt, **bay_dict)
|
||||
res_bay = pecan.request.rpcapi.bay_create(new_bay)
|
||||
|
||||
# Set the HTTP Location Header
|
||||
|
|
|
@ -329,8 +329,12 @@ class ContainersController(rest.RestController):
|
|||
if self.from_containers:
|
||||
raise exception.OperationNotPermitted
|
||||
|
||||
new_container = objects.Container(pecan.request.context,
|
||||
**container.as_dict())
|
||||
container_dict = container.as_dict()
|
||||
ctxt = pecan.request.context
|
||||
auth_token = ctxt.auth_token_info['token']
|
||||
container_dict['project_id'] = auth_token['project']['id']
|
||||
container_dict['user_id'] = auth_token['user']['id']
|
||||
new_container = objects.Container(ctxt, **container_dict)
|
||||
new_container.create()
|
||||
res_container = backend_api.container_create(new_container.name,
|
||||
new_container.uuid,
|
||||
|
|
|
@ -256,8 +256,12 @@ class NodesController(rest.RestController):
|
|||
if self.from_nodes:
|
||||
raise exception.OperationNotPermitted
|
||||
|
||||
new_node = objects.Node(pecan.request.context,
|
||||
**node.as_dict())
|
||||
node_dict = node.as_dict()
|
||||
ctxt = pecan.request.context
|
||||
auth_token = ctxt.auth_token_info['token']
|
||||
node_dict['project_id'] = auth_token['project']['id']
|
||||
node_dict['user_id'] = auth_token['user']['id']
|
||||
new_node = objects.Node(ctxt, **node_dict)
|
||||
new_node.create()
|
||||
# Set the HTTP Location Header
|
||||
pecan.response.location = link.build_url('nodes', new_node.uuid)
|
||||
|
|
|
@ -26,7 +26,8 @@ class TestBayController(db_base.DbTestCase):
|
|||
bay = objects.Bay.get_by_uuid({}, bay_uuid)
|
||||
bay.destroy()
|
||||
|
||||
def test_bay_api(self):
|
||||
@patch('magnum.common.context.RequestContext')
|
||||
def test_bay_api(self, mock_RequestContext):
|
||||
with patch.object(api.API, 'bay_create') as mock_method:
|
||||
# Create a baymodel
|
||||
baymodel = db_utils.get_test_baymodel()
|
||||
|
@ -34,6 +35,9 @@ class TestBayController(db_base.DbTestCase):
|
|||
|
||||
# Create a bay
|
||||
mock_method.side_effect = self.simulate_rpc_bay_create
|
||||
mock_auth_token = mock_RequestContext.auth_token_info['token']
|
||||
mock_auth_token['project']['id'].return_value = 'fake_project'
|
||||
mock_auth_token['user']['id'].return_value = 'fake_user'
|
||||
params = '{"name": "bay_example_A", "baymodel_id": "12345", \
|
||||
"node_count": "3", "baymodel_id": "%s"}' % baymodel['uuid']
|
||||
response = self.app.post('/v1/bays',
|
||||
|
|
|
@ -15,6 +15,7 @@ from mock import patch
|
|||
|
||||
|
||||
class TestContainerController(db_base.DbTestCase):
|
||||
@patch('magnum.common.context.RequestContext')
|
||||
@patch('magnum.conductor.api.API.container_create')
|
||||
@patch('magnum.conductor.api.API.container_delete')
|
||||
@patch('magnum.conductor.api.API.container_start')
|
||||
|
@ -33,7 +34,8 @@ class TestContainerController(db_base.DbTestCase):
|
|||
mock_container_stop,
|
||||
mock_container_start,
|
||||
mock_container_delete,
|
||||
mock_container_create):
|
||||
mock_container_create,
|
||||
mock_RequestContext):
|
||||
mock_container_create.side_effect = lambda x, y, z: z
|
||||
mock_container_start.return_value = None
|
||||
mock_container_stop.return_value = None
|
||||
|
@ -42,6 +44,9 @@ class TestContainerController(db_base.DbTestCase):
|
|||
mock_container_reboot.return_value = None
|
||||
mock_container_logs.return_value = None
|
||||
mock_container_execute.return_value = None
|
||||
mock_auth_token = mock_RequestContext.auth_token_info['token']
|
||||
mock_auth_token['project']['id'].return_value = 'fake_project'
|
||||
mock_auth_token['user']['id'].return_value = 'fake_user'
|
||||
|
||||
# Create a container
|
||||
params = '{"name": "My Docker", "image_id": "ubuntu"}'
|
||||
|
|
|
@ -9,13 +9,19 @@
|
|||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
from mock import patch
|
||||
|
||||
from magnum.tests.db import base as db_base
|
||||
|
||||
|
||||
class TestNodeController(db_base.DbTestCase):
|
||||
def test_node_api(self):
|
||||
@patch('magnum.common.context.RequestContext')
|
||||
def test_node_api(self, mock_RequestContext):
|
||||
# Create a node
|
||||
params = '{"type": "bare", "image_id": "Fedora"}'
|
||||
mock_auth_token = mock_RequestContext.auth_token_info['token']
|
||||
mock_auth_token['project']['id'].return_value = 'fake_project'
|
||||
mock_auth_token['user']['id'].return_value = 'fake_user'
|
||||
response = self.app.post('/v1/nodes',
|
||||
params=params,
|
||||
content_type='application/json')
|
||||
|
|
Loading…
Reference in New Issue