Enable bay delete support multi tenant
Implementes part of bp multi-tenant Change-Id: I4eb26adabc34f8f359539cbd41cc2cda070db878
This commit is contained in:
parent
129a1bcc62
commit
d321980cb4
|
@ -90,9 +90,10 @@ class Connection(object):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def get_bay_by_uuid(self, bay_uuid):
|
def get_bay_by_uuid(self, ctxt, bay_uuid):
|
||||||
"""Return a bay.
|
"""Return a bay.
|
||||||
|
|
||||||
|
:param ctxt: The security context
|
||||||
:param bay_uuid: The uuid of a bay.
|
:param bay_uuid: The uuid of a bay.
|
||||||
:returns: A bay.
|
:returns: A bay.
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -171,7 +171,12 @@ class Connection(api.Connection):
|
||||||
except NoResultFound:
|
except NoResultFound:
|
||||||
raise exception.BayNotFound(bay=bay_id)
|
raise exception.BayNotFound(bay=bay_id)
|
||||||
|
|
||||||
def get_bay_by_uuid(self, bay_uuid):
|
def get_bay_by_uuid(self, ctxt, bay_uuid):
|
||||||
|
auth_token = ctxt.auth_token_info['token']
|
||||||
|
project_id = auth_token['project']['id']
|
||||||
|
user_id = auth_token['user']['id']
|
||||||
|
query = model_query(models.Bay).filter_by(uuid=bay_uuid,
|
||||||
|
project_id=project_id, user_id=user_id)
|
||||||
query = model_query(models.Bay).filter_by(uuid=bay_uuid)
|
query = model_query(models.Bay).filter_by(uuid=bay_uuid)
|
||||||
try:
|
try:
|
||||||
return query.one()
|
return query.one()
|
||||||
|
|
|
@ -86,7 +86,7 @@ class Bay(base.MagnumObject):
|
||||||
:param context: Security context
|
:param context: Security context
|
||||||
:returns: a :class:`Bay` object.
|
:returns: a :class:`Bay` object.
|
||||||
"""
|
"""
|
||||||
db_bay = cls.dbapi.get_bay_by_uuid(uuid)
|
db_bay = cls.dbapi.get_bay_by_uuid(context, uuid)
|
||||||
bay = Bay._from_db_object(cls(context), db_bay)
|
bay = Bay._from_db_object(cls(context), db_bay)
|
||||||
return bay
|
return bay
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,12 @@ class TestListBay(api_base.FunctionalTest):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestListBay, self).setUp()
|
super(TestListBay, self).setUp()
|
||||||
obj_utils.create_test_baymodel(self.context)
|
obj_utils.create_test_baymodel(self.context)
|
||||||
|
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)
|
||||||
|
|
||||||
def test_empty(self):
|
def test_empty(self):
|
||||||
response = self.get_json('/bays')
|
response = self.get_json('/bays')
|
||||||
|
@ -130,6 +136,12 @@ class TestPatch(api_base.FunctionalTest):
|
||||||
self.bay = obj_utils.create_test_bay(self.context,
|
self.bay = obj_utils.create_test_bay(self.context,
|
||||||
name='bay_example_A',
|
name='bay_example_A',
|
||||||
node_count=3)
|
node_count=3)
|
||||||
|
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_replace_ok(self, mock_utcnow):
|
def test_replace_ok(self, mock_utcnow):
|
||||||
|
@ -372,9 +384,15 @@ class TestDelete(api_base.FunctionalTest):
|
||||||
self.mock_bay_delete = p.start()
|
self.mock_bay_delete = p.start()
|
||||||
self.mock_bay_delete.side_effect = self._simulate_rpc_bay_delete
|
self.mock_bay_delete.side_effect = self._simulate_rpc_bay_delete
|
||||||
self.addCleanup(p.stop)
|
self.addCleanup(p.stop)
|
||||||
|
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)
|
||||||
|
|
||||||
def _simulate_rpc_bay_delete(self, bay_uuid):
|
def _simulate_rpc_bay_delete(self, bay_uuid):
|
||||||
bay = objects.Bay.get_by_uuid(self.context, bay_uuid)
|
bay = objects.Bay.get_by_uuid(self.mock_request_context, bay_uuid)
|
||||||
bay.destroy()
|
bay.destroy()
|
||||||
|
|
||||||
def test_delete_bay(self):
|
def test_delete_bay(self):
|
||||||
|
@ -417,4 +435,4 @@ class TestDelete(api_base.FunctionalTest):
|
||||||
response = self.delete('/bays/%s' % uuid, expect_errors=True)
|
response = self.delete('/bays/%s' % uuid, expect_errors=True)
|
||||||
self.assertEqual(404, response.status_int)
|
self.assertEqual(404, response.status_int)
|
||||||
self.assertEqual('application/json', response.content_type)
|
self.assertEqual('application/json', response.content_type)
|
||||||
self.assertTrue(response.json['error_message'])
|
self.assertTrue(response.json['error_message'])
|
||||||
|
|
|
@ -26,9 +26,13 @@ class TestPodController(db_base.DbTestCase):
|
||||||
pod = objects.Pod.get_by_uuid({}, pod_uuid)
|
pod = objects.Pod.get_by_uuid({}, pod_uuid)
|
||||||
pod.destroy()
|
pod.destroy()
|
||||||
|
|
||||||
def test_pod_api(self):
|
@patch('magnum.common.context.RequestContext')
|
||||||
|
def test_pod_api(self, mock_RequestContext):
|
||||||
with patch.object(api.API, 'pod_create') as mock_method:
|
with patch.object(api.API, 'pod_create') as mock_method:
|
||||||
mock_method.side_effect = self.mock_pod_create
|
mock_method.side_effect = self.mock_pod_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'
|
||||||
# Create a bay
|
# Create a bay
|
||||||
bay = db_utils.create_test_bay()
|
bay = db_utils.create_test_bay()
|
||||||
|
|
||||||
|
|
|
@ -26,9 +26,13 @@ class TestRCController(db_base.DbTestCase):
|
||||||
rc = objects.ReplicationController.get_by_uuid({}, uuid)
|
rc = objects.ReplicationController.get_by_uuid({}, uuid)
|
||||||
rc.destroy()
|
rc.destroy()
|
||||||
|
|
||||||
def test_rc_api(self):
|
@patch('magnum.common.context.RequestContext')
|
||||||
|
def test_rc_api(self, mock_RequestContext):
|
||||||
with patch.object(api.API, 'rc_create') as mock_method:
|
with patch.object(api.API, 'rc_create') as mock_method:
|
||||||
mock_method.side_effect = self.mock_rc_create
|
mock_method.side_effect = self.mock_rc_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'
|
||||||
# Create a bay
|
# Create a bay
|
||||||
bay = db_utils.create_test_bay()
|
bay = db_utils.create_test_bay()
|
||||||
|
|
||||||
|
|
|
@ -27,9 +27,13 @@ class TestServiceController(db_base.DbTestCase):
|
||||||
service = objects.Service.get_by_uuid({}, uuid)
|
service = objects.Service.get_by_uuid({}, uuid)
|
||||||
service.destroy()
|
service.destroy()
|
||||||
|
|
||||||
def test_service_api(self):
|
@patch('magnum.common.context.RequestContext')
|
||||||
|
def test_service_api(self, mock_RequestContext):
|
||||||
with patch.object(api.API, 'service_create') as mock_method:
|
with patch.object(api.API, 'service_create') as mock_method:
|
||||||
mock_method.side_effect = self.mock_service_create
|
mock_method.side_effect = self.mock_service_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'
|
||||||
# Create a bay
|
# Create a bay
|
||||||
bay = db_utils.create_test_bay()
|
bay = db_utils.create_test_bay()
|
||||||
|
|
||||||
|
|
|
@ -15,8 +15,10 @@
|
||||||
|
|
||||||
"""Tests for manipulating Bays via the DB API"""
|
"""Tests for manipulating Bays via the DB API"""
|
||||||
|
|
||||||
|
from mock import patch
|
||||||
import six
|
import six
|
||||||
|
|
||||||
|
from magnum.common import context
|
||||||
from magnum.common import exception
|
from magnum.common import exception
|
||||||
from magnum.common import utils as magnum_utils
|
from magnum.common import utils as magnum_utils
|
||||||
from magnum.tests.db import base
|
from magnum.tests.db import base
|
||||||
|
@ -25,6 +27,15 @@ from magnum.tests.db import utils
|
||||||
|
|
||||||
class DbBayTestCase(base.DbTestCase):
|
class DbBayTestCase(base.DbTestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(DbBayTestCase, self).setUp()
|
||||||
|
p = patch.object(context, 'RequestContext')
|
||||||
|
self.mock_context = p.start()
|
||||||
|
mock_auth_token = self.mock_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)
|
||||||
|
|
||||||
def test_create_bay(self):
|
def test_create_bay(self):
|
||||||
utils.create_test_bay()
|
utils.create_test_bay()
|
||||||
|
|
||||||
|
@ -44,7 +55,7 @@ class DbBayTestCase(base.DbTestCase):
|
||||||
|
|
||||||
def test_get_bay_by_uuid(self):
|
def test_get_bay_by_uuid(self):
|
||||||
bay = utils.create_test_bay()
|
bay = utils.create_test_bay()
|
||||||
res = self.dbapi.get_bay_by_uuid(bay.uuid)
|
res = self.dbapi.get_bay_by_uuid(self.mock_context, bay.uuid)
|
||||||
self.assertEqual(bay.id, res.id)
|
self.assertEqual(bay.id, res.id)
|
||||||
self.assertEqual(bay.uuid, res.uuid)
|
self.assertEqual(bay.uuid, res.uuid)
|
||||||
|
|
||||||
|
@ -53,6 +64,7 @@ class DbBayTestCase(base.DbTestCase):
|
||||||
self.dbapi.get_bay_by_id, 999)
|
self.dbapi.get_bay_by_id, 999)
|
||||||
self.assertRaises(exception.BayNotFound,
|
self.assertRaises(exception.BayNotFound,
|
||||||
self.dbapi.get_bay_by_uuid,
|
self.dbapi.get_bay_by_uuid,
|
||||||
|
self.mock_context,
|
||||||
'12345678-9999-0000-aaaa-123456789012')
|
'12345678-9999-0000-aaaa-123456789012')
|
||||||
|
|
||||||
def test_get_bayinfo_list_defaults(self):
|
def test_get_bayinfo_list_defaults(self):
|
||||||
|
@ -182,10 +194,12 @@ class DbBayTestCase(base.DbTestCase):
|
||||||
|
|
||||||
def test_destroy_bay_by_uuid(self):
|
def test_destroy_bay_by_uuid(self):
|
||||||
bay = utils.create_test_bay()
|
bay = utils.create_test_bay()
|
||||||
self.assertIsNotNone(self.dbapi.get_bay_by_uuid(bay.uuid))
|
self.assertIsNotNone(self.dbapi.get_bay_by_uuid(self.mock_context,
|
||||||
|
bay.uuid))
|
||||||
self.dbapi.destroy_bay(bay.uuid)
|
self.dbapi.destroy_bay(bay.uuid)
|
||||||
self.assertRaises(exception.BayNotFound,
|
self.assertRaises(exception.BayNotFound,
|
||||||
self.dbapi.get_bay_by_uuid, bay.uuid)
|
self.dbapi.get_bay_by_uuid, self.mock_context,
|
||||||
|
bay.uuid)
|
||||||
|
|
||||||
def test_destroy_bay_that_does_not_exist(self):
|
def test_destroy_bay_that_does_not_exist(self):
|
||||||
self.assertRaises(exception.BayNotFound,
|
self.assertRaises(exception.BayNotFound,
|
||||||
|
|
|
@ -44,7 +44,7 @@ class TestBayObject(base.DbTestCase):
|
||||||
autospec=True) as mock_get_bay:
|
autospec=True) as mock_get_bay:
|
||||||
mock_get_bay.return_value = self.fake_bay
|
mock_get_bay.return_value = self.fake_bay
|
||||||
bay = objects.Bay.get(self.context, uuid)
|
bay = objects.Bay.get(self.context, uuid)
|
||||||
mock_get_bay.assert_called_once_with(uuid)
|
mock_get_bay.assert_called_once_with(self.context, uuid)
|
||||||
self.assertEqual(self.context, bay._context)
|
self.assertEqual(self.context, bay._context)
|
||||||
|
|
||||||
def test_get_bad_id_and_uuid(self):
|
def test_get_bad_id_and_uuid(self):
|
||||||
|
@ -79,7 +79,7 @@ class TestBayObject(base.DbTestCase):
|
||||||
autospec=True) as mock_destroy_bay:
|
autospec=True) as mock_destroy_bay:
|
||||||
bay = objects.Bay.get_by_uuid(self.context, uuid)
|
bay = objects.Bay.get_by_uuid(self.context, uuid)
|
||||||
bay.destroy()
|
bay.destroy()
|
||||||
mock_get_bay.assert_called_once_with(uuid)
|
mock_get_bay.assert_called_once_with(self.context, uuid)
|
||||||
mock_destroy_bay.assert_called_once_with(uuid)
|
mock_destroy_bay.assert_called_once_with(uuid)
|
||||||
self.assertEqual(self.context, bay._context)
|
self.assertEqual(self.context, bay._context)
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ class TestBayObject(base.DbTestCase):
|
||||||
bay.node_count = 10
|
bay.node_count = 10
|
||||||
bay.save()
|
bay.save()
|
||||||
|
|
||||||
mock_get_bay.assert_called_once_with(uuid)
|
mock_get_bay.assert_called_once_with(self.context, uuid)
|
||||||
mock_update_bay.assert_called_once_with(
|
mock_update_bay.assert_called_once_with(
|
||||||
uuid, {'node_count': 10})
|
uuid, {'node_count': 10})
|
||||||
self.assertEqual(self.context, bay._context)
|
self.assertEqual(self.context, bay._context)
|
||||||
|
@ -104,7 +104,8 @@ class TestBayObject(base.DbTestCase):
|
||||||
new_uuid = magnum_utils.generate_uuid()
|
new_uuid = magnum_utils.generate_uuid()
|
||||||
returns = [dict(self.fake_bay, uuid=uuid),
|
returns = [dict(self.fake_bay, uuid=uuid),
|
||||||
dict(self.fake_bay, uuid=new_uuid)]
|
dict(self.fake_bay, uuid=new_uuid)]
|
||||||
expected = [mock.call(uuid), mock.call(uuid)]
|
expected = [mock.call(self.context, uuid),
|
||||||
|
mock.call(self.context, uuid)]
|
||||||
with mock.patch.object(self.dbapi, 'get_bay_by_uuid',
|
with mock.patch.object(self.dbapi, 'get_bay_by_uuid',
|
||||||
side_effect=returns,
|
side_effect=returns,
|
||||||
autospec=True) as mock_get_bay:
|
autospec=True) as mock_get_bay:
|
||||||
|
@ -113,4 +114,4 @@ class TestBayObject(base.DbTestCase):
|
||||||
bay.refresh()
|
bay.refresh()
|
||||||
self.assertEqual(new_uuid, bay.uuid)
|
self.assertEqual(new_uuid, bay.uuid)
|
||||||
self.assertEqual(expected, mock_get_bay.call_args_list)
|
self.assertEqual(expected, mock_get_bay.call_args_list)
|
||||||
self.assertEqual(self.context, bay._context)
|
self.assertEqual(self.context, bay._context)
|
||||||
|
|
Loading…
Reference in New Issue