From 0f877f2594d415513856af3c528275fce2228ac1 Mon Sep 17 00:00:00 2001 From: Terry Wilson Date: Tue, 20 May 2014 10:58:32 -0500 Subject: [PATCH] Remove hard dependency on novaclient The nova notification patch introduces a hard dependency on novaclient when it is a runtime-configurable dependency. The import from novaclient should be conditional on the appropriate nova notification options being enabled in the config. Change-Id: I2ef4bfa4d53afc7e8c800ad8e2a8737e117af238 Closes-Bug: #1321352 --- neutron/api/v2/base.py | 23 +++++++++++++---------- neutron/db/db_base_plugin_v2.py | 2 +- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/neutron/api/v2/base.py b/neutron/api/v2/base.py index c9df5d3fb..5692df01b 100644 --- a/neutron/api/v2/base.py +++ b/neutron/api/v2/base.py @@ -27,7 +27,6 @@ from neutron.api.v2 import attributes from neutron.api.v2 import resource as wsgi_resource from neutron.common import constants as const from neutron.common import exceptions -from neutron.notifiers import nova from neutron.openstack.common import log as logging from neutron.openstack.common.notifier import api as notifier_api from neutron import policy @@ -77,7 +76,9 @@ class Controller(object): agent_notifiers.get(const.AGENT_TYPE_DHCP) or dhcp_rpc_agent_api.DhcpAgentNotifyAPI() ) - self._nova_notifier = nova.Notifier() + if cfg.CONF.notify_nova_on_port_data_changes: + from neutron.notifiers import nova + self._nova_notifier = nova.Notifier() self._member_actions = member_actions self._primary_key = self._get_primary_key() if self._allow_pagination and self._native_pagination: @@ -296,6 +297,10 @@ class Controller(object): else: self._dhcp_agent_notifier.notify(context, data, methodname) + def _send_nova_notification(self, action, orig, returned): + if hasattr(self, '_nova_notifier'): + self._nova_notifier.send_network_change(action, orig, returned) + def index(self, request, **kwargs): """Returns a list of the requested entity.""" parent_id = kwargs.get(self._parent_id_name) @@ -446,11 +451,10 @@ class Controller(object): else: kwargs.update({self._resource: body}) obj = obj_creator(request.context, **kwargs) - - self._nova_notifier.send_network_change( - action, {}, {self._resource: obj}) - return notify({self._resource: self._view( - request.context, obj)}) + self._send_nova_notification(action, {}, + {self._resource: obj}) + return notify({self._resource: self._view(request.context, + obj)}) def delete(self, request, id, **kwargs): """Deletes the specified entity.""" @@ -484,7 +488,7 @@ class Controller(object): notifier_api.CONF.default_notification_level, {self._resource + '_id': id}) result = {self._resource: self._view(request.context, obj)} - self._nova_notifier.send_network_change(action, {}, result) + self._send_nova_notification(action, {}, result) self._send_dhcp_notification(request.context, result, notifier_method) @@ -545,8 +549,7 @@ class Controller(object): self._send_dhcp_notification(request.context, result, notifier_method) - self._nova_notifier.send_network_change( - action, orig_object_copy, result) + self._send_nova_notification(action, orig_object_copy, result) return result @staticmethod diff --git a/neutron/db/db_base_plugin_v2.py b/neutron/db/db_base_plugin_v2.py index 7cfda75fa..cf65c954b 100644 --- a/neutron/db/db_base_plugin_v2.py +++ b/neutron/db/db_base_plugin_v2.py @@ -33,7 +33,6 @@ from neutron.db import sqlalchemyutils from neutron.extensions import l3 from neutron import manager from neutron import neutron_plugin_base_v2 -from neutron.notifiers import nova from neutron.openstack.common import excutils from neutron.openstack.common import log as logging from neutron.openstack.common import uuidutils @@ -238,6 +237,7 @@ class NeutronDbPluginV2(neutron_plugin_base_v2.NeutronPluginBaseV2, def __init__(self): db.configure_db() if cfg.CONF.notify_nova_on_port_status_changes: + from neutron.notifiers import nova # NOTE(arosen) These event listners are here to hook into when # port status changes and notify nova about their change. self.nova_notifier = nova.Notifier() -- 2.45.2