def test50():
    """
    test50: wrap a config class with a sequence of tasks in ConfigClassTask
    wrapper, then drive the creation of instances of the ConfigClassTask
    with a MultiTask wrapper.
    """
    class IPGen(object):
        def __init__(self):
            self.host_part = 0
            
        def __call__(self, context):
            self.host_part += 1
            return "127.0.0.{}".format(self.host_part)
    ipgen = IPGen()
        
    class Infra(InfraModel):
        setup_server = MultiResource(StaticServer("setup_helper", ipgen))
    infra = Infra("helper")
    
    class NS(NamespaceModel):
        task_role = MultiRole(Role("tp",
                                                    host_ref=ctxt.model.infra.setup_server[ctxt.name]))
        default = Role("default", "127.0.1.1")
    ns = NS()
    ns.set_infra_model(infra)
    for i in range(3):
        _ = ns.task_role[i]
    
    cap = Capture()
    class InnerCfg(ConfigModel):
        t1 = ReportingTask("inner_task1", report=cap)
        t2 = ReportingTask("inner_task2", report=cap)
        t3 = ReportingTask("inner_task3", report=cap)
        with_dependencies(t1 | t2 | t3)
        
    class OuterCfg(ConfigModel):
        wrapped_task = MultiTask("setupSuite",
                                 ConfigClassTask("wrapper", InnerCfg),
                                 NS.q.task_role.all())
        initial = ReportingTask("initial", target=NS.default, report=cap)
        final = ReportingTask("final", target=NS.default, report=cap)
        
        with_dependencies(initial | wrapped_task | final)
        
    cfg = OuterCfg()
    cfg.set_namespace(ns)
    
    ea = ExecutionAgent(config_model_instance=cfg, namespace_model_instance=ns,
                        infra_model_instance=infra, no_delay=True)
    try:
        ea.perform_config()
    except ExecutionException, e:
        import traceback
        for task, etype, value, tb in ea.get_aborted_tasks():
            print ">>>Task {} failed with the following:".format(task.name)
            traceback.print_exception(etype, value, tb)
            print
        assert False, e.message

    assert (len(cap.performed) == 11 and
            cap.pos("default", "final") == len(cap.performed) -1 and
            cap.pos("default", "initial") == 0)
dataset/ETHPy150Open haxsaw/actuator/src/tests/config_tests.py/test50/original