summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvladimir.p <vladimir@zadarastorage.com>2011-08-24 16:54:00 -0700
committervladimir.p <vladimir@zadarastorage.com>2011-08-24 16:54:00 -0700
commit2d7f401c4fb555d947bc10b4f0ddf9bdfd86b69d (patch)
tree8c1f7a012ffc563baeb4194a506af06fea611030
parent08af6ab6325e27b60d3d036d6e780f8e594234cc (diff)
parent3a2cdb0d9dc3e8a4ebf30bb31b37bb6bca84330f (diff)
downloadnova-2d7f401c4fb555d947bc10b4f0ddf9bdfd86b69d.tar.gz
merged with volume types (based on rev.1490). no code rework yet
-rw-r--r--Authors1
-rw-r--r--nova/db/sqlalchemy/migration.py5
-rw-r--r--nova/notifier/list_notifier.py68
-rw-r--r--nova/tests/notifier/__init__.py16
-rw-r--r--nova/tests/notifier/test_list_notifier.py88
-rw-r--r--nova/volume/driver.py2
6 files changed, 177 insertions, 3 deletions
diff --git a/Authors b/Authors
index 310c0c8b9f..2d2cde97ef 100644
--- a/Authors
+++ b/Authors
@@ -100,6 +100,7 @@ Scott Moser <smoser@ubuntu.com>
Soren Hansen <soren.hansen@rackspace.com>
Stephanie Reese <reese.sm@gmail.com>
Thierry Carrez <thierry@openstack.org>
+Tim Simpson <tim.simpson@rackspace.com>
Todd Willey <todd@ansolabs.com>
Trey Morris <trey.morris@rackspace.com>
Troy Toman <troy.toman@rackspace.com>
diff --git a/nova/db/sqlalchemy/migration.py b/nova/db/sqlalchemy/migration.py
index f75ab7833d..bb05986c98 100644
--- a/nova/db/sqlalchemy/migration.py
+++ b/nova/db/sqlalchemy/migration.py
@@ -64,8 +64,9 @@ def db_version():
'users', 'user_project_association',
'user_project_role_association',
'user_role_association',
- 'virtual_storage_arrays', 'drive_types',
- 'volumes'):
+ 'virtual_storage_arrays',
+ 'volumes', 'volume_metadata',
+ 'volume_types', 'volume_type_extra_specs'):
assert table in meta.tables
return db_version_control(1)
except AssertionError:
diff --git a/nova/notifier/list_notifier.py b/nova/notifier/list_notifier.py
new file mode 100644
index 0000000000..955ae1b57d
--- /dev/null
+++ b/nova/notifier/list_notifier.py
@@ -0,0 +1,68 @@
+# Copyright 2011 OpenStack LLC.
+# 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.
+
+from nova import flags
+from nova import log as logging
+from nova import utils
+from nova.exception import ClassNotFound
+
+flags.DEFINE_multistring('list_notifier_drivers',
+ ['nova.notifier.no_op_notifier'],
+ 'List of drivers to send notifications')
+
+FLAGS = flags.FLAGS
+
+LOG = logging.getLogger('nova.notifier.list_notifier')
+
+drivers = None
+
+
+class ImportFailureNotifier(object):
+ """Noisily re-raises some exception over-and-over when notify is called."""
+
+ def __init__(self, exception):
+ self.exception = exception
+
+ def notify(self, message):
+ raise self.exception
+
+
+def _get_drivers():
+ """Instantiates and returns drivers based on the flag values."""
+ global drivers
+ if not drivers:
+ drivers = []
+ for notification_driver in FLAGS.list_notifier_drivers:
+ try:
+ drivers.append(utils.import_object(notification_driver))
+ except ClassNotFound as e:
+ drivers.append(ImportFailureNotifier(e))
+ return drivers
+
+
+def notify(message):
+ """Passes notification to mulitple notifiers in a list."""
+ for driver in _get_drivers():
+ try:
+ driver.notify(message)
+ except Exception as e:
+ LOG.exception(_("Problem '%(e)s' attempting to send to "
+ "notification driver %(driver)s." % locals()))
+
+
+def _reset_drivers():
+ """Used by unit tests to reset the drivers."""
+ global drivers
+ drivers = None
diff --git a/nova/tests/notifier/__init__.py b/nova/tests/notifier/__init__.py
new file mode 100644
index 0000000000..bd862c46a9
--- /dev/null
+++ b/nova/tests/notifier/__init__.py
@@ -0,0 +1,16 @@
+# Copyright 2011 Openstack LLC.
+# 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.
+
+from nova.tests import *
diff --git a/nova/tests/notifier/test_list_notifier.py b/nova/tests/notifier/test_list_notifier.py
new file mode 100644
index 0000000000..b777207596
--- /dev/null
+++ b/nova/tests/notifier/test_list_notifier.py
@@ -0,0 +1,88 @@
+# Copyright 2011 OpenStack LLC.
+# 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 stubout
+import sys
+
+import nova
+from nova import log as logging
+import nova.notifier.api
+from nova.notifier.api import notify
+from nova.notifier import log_notifier
+from nova.notifier import no_op_notifier
+from nova.notifier import list_notifier
+from nova import test
+
+
+class NotifierListTestCase(test.TestCase):
+ """Test case for notifications"""
+
+ def setUp(self):
+ super(NotifierListTestCase, self).setUp()
+ list_notifier._reset_drivers()
+ self.stubs = stubout.StubOutForTesting()
+ # Mock log to add one to exception_count when log.exception is called
+
+ def mock_exception(cls, *args):
+ self.exception_count += 1
+
+ self.exception_count = 0
+ list_notifier_log = logging.getLogger('nova.notifier.list_notifier')
+ self.stubs.Set(list_notifier_log, "exception", mock_exception)
+ # Mock no_op notifier to add one to notify_count when called.
+
+ def mock_notify(cls, *args):
+ self.notify_count += 1
+
+ self.notify_count = 0
+ self.stubs.Set(nova.notifier.no_op_notifier, 'notify', mock_notify)
+ # Mock log_notifier to raise RuntimeError when called.
+
+ def mock_notify2(cls, *args):
+ raise RuntimeError("Bad notifier.")
+
+ self.stubs.Set(nova.notifier.log_notifier, 'notify', mock_notify2)
+
+ def tearDown(self):
+ self.stubs.UnsetAll()
+ list_notifier._reset_drivers()
+ super(NotifierListTestCase, self).tearDown()
+
+ def test_send_notifications_successfully(self):
+ self.flags(notification_driver='nova.notifier.list_notifier',
+ list_notifier_drivers=['nova.notifier.no_op_notifier',
+ 'nova.notifier.no_op_notifier'])
+ notify('publisher_id', 'event_type',
+ nova.notifier.api.WARN, dict(a=3))
+ self.assertEqual(self.notify_count, 2)
+ self.assertEqual(self.exception_count, 0)
+
+ def test_send_notifications_with_errors(self):
+
+ self.flags(notification_driver='nova.notifier.list_notifier',
+ list_notifier_drivers=['nova.notifier.no_op_notifier',
+ 'nova.notifier.log_notifier'])
+ notify('publisher_id', 'event_type', nova.notifier.api.WARN, dict(a=3))
+ self.assertEqual(self.notify_count, 1)
+ self.assertEqual(self.exception_count, 1)
+
+ def test_when_driver_fails_to_import(self):
+ self.flags(notification_driver='nova.notifier.list_notifier',
+ list_notifier_drivers=['nova.notifier.no_op_notifier',
+ 'nova.notifier.logo_notifier',
+ 'fdsjgsdfhjkhgsfkj'])
+ notify('publisher_id', 'event_type', nova.notifier.api.WARN, dict(a=3))
+ self.assertEqual(self.exception_count, 2)
+ self.assertEqual(self.notify_count, 1)
diff --git a/nova/volume/driver.py b/nova/volume/driver.py
index a1d7f700e2..9e046d054d 100644
--- a/nova/volume/driver.py
+++ b/nova/volume/driver.py
@@ -501,7 +501,7 @@ class ISCSIDriver(VolumeDriver):
(out, err) = self._execute('iscsiadm', '-m', 'node', '-T',
iscsi_properties['target_iqn'],
'-p', iscsi_properties['target_portal'],
- iscsi_command, run_as_root=True)
+ *iscsi_command, run_as_root=True)
LOG.debug("iscsiadm %s: stdout=%s stderr=%s" %
(iscsi_command, out, err))
return (out, err)