Browse Source

Fix broken unit tests

Commit I0a9b91b09d6260ff96fdba2f0a455de53bbc1f00 broke the unit tests
This patch adds the security rules quota mock were needed.

Change-Id: I7e68c9d0e40e03c0e3e708e04c996fdceed56df4
(cherry picked from commit 8fa0e7daac)
changes/96/725896/3
asarfaty 5 months ago
parent
commit
136a4005ae
2 changed files with 23 additions and 1 deletions
  1. +8
    -1
      vmware_nsx/tests/unit/nsx_mh/test_sync.py
  2. +15
    -0
      vmware_nsx/tests/unit/shell/test_admin_utils.py

+ 8
- 1
vmware_nsx/tests/unit/nsx_mh/test_sync.py View File

@@ -27,6 +27,7 @@ from oslo_config import cfg
from oslo_log import log
from oslo_serialization import jsonutils

from neutron import quota
from neutron.tests import base
from neutron.tests.unit.api.v2 import test_base
from neutron.tests.unit import testlib_api
@@ -302,10 +303,16 @@ class SyncTestCase(testlib_api.SqlTestCase):
"neutron_lib.plugins.directory.get_plugin")
self.mock_nm_get_plugin = mock_nm_get_plugin.start()
self.mock_nm_get_plugin.return_value = self._plugin
self._init_mock_quota()
super(SyncTestCase, self).setUp()
self.addCleanup(self.fc.reset_all)

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()

@contextlib.contextmanager
def _populate_data(self, ctx, net_size=2, port_size=2, router_size=2):



+ 15
- 0
vmware_nsx/tests/unit/shell/test_admin_utils.py View File

@@ -24,6 +24,7 @@ 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
@@ -33,6 +34,7 @@ from vmware_nsx._i18n import _
from vmware_nsx.common import config # noqa
from vmware_nsx.db import nsxv_db
from vmware_nsx.dvs import dvs_utils
from vmware_nsx.shell.admin.plugins.nsxp.resources import utils as nsxp_utils
from vmware_nsx.shell.admin.plugins.nsxv.resources import utils as nsxv_utils
from vmware_nsx.shell.admin.plugins.nsxv3.resources import utils as nsxv3_utils
from vmware_nsx.shell import resources
@@ -72,6 +74,12 @@ 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
@@ -148,6 +156,7 @@ 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()
@@ -267,6 +276,8 @@ 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'

@@ -320,5 +331,9 @@ class TestNsxpAdminUtils(AbstractTestAdminUtils,
def _get_plugin_name(self):
return 'nsxp'

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