Exclude on maintenance reserved_hosts for host_failure recovery

masakari-engine considers reserved_hosts which are under maintenance
for host failure recovery when recovery_method is reserved_host,
auto_priority or rh_priority and passes it to workflow for processing.

If the reserved_host is under maintenance then it should not be used
for evacuating the instances for host_failure recovery.

This patch excludes reserved_hosts which are on maintenance for
host_failure recovery by filtering host_list with
'on_maintenance'=False.

Closes-Bug: #1697902
Change-Id: Ie6beff110d03b67d6f5d8694603816c0db017660
This commit is contained in:
Dinesh Bhor 2017-06-14 10:58:59 +05:30
parent 00969f0bf2
commit 81ed98101e
3 changed files with 27 additions and 1 deletions

View File

@ -154,7 +154,9 @@ class MasakariManager(manager.Manager):
reserved_host_list = objects.HostList.get_all(
context, filters={
'failover_segment_id': host_obj.failover_segment_id,
'reserved': True})
'reserved': True,
'on_maintenance': False
})
try:
self.driver.execute_host_failure(

View File

@ -296,6 +296,27 @@ class HostsTestCase(test.TestCase, ModelsObjectComparatorMixin):
sort_dirs=['asc'])
self._assertEqualListsOfObjects([hosts[1]], real_host, ignored_keys)
def test_host_get_all_by_filter_on_maintenance(self):
for p in self._get_fake_values_list():
# create temporary reserved_hosts, all are on maintenance
self._create_host(p)
# create one more reserved_host which is not on maintenance
temp_host = self._get_fake_values()
temp_host['on_maintenance'] = False
self._create_host(temp_host)
ignored_keys = ['deleted', 'created_at', 'updated_at', 'deleted_at',
'id', 'failover_segment']
real_host = db.host_get_all_by_filters(
context=self.ctxt,
filters={'on_maintenance': False},
marker=1,
limit=1,
sort_keys=['id'],
sort_dirs=['asc'])
self._assertEqualListsOfObjects([temp_host], real_host, ignored_keys)
def test_host_not_found(self):
self._create_host(self._get_fake_values())
self.assertRaises(exception.HostNotFound,

View File

@ -303,6 +303,9 @@ class EngineManagerUnitTestCase(test.NoDBTestCase):
fake_host.name, fake_host.failover_segment.recovery_method,
notification.notification_uuid,
reserved_host_list=reserved_host_list)
mock_get_all.assert_called_once_with(self.context, filters={
'failover_segment_id': fake_host.failover_segment.uuid,
'reserved': True, 'on_maintenance': False})
@mock.patch.object(host_obj.Host, "get_by_uuid")
@mock.patch.object(host_obj.Host, "save")