Browse Source

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
(cherry picked from commit fb2c27bebf)
changes/13/731813/1
asarfaty 1 month ago
committed by Adit Sarfaty
parent
commit
c0da5a9c44
7 changed files with 14 additions and 11 deletions
  1. +8
    -0
      vmware_nsx/shell/admin/plugins/common/utils.py
  2. +2
    -0
      vmware_nsx/shell/admin/plugins/nsxp/resources/utils.py
  3. +1
    -0
      vmware_nsx/shell/admin/plugins/nsxv/resources/securitygroups.py
  4. +1
    -0
      vmware_nsx/shell/admin/plugins/nsxv/resources/utils.py
  5. +1
    -0
      vmware_nsx/shell/admin/plugins/nsxv3/resources/securitygroups.py
  6. +1
    -0
      vmware_nsx/shell/admin/plugins/nsxv3/resources/utils.py
  7. +0
    -11
      vmware_nsx/tests/unit/shell/test_admin_utils.py

+ 8
- 0
vmware_nsx/shell/admin/plugins/common/utils.py View File

@@ -14,6 +14,9 @@

import sys

import mock

from neutron import quota
import six
from vmware_nsx._i18n import _
from vmware_nsx.db import db
@@ -126,3 +129,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()

+ 2
- 0
vmware_nsx/shell/admin/plugins/nsxp/resources/utils.py View File

@@ -24,6 +24,7 @@ from vmware_nsx.common import config
from vmware_nsx.plugins.nsx_p import plugin
from vmware_nsx.plugins.nsx_v3 import utils as v3_utils
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
@@ -77,6 +78,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)


+ 1
- 0
vmware_nsx/shell/admin/plugins/nsxv/resources/securitygroups.py 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(


+ 1
- 0
vmware_nsx/shell/admin/plugins/nsxv/resources/utils.py 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


+ 1
- 0
vmware_nsx/shell/admin/plugins/nsxv3/resources/securitygroups.py View File

@@ -43,6 +43,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,


+ 1
- 0
vmware_nsx/shell/admin/plugins/nsxv3/resources/utils.py 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)


+ 0
- 11
vmware_nsx/tests/unit/shell/test_admin_utils.py 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
@@ -74,12 +73,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
@@ -156,7 +149,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()
@@ -276,8 +268,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'

@@ -333,7 +323,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)

Loading…
Cancel
Save