def test_multiple_errors(self): """ If bulk add returns 409 then multiple errors returned are collected and raised as a single `BulkErrors` """ errors = { "errors": [ lb_inactive(self.lbs[0]), "Load Balancer Pool {} does not exist".format(self.lbs[1]), "Cloud Server {} is unprocessable".format(self.nodes[2]) ] } seq = [(self.svc_req_intent(self.data), const(stub_json_response(errors, 409))), (log_intent("request-rcv3-bulk", errors, req_body=("jsonified", self.data)), noop)] with self.assertRaises(r.BulkErrors) as ec: perform_sequence(seq, r.bulk_add(self.pairs)) self.assertEqual( ec.exception.errors, pset([ r.LBInactive(self.lbs[0]), r.NoSuchLBError(self.lbs[1]), r.ServerUnprocessableError(self.nodes[2]) ]))
def test_multiple_errors(self): """ If bulk add returns 409 then multiple errors returned are collected and raised as a single `BulkErrors` """ errors = { "errors": [ lb_inactive(self.lbs[0]), "Load Balancer Pool {} does not exist".format(self.lbs[1]), "Cloud Server {} is unprocessable".format(self.nodes[2]) ] } seq = [ (self.svc_req_intent(self.data), const(stub_json_response(errors, 409))), (log_intent( "request-rcv3-bulk", errors, req_body=("jsonified", self.data)), noop) ] with self.assertRaises(r.BulkErrors) as ec: perform_sequence(seq, r.bulk_add(self.pairs)) self.assertEqual( ec.exception.errors, pset([r.LBInactive(self.lbs[0]), r.NoSuchLBError(self.lbs[1]), r.ServerUnprocessableError(self.nodes[2])]) )
def as_effect(self): """ Produce a :obj:`Effect` to add some nodes to some RCv3 load balancers. """ eff = rcv3.bulk_add(self.lb_node_pairs) return eff.on( success=lambda _: (StepResult.RETRY, [ErrorReason.String( 'must re-gather after LB add in order to update the ' 'active cache')]), error=catch(rcv3.BulkErrors, _handle_bulk_add_errors))
def test_success(self): """ bulk add resulting in 201 returns Effect of None """ resp = {"resp": "yo"} seq = [(self.svc_req_intent(self.data), const(stub_json_response(resp, 201))), (log_intent("request-rcv3-bulk", resp, req_body=("jsonified", self.data)), noop)] self.assertEqual(perform_sequence(seq, r.bulk_add(self.pairs)), resp)
def as_effect(self): """ Produce a :obj:`Effect` to add some nodes to some RCv3 load balancers. """ eff = rcv3.bulk_add(self.lb_node_pairs) return eff.on(success=lambda _: (StepResult.RETRY, [ ErrorReason.String( 'must re-gather after LB add in order to update the ' 'active cache') ]), error=catch(rcv3.BulkErrors, _handle_bulk_add_errors))
def test_success(self): """ bulk add resulting in 201 returns Effect of None """ resp = {"resp": "yo"} seq = [ (self.svc_req_intent(self.data), const(stub_json_response(resp, 201))), (log_intent( "request-rcv3-bulk", resp, req_body=("jsonified", self.data)), noop) ] self.assertEqual(perform_sequence(seq, r.bulk_add(self.pairs)), resp)
def test_empty_errors(self): """ If bulk add returns 409 with empty errors then `UnknownBulkResponse` is raised """ errors = {"errors": []} seq = [(self.svc_req_intent(self.data), const(stub_json_response(errors, 409))), (log_intent("request-rcv3-bulk", errors, req_body=("jsonified", self.data)), noop)] self.assertRaises(r.UnknownBulkResponse, perform_sequence, seq, r.bulk_add(self.pairs))
def test_unknown_errors(self): """ If any of the errors returned with 409 are unknown then `UnknownBulkResponse` is raised """ errors = {"errors": ["unknown error", lb_inactive(self.lbs[0])]} seq = [(self.svc_req_intent(self.data), const(stub_json_response(errors, 409))), (log_intent("request-rcv3-bulk", errors, req_body=("jsonified", self.data)), noop)] self.assertRaises(r.UnknownBulkResponse, perform_sequence, seq, r.bulk_add(self.pairs))
def _check_retries(self, pairs, data, retried_data, errors): resp = {"response": "yo"} seq = [(self.svc_req_intent(data), const(stub_json_response(errors, 409))), (log_intent("request-rcv3-bulk", errors, req_body=("jsonified", data)), noop), (self.svc_req_intent(retried_data), const(stub_json_response(resp, 201))), (log_intent("request-rcv3-bulk", resp, req_body=("jsonified", retried_data)), noop)] self.assertEqual(perform_sequence(seq, r.bulk_add(pairs)), resp)
def test_all_already_member(self): """ If bulk_add returns 409 with all attempted pairs as "lb node already member" then it will return None """ errors = { "errors": [node_already_member(lb.upper(), node) for lb, node in self.pairs] } seq = [(self.svc_req_intent(self.data), const(stub_json_response(errors, 409))), (log_intent("request-rcv3-bulk", errors, req_body=("jsonified", self.data)), noop)] self.assertIsNone(perform_sequence(seq, r.bulk_add(self.pairs)))
def test_empty_errors(self): """ If bulk add returns 409 with empty errors then `UnknownBulkResponse` is raised """ errors = {"errors": []} seq = [ (self.svc_req_intent(self.data), const(stub_json_response(errors, 409))), (log_intent( "request-rcv3-bulk", errors, req_body=("jsonified", self.data)), noop) ] self.assertRaises( r.UnknownBulkResponse, perform_sequence, seq, r.bulk_add(self.pairs))
def _check_retries(self, pairs, data, retried_data, errors): resp = {"response": "yo"} seq = [ (self.svc_req_intent(data), const(stub_json_response(errors, 409))), (log_intent( "request-rcv3-bulk", errors, req_body=("jsonified", data)), noop), (self.svc_req_intent(retried_data), const(stub_json_response(resp, 201))), (log_intent( "request-rcv3-bulk", resp, req_body=("jsonified", retried_data)), noop) ] self.assertEqual(perform_sequence(seq, r.bulk_add(pairs)), resp)
def test_all_already_member(self): """ If bulk_add returns 409 with all attempted pairs as "lb node already member" then it will return None """ errors = { "errors": [ node_already_member(lb.upper(), node) for lb, node in self.pairs ] } seq = [ (self.svc_req_intent(self.data), const(stub_json_response(errors, 409))), (log_intent( "request-rcv3-bulk", errors, req_body=("jsonified", self.data)), noop) ] self.assertIsNone(perform_sequence(seq, r.bulk_add(self.pairs)))
def test_bulk_and_retry_error(self): """ If bulk adding returns "LB node already member" error along with other errors then there is no retry and BulkErrors is raised """ errors = { "errors": [ node_already_member(self.lbs[0].upper(), self.nodes[0]), lb_inactive(self.lbs[1]) ] } seq = [(self.svc_req_intent(self.data), const(stub_json_response(errors, 409))), (log_intent("request-rcv3-bulk", errors, req_body=("jsonified", self.data)), noop)] with self.assertRaises(r.BulkErrors) as ec: perform_sequence(seq, r.bulk_add(self.pairs)) self.assertEqual(ec.exception.errors, pset([r.LBInactive(self.lbs[1])]))
def test_unknown_errors(self): """ If any of the errors returned with 409 are unknown then `UnknownBulkResponse` is raised """ errors = { "errors": [ "unknown error", lb_inactive(self.lbs[0]) ] } seq = [ (self.svc_req_intent(self.data), const(stub_json_response(errors, 409))), (log_intent( "request-rcv3-bulk", errors, req_body=("jsonified", self.data)), noop) ] self.assertRaises( r.UnknownBulkResponse, perform_sequence, seq, r.bulk_add(self.pairs))
def test_bulk_and_retry_error(self): """ If bulk adding returns "LB node already member" error along with other errors then there is no retry and BulkErrors is raised """ errors = { "errors": [ node_already_member(self.lbs[0].upper(), self.nodes[0]), lb_inactive(self.lbs[1]) ] } seq = [ (self.svc_req_intent(self.data), const(stub_json_response(errors, 409))), (log_intent( "request-rcv3-bulk", errors, req_body=("jsonified", self.data)), noop) ] with self.assertRaises(r.BulkErrors) as ec: perform_sequence(seq, r.bulk_add(self.pairs)) self.assertEqual( ec.exception.errors, pset([r.LBInactive(self.lbs[1])]))