Esempio n. 1
0
    class NodeControl(object):

        def __init__(self, control_uri, barrier):
            super(NodeControl, self).__init__()
            self._id = None
            self._uri = None
            self.control_uri = control_uri
            self.request_handler = RequestHandler()
            # When barrier ordered make sure we can contact the runtime
            if barrier:
                failed = True
                # Try 20 times waiting for control API to be up and running
                for i in range(20):
                    try:
                        self._id = self.request_handler.get_node_id(self)
                        failed = False
                        break
                    except:
                        time.sleep(0.1)
                assert not failed

        @property
        def id(self):
            if self._id is None:
                self._id = self.request_handler.get_node_id(self)
            return self._id

        @property
        def uri(self):
            if self._uri is None:
                self._uri = self.request_handler.get_node(self, self.id)["uri"]
            return self._uri
Esempio n. 2
0
def setup_module(module):
    global request_handler
    global runtime1
    global runtime2
    global constrained_id
    global constrained_process

    request_handler = RequestHandler()
    runtime1 = RT("http://127.0.0.1:5001")
    runtime1.id = request_handler.get_node_id(runtime1.control_uri)
    runtime2 = RT("http://127.0.0.1:5003")
    runtime2.id = request_handler.get_node_id(runtime2.control_uri)

    # start constrained
    constrained_process = subprocess.Popen(
        calvin_command +
        " -a '{\"indexed_public\": {\"node_name\": {\"organization\": \"com.ericsson\", \"purpose\": \"distributed-test\", \"group\": \"rest\", \"name\": \"constrained\"}}}' -u '[\"calvinip://127.0.0.1:5000\", \"ssdp\"]'",
        shell=True)
    for x in range(0, 10):
        peers = request_handler.get_nodes(runtime1)
        for peer in peers:
            peer_info = request_handler.get_node(runtime1, peer)
            if "constrained" in peer_info["attributes"]["indexed_public"][0]:
                constrained_id = peer
                return
        time.sleep(1)

    pytest.exit("Failed to get constrained runtimes")
Esempio n. 3
0
    class NodeControl(object):
        def __init__(self, control_uri, barrier):
            super(NodeControl, self).__init__()
            self._id = None
            self._uris = None
            self.control_uri = control_uri
            self.request_handler = RequestHandler()
            delay = 0.1
            # When barrier ordered make sure we can contact the runtime
            if barrier:
                success = False
                # Try 20 times waiting for control API to be up and running
                for i in range(20):
                    try:
                        self._id = self.request_handler.get_node_id(self)
                        success = True
                        break
                    except Exception:
                        time.sleep(delay)
                        delay = 2 * delay if delay < 1.0 else 1.0
                assert success

        @property
        def id(self):
            if self._id is None:
                self._id = self.request_handler.get_node_id(self)
            return self._id

        @property
        def uris(self):
            if self._uris is None:
                self._uris = self.request_handler.get_node(self,
                                                           self.id)["uris"]
            return self._uris
Esempio n. 4
0
def setup_module(module):
    global runtime
    global runtimes
    global peerlist
    global kill_peers
    global request_handler
    ip_addr = None
    bt_master_controluri = None

    request_handler = RequestHandler()
    try:
        ip_addr = os.environ["CALVIN_TEST_IP"]
        purpose = os.environ["CALVIN_TEST_UUID"]
    except KeyError:
        pass

    if ip_addr is None:
        # Bluetooth tests assumes one master runtime with two connected peers
        # CALVIN_TEST_BT_MASTERCONTROLURI is the control uri of the master runtime
        try:
            bt_master_controluri = os.environ["CALVIN_TEST_BT_MASTERCONTROLURI"]
            _log.debug("Running Bluetooth tests")
        except KeyError:
            pass

    if ip_addr:
        remote_node_count = 2
        kill_peers = False
        test_peers = None


        import socket
        ports=[]
        for a in range(2):
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            s.bind(('', 0))
            addr = s.getsockname()
            ports.append(addr[1])
            s.close()

        runtime,_ = dispatch_node(["calvinip://%s:%s" % (ip_addr, ports[0])], "http://%s:%s" % (ip_addr, ports[1]))

        _log.debug("First runtime started, control http://%s:%s, calvinip://%s:%s" % (ip_addr, ports[1], ip_addr, ports[0]))

        interval = 0.5
        for retries in range(1,20):
            time.sleep(interval)
            _log.debug("Trying to get test nodes for 'purpose' %s" % purpose)
            test_peers = request_handler.get_index(runtime, format_index_string({'node_name':
                                                                         {'organization': 'com.ericsson',
                                                                          'purpose': purpose}
                                                                      }))
            if not test_peers is None and not test_peers["result"] is None and \
                    len(test_peers["result"]) == remote_node_count:
                test_peers = test_peers["result"]
                break

        if test_peers is None or len(test_peers) != remote_node_count:
            _log.debug("Failed to find all remote nodes within time, peers = %s" % test_peers)
            raise Exception("Not all nodes found dont run tests, peers = %s" % test_peers)

        test_peer2_id = test_peers[0]
        test_peer2 = request_handler.get_node(runtime, test_peer2_id)
        if test_peer2:
            runtime2 = RT(test_peer2["control_uri"])
            runtime2.id = test_peer2_id
            runtime2.uri = test_peer2["uri"]
            runtimes.append(runtime2)
        test_peer3_id = test_peers[1]
        if test_peer3_id:
            test_peer3 = request_handler.get_node(runtime, test_peer3_id)
            if test_peer3:
                runtime3 = RT(test_peer3["control_uri"])
                runtime3.id = test_peer3_id
                runtime3.uri = test_peer3["uri"]
                runtimes.append(runtime3)
    elif bt_master_controluri:
        runtime = RT(bt_master_controluri)
        bt_master_id = request_handler.get_node_id(bt_master_controluri)
        data = request_handler.get_node(runtime, bt_master_id)
        if data:
            runtime.id = bt_master_id
            runtime.uri = data["uri"]
            test_peers = request_handler.get_nodes(runtime)
            test_peer2_id = test_peers[0]
            test_peer2 = request_handler.get_node(runtime, test_peer2_id)
            if test_peer2:
                rt2 = RT(test_peer2["control_uri"])
                rt2.id = test_peer2_id
                rt2.uri = test_peer2["uri"]
                runtimes.append(rt2)
            test_peer3_id = test_peers[1]
            if test_peer3_id:
                test_peer3 = request_handler.get_node(runtime, test_peer3_id)
                if test_peer3:
                    rt3 = request_handler.RT(test_peer3["control_uri"])
                    rt3.id = test_peer3_id
                    rt3.uri = test_peer3["uri"]
                    runtimes.append(rt3)
    else:
        try:
            ip_addr = os.environ["CALVIN_TEST_LOCALHOST"]
        except:
            import socket
            ip_addr = socket.gethostbyname(socket.gethostname())
        localhost = "calvinip://%s:5000" % (ip_addr,), "http://localhost:5001"
        remotehosts = [("calvinip://%s:%d" % (ip_addr, d), "http://localhost:%d" % (d+1)) for d in range(5002, 5005, 2)]
        # remotehosts = [("calvinip://127.0.0.1:5002", "http://localhost:5003")]

        for host in remotehosts:
            runtimes += [dispatch_node([host[0]], host[1])[0]]

        runtime, _ = dispatch_node([localhost[0]], localhost[1])

        time.sleep(1)

        # FIXME When storage up and running peersetup not needed, but still useful during testing
        request_handler.peer_setup(runtime, [i[0] for i in remotehosts])

        time.sleep(0.5)
        """

        # FIXME Does not yet support peerlist
        try:
            self.peerlist = peerlist(
                self.runtime, self.runtime.id, len(remotehosts))

            # Make sure all peers agree on network
            [peerlist(self.runtime, p, len(self.runtimes)) for p in self.peerlist]
        except:
            self.peerlist = []
        """

    peerlist = [rt.control_uri for rt in runtimes]
    print "SETUP DONE ***", peerlist
Esempio n. 5
0
def setup_module(module):
    global runtime
    global runtimes
    global peerlist
    global kill_peers
    global request_handler
    ip_addr = None
    bt_master_controluri = None

    request_handler = RequestHandler()
    try:
        ip_addr = os.environ["CALVIN_TEST_IP"]
        purpose = os.environ["CALVIN_TEST_UUID"]
    except KeyError:
        pass

    if ip_addr is None:
        # Bluetooth tests assumes one master runtime with two connected peers
        # CALVIN_TEST_BT_MASTERCONTROLURI is the control uri of the master runtime
        try:
            bt_master_controluri = os.environ[
                "CALVIN_TEST_BT_MASTERCONTROLURI"]
            _log.debug("Running Bluetooth tests")
        except KeyError:
            pass

    if ip_addr:
        remote_node_count = 2
        kill_peers = False
        test_peers = None

        import socket
        ports = []
        for a in range(2):
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            s.bind(('', 0))
            addr = s.getsockname()
            ports.append(addr[1])
            s.close()

        runtime, _ = dispatch_node(["calvinip://%s:%s" % (ip_addr, ports[0])],
                                   "http://%s:%s" % (ip_addr, ports[1]))

        _log.debug(
            "First runtime started, control http://%s:%s, calvinip://%s:%s" %
            (ip_addr, ports[1], ip_addr, ports[0]))

        interval = 0.5
        for retries in range(1, 20):
            time.sleep(interval)
            _log.debug("Trying to get test nodes for 'purpose' %s" % purpose)
            test_peers = request_handler.get_index(
                runtime,
                format_index_string({
                    'node_name': {
                        'organization': 'com.ericsson',
                        'purpose': purpose
                    }
                }))
            if not test_peers is None and not test_peers["result"] is None and \
                    len(test_peers["result"]) == remote_node_count:
                test_peers = test_peers["result"]
                break

        if test_peers is None or len(test_peers) != remote_node_count:
            _log.debug(
                "Failed to find all remote nodes within time, peers = %s" %
                test_peers)
            raise Exception("Not all nodes found dont run tests, peers = %s" %
                            test_peers)

        test_peer2_id = test_peers[0]
        test_peer2 = request_handler.get_node(runtime, test_peer2_id)
        if test_peer2:
            runtime2 = RT(test_peer2["control_uri"])
            runtime2.id = test_peer2_id
            runtime2.uri = test_peer2["uri"]
            runtimes.append(runtime2)
        test_peer3_id = test_peers[1]
        if test_peer3_id:
            test_peer3 = request_handler.get_node(runtime, test_peer3_id)
            if test_peer3:
                runtime3 = RT(test_peer3["control_uri"])
                runtime3.id = test_peer3_id
                runtime3.uri = test_peer3["uri"]
                runtimes.append(runtime3)
    elif bt_master_controluri:
        runtime = RT(bt_master_controluri)
        bt_master_id = request_handler.get_node_id(bt_master_controluri)
        data = request_handler.get_node(runtime, bt_master_id)
        if data:
            runtime.id = bt_master_id
            runtime.uri = data["uri"]
            test_peers = request_handler.get_nodes(runtime)
            test_peer2_id = test_peers[0]
            test_peer2 = request_handler.get_node(runtime, test_peer2_id)
            if test_peer2:
                rt2 = RT(test_peer2["control_uri"])
                rt2.id = test_peer2_id
                rt2.uri = test_peer2["uri"]
                runtimes.append(rt2)
            test_peer3_id = test_peers[1]
            if test_peer3_id:
                test_peer3 = request_handler.get_node(runtime, test_peer3_id)
                if test_peer3:
                    rt3 = request_handler.RT(test_peer3["control_uri"])
                    rt3.id = test_peer3_id
                    rt3.uri = test_peer3["uri"]
                    runtimes.append(rt3)
    else:
        try:
            ip_addr = os.environ["CALVIN_TEST_LOCALHOST"]
        except:
            import socket
            ip_addr = socket.gethostbyname(socket.gethostname())
        localhost = "calvinip://%s:5000" % (ip_addr, ), "http://localhost:5001"
        remotehosts = [("calvinip://%s:%d" % (ip_addr, d),
                        "http://localhost:%d" % (d + 1))
                       for d in range(5002, 5005, 2)]
        # remotehosts = [("calvinip://127.0.0.1:5002", "http://localhost:5003")]

        for host in remotehosts:
            runtimes += [dispatch_node([host[0]], host[1])[0]]

        runtime, _ = dispatch_node([localhost[0]], localhost[1])

        time.sleep(1)

        # FIXME When storage up and running peersetup not needed, but still useful during testing
        request_handler.peer_setup(runtime, [i[0] for i in remotehosts])

        time.sleep(0.5)
        """

        # FIXME Does not yet support peerlist
        try:
            self.peerlist = peerlist(
                self.runtime, self.runtime.id, len(remotehosts))

            # Make sure all peers agree on network
            [peerlist(self.runtime, p, len(self.runtimes)) for p in self.peerlist]
        except:
            self.peerlist = []
        """

    peerlist = [rt.control_uri for rt in runtimes]
    print "SETUP DONE ***", peerlist