def test_buckets_acquired(self): """ When buckets are allocated, the result of converge_all_groups is performed. """ def converge_all_groups(currently_converging, recent, _my_buckets, all_buckets, divergent_flags, build_timeout, interval): return Effect( ('converge-all', currently_converging, _my_buckets, all_buckets, divergent_flags, build_timeout, interval)) my_buckets = [0, 5] bound_sequence = [ (GetChildren(CONVERGENCE_DIRTY_DIR), lambda i: ['flag1', 'flag2']), (('converge-all', transform_eq(lambda cc: cc is converger.currently_converging, True), my_buckets, range(self.num_buckets), ['flag1', 'flag2'], 3600, 15), lambda i: 'foo') ] sequence = self._log_sequence(bound_sequence) converger = self._converger(converge_all_groups, dispatcher=sequence) with sequence.consume(): result, = self.fake_partitioner.got_buckets(my_buckets) self.assertEqual(self.successResultOf(result), 'foo')
def test_remove_nodes_from_clb_retry(self): """ :obj:`RemoveNodesFromCLB`, on receiving a 400, parses out the nodes that are no longer on the load balancer, and retries the bulk delete with those nodes removed. TODO: this has been left in as a regression test - this can probably be removed the next time it's touched, as this functionality happens in cloud_client now and there is a similar test there. """ lb_id = "12345" node_ids = [str(i) for i in range(5)] error_body = { "validationErrors": { "messages": [ "Node ids 1,2,3 are not a part of your loadbalancer" ] }, "message": "Validation Failure", "code": 400, "details": "The object is not valid" } expected_req = service_request( ServiceType.CLOUD_LOAD_BALANCERS, 'DELETE', 'loadbalancers/12345/nodes', params={'id': transform_eq(sorted, node_ids)}, success_pred=ANY, json_response=True).intent expected_req2 = service_request( ServiceType.CLOUD_LOAD_BALANCERS, 'DELETE', 'loadbalancers/12345/nodes', params={'id': transform_eq(sorted, ['0', '4'])}, success_pred=ANY, json_response=True).intent step = RemoveNodesFromCLB(lb_id=lb_id, node_ids=pset(node_ids)) seq = [ (expected_req, lambda i: raise_(APIError(400, json.dumps(error_body)))), (expected_req2, lambda i: stub_pure_response('', 202)), ] r = perform_sequence(seq, step.as_effect()) self.assertEqual(r, (StepResult.SUCCESS, []))
def test_retries(self): """ If `rcv3.bulk_add` results in BulkErrors with only ServerUnprocessableError errors in it then step returns RETRY """ excp1 = rcv3.ServerUnprocessableError("s1") excp2 = rcv3.ServerUnprocessableError("s2") seq = [(("ba", self.pairs), self.ba_raiser(excp1, excp2))] self.assertEqual( perform_sequence(seq, self.step.as_effect()), (StepResult.RETRY, transform_eq(pset, pset([ ErrorReason.String(excp1.message), ErrorReason.String(excp2.message)]))) )
def test_failures(self): """ If `rcv3.bulk_add` results in BulkErrors with only non-ServerUnprocessableError errors in it then step returns FAILURE """ excp1 = rcv3.LBInactive("l1") excp2 = rcv3.NoSuchLBError("l2") seq = [(("ba", self.pairs), self.ba_raiser(excp1, excp2))] self.assertEqual( perform_sequence(seq, self.step.as_effect()), (StepResult.FAILURE, transform_eq(pset, pset([ ErrorReason.String(excp1.message), ErrorReason.String(excp2.message)]))) )
def test_remove_nodes_from_clb(self): """ :obj:`RemoveNodesFromCLB` produces a request for deleting any number of nodes from a cloud load balancer. """ lb_id = "12345" node_ids = [str(i) for i in range(5)] step = RemoveNodesFromCLB(lb_id=lb_id, node_ids=pset(node_ids)) request = step.as_effect() self.assertEqual( request.intent, service_request( ServiceType.CLOUD_LOAD_BALANCERS, 'DELETE', "loadbalancers/12345/nodes", params={'id': transform_eq(sorted, node_ids)}, json_response=True, success_pred=ANY).intent)