Consolidating multiple volume flags into a single flag.

Implements blueprint reddwarf/fix-volume-flags

Change-Id: If5f2333579835483455e112351887e13d665976d
This commit is contained in:
Michael Basnight 2013-01-10 10:12:01 -06:00
parent 3ddfd656d5
commit 07db67168d
6 changed files with 19 additions and 20 deletions

View File

@ -36,7 +36,6 @@ common_opts = [
cfg.BoolOpt('reddwarf_volume_support',
default=False,
help='File name for the paste.deploy config for reddwarf-api'),
cfg.BoolOpt('reddwarf_must_use_volume', default=False),
cfg.ListOpt('admin_roles', default=[]),
cfg.StrOpt('remote_implementation',
default="real",

View File

@ -272,15 +272,14 @@ class InstanceController(wsgi.Controller):
if not name:
raise exception.MissingKey(key='name')
vol_enabled = CONF.reddwarf_volume_support
must_have_vol = CONF.reddwarf_must_use_volume
if vol_enabled:
if body['instance'].get('volume', None):
if body['instance']['volume'].get('size', None):
volume_size = body['instance']['volume']['size']
InstanceController._validate_volume_size(volume_size)
elif must_have_vol:
else:
raise exception.MissingKey(key="size")
elif must_have_vol:
else:
raise exception.MissingKey(key="volume")
except KeyError as e:

View File

@ -235,7 +235,7 @@ class CreateInstance(unittest.TestCase):
"""
def test_instance_size_too_big(self):
vol_ok = CONFIG.get('reddwarf_can_have_volume', False)
vol_ok = CONFIG.get('reddwarf_volume_support', False)
if 'reddwarf_max_accepted_volume_size' in CONFIG.values and vol_ok:
too_big = CONFIG.values['reddwarf_max_accepted_volume_size']
assert_raises(exceptions.OverLimit, dbaas.instances.create,
@ -253,7 +253,7 @@ class CreateInstance(unittest.TestCase):
users.append({"name": "lite", "password": "litepass",
"databases": [{"name": "firstdb"}]})
instance_info.users = users
if CONFIG.values['reddwarf_main_instance_has_volume']:
if CONFIG.values['reddwarf_volume_support']:
instance_info.volume = {'size': 1}
else:
instance_info.volume = None
@ -290,7 +290,7 @@ class CreateInstance(unittest.TestCase):
# Check these attrs only are returned in create response
expected_attrs = ['created', 'flavor', 'addresses', 'id', 'links',
'name', 'status', 'updated']
if CONFIG.values['reddwarf_can_have_volume']:
if CONFIG.values['reddwarf_volume_support']:
expected_attrs.append('volume')
if CONFIG.values['reddwarf_dns_support']:
expected_attrs.append('hostname')
@ -302,11 +302,11 @@ class CreateInstance(unittest.TestCase):
# Don't CheckInstance if the instance already exists.
check.flavor()
check.links(result._info['links'])
if CONFIG.values['reddwarf_can_have_volume']:
if CONFIG.values['reddwarf_volume_support']:
check.volume()
def test_create_failure_with_empty_volume(self):
if CONFIG.values['reddwarf_must_have_volume']:
if CONFIG.values['reddwarf_volume_support']:
instance_name = "instance-failure-with-no-volume-size"
databases = []
volume = {}
@ -316,7 +316,7 @@ class CreateInstance(unittest.TestCase):
assert_equal(400, dbaas.last_http_code)
def test_create_failure_with_no_volume_size(self):
if CONFIG.values['reddwarf_must_have_volume']:
if CONFIG.values['reddwarf_volume_support']:
instance_name = "instance-failure-with-no-volume-size"
databases = []
volume = {'size': None}
@ -326,7 +326,7 @@ class CreateInstance(unittest.TestCase):
assert_equal(400, dbaas.last_http_code)
def test_create_failure_with_no_name(self):
if CONFIG.values['reddwarf_main_instance_has_volume']:
if CONFIG.values['reddwarf_volume_support']:
volume = {'size': 1}
else:
volume = None
@ -338,7 +338,7 @@ class CreateInstance(unittest.TestCase):
assert_equal(400, dbaas.last_http_code)
def test_create_failure_with_spaces_for_name(self):
if CONFIG.values['reddwarf_main_instance_has_volume']:
if CONFIG.values['reddwarf_volume_support']:
volume = {'size': 1}
else:
volume = None
@ -650,7 +650,7 @@ class TestInstanceListing(object):
def test_get_legacy_status_notfound(self):
assert_raises(exceptions.NotFound, dbaas.instances.get, -2)
@test(enabled=CONFIG.values["reddwarf_main_instance_has_volume"])
@test(enabled=CONFIG.values["reddwarf_volume_support"])
def test_volume_found(self):
instance = dbaas.instances.get(instance_info.id)
if create_new_instance():
@ -756,7 +756,7 @@ class DeleteInstance(object):
"time: %s" % (str(instance_info.id), attempts, str(ex)))
@time_out(30)
@test(enabled=CONFIG.values["reddwarf_can_have_volume"],
@test(enabled=CONFIG.values["reddwarf_volume_support"],
depends_on=[test_delete])
def test_volume_is_deleted(self):
raise SkipTest("Cannot test volume is deleted from db.")
@ -881,14 +881,14 @@ class CheckInstance(AttrCheck):
self.links(self.instance['flavor']['links'])
def volume_key_exists(self):
if CONFIG.values['reddwarf_main_instance_has_volume']:
if CONFIG.values['reddwarf_volume_support']:
if 'volume' not in self.instance:
self.fail("'volume' not found in instance.")
return False
return True
def volume(self):
if not CONFIG.values["reddwarf_can_have_volume"]:
if not CONFIG.values["reddwarf_volume_support"]:
return
if self.volume_key_exists():
expected_attrs = ['size']
@ -898,7 +898,7 @@ class CheckInstance(AttrCheck):
msg="Volumes")
def used_volume(self):
if not CONFIG.values["reddwarf_can_have_volume"]:
if not CONFIG.values["reddwarf_volume_support"]:
return
if self.volume_key_exists():
expected_attrs = ['size', 'used']

View File

@ -314,7 +314,7 @@ class StopTests(RebootTestBase):
Confirms the get call behaves appropriately while an instance is
down.
"""
if not CONFIG.reddwarf_main_instance_has_volume:
if not CONFIG.reddwarf_volume_support:
raise SkipTest("Not testing volumes.")
instance = self.dbaas.instances.get(self.instance_id)
with TypeCheck("instance", instance) as check:
@ -489,7 +489,7 @@ def resize_should_not_delete_users():
@test(depends_on_classes=[ResizeInstanceTest], depends_on=[create_user],
groups=[GROUP, tests.INSTANCES],
enabled=CONFIG.reddwarf_main_instance_has_volume)
enabled=CONFIG.reddwarf_volume_support)
class ResizeInstanceVolume(object):
""" Resize the volume of the instance """

View File

@ -95,7 +95,7 @@ def mgmt_instance_get():
instance.has_field('tenant_id', basestring)
instance.has_field('updated', basestring)
# Can be None if no volume is given on this instance.
if CONFIG.reddwarf_main_instance_has_volume:
if CONFIG.reddwarf_volume_support:
instance.has_field('volume', dict, volume_check)
else:
instance.has_field('volume', None)

View File

@ -79,6 +79,7 @@ class TestConfig(object):
"report_directory": os.environ.get("REPORT_DIRECTORY", None),
"sleep_mode": "simulated",
"simulate_events": False,
"reddwarf_volume_support": True,
}
self._frozen_values = FrozenDict(self._values)
self._users = None