extract_host: Handle empty host string input
This fixes an HTTP 500 error caused by the assumption that this field is always populated for a volume. Closes-Bug: #1628536 Change-Id: I19df26c37c03f8220fb3d87395f32b5ddef6bf9d
This commit is contained in:
parent
1a120c9887
commit
b66a41cefe
@ -716,6 +716,11 @@ class VolumeUtilsTestCase(test.TestCase):
|
||||
self.assertEqual(pool,
|
||||
volume_utils.extract_host(host, 'pool', True))
|
||||
|
||||
def test_extract_host_none_string(self):
|
||||
self.assertRaises(exception.InvalidVolume,
|
||||
volume_utils.extract_host,
|
||||
None)
|
||||
|
||||
def test_get_volume_rpc_host(self):
|
||||
host = 'Host@backend'
|
||||
# default level is 'backend'
|
||||
|
@ -648,7 +648,8 @@ def extract_host(host, level='backend', default_pool_name=False):
|
||||
string. default_pool_name=True will return
|
||||
DEFAULT_POOL_NAME, otherwise we return None.
|
||||
Default value of this parameter is False.
|
||||
:return: expected level of information
|
||||
:return: expected information, string or None
|
||||
:raises: exception.InvalidVolume
|
||||
|
||||
For example:
|
||||
host = 'HostA@BackendB#PoolC'
|
||||
@ -665,6 +666,11 @@ def extract_host(host, level='backend', default_pool_name=False):
|
||||
ret = extract_host(host, 'pool', True)
|
||||
# ret is '_pool0'
|
||||
"""
|
||||
|
||||
if host is None:
|
||||
msg = _LE("volume is not assigned to a host")
|
||||
raise exception.InvalidVolume(reason=msg)
|
||||
|
||||
if level == 'host':
|
||||
# make sure pool is not included
|
||||
hst = host.split('#')[0]
|
||||
|
Loading…
Reference in New Issue
Block a user