def test_failure_without_consuming_errors(self): d1 = succeed(1) d2 = fail(AssertionError("Expected failure")) d = gather_results([d1, d2], consume_errors=False) self.assertFailure(d, AssertionError) self.assertFailure(d2, AssertionError) return d
def test_prioritize_with_queued(self): """A prioritized hook will execute before queued hooks. """ results = [] execs = [] hooks = [self.makeFile(str(i)) for i in range(5)] class _Invoker(object): def get_context(self): return None def __call__(self, hook_path): results.append(hook_path) invoke = _Invoker() for i in hooks: execs.append(self._executor(invoke, i)) priority_hook = self.makeFile(str("me first")) yield self._executor.run_priority_hook(invoke, priority_hook) self._executor.start() yield gather_results(execs) hooks.insert(0, priority_hook) self.assertEqual(results, hooks)
def remove_security_groups(provider, instance_ids): """Remove security groups associated with `instance_ids` for `provider`""" log.info( "Waiting on %d EC2 instances to transition to terminated state, " "this may take a while", len(instance_ids) ) # Repeatedly poll EC2 until instances are in terminated state; # upon reaching that state, delete associated machine security # groups. The limit of 200 polls is arbitrary and could be # specified by a command line option (and/or an overall # timeout). It's based on an observed ~500 ms roundtrip time per # call of the describe_instances web service, along with typically # taking about 40s to move all instances to a terminated state. wait_on = set(instance_ids) pending_deletions = [] for i in xrange(200): if not wait_on: break instances = yield provider.ec2.describe_instances(*wait_on) for instance in instances: if instance.instance_state == "terminated": log.debug("Instance %r was terminated", instance.instance_id) wait_on.discard(instance.instance_id) group = _get_machine_security_group_from_instance(provider, instance) if group: pending_deletions.append(_delete_security_group(provider, group)) if wait_on: outstanding = [_get_machine_security_group_from_instance(provider, instance) for instance in instances] log.error("Instance shutdown taking too long, " "could not delete groups %s", ", ".join(sorted(outstanding))) # Wait for all pending deletions to complete yield gather_results(pending_deletions)
def test_empty(self): d = gather_results([]) def check_result(result): self.assertEqual(result, []) d.addCallback(check_result) return d
def test_success(self): d1 = succeed(1) d2 = succeed(2) d = gather_results([d1, d2]) def check_result(result): self.assertEqual(result, [1, 2]) d.addCallback(check_result) return d
def tearDown(self): """ Cleanup client and server connections, and check the error got at C{connectionLost}. """ L = [] for conn in self.client, self.server: if conn.transport is not None: # depend on amp's function connection-dropping behavior d = defer.Deferred().addErrback(_loseAndPass, conn) conn.connectionLost = d.errback conn.transport.loseConnection() L.append(d) super(LiveFireBase, self).tearDown() return gather_results(L)
def remove_security_groups(provider, instance_ids): """Remove security groups associated with `instance_ids` for `provider`""" log.info( "Waiting on %d EC2 instances to transition to terminated state, " "this may take a while", len(instance_ids)) # Repeatedly poll EC2 until instances are in terminated state; # upon reaching that state, delete associated machine security # groups. The limit of 200 polls is arbitrary and could be # specified by a command line option (and/or an overall # timeout). It's based on an observed ~500 ms roundtrip time per # call of the describe_instances web service, along with typically # taking about 40s to move all instances to a terminated state. wait_on = set(instance_ids) pending_deletions = [] for i in xrange(200): if not wait_on: break instances = yield provider.ec2.describe_instances(*wait_on) for instance in instances: if instance.instance_state == "terminated": log.debug("Instance %r was terminated", instance.instance_id) wait_on.discard(instance.instance_id) group = _get_machine_security_group_from_instance( provider, instance) if group: pending_deletions.append( _delete_security_group(provider, group)) if wait_on: outstanding = [ _get_machine_security_group_from_instance(provider, instance) for instance in instances] log.error("Instance shutdown taking too long, " "could not delete groups %s", ", ".join(sorted(outstanding))) # Wait for all pending deletions to complete yield gather_results(pending_deletions)