Adding FlagNotSet exception

This commit is contained in:
Rick Harris 2011-05-18 14:46:39 -05:00
parent 6c850d72a6
commit 01f7b0aa8d
3 changed files with 18 additions and 1 deletions

View File

@ -18,6 +18,7 @@ import urlparse
from nova import crypto
from nova import db
from nova import exception
from nova import flags
from nova import log as logging
from nova.api.openstack import common
@ -54,7 +55,7 @@ def _scrub_zone(zone):
def check_encryption_key(func):
def wrapped(*args, **kwargs):
if not FLAGS.build_plan_encryption_key:
raise exception.Error(_("--build_plan_encryption_key not set"))
raise exception.FlagNotSet(flag='build_plan_encryption_key')
return func(*args, **kwargs)
return wrapped

View File

@ -255,6 +255,10 @@ class NotFound(NovaException):
super(NotFound, self).__init__(**kwargs)
class FlagNotSet(NotFound):
message = _("Required flag %(flag)s not set.")
class InstanceNotFound(NotFound):
message = _("Instance %(instance_id)s could not be found.")

View File

@ -21,6 +21,7 @@ import json
import nova.db
from nova import context
from nova import crypto
from nova import exception
from nova import flags
from nova import test
from nova.api.openstack import zones
@ -120,6 +121,17 @@ class ZonesTest(test.TestCase):
FLAGS.zone_capabilities = self.old_zone_capabilities
super(ZonesTest, self).tearDown()
def test_check_encryption_key(self):
@zones.check_encryption_key
def test_func():
return 42
self.assertRaises(exception.FlagNotSet, test_func)
FLAGS.build_plan_encryption_key = "something"
ret = test_func()
self.assertEqual(ret, 42)
def test_get_zone_list_scheduler(self):
self.stubs.Set(api, '_call_scheduler', zone_get_all_scheduler)
req = webob.Request.blank('/v1.0/zones')