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
(cherry picked from commit b66a41cefe
)
This commit is contained in:
parent
ab95181121
commit
a0b0d110da
@ -716,6 +716,11 @@ class VolumeUtilsTestCase(test.TestCase):
|
|||||||
self.assertEqual(pool,
|
self.assertEqual(pool,
|
||||||
volume_utils.extract_host(host, 'pool', True))
|
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):
|
def test_get_volume_rpc_host(self):
|
||||||
host = 'Host@backend'
|
host = 'Host@backend'
|
||||||
# default level is 'backend'
|
# default level is 'backend'
|
||||||
|
@ -645,7 +645,8 @@ def extract_host(host, level='backend', default_pool_name=False):
|
|||||||
string. default_pool_name=True will return
|
string. default_pool_name=True will return
|
||||||
DEFAULT_POOL_NAME, otherwise we return None.
|
DEFAULT_POOL_NAME, otherwise we return None.
|
||||||
Default value of this parameter is False.
|
Default value of this parameter is False.
|
||||||
:return: expected level of information
|
:return: expected information, string or None
|
||||||
|
:raises: exception.InvalidVolume
|
||||||
|
|
||||||
For example:
|
For example:
|
||||||
host = 'HostA@BackendB#PoolC'
|
host = 'HostA@BackendB#PoolC'
|
||||||
@ -662,6 +663,11 @@ def extract_host(host, level='backend', default_pool_name=False):
|
|||||||
ret = extract_host(host, 'pool', True)
|
ret = extract_host(host, 'pool', True)
|
||||||
# ret is '_pool0'
|
# ret is '_pool0'
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
if host is None:
|
||||||
|
msg = _LE("volume is not assigned to a host")
|
||||||
|
raise exception.InvalidVolume(reason=msg)
|
||||||
|
|
||||||
if level == 'host':
|
if level == 'host':
|
||||||
# make sure pool is not included
|
# make sure pool is not included
|
||||||
hst = host.split('#')[0]
|
hst = host.split('#')[0]
|
||||||
|
Loading…
Reference in New Issue
Block a user