diff --git a/cinder/tests/unit/test_volume_utils.py b/cinder/tests/unit/test_volume_utils.py index ad7856429..c49b113a7 100644 --- a/cinder/tests/unit/test_volume_utils.py +++ b/cinder/tests/unit/test_volume_utils.py @@ -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' diff --git a/cinder/volume/utils.py b/cinder/volume/utils.py index 713351d29..0aec08aad 100644 --- a/cinder/volume/utils.py +++ b/cinder/volume/utils.py @@ -645,7 +645,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' @@ -662,6 +663,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]