]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Add sanity check for nova notification support
authorTerry Wilson <twilson@redhat.com>
Wed, 25 Jun 2014 19:49:58 +0000 (14:49 -0500)
committerTerry Wilson <twilson@redhat.com>
Fri, 27 Jun 2014 14:14:27 +0000 (09:14 -0500)
Since nova notification support adds a runtime dependency on
novaclient, add an external sanity check testing the system's
ability to import neutron.notifiers.nova

Change-Id: I8a72c8763bb69a01178fc4ec91071a64a4648aab
Closes-bug: #1334412

neutron/cmd/sanity/checks.py
neutron/cmd/sanity_check.py
neutron/tests/functional/sanity/test_sanity.py [moved from neutron/tests/functional/sanity/test_ovs_sanity.py with 58% similarity]

index f231f86adba9db580abbddcebe7810339a9aea7e..60081573e0d17a61fe651f5a341741350b161d6f 100644 (file)
@@ -34,3 +34,11 @@ def patch_supported(root_helper):
     with ovs_lib.OVSBridge(name, root_helper) as br:
         port = br.add_patch_port(patch_name, peer_name)
         return port != ovs_const.INVALID_OFPORT
+
+
+def nova_notify_supported():
+    try:
+        import neutron.notifiers.nova  # noqa since unused
+        return True
+    except ImportError:
+        return False
index e2f7d145a031d34d214e19a8bc728b902b5a35b1..1cc7088dc0e8104332776bee0633ce197285145a 100644 (file)
@@ -51,12 +51,23 @@ def check_ovs_patch():
     return result
 
 
+def check_nova_notify():
+    result = checks.nova_notify_supported()
+    if not result:
+        LOG.error(_('Nova notifcations are enabled, but novaclient is not '
+                    'installed. Either disable nova notifications or install '
+                    'python-novaclient.'))
+    return result
+
+
 # Define CLI opts to test specific features, with a calback for the test
 OPTS = [
     BoolOptCallback('ovs_vxlan', check_ovs_vxlan, default=False,
                     help=_('Check for vxlan support')),
     BoolOptCallback('ovs_patch', check_ovs_patch, default=False,
                     help=_('Check for patch port support')),
+    BoolOptCallback('nova_notify', check_nova_notify, default=False,
+                    help=_('Check for nova notification support')),
 ]
 
 
@@ -72,6 +83,9 @@ def enable_tests_from_config():
         cfg.CONF.set_override('ovs_patch', True)
     if not cfg.CONF.OVS.use_veth_interconnection:
         cfg.CONF.set_override('ovs_patch', True)
+    if (cfg.CONF.notify_nova_on_port_status_changes or
+            cfg.CONF.notify_nova_on_port_data_changes):
+        cfg.CONF.set_override('nova_notify', True)
 
 
 def all_tests_passed():
similarity index 58%
rename from neutron/tests/functional/sanity/test_ovs_sanity.py
rename to neutron/tests/functional/sanity/test_sanity.py
index 552e064a992f2ca4c67319208223930642d75631..be35484cb493741b1d494182b0b48887604cb2e3 100644 (file)
@@ -19,26 +19,40 @@ from neutron.cmd.sanity import checks
 from neutron.tests import base
 
 
-class OVSSanityTestCase(base.BaseTestCase):
+class SanityTestCase(base.BaseTestCase):
+    """Sanity checks that do not require root access.
+
+    Tests that just call checks.some_function() are to ensure that
+    neutron-sanity-check runs without throwing an exception, as in the case
+    where someone modifies the API without updating the check script.
+    """
+
+    def setUp(self):
+        super(SanityTestCase, self).setUp()
+
+    def test_nova_notify_runs(self):
+        checks.nova_notify_supported()
+
+
+class SanityTestCaseRoot(base.BaseTestCase):
+    """Sanity checks that require root access.
+
+    Tests that just call checks.some_function() are to ensure that
+    neutron-sanity-check runs without throwing an exception, as in the case
+    where someone modifies the API without updating the check script.
+    """
     def setUp(self):
-        super(OVSSanityTestCase, self).setUp()
+        super(SanityTestCaseRoot, self).setUp()
 
         self.root_helper = 'sudo'
+        self.check_sudo_enabled()
 
     def check_sudo_enabled(self):
         if os.environ.get('OS_SUDO_TESTING') not in base.TRUE_STRING:
             self.skipTest('testing with sudo is not enabled')
 
     def test_ovs_vxlan_support_runs(self):
-        """This test just ensures that the test in neutron-sanity-check
-            can run through without error, without mocking anything out
-        """
-        self.check_sudo_enabled()
         checks.vxlan_supported(self.root_helper)
 
     def test_ovs_patch_support_runs(self):
-        """This test just ensures that the test in neutron-sanity-check
-            can run through without error, without mocking anything out
-        """
-        self.check_sudo_enabled()
         checks.patch_supported(self.root_helper)