]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Restore and fix vmware unit tests
authorSalvatore Orlando <salv.orlando@gmail.com>
Sun, 1 Feb 2015 07:49:38 +0000 (23:49 -0800)
committerSalvatore Orlando <salv.orlando@gmail.com>
Thu, 5 Feb 2015 18:10:34 +0000 (10:10 -0800)
This patch actually restores vmware unit tests, by adding back
the __init__.py file which was renamed during the advanced
service spinoff and not reinstated when fixing vmware code to
comply with the spinoff.

Furthermore, this patch also fixes a minor issue with context
usage in vmware unit tests which is triggering failures because
of the new database constraint introduced with the commit
79c97120de9cff4d0992b5d41ff4bbf05e890f89

Finally, flake8 tests on vmware directories are also restored
with this patch.

Change-Id: Ib63463fca28bbb4a1eb60b8f5f4b63b3d3367c9e
Closes-Bug: #1416593
Closes-Bug: #1416596

neutron/tests/unit/vmware/__init__.py [new file with mode: 0644]
neutron/tests/unit/vmware/apiclient/fake.py
neutron/tests/unit/vmware/db/test_lsn_db.py
neutron/tests/unit/vmware/test_nsx_plugin.py
tox.ini

diff --git a/neutron/tests/unit/vmware/__init__.py b/neutron/tests/unit/vmware/__init__.py
new file mode 100644 (file)
index 0000000..eb6887d
--- /dev/null
@@ -0,0 +1,44 @@
+# Copyright 2013 OpenStack Foundation.
+#
+# All Rights Reserved.
+#
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
+#    not use this file except in compliance with the License. You may obtain
+#    a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS, 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.
+
+import os
+
+from neutron.plugins.vmware.api_client import client as nsx_client
+from neutron.plugins.vmware.api_client import eventlet_client
+from neutron.plugins.vmware import extensions
+import neutron.plugins.vmware.plugin as neutron_plugin
+from neutron.plugins.vmware.vshield import vcns
+
+
+plugin = neutron_plugin.NsxPlugin
+api_client = nsx_client.NsxApiClient
+evt_client = eventlet_client.EventletApiClient
+vcns_class = vcns.Vcns
+
+STUBS_PATH = os.path.join(os.path.dirname(__file__), 'etc')
+NSXEXT_PATH = os.path.dirname(extensions.__file__)
+NSXAPI_NAME = '%s.%s' % (api_client.__module__, api_client.__name__)
+PLUGIN_NAME = '%s.%s' % (plugin.__module__, plugin.__name__)
+CLIENT_NAME = '%s.%s' % (evt_client.__module__, evt_client.__name__)
+VCNS_NAME = '%s.%s' % (vcns_class.__module__, vcns_class.__name__)
+
+
+def get_fake_conf(filename):
+    return os.path.join(STUBS_PATH, filename)
+
+
+def nsx_method(method_name, module_name='nsxlib'):
+    return '%s.%s.%s' % ('neutron.plugins.vmware', module_name, method_name)
index 0dbb69c6dc5de7bb47468570643dc2f139830e40..b7a30539f57746d53ff8140e3129faa19d368e68 100644 (file)
@@ -34,7 +34,7 @@ def _validate_resource(body):
     _validate_name(body.get('display_name'))
 
 
-class FakeClient:
+class FakeClient(object):
 
     LSWITCH_RESOURCE = 'lswitch'
     LPORT_RESOURCE = 'lport'
index 42dd3e6e63ebd334a91bd3144e52b1d57a271254..56840939f24c1f24791bb921983eb964b65031f8 100644 (file)
@@ -18,6 +18,7 @@ from sqlalchemy import orm
 from neutron import context
 from neutron.plugins.vmware.common import exceptions as p_exc
 from neutron.plugins.vmware.dbexts import lsn_db
+from neutron.plugins.vmware.dbexts import nsx_models
 from neutron.tests.unit import testlib_api
 
 
@@ -34,20 +35,22 @@ class LSNTestCase(testlib_api.SqlTestCase):
 
     def test_lsn_add(self):
         lsn_db.lsn_add(self.ctx, self.net_id, self.lsn_id)
-        lsn = (self.ctx.session.query(lsn_db.Lsn).
+        lsn = (self.ctx.session.query(nsx_models.Lsn).
                filter_by(lsn_id=self.lsn_id).one())
         self.assertEqual(self.lsn_id, lsn.lsn_id)
 
     def test_lsn_remove(self):
         lsn_db.lsn_add(self.ctx, self.net_id, self.lsn_id)
         lsn_db.lsn_remove(self.ctx, self.lsn_id)
-        q = self.ctx.session.query(lsn_db.Lsn).filter_by(lsn_id=self.lsn_id)
+        q = self.ctx.session.query(nsx_models.Lsn).filter_by(
+            lsn_id=self.lsn_id)
         self.assertRaises(orm.exc.NoResultFound, q.one)
 
     def test_lsn_remove_for_network(self):
         lsn_db.lsn_add(self.ctx, self.net_id, self.lsn_id)
         lsn_db.lsn_remove_for_network(self.ctx, self.net_id)
-        q = self.ctx.session.query(lsn_db.Lsn).filter_by(lsn_id=self.lsn_id)
+        q = self.ctx.session.query(nsx_models.Lsn).filter_by(
+            lsn_id=self.lsn_id)
         self.assertRaises(orm.exc.NoResultFound, q.one)
 
     def test_lsn_get_for_network(self):
@@ -64,7 +67,7 @@ class LSNTestCase(testlib_api.SqlTestCase):
         lsn_db.lsn_add(self.ctx, self.net_id, self.lsn_id)
         lsn_db.lsn_port_add_for_lsn(self.ctx, self.lsn_port_id,
                                     self.subnet_id, self.mac_addr, self.lsn_id)
-        result = (self.ctx.session.query(lsn_db.LsnPort).
+        result = (self.ctx.session.query(nsx_models.LsnPort).
                   filter_by(lsn_port_id=self.lsn_port_id).one())
         self.assertEqual(self.lsn_port_id, result.lsn_port_id)
 
@@ -95,6 +98,6 @@ class LSNTestCase(testlib_api.SqlTestCase):
     def test_lsn_port_remove(self):
         lsn_db.lsn_add(self.ctx, self.net_id, self.lsn_id)
         lsn_db.lsn_port_remove(self.ctx, self.lsn_port_id)
-        q = (self.ctx.session.query(lsn_db.LsnPort).
+        q = (self.ctx.session.query(nsx_models.LsnPort).
              filter_by(lsn_port_id=self.lsn_port_id))
         self.assertRaises(orm.exc.NoResultFound, q.one)
index 4dd422ba14daa07529dc90392cb246580bf9d11e..b6b659d8247073088c9c947892e9a282080c07c7 100644 (file)
@@ -345,7 +345,7 @@ class TestNetworksV2(test_plugin.TestNetworksV2, NsxPluginV2TestCase):
             nsxlib.switch, 'update_lswitch') as update_lswitch_mock:
             # don't worry about deleting this network, do not use
             # context manager
-            ctx = context.get_admin_context()
+            ctx = context.Context(user_id=None, tenant_id='gonzalo')
             plugin = manager.NeutronManager.get_plugin()
             net = plugin.create_network(
                 ctx, {'network': {'name': 'xxx',
diff --git a/tox.ini b/tox.ini
index 90d6019fd63791a1ded19ebaa9f11e186028a3d3..3d1f62f44fd0618b7eb588d8d9f33f976b245745 100644 (file)
--- a/tox.ini
+++ b/tox.ini
@@ -78,8 +78,7 @@ commands = python setup.py build_sphinx
 ignore = E125,E126,E128,E129,E265,H305,H404,H405
 show-source = true
 builtins = _
-# TODO(dougw) neutron/tests/unit/vmware exclusion is a temporary services split hack
-exclude = ./.*,build,dist,neutron/openstack/common/*,neutron/tests/unit/vmware*
+exclude = ./.*,build,dist,neutron/openstack/common/*
 
 [testenv:pylint]
 deps =