def test_returns_failure_set_error_state(self): """ The group is put into ERROR state if any step returns FAILURE, and FAILURE is the final result of convergence. """ exc_info = raise_to_exc_info(NoSuchCLBError(lb_id=u'nolb1')) exc_info2 = raise_to_exc_info(NoSuchCLBError(lb_id=u'nolb2')) def plan(*args, **kwargs): return [ TestStep(Effect("success1")), TestStep(Effect("retry")), TestStep(Effect("success2")), TestStep(Effect("fail1")), TestStep(Effect("fail2")), TestStep(Effect("success3"))] def success(i): return StepResult.SUCCESS, [] sequence = [ parallel_sequence([]), (Log(msg='execute-convergence', fields=mock.ANY), noop), parallel_sequence([ [("success1", success)], [("retry", lambda i: (StepResult.RETRY, []))], [("success2", success)], [("fail1", lambda i: (StepResult.FAILURE, [ErrorReason.Exception(exc_info)]))], [("fail2", lambda i: (StepResult.FAILURE, [ErrorReason.Exception(exc_info2)]))], [("success3", success)], ]), (Log(msg='execute-convergence-results', fields=mock.ANY), noop), (UpdateGroupStatus(scaling_group=self.group, status=ScalingGroupStatus.ERROR), noop), (Log('group-status-error', dict(isError=True, cloud_feed=True, status='ERROR', reasons=['Cloud Load Balancer does not exist: nolb1', 'Cloud Load Balancer does not exist: nolb2'])), noop), (UpdateGroupErrorReasons( self.group, ['Cloud Load Balancer does not exist: nolb1', 'Cloud Load Balancer does not exist: nolb2']), noop) ] self.assertEqual( perform_sequence(self.get_seq() + sequence, self._invoke(plan)), (StepResult.FAILURE, ScalingGroupStatus.ERROR))
def test_failure_unknown_reasons(self): """ The group is put into ERROR state if any step returns FAILURE, and unknown error is defaulted to fixed reason """ exc_info = raise_to_exc_info(ValueError('wat')) def plan(*args, **kwargs): return [TestStep(Effect("fail"))] sequence = [ parallel_sequence([]), (Log(msg='execute-convergence', fields=mock.ANY), noop), parallel_sequence([ [("fail", lambda i: (StepResult.FAILURE, [ErrorReason.Exception(exc_info)]))] ]), (Log(msg='execute-convergence-results', fields=mock.ANY), noop), (UpdateGroupStatus(scaling_group=self.group, status=ScalingGroupStatus.ERROR), noop), (Log('group-status-error', dict(isError=True, cloud_feed=True, status='ERROR', reasons=['Unknown error occurred'])), noop), (UpdateGroupErrorReasons(self.group, ['Unknown error occurred']), noop) ] self.assertEqual( perform_sequence(self.get_seq() + sequence, self._invoke(plan)), (StepResult.FAILURE, ScalingGroupStatus.ERROR))
def test_present_exceptions(self): """Some exceptions are presented.""" excs = { NoSuchCLBError(lb_id=u'lbid1'): 'Cloud Load Balancer does not exist: lbid1', CLBDeletedError(lb_id=u'lbid2'): 'Cloud Load Balancer is currently being deleted: lbid2', NoSuchCLBNodeError(lb_id=u'lbid3', node_id=u'node1'): "Node node1 of Cloud Load Balancer lbid3 does not exist", CLBNodeLimitError(lb_id=u'lb2', node_limit=25): "Cannot create more than 25 nodes in Cloud Load Balancer lb2", CLBHealthInfoNotFound(u'lb2'): "Could not find health monitor configuration of " "Cloud Load Balancer lb2", CreateServerConfigurationError("Your server is wrong"): 'Server launch configuration is invalid: Your server is wrong', CreateServerOverQuoteError("You are over quota"): 'Servers cannot be created: You are over quota', NoSuchEndpoint(service_name="nova", region="ord"): "Could not locate service nova in the service catalog. " "Please check if your account is still active." } excs = excs.items() self.assertEqual( present_reasons([ErrorReason.Exception(raise_to_exc_info(exc)) for (exc, _) in excs]), [reason for (_, reason) in excs])
def test_present_exceptions(self): """Some exceptions are presented.""" excs = { NoSuchCLBError(lb_id=u'lbid1'): 'Cloud Load Balancer does not exist: lbid1', CLBDeletedError(lb_id=u'lbid2'): 'Cloud Load Balancer is currently being deleted: lbid2', NoSuchCLBNodeError(lb_id=u'lbid3', node_id=u'node1'): "Node node1 of Cloud Load Balancer lbid3 does not exist", CLBNodeLimitError(lb_id=u'lb2', node_limit=25): "Cannot create more than 25 nodes in Cloud Load Balancer lb2", CLBHealthInfoNotFound(u'lb2'): "Could not find health monitor configuration of " "Cloud Load Balancer lb2", CreateServerConfigurationError("Your server is wrong"): 'Server launch configuration is invalid: Your server is wrong', CreateServerOverQuoteError("You are over quota"): 'Servers cannot be created: You are over quota', NoSuchEndpoint(service_name="nova", region="ord"): "Could not locate service nova in the service catalog. " "Please check if your account is still active." } excs = excs.items() self.assertEqual( present_reasons([ ErrorReason.Exception(raise_to_exc_info(exc)) for (exc, _) in excs ]), [reason for (_, reason) in excs])
def test_exception(self): """Exceptions get serialized along with their traceback.""" exc_info = raise_to_exc_info(ZeroDivisionError('foo')) reason = ErrorReason.Exception(exc_info) expected_tb = ''.join(traceback.format_exception(*exc_info)) self.assertEqual(structure_reason(reason), { 'exception': "ZeroDivisionError('foo',)", 'traceback': expected_tb })
def test_exception(self): """Exceptions get serialized along with their traceback.""" exc_info = raise_to_exc_info(ZeroDivisionError('foo')) reason = ErrorReason.Exception(exc_info) expected_tb = ''.join(traceback.format_exception(*exc_info)) self.assertEqual( structure_reason(reason), {'exception': "ZeroDivisionError('foo',)", 'traceback': expected_tb} )
def test_present_exceptions(self): """Some exceptions are presented.""" excs = { NoSuchCLBError(lb_id=u'lbid1'): 'Cloud Load Balancer does not exist: lbid1', CLBDeletedError(lb_id=u'lbid2'): 'Cloud Load Balancer is currently being deleted: lbid2', NoSuchCLBNodeError(lb_id=u'lbid3', node_id=u'node1'): "Node node1 of Cloud Load Balancer lbid3 does not exist", CLBNodeLimitError(lb_id=u'lb2', node_limit=25): "Cannot create more than 25 nodes in Cloud Load Balancer lb2", CreateServerConfigurationError("Your server is wrong"): 'Server launch configuration is invalid: Your server is wrong', CreateServerOverQuoteError("You are over quota"): 'Servers cannot be created: You are over quota' } excs = excs.items() self.assertEqual( present_reasons([ErrorReason.Exception(raise_to_exc_info(exc)) for (exc, _) in excs]), [reason for (_, reason) in excs])
def test_present_arbitrary_exception(self): """Arbitrary exceptions are not presented.""" exc_info = raise_to_exc_info(ZeroDivisionError()) self.assertEqual(present_reasons([ErrorReason.Exception(exc_info)]), [])