From 5e074a59d276fa869797e0e6b7584e992e5bc3cf Mon Sep 17 00:00:00 2001 From: Balazs Gibizer Date: Wed, 13 Apr 2016 10:35:37 +0200 Subject: [PATCH] Move notification related code to separate package To be able to separate the versioned notification related object model from the nova internal object model a new nova.notification.object package is introduced. As nova had nova/notifications.py already in the tree the code from that file is moved into the new nova.notification package as a first step. Implements: bp versioned-notification-transformation-newton Change-Id: I315f548180c260c22a2ebcf7b7cb56d284b6e580 --- doc/ext/versioned_notifications.py | 2 +- nova/notifications/__init__.py | 27 +++++++++++++++++++ .../base.py} | 0 nova/notifications/objects/__init__.py | 0 .../objects/base.py} | 0 nova/objects/__init__.py | 1 - nova/objects/service.py | 2 +- nova/tests/unit/notifications/__init__.py | 0 .../unit/notifications/objects/__init__.py | 0 .../objects/test_notification.py | 2 +- nova/tests/unit/objects/test_objects.py | 2 +- nova/tests/unit/test_notifications.py | 8 +++--- 12 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 nova/notifications/__init__.py rename nova/{notifications.py => notifications/base.py} (100%) create mode 100644 nova/notifications/objects/__init__.py rename nova/{objects/notification.py => notifications/objects/base.py} (100%) create mode 100644 nova/tests/unit/notifications/__init__.py create mode 100644 nova/tests/unit/notifications/objects/__init__.py rename nova/tests/unit/{ => notifications}/objects/test_notification.py (99%) diff --git a/doc/ext/versioned_notifications.py b/doc/ext/versioned_notifications.py index 5f7fe5ed1874..795ed59d141d 100644 --- a/doc/ext/versioned_notifications.py +++ b/doc/ext/versioned_notifications.py @@ -23,8 +23,8 @@ It is used via a single directive in the .rst file from sphinx.util.compat import Directive from docutils import nodes +from nova.notifications.objects import base as notification from nova.objects import base -from nova.objects import notification def full_name(cls): diff --git a/nova/notifications/__init__.py b/nova/notifications/__init__.py new file mode 100644 index 000000000000..aee73704128b --- /dev/null +++ b/nova/notifications/__init__.py @@ -0,0 +1,27 @@ +# Copyright (c) 2016 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. + +# Note(gibi): Importing publicly called functions so the caller code does not +# need to be changed after we moved these function inside the package +# Todo(gibi): remove these imports after legacy notifications using these are +# transformed to versioned notifications +from nova.notifications.base import audit_period_bounds # noqa +from nova.notifications.base import bandwidth_usage # noqa +from nova.notifications.base import image_meta # noqa +from nova.notifications.base import info_from_instance # noqa +from nova.notifications.base import notify_decorator # noqa +from nova.notifications.base import send_api_fault # noqa +from nova.notifications.base import send_update # noqa +from nova.notifications.base import send_update_with_states # noqa diff --git a/nova/notifications.py b/nova/notifications/base.py similarity index 100% rename from nova/notifications.py rename to nova/notifications/base.py diff --git a/nova/notifications/objects/__init__.py b/nova/notifications/objects/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/nova/objects/notification.py b/nova/notifications/objects/base.py similarity index 100% rename from nova/objects/notification.py rename to nova/notifications/objects/base.py diff --git a/nova/objects/__init__.py b/nova/objects/__init__.py index c5d28f574bcf..21a6ce78ac93 100644 --- a/nova/objects/__init__.py +++ b/nova/objects/__init__.py @@ -56,7 +56,6 @@ def register_all(): __import__('nova.objects.monitor_metric') __import__('nova.objects.network') __import__('nova.objects.network_request') - __import__('nova.objects.notification') __import__('nova.objects.numa') __import__('nova.objects.pci_device') __import__('nova.objects.pci_device_pool') diff --git a/nova/objects/service.py b/nova/objects/service.py index 45798a55c661..086276fac061 100644 --- a/nova/objects/service.py +++ b/nova/objects/service.py @@ -19,10 +19,10 @@ from nova import availability_zones from nova import db from nova import exception from nova.i18n import _LW +from nova.notifications.objects import base as notification from nova import objects from nova.objects import base from nova.objects import fields -from nova.objects import notification LOG = logging.getLogger(__name__) diff --git a/nova/tests/unit/notifications/__init__.py b/nova/tests/unit/notifications/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/nova/tests/unit/notifications/objects/__init__.py b/nova/tests/unit/notifications/objects/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/nova/tests/unit/objects/test_notification.py b/nova/tests/unit/notifications/objects/test_notification.py similarity index 99% rename from nova/tests/unit/objects/test_notification.py rename to nova/tests/unit/notifications/objects/test_notification.py index ada34b80ddbc..616484e45d72 100644 --- a/nova/tests/unit/objects/test_notification.py +++ b/nova/tests/unit/notifications/objects/test_notification.py @@ -15,10 +15,10 @@ import mock from oslo_utils import timeutils +from nova.notifications.objects import base as notification from nova import objects from nova.objects import base from nova.objects import fields -from nova.objects import notification from nova import test diff --git a/nova/tests/unit/objects/test_objects.py b/nova/tests/unit/objects/test_objects.py index 101c5b0ca2a9..17aee10ccf32 100644 --- a/nova/tests/unit/objects/test_objects.py +++ b/nova/tests/unit/objects/test_objects.py @@ -32,10 +32,10 @@ import six from nova import context from nova import exception +from nova.notifications.objects import base as notification from nova import objects from nova.objects import base from nova.objects import fields -from nova.objects import notification from nova.objects import virt_device_metadata from nova import test from nova.tests import fixtures as nova_fixtures diff --git a/nova/tests/unit/test_notifications.py b/nova/tests/unit/test_notifications.py index 405fbc4dd2df..1a1f1cf2b1e7 100644 --- a/nova/tests/unit/test_notifications.py +++ b/nova/tests/unit/test_notifications.py @@ -26,7 +26,7 @@ from nova.compute import task_states from nova.compute import vm_states from nova import context from nova import exception -from nova import notifications +from nova.notifications import base as notifications from nova import objects from nova.objects import base as obj_base from nova import test @@ -417,7 +417,8 @@ class NotificationsTestCase(test.TestCase): def sending_no_state_change(context, instance, **kwargs): called[0] = True - self.stub_out('nova.notifications._send_instance_update_notification', + self.stub_out('nova.notifications.base.' + '_send_instance_update_notification', sending_no_state_change) notifications.send_update(self.context, self.instance, self.instance) self.assertTrue(called[0]) @@ -425,7 +426,8 @@ class NotificationsTestCase(test.TestCase): def test_fail_sending_update(self): def fail_sending(context, instance, **kwargs): raise Exception('failed to notify') - self.stub_out('nova.notifications._send_instance_update_notification', + self.stub_out('nova.notifications.base.' + '_send_instance_update_notification', fail_sending) notifications.send_update(self.context, self.instance, self.instance)