Enable bay delete support multi tenant

Implementes part of bp multi-tenant

Change-Id: I4eb26adabc34f8f359539cbd41cc2cda070db878
This commit is contained in:
Jay Lau (Guangya Liu) 2015-01-27 01:09:18 -05:00
parent 5f26f671cd
commit ca9975b1b2
4 changed files with 16 additions and 6 deletions

View File

@ -90,9 +90,10 @@ class Connection(object):
"""
@abc.abstractmethod
def get_bay_by_uuid(self, bay_uuid):
def get_bay_by_uuid(self, ctxt, bay_uuid):
"""Return a bay.
:param ctxt: The security context
:param bay_uuid: The uuid of a bay.
:returns: A bay.
"""

View File

@ -171,8 +171,12 @@ class Connection(api.Connection):
except NoResultFound:
raise exception.BayNotFound(bay=bay_id)
def get_bay_by_uuid(self, bay_uuid):
query = model_query(models.Bay).filter_by(uuid=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)
try:
return query.one()
except NoResultFound:

View File

@ -86,7 +86,7 @@ class Bay(base.MagnumObject):
:param context: Security context
: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)
return bay

View File

@ -9,6 +9,7 @@
# 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 magnum.common import context
from magnum.conductor import api
from magnum import objects
from magnum.tests.db import base as db_base
@ -23,8 +24,12 @@ class TestBayController(db_base.DbTestCase):
return bay
def mock_bay_destroy(self, bay_uuid):
bay = objects.Bay.get_by_uuid({}, bay_uuid)
bay.destroy()
with patch.object(context, 'RequestContext') as mock_context:
mock_auth_token = mock_context.auth_token_info['token']
mock_auth_token['project']['id'].return_value = 'fake_project'
mock_auth_token['user']['id'].return_value = 'fake_user'
bay = objects.Bay.get_by_uuid(mock_context, bay_uuid)
bay.destroy()
def test_bay_api(self):
with patch.object(api.API, 'bay_create') as mock_method: