From a630b3bae84091f0ff1029a87e3fc27eb9d7f5e3 Mon Sep 17 00:00:00 2001 From: Terry Wilson Date: Wed, 25 Jun 2014 14:49:58 -0500 Subject: [PATCH] Add sanity check for nova notification support 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 | 8 +++++ neutron/cmd/sanity_check.py | 14 ++++++++ .../{test_ovs_sanity.py => test_sanity.py} | 34 +++++++++++++------ 3 files changed, 46 insertions(+), 10 deletions(-) rename neutron/tests/functional/sanity/{test_ovs_sanity.py => test_sanity.py} (58%) diff --git a/neutron/cmd/sanity/checks.py b/neutron/cmd/sanity/checks.py index f231f86adba..60081573e0d 100644 --- a/neutron/cmd/sanity/checks.py +++ b/neutron/cmd/sanity/checks.py @@ -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 diff --git a/neutron/cmd/sanity_check.py b/neutron/cmd/sanity_check.py index e2f7d145a03..1cc7088dc0e 100644 --- a/neutron/cmd/sanity_check.py +++ b/neutron/cmd/sanity_check.py @@ -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(): diff --git a/neutron/tests/functional/sanity/test_ovs_sanity.py b/neutron/tests/functional/sanity/test_sanity.py similarity index 58% rename from neutron/tests/functional/sanity/test_ovs_sanity.py rename to neutron/tests/functional/sanity/test_sanity.py index 552e064a992..be35484cb49 100644 --- a/neutron/tests/functional/sanity/test_ovs_sanity.py +++ b/neutron/tests/functional/sanity/test_sanity.py @@ -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(OVSSanityTestCase, self).setUp() + 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(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)