Fix admin utils quota issue

Commit I7e68c9d0e40e03c0e3e708e04c996fdceed56df4 fixed the sg rule quota
issue in the admin utilities tests, instead of in their mock plugins

Change-Id: I95b6411e960c62def3bbc6a9d7b6cdd92fc4aa92
This commit is contained in:
asarfaty 2020-05-12 14:43:21 +02:00 committed by Adit Sarfaty
parent 266763363a
commit cf68d19a15
7 changed files with 13 additions and 11 deletions

View File

@ -13,7 +13,9 @@
# under the License.
import sys
from unittest import mock
from neutron import quota
import six
from vmware_nsx._i18n import _
from vmware_nsx.db import db
@ -126,3 +128,8 @@ def get_plugin_filters(context, plugin):
if maps:
filters['project_id'] = [m.project for m in maps]
return filters
def _init_plugin_mock_quota():
mock.patch.object(quota.QuotaEngine, 'make_reservation').start()
mock.patch.object(quota.QuotaEngine, 'commit_reservation').start()

View File

@ -26,6 +26,7 @@ from vmware_nsx.plugins.common_v3 import utils as v3_utils
from vmware_nsx.plugins.nsx_p import plugin
from vmware_nsx.services.fwaas.nsx_p import fwaas_callbacks_v2
from vmware_nsx.shell.admin.plugins.common import formatters
from vmware_nsx.shell.admin.plugins.common import utils as admin_utils
LOG = logging.getLogger(__name__)
_NSXPOLICY = None
@ -80,6 +81,7 @@ class NsxPolicyPluginWrapper(plugin.NsxPolicyPlugin):
config.register_nsxp_azs(cfg.CONF, cfg.CONF.nsx_p.availability_zones)
super(NsxPolicyPluginWrapper, self).__init__()
self.context = context.get_admin_context()
admin_utils._init_plugin_mock_quota()
def __enter__(self):
directory.add_plugin(const.CORE, self)

View File

@ -54,6 +54,7 @@ class NeutronSecurityGroupDB(
super(NeutronSecurityGroupDB, self)
# FIXME(roeyc): context is already defined in NeutrondDbClient
self.context = n_context.get_admin_context()
admin_utils._init_plugin_mock_quota()
def get_security_groups_mappings(self):
q = self.context.session.query(

View File

@ -65,6 +65,7 @@ class NsxVPluginWrapper(plugin.NsxVPlugin):
with mock.patch("vmware_nsx.plugins.common.housekeeper."
"housekeeper.NsxHousekeeper"):
self.init_complete(0, 0, 0)
admin_utils._init_plugin_mock_quota()
def start_rpc_listeners(self):
pass

View File

@ -42,6 +42,7 @@ class NeutronSecurityGroupApi(securitygroups_db.SecurityGroupDbMixin):
super(NeutronSecurityGroupApi, self)
self.context = neutron_context.get_admin_context()
self.filters = v3_utils.get_plugin_filters(self.context)
admin_utils._init_plugin_mock_quota()
def get_security_groups(self):
return super(NeutronSecurityGroupApi,

View File

@ -122,6 +122,7 @@ class NsxV3PluginWrapper(plugin.NsxV3Plugin):
config.register_nsxv3_azs(cfg.CONF, cfg.CONF.nsx_v3.availability_zones)
super(NsxV3PluginWrapper, self).__init__()
self.context = context.get_admin_context()
admin_utils._init_plugin_mock_quota()
def __enter__(self):
directory.add_plugin(const.CORE, self)

View File

@ -24,7 +24,6 @@ import six
from neutron.common import config as neutron_config
from neutron.db import servicetype_db # noqa
from neutron import quota
from neutron.quota import resource_registry
from neutron.tests import base
from neutron_lib.callbacks import registry
@ -77,12 +76,6 @@ class AbstractTestAdminUtils(base.BaseTestCase):
"vmware_nsx.shell.admin.plugins.common.utils.query_yes_no")
mock_query.start()
def _init_mock_quota(self):
make_res = mock.patch.object(quota.QuotaEngine, 'make_reservation')
self.mock_quota_make_res = make_res.start()
commit_res = mock.patch.object(quota.QuotaEngine, 'commit_reservation')
self.mock_quota_commit_res = commit_res.start()
@abc.abstractmethod
def _get_plugin_name(self):
pass
@ -166,7 +159,6 @@ class TestNsxvAdminUtils(AbstractTestAdminUtils,
mock.patch("neutron_lib.plugins.directory.get_plugin",
side_effect=get_plugin_mock).start()
self._init_mock_quota()
# Create a router to make sure we have deployed an edge
self.router = self._create_router()
@ -337,8 +329,6 @@ class TestNsxv3AdminUtils(AbstractTestAdminUtils,
self.mock_nm_get_plugin = mock_nm_get_plugin.start()
self.mock_nm_get_plugin.return_value = self._plugin
self._init_mock_quota()
def _get_plugin_name(self):
return 'nsxv3'
@ -391,7 +381,6 @@ class TestNsxpAdminUtils(AbstractTestAdminUtils,
def _init_mock_plugin(self):
self._plugin = nsxp_utils.NsxPolicyPluginWrapper()
self._init_mock_quota()
def test_nsxp_resources(self):
self._test_resources(resources.nsxp_resources)