fix the error in cluster_action.do_recover(...)

The action should also accept the parameters come from the api request,
but not only use the parameters come from health policy.

Change-Id: Idb0e41e66a5b13ef7f729a058a4d70866c1218e0
This commit is contained in:
RUIJIE YUAN 2017-05-26 14:53:47 +08:00
parent 280a690ee7
commit c09e113663
2 changed files with 56 additions and 3 deletions

View File

@ -666,15 +666,20 @@ class ClusterAction(base.Action):
pd = self.data.get('health', None)
inputs = {}
if pd:
check = self.data.get('check', False)
recover_action = pd.get('recover_action', None)
fencing = pd.get('fencing', None)
if recover_action is not None:
inputs['operation'] = recover_action
if fencing is not None and 'COMPUTE' in fencing:
inputs['params'] = {'fence_compute': True}
else:
check = self.inputs.get('check', False)
recover_action = self.inputs.get('operation', None)
if recover_action is not None:
inputs['operation'] = recover_action
children = []
check = self.data.get('check', False)
for node in self.entity.nodes:
if check:
node.do_check(self.context)

View File

@ -127,6 +127,54 @@ class ClusterRecoverTest(base.SenlinTestCase):
cluster.eval_status.assert_called_once_with(
action.context, consts.CLUSTER_RECOVER)
@mock.patch.object(ao.Action, 'update')
@mock.patch.object(ab.Action, 'create')
@mock.patch.object(dobj.Dependency, 'create')
@mock.patch.object(dispatcher, 'start_action')
@mock.patch.object(ca.ClusterAction, '_wait_for_dependents')
def test_do_recover_with_input(self, mock_wait, mock_start, mock_dep,
mock_action, mock_update, mock_load):
node1 = mock.Mock(id='NODE_1', cluster_id='FAKE_ID', status='ERROR')
cluster = mock.Mock(id='FAKE_ID', RECOVERING='RECOVERING')
cluster.nodes = [node1]
cluster.do_recover.return_value = True
mock_load.return_value = cluster
action = ca.ClusterAction(cluster.id, 'CLUSTER_RECOVER', self.ctx)
action.id = 'CLUSTER_ACTION_ID'
action.inputs = {
'operation': consts.RECOVER_REBOOT,
'check': False,
}
mock_action.return_value = 'NODE_RECOVER_ID'
mock_wait.return_value = (action.RES_OK, 'Everything is Okay')
# do it
res_code, res_msg = action.do_recover()
# assertions
self.assertEqual(action.RES_OK, res_code)
self.assertEqual('Cluster recovery succeeded.', res_msg)
cluster.do_recover.assert_called_once_with(action.context)
mock_action.assert_called_once_with(
action.context, 'NODE_1', 'NODE_RECOVER',
name='node_recover_NODE_1',
cause=consts.CAUSE_DERIVED,
inputs={
'operation': consts.RECOVER_REBOOT
}
)
mock_dep.assert_called_once_with(action.context, ['NODE_RECOVER_ID'],
'CLUSTER_ACTION_ID')
mock_update.assert_called_once_with(action.context, 'NODE_RECOVER_ID',
{'status': 'READY'})
mock_start.assert_called_once_with()
mock_wait.assert_called_once_with()
cluster.eval_status.assert_called_once_with(
action.context, consts.CLUSTER_RECOVER)
def test_do_recover_all_nodes_active(self, mock_load):
cluster = mock.Mock(id='FAKE_ID')
cluster.do_recover.return_value = True
@ -205,7 +253,7 @@ class ClusterRecoverTest(base.SenlinTestCase):
node2.do_check = mock_check
action = ca.ClusterAction(cluster.id, 'CLUSTER_RECOVER', self.ctx)
action.data = {'check': True}
action.inputs = {'check': True}
# do it
res_code, res_msg = action.do_recover()
@ -235,7 +283,7 @@ class ClusterRecoverTest(base.SenlinTestCase):
action = ca.ClusterAction(cluster.id, 'CLUSTER_RECOVER', self.ctx)
action.id = 'CLUSTER_ACTION_ID'
action.data = {'check': True}
action.inputs = {'check': True}
mock_action.return_value = 'NODE_RECOVER_ID'
mock_wait.return_value = (action.RES_OK, 'Everything is Okay')