Merge "Check if the newhost exists instead of currenthost"

This commit is contained in:
Zuul 2022-04-25 12:20:36 +00:00 committed by Gerrit Code Review
commit bc3b511544
2 changed files with 7 additions and 6 deletions

View File

@ -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):

View File

@ -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')
@mock.patch.object(cinder_manage, 'cinder_manage_service_list')
@mock.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')