def test_node_recover2_not_found(self, mock_find): mock_find.side_effect = exc.ResourceNotFound(type='node', id='Bogus') req = orno.NodeRecoverRequest(identity='Bogus') ex = self.assertRaises(rpc.ExpectedException, self.eng.node_recover2, self.ctx, req.obj_to_primitive()) self.assertEqual(exc.ResourceNotFound, ex.exc_info[0]) self.assertEqual('The node (Bogus) could not be found.', six.text_type(ex.exc_info[1])) mock_find.assert_called_once_with(self.ctx, 'Bogus')
def test_node_recover_invalid_operation(self, mock_find, mock_action): mock_find.return_value = mock.Mock(id='12345678AB') mock_action.return_value = 'ACTION_ID' params = {'bogus': 'illegal'} req = orno.NodeRecoverRequest(identity='FAKE_NODE', params=params) ex = self.assertRaises(rpc.ExpectedException, self.eng.node_recover, self.ctx, req.obj_to_primitive()) self.assertEqual(exc.BadRequest, ex.exc_info[0]) self.assertEqual("Action parameter ['bogus'] is not recognizable.", six.text_type(ex.exc_info[1])) mock_find.assert_called_once_with(self.ctx, 'FAKE_NODE') self.assertEqual(0, mock_action.call_count)
def test_node_recover_with_check(self, mock_find, mock_action, mock_start): mock_find.return_value = mock.Mock(id='12345678AB') mock_action.return_value = 'ACTION_ID' params = {'check': True, 'operation': 'some_action'} req = orno.NodeRecoverRequest(identity='FAKE_NODE', params=params) result = self.eng.node_recover(self.ctx, req.obj_to_primitive()) self.assertEqual({'action': 'ACTION_ID'}, result) mock_find.assert_called_once_with(self.ctx, 'FAKE_NODE') mock_action.assert_called_once_with( self.ctx, '12345678AB', consts.NODE_RECOVER, name='node_recover_12345678', cause=consts.CAUSE_RPC, status=action_mod.Action.READY, inputs={'check': True, 'operation': [{'name': 'some_action'}]}) mock_start.assert_called_once_with()
def test_node_recover_request(self): sot = nodes.NodeRecoverRequest(**self.body) self.assertEqual({'foo': 'bar'}, sot.params)