Exemple #1
0
 def __init__(self):
     self.id = calvinuuid.uuid("NODE")
     self.control_uri = "http://localhost:5001"
     self.pm = Mock()
     self.storage = Mock()
     self.control = Mock()
     self.attributes = attribute_resolver.AttributeResolver({})
Exemple #2
0
 def __init__(self, uris, node_name=None, control_uri=None):
     self.id = calvinuuid.uuid("NODE")
     self.node_name = node_name or self.id
     self.uris = uris
     self.control_uri = control_uri or uris[0]
     self.external_control_uri = self.control_uri
     self.pm = Mock()
     self.storage = Mock()
     self.control = Mock()
     self.attributes = attribute_resolver.AttributeResolver({})
Exemple #3
0
 def __init__(self, uris, node_name=None, control_uri=None):
     self.id = calvinuuid.uuid("NODE")
     self.node_name = node_name or self.id
     self.uris = uris
     self.control_uri = control_uri or uris[0]
     self.external_control_uri = self.control_uri
     self.pm = Mock()
     self._calvinsys = DummySys(self)
     self.storage = Mock()
     self.control = Mock()
     self.metering = metering.set_metering(metering.Metering(self))
     self.attributes = attribute_resolver.AttributeResolver({})
def setup(request):
    # Create 3 test nodes per storage type
    print "###SETUP"

    tunnels = {}
    nodes = {}
    for ti in range(len(storage_types)):
        nodes[storage_types[ti]] = [
            calvin.tests.TestNode(
                ["calvinip://127.0.0.1:50{}{}".format(ti, i)])
            for i in range(3)
        ]

    def prep_node(stype, n):
        n.storage = storage.Storage(n)
        if stype == "proxy":
            try:
                n.network = DummyNetwork(n)
                n.proto = DummyProto(n)
            except:
                traceback.print_exc()
        if stype != "notstarted":
            cb, d = create_callback(timeout=10, test_part=stype + " start")
            n.storage.start(cb=cb)
            return d

    all_started = []
    for ti in range(len(storage_types)):
        stype = storage_types[ti]
        if stype == "dht":
            try:
                _conf.set('global', 'storage_type', 'dht')
                all_started.extend(map(partial(prep_node, stype),
                                       nodes[stype]))
            except:
                traceback.print_exc()
        elif stype == "securedht":
            try:
                homefolder = get_home()
                credentials_testdir = os.path.join(homefolder, ".calvin",
                                                   "test_all_storage_dir")
                runtimesdir = os.path.join(credentials_testdir, "runtimes")
                security_testdir = os.path.join(os.path.dirname(__file__),
                                                "security_test")
                domain_name = "test_security_domain"
                code_signer_name = "test_signer"
                orig_identity_provider_path = os.path.join(
                    security_testdir, "identity_provider")
                identity_provider_path = os.path.join(credentials_testdir,
                                                      "identity_provider")
                policy_storage_path = os.path.join(security_testdir,
                                                   "policies")
                try:
                    shutil.rmtree(credentials_testdir)
                except Exception as err:
                    print "Failed to remove old tesdir, err={}".format(err)
                    pass
                try:
                    shutil.copytree(orig_identity_provider_path,
                                    identity_provider_path)
                except Exception as err:
                    _log.error(
                        "Failed to copy the identity provider files, err={}".
                        format(err))
                    raise
                runtimes = helpers.create_CA_and_generate_runtime_certs(
                    domain_name, credentials_testdir, 3)

                for r, n in zip(runtimes, nodes[stype]):
                    n.attributes = attribute_resolver.AttributeResolver(
                        r['attributes'])
                    n.enrollment_password = r['enrollment_password']
                    n.id = r['id']
                    n.runtime_credentials = r['credentials']
                    n.node_name = r['node_name']

                #print "###RUNTIMES", runtimes

                _conf.add_section("security")
                _conf.set('security', 'security_dir', credentials_testdir)
                _conf.set('global', 'storage_type', 'securedht')
                all_started.extend(map(partial(prep_node, stype),
                                       nodes[stype]))
                _conf.remove_section("security")
            except:
                traceback.print_exc()
        elif stype == "notstarted":
            _conf.set('global', 'storage_type', 'dht')
            map(partial(prep_node, stype), nodes[stype])
        elif stype == "sql":
            _conf.set('global', 'storage_type', 'sql')
            _conf.set(
                'global', 'storage_sql',
                {})  # Use the default, i.e. local passwd-less root mysql DB
            all_started.extend(map(partial(prep_node, stype), nodes[stype]))
        elif stype == "proxy":
            # Setting up proxy storage for testing is a bit complicated
            # We short circuit so that fake tunnels' send directly calls peer's receive-method
            # The master (0) is setup as local and the others (1,2) as proxy
            # Give the master node ref to the proxies (to be used in fake network, proto & tunnel)
            nodes["proxy"][1].master_node = nodes["proxy"][0]
            nodes["proxy"][2].master_node = nodes["proxy"][0]
            # Create fake tunnels
            for n2 in nodes["proxy"]:
                tt = {}
                for n1 in nodes["proxy"]:
                    if n1 != n2:
                        tt[n1.id] = FakeTunnel(DummyNetwork(n1),
                                               tt,
                                               n1.id,
                                               'storage',
                                               None,
                                               rt_id=n2.id,
                                               id=calvinuuid.uuid("TUNNEL"))
                tunnels[n2.id] = tt
                n2.tunnels = tunnels
            # Give a tunnel its peers tunnel
            for n2 in nodes["proxy"]:
                for n1 in nodes["proxy"]:
                    if n1 != n2:
                        tunnels[n2.id][n1.id]._peers_fake_tunnel = tunnels[
                            n1.id][n2.id]
            # Start master
            _conf.set('global', 'storage_type', 'local')
            prep_node(stype, nodes[stype][0])
            # Inform master it has 2 proxy storage clients
            [
                nodes[stype][0].storage.tunnel_request_handles(t)
                for t in tunnels[nodes[stype][0].id].values()
            ]
            # Start proxies
            _conf.set('global', 'storage_type', 'proxy')
            _conf.set('global', 'storage_proxy', nodes[stype][0].uris[0])
            all_started.extend(map(partial(prep_node, stype),
                                   nodes[stype][1:]))
            # Inform proxy that it is connected, first wait until up_handler set
            count = 0
            while (tunnels[nodes[stype][1].id][nodes[stype][0].id].up_handler
                   is None or
                   tunnels[nodes[stype][2].id][nodes[stype][0].id].up_handler
                   is None) and count < 100:
                pytest.blockon(threads.defer_to_thread(time.sleep, 0.1))
                count += 1
            tunnels[nodes[stype][1].id][nodes[stype][0].id].up_handler()
            tunnels[nodes[stype][2].id][nodes[stype][0].id].up_handler()
    dl = defer.DeferredList(all_started)
    print time.time()
    try:
        pytest.blockon(dl)
    except:
        print "### Some storage plugins might have failed to start! ###"
        traceback.print_exc()
    print time.time()

    def teardown():
        print "#####TEARDOWN"
        all_stopped = []
        for ntypes in nodes.values():
            for n in ntypes:
                cb, d = create_callback(timeout=10)
                n.storage.stop(cb=cb)
                all_stopped.append(d)
        dl = defer.DeferredList(all_stopped)
        try:
            pytest.blockon(dl)
        except:
            print "### Some storage plugins might have failed to stopp ###"
            traceback.print_exc()

    request.addfinalizer(teardown)
    return {"nodes": nodes}