From 584d960a93a5ee278fd2c79887cd96da224e8fc5 Mon Sep 17 00:00:00 2001
From: Gary Kotton <gkotton@vmware.com>
Date: Fri, 8 Jan 2016 07:34:27 -0800
Subject: [PATCH] Ensure that decomposed plugins do not break

Commit 5d53dfb8d64186b5b1d2f356fbff8f222e15d1b2 removed the
method _get_tenant_id_for_create. This is used by various plugins
and the *aaS libaries.

Change-Id: I6d5e2555d6c198102a3d5400609f1d671e0d388d
---
 neutron/db/common_db_mixin.py | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/neutron/db/common_db_mixin.py b/neutron/db/common_db_mixin.py
index ba913bfbab3..b504cfbb5a7 100644
--- a/neutron/db/common_db_mixin.py
+++ b/neutron/db/common_db_mixin.py
@@ -15,11 +15,14 @@
 
 import weakref
 
+from debtcollector import removals
 import six
 from sqlalchemy import and_
 from sqlalchemy import or_
 from sqlalchemy import sql
 
+from neutron._i18n import _
+from neutron.common import exceptions as n_exc
 from neutron.db import sqlalchemyutils
 
 
@@ -167,6 +170,18 @@ class CommonDbMixin(object):
                          if key in fields))
         return resource
 
+    @removals.remove(message='This method will be removed in N')
+    def _get_tenant_id_for_create(self, context, resource):
+        if context.is_admin and 'tenant_id' in resource:
+            tenant_id = resource['tenant_id']
+        elif ('tenant_id' in resource and
+              resource['tenant_id'] != context.tenant_id):
+            reason = _('Cannot create resource for another tenant')
+            raise n_exc.AdminRequired(reason=reason)
+        else:
+            tenant_id = context.tenant_id
+        return tenant_id
+
     def _get_by_id(self, context, model, id):
         query = self._model_query(context, model)
         return query.filter(model.id == id).one()