Check if the newhost exists instead of currenthost
Closes-Bug: #1956470
Signed-off-by: Dongdong Tao <dongdong.tao@canonical.com>
Change-Id: I2b9eec030a5b0f6d9a405cecea29bef04eb72f5d
(cherry picked from commit 93dfc624d4
)
This commit is contained in:
parent
7cd922842d
commit
0a0cbaeee7
|
@ -143,7 +143,8 @@ def remove_services(args):
|
|||
|
||||
def _rename_volume_host(currenthost, newhost):
|
||||
services = cinder_manage_service_list()
|
||||
services = [s for s in services if s.host == currenthost]
|
||||
services = [s for s in services if s.host == newhost or
|
||||
("#" in newhost and s.host == newhost[0:newhost.rfind('#')])]
|
||||
if services:
|
||||
try:
|
||||
cinder_manage_volume_update_host(currenthost, newhost)
|
||||
|
@ -151,8 +152,8 @@ def _rename_volume_host(currenthost, newhost):
|
|||
action_set({'traceback': traceback.format_exc()})
|
||||
action_fail("Cannot update host {}".format(currenthost))
|
||||
else:
|
||||
action_fail("Cannot update host attribute from {}, {} not found"
|
||||
.format(currenthost, currenthost))
|
||||
action_fail("Cannot update host attribute to {}, {} not found"
|
||||
.format(newhost, newhost))
|
||||
|
||||
|
||||
def rename_volume_host(args):
|
||||
|
|
|
@ -107,7 +107,7 @@ class CinderManageTestCase(CharmTestCase):
|
|||
self.action_get.return_value = 'myhost'
|
||||
svc1_mock = mock.MagicMock()
|
||||
svc1_mock.binary = "cinder-volume"
|
||||
svc1_mock.host = "a"
|
||||
svc1_mock.host = "b"
|
||||
cinder_manage_service_list.return_value = [svc1_mock]
|
||||
cinder_manage._rename_volume_host('a', 'b')
|
||||
cinder_manage_volume_update_host.assert_called_once_with('a', 'b')
|
||||
|
@ -122,7 +122,7 @@ class CinderManageTestCase(CharmTestCase):
|
|||
cinder_manage._rename_volume_host('a', 'b')
|
||||
self.assertFalse(cinder_manage_volume_update_host.called)
|
||||
self.action_fail.assert_called_once_with(
|
||||
'Cannot update host attribute from a, a not found')
|
||||
'Cannot update host attribute to b, b not found')
|
||||
|
||||
@patch.object(cinder_manage, 'cinder_manage_service_list')
|
||||
@patch.object(cinder_manage, 'cinder_manage_volume_update_host')
|
||||
|
@ -133,7 +133,7 @@ class CinderManageTestCase(CharmTestCase):
|
|||
self.action_get.return_value = 'myhost'
|
||||
svc1_mock = mock.MagicMock()
|
||||
svc1_mock.binary = "cinder-volume"
|
||||
svc1_mock.host = "a"
|
||||
svc1_mock.host = "b"
|
||||
cinder_manage_service_list.return_value = [svc1_mock]
|
||||
cinder_manage._rename_volume_host('a', 'b')
|
||||
cinder_manage_volume_update_host.assert_called_once_with('a', 'b')
|
||||
|
|
Loading…
Reference in New Issue