示例#1
0
 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])
         ]))
示例#2
0
 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])])
     )
示例#3
0
文件: steps.py 项目: meker12/otter
 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))
示例#4
0
 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)
示例#5
0
文件: steps.py 项目: stephamon/otter
 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))
示例#6
0
 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)
示例#7
0
 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))
示例#8
0
 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))
示例#9
0
 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)
示例#10
0
 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)))
示例#11
0
 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))
示例#12
0
 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)
示例#13
0
 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)))
示例#14
0
 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])]))
示例#15
0
 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))
示例#16
0
 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])]))