Ejemplo n.º 1
0
    def test_interrupt_kernel_success(self): # depends on add_computer, new_session
        x = self.a.add_computer(self.default_comp_config)
        kern1 = self.a.new_session()

        reply = self.a.interrupt_kernel(kern1)

        assert_equal(reply["type"], "success")
    def test_interrupt_kernel_success(self):  # depends on add_computer, new_session
        x = self.a.add_computer(self.default_comp_config)
        kern1 = self.a.new_session()

        reply = self.a.interrupt_kernel(kern1)

        assert_equal(reply["type"], "success")
    def test_restart_kernel_success(self):  # depends on add_computer, new_session
        x = self.a.add_computer(self.default_comp_config)
        kern1 = self.a.new_session()
        kern2 = self.a.new_session()

        with capture_output() as (out, err):
            self.a.restart_kernel(kern2)
        out = out[0]

        y = ast.literal_eval(out)
        assert_is_instance(y, dict)
        assert_in("content", y)
        assert_len(y["content"], 2)
        assert_in("type", y)
        assert_equal(y["type"], "success")
        assert_in("kernel_id", y["content"])
        assert_uuid(y["content"]["kernel_id"])
        assert_in("connection", y["content"])
        assert_len(y["content"]["connection"], 6)
        for s in ("stdin_port", "hb_port", "shell_port", "iopub_port"):
            assert_in(s, y["content"]["connection"])
            assert_len(str(y["content"]["connection"][s]), 5)
        assert_in("ip", y["content"]["connection"])
        assert_equal(y["content"]["connection"]["ip"], "127.0.0.1")
        assert_in("key", y["content"]["connection"])
        assert_uuid(y["content"]["connection"]["key"])
Ejemplo n.º 4
0
    def test_restart_kernel_success(self): # depends on add_computer, new_session
        x = self.a.add_computer(self.default_comp_config)
        kern1 = self.a.new_session()
        kern2 = self.a.new_session()

        with capture_output() as (out, err):
            self.a.restart_kernel(kern2)
        out = out[0]

        y = ast.literal_eval(out)
        assert_is_instance(y, dict)
        assert_in("content", y)
        assert_len(y["content"], 2)
        assert_in("type", y)
        assert_equal(y["type"], "success")
        assert_in("kernel_id", y["content"])
        assert_uuid(y["content"]["kernel_id"])
        assert_in("connection", y["content"])
        assert_len(y["content"]["connection"], 6)
        for s in ("stdin_port", "hb_port", "shell_port", "iopub_port"):
            assert_in(s, y["content"]["connection"])
            assert_len(str(y["content"]["connection"][s]), 5)        
        assert_in("ip", y["content"]["connection"])
        assert_equal(y["content"]["connection"]["ip"], "127.0.0.1")
        assert_in("key", y["content"]["connection"])
        assert_uuid(y["content"]["connection"]["key"])
    def test_create_hb_stream(self):  # depends on create_connected_stream
        kernel_id = "kern1"
        comp_id = "testcomp1"
        self.a._kernels[kernel_id] = {"comp_id": comp_id, "connection": {"ip": "127.0.0.1", "hb_port": 50101}}
        self.a._comps[comp_id] = {"host": "localhost"}

        ret = self.a.create_hb_stream(kernel_id)
        assert_is(ret.closed(), False)
        assert_equal(ret.socket.socket_type, zmq.REQ)
Ejemplo n.º 6
0
    def test_create_hb_stream(self): # depends on create_connected_stream
        kernel_id = "kern1"
        comp_id = "testcomp1"
        self.a._kernels[kernel_id] = {"comp_id": comp_id, "connection": {"ip": "127.0.0.1", "hb_port": 50101}}
        self.a._comps[comp_id] = {"host": "localhost"}

        ret = self.a.create_hb_stream(kernel_id)
        assert_is(ret.closed(), False)
        assert_equal(ret.socket.socket_type, zmq.REQ)
Ejemplo n.º 7
0
    def test_purge_kernels_no_kernels(self): # depends on add_computer
        x = self.a.add_computer(self.default_comp_config)

        with capture_output() as (out, err):
            self.a.purge_kernels(x)
        out = out[0]

        self._check_all_kernels_killed_out(out)
        assert_equal(self.a._comps[x]["kernels"], {})
        assert_equal(self.a._kernels, {})
    def test_purge_kernels_no_kernels(self):  # depends on add_computer
        x = self.a.add_computer(self.default_comp_config)

        with capture_output() as (out, err):
            self.a.purge_kernels(x)
        out = out[0]

        self._check_all_kernels_killed_out(out)
        assert_equal(self.a._comps[x]["kernels"], {})
        assert_equal(self.a._kernels, {})
Ejemplo n.º 9
0
    def test_find_open_computer_success(self):
        self.a._comps["testcomp1"] = {"max_kernels": 3, "kernels": {}}
        self.a._comps["testcomp2"] = {"max_kernels": 5, "kernels": {}}

        for i in range(8):
            y = self.a._find_open_computer()
            assert_equal(y == "testcomp1" or y == "testcomp2", True)
            self.a._comps[y]["max_kernels"] -= 1

        try:
            self.a._find_open_computer()
        except IOError as e:
            assert_equal("Could not find open computer. There are 2 computers available.", e.message)
Ejemplo n.º 10
0
    def test_find_open_computer_success(self):
        self.a._comps["testcomp1"] = {"max_kernels": 3, "kernels": {}}
        self.a._comps["testcomp2"] = {"max_kernels": 5, "kernels": {}}

        for i in range(8):
            y = self.a._find_open_computer()
            assert_equal(y == "testcomp1" or y == "testcomp2", True)
            self.a._comps[y]["max_kernels"] -= 1

        try:
            self.a._find_open_computer()
        except IOError as e:
            assert_equal("Could not find open computer. There are 2 computers available.", e.message)
Ejemplo n.º 11
0
 def test_get_hb_info_success(self):
     self._populate_comps_kernels()
     (b, c) = self.a.get_hb_info("kone")
     assert_equal(b, 3.0)
     assert_equal(c, 5.0)
     (b, c) = self.a.get_hb_info("kthree")
     assert_equal(b, 2.0)
     assert_equal(c, 4.0)
Ejemplo n.º 12
0
 def test_get_hb_info_success(self):
     self._populate_comps_kernels()
     (b, c) = self.a.get_hb_info("kone")
     assert_equal(b, 3.0)
     assert_equal(c, 5.0)
     (b, c) = self.a.get_hb_info("kthree")
     assert_equal(b, 2.0)
     assert_equal(c, 4.0)
Ejemplo n.º 13
0
    def test_add_computer_success(self): # depends on _setup_ssh_connection, _ssh_untrusted
        new_config = self.default_comp_config.copy()
        new_config.update({'beat_interval': 0.5, 'first_beat': 1, 'kernels': {}})

        with capture_output(split=True) as (out,err):
            x = self.a.add_computer(self.default_comp_config)
        assert_is_not_none(x)
        assert_uuid(x)
        assert_in(x, self.a._comps)
        for k in new_config:
            assert_equal(self.a._comps[x][k], new_config[k], "config value %s (%s) does not agree (should be %s)"%(k,self.a._comps[x][k], new_config[k]))

        assert_in("ssh", self.a._clients[x])

        #assert_regexp_matches(out[0], self.executing_re)
        assert_regexp_matches(out[0], r'ZMQ Connection with computer [a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12} at port \d+ established')
    def test_restart_kernel_success(self): # depends on start_kernel
        y = self.a.start_kernel()
        kernel_id = y["kernel_id"]
        proc = self.a.kernels[kernel_id][0]
        preports = self.a.kernels[kernel_id][1]

        assert_is(proc.is_alive(), True)
        retval = self.a.restart_kernel(kernel_id)
        assert_is(proc.is_alive(), False) # old kernel process is killed

        proc = self.a.kernels[kernel_id][0]
        assert_is(proc.is_alive(), True) # and a new kernel process with the same kernel_id exists
        postports = self.a.kernels[kernel_id][1]

        for s in ("stdin_port", "hb_port", "shell_port", "iopub_port"):
            assert_equal(preports[s], postports[s]) # and that it has the same ports as before
Ejemplo n.º 15
0
 def test_start_kernel_success(self):
     y = self.a.start_kernel()
     assert_is_instance(y, dict)
     assert_len(y, 2)
     assert_in("kernel_id", y)
     assert_uuid(y["kernel_id"])
     assert_in(y["kernel_id"], self.a._kernels)
     assert_in("connection", y)
     assert_len(y["connection"], 6)
     for s in ("stdin_port", "hb_port", "shell_port", "iopub_port"):
         assert_in(s, y["connection"])
         assert_len(str(y["connection"][s]), 5)
     assert_in("ip", y["connection"])
     assert_equal(y["connection"]["ip"], "127.0.0.1")
     assert_in("key", y["connection"])
     assert_uuid(y["connection"]["key"])
 def test_start_kernel_success(self):
     y = self.a.start_kernel()
     assert_is_instance(y, dict)
     assert_len(y, 2)
     assert_in("kernel_id", y)
     assert_uuid(y["kernel_id"])
     assert_in(y["kernel_id"], self.a._kernels)
     assert_in("connection", y)
     assert_len(y["connection"], 6)
     for s in ("stdin_port", "hb_port", "shell_port", "iopub_port"):
         assert_in(s, y["connection"])
         assert_len(str(y["connection"][s]), 5)
     assert_in("ip", y["connection"])
     assert_equal(y["connection"]["ip"], "127.0.0.1")
     assert_in("key", y["connection"])
     assert_uuid(y["connection"]["key"])
Ejemplo n.º 17
0
    def test_restart_kernel_success(self):  # depends on start_kernel
        y = self.a.start_kernel()
        kernel_id = y["kernel_id"]
        proc = self.a.kernels[kernel_id][0]
        preports = self.a.kernels[kernel_id][1]

        assert_is(proc.is_alive(), True)
        retval = self.a.restart_kernel(kernel_id)
        assert_is(proc.is_alive(), False)  # old kernel process is killed

        proc = self.a.kernels[kernel_id][0]
        assert_is(
            proc.is_alive(),
            True)  # and a new kernel process with the same kernel_id exists
        postports = self.a.kernels[kernel_id][1]

        for s in ("stdin_port", "hb_port", "shell_port", "iopub_port"):
            assert_equal(
                preports[s],
                postports[s])  # and that it has the same ports as before
Ejemplo n.º 18
0
    def test_create_connected_stream(self):
        host = "localhost"
        port = 51337
        socket_type = zmq.SUB

        with capture_output() as (out, err):
            ret = self.a._create_connected_stream(host, port, socket_type)
        out = out[0]

        assert_is(ret.closed(), False)
        assert_equal(ret.socket.socket_type, zmq.SUB)
        # assert_equal(out, "Connecting to: tcp://%s:%i\n" % (host, port))

        host = "localhost"
        port = 51337
        socket_type = zmq.REQ

        ret = self.a._create_connected_stream(host, port, socket_type)

        assert_is(ret.closed(), False)
        assert_equal(ret.socket.socket_type, zmq.REQ)

        host = "localhost"
        port = 51337
        socket_type = zmq.DEALER

        ret = self.a._create_connected_stream(host, port, socket_type)

        assert_is(ret.closed(), False)
        assert_equal(ret.socket.socket_type, zmq.DEALER)
Ejemplo n.º 19
0
    def test_create_connected_stream(self):
        host="localhost"
        port = 51337
        socket_type = zmq.SUB

        with capture_output() as (out, err):
            ret = self.a._create_connected_stream(host, port, socket_type)
        out = out[0]

        assert_is(ret.closed(), False)
        assert_equal(ret.socket.socket_type, zmq.SUB)
        #assert_equal(out, "Connecting to: tcp://%s:%i\n" % (host, port))

        host="localhost"
        port = 51337
        socket_type = zmq.REQ

        ret = self.a._create_connected_stream(host, port, socket_type)

        assert_is(ret.closed(), False)
        assert_equal(ret.socket.socket_type, zmq.REQ)

        host="localhost"
        port = 51337
        socket_type = zmq.DEALER

        ret = self.a._create_connected_stream(host, port, socket_type)

        assert_is(ret.closed(), False)
        assert_equal(ret.socket.socket_type, zmq.DEALER)
Ejemplo n.º 20
0
    def test_add_computer_success(self):  # depends on _setup_ssh_connection, _ssh_untrusted
        new_config = self.default_comp_config.copy()
        new_config.update({"beat_interval": 0.5, "first_beat": 1, "kernels": {}})

        with capture_output(split=True) as (out, err):
            x = self.a.add_computer(self.default_comp_config)
        assert_is_not_none(x)
        assert_uuid(x)
        assert_in(x, self.a._comps)
        for k in new_config:
            assert_equal(
                self.a._comps[x][k],
                new_config[k],
                "config value %s (%s) does not agree (should be %s)" % (k, self.a._comps[x][k], new_config[k]),
            )

        assert_in("ssh", self.a._clients[x])

        # assert_regexp_matches(out[0], self.executing_re)
        assert_regexp_matches(
            out[0],
            r"ZMQ Connection with computer [a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12} at port \d+ established",
        )
Ejemplo n.º 21
0
def test_init_parameters():
    tmkm = trusted_kernel_manager.TrustedMultiKernelManager(default_computer_config = {"a": "b"}, kernel_timeout = 3.14)
    assert_equal(tmkm.default_computer_config, {"a": "b"})
    assert_equal(tmkm.kernel_timeout, 3.14)
def test_init():
    fkm = forking_kernel_manager.ForkingKernelManager("testing.log", '127.0.0.1', update_function=test_init)
    assert_len(fkm.kernels, 0)
    assert_equal(fkm.filename, "testing.log")
    assert_in("function test_init at ", repr(fkm.update_function))
Ejemplo n.º 23
0
    def test_purge_kernels_success(self):  # depends on start_kernel
        for i in xrange(5):
            self.a.start_kernel()

        retval = self.a.purge_kernels()
        assert_equal(retval, [])
Ejemplo n.º 24
0
def test_init():
    umkm = untrusted_kernel_manager.UntrustedMultiKernelManager(
        "testing.log", '127.0.0.1', update_function=test_init)
    assert_len(umkm._kernels, 0)
    assert_equal(umkm.filename, "testing.log")
    assert_is(hasattr(umkm, "fkm"), True)
Ejemplo n.º 25
0
def test_init():
    fkm = forking_kernel_manager.ForkingKernelManager(
        "testing.log", '127.0.0.1', update_function=test_init)
    assert_len(fkm.kernels, 0)
    assert_equal(fkm.filename, "testing.log")
    assert_in("function test_init at ", repr(fkm.update_function))
    def test_purge_kernels_success(self):  # depends on start_kernel
        for i in xrange(5):
            self.a.start_kernel()

        retval = self.a.purge_kernels()
        assert_equal(retval, [])
def test_init():
    umkm = untrusted_kernel_manager.UntrustedMultiKernelManager("testing.log", "127.0.0.1", update_function=test_init)
    assert_len(umkm._kernels, 0)
    assert_equal(umkm.filename, "testing.log")
    assert_is(hasattr(umkm, "fkm"), True)
Ejemplo n.º 28
0
 def _check_all_kernels_killed_out(self, out):
     expected_out = {"content": {"status": "All kernels killed!"}, "type": "success"}
     outdict = ast.literal_eval(out)
     assert_equal(outdict, expected_out)
Ejemplo n.º 29
0
def test_init_parameters():
    tmkm = trusted_kernel_manager.TrustedMultiKernelManager(default_computer_config={"a": "b"}, kernel_timeout=3.14)
    assert_equal(tmkm.default_computer_config, {"a": "b"})
    assert_equal(tmkm.kernel_timeout, 3.14)
Ejemplo n.º 30
0
 def _check_all_kernels_killed_out(self, out):
     expected_out = {'content': {'status': 'All kernels killed!'}, 'type': 'success'}
     outdict = ast.literal_eval(out)
     assert_equal(outdict, expected_out)