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 convergence_failed(tenant_id, group_id, reasons, timedout=False): """ Handle convergence failure :param str tenant_id: Tenant ID :param str group_id: Group ID :param reasons: List of :obj:`ErrorReason` objects :param bool timedout: Has convergence failed due to reason timing out? :return: convergence execution status :rtype: :obj:`ConvergenceIterationStatus` """ yield Effect(LoadAndUpdateGroupStatus(tenant_id, group_id, ScalingGroupStatus.ERROR)) presented_reasons = sorted(present_reasons(reasons)) if len(presented_reasons) == 0: presented_reasons = [u"Unknown error occurred"] elif timedout: presented_reasons = ["Timed out: {}".format(reason) for reason in presented_reasons] yield cf_err( 'group-status-error', status=ScalingGroupStatus.ERROR.name, reasons=presented_reasons) yield Effect(UpdateGroupErrorReasons(tenant_id, group_id, presented_reasons)) yield do_return(ConvergenceIterationStatus.Stop())
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 convergence_failed(scaling_group, reasons): """ Handle convergence failure """ yield Effect(UpdateGroupStatus(scaling_group=scaling_group, status=ScalingGroupStatus.ERROR)) presented_reasons = sorted(present_reasons(reasons)) if len(presented_reasons) == 0: presented_reasons = [u"Unknown error occurred"] yield cf_err( 'group-status-error', status=ScalingGroupStatus.ERROR.name, reasons=presented_reasons) yield Effect(UpdateGroupErrorReasons(scaling_group, presented_reasons)) yield do_return(ConvergenceIterationStatus.Stop())
def convergence_failed(scaling_group, reasons, timedout=False): """ Handle convergence failure """ yield Effect( UpdateGroupStatus(scaling_group=scaling_group, status=ScalingGroupStatus.ERROR)) presented_reasons = sorted(present_reasons(reasons)) if len(presented_reasons) == 0: presented_reasons = [u"Unknown error occurred"] elif timedout: presented_reasons = [ "Timed out: {}".format(reason) for reason in presented_reasons ] yield cf_err('group-status-error', status=ScalingGroupStatus.ERROR.name, reasons=presented_reasons) yield Effect(UpdateGroupErrorReasons(scaling_group, presented_reasons)) yield do_return(ConvergenceIterationStatus.Stop())
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)]), [])
def test_present_user_message(self): self.assertEqual(present_reasons([ErrorReason.UserMessage('foo bar')]), ['foo bar'])
def test_present_other(self): """non-Exceptions are not presented.""" self.assertEqual(present_reasons([ErrorReason.String('foo')]), [])