示例#1
0
def test_client(security, kinit, tmpdir):
    logpath = str(tmpdir.join("log.txt"))

    with skein.Client(security=security, log=logpath) as client:
        # smoketests
        client.get_applications()
        repr(client)

        client2 = skein.Client(address=client.address, security=security)
        assert client2._proc is None

        # smoketests
        client2.get_applications()
        repr(client2)

    # Process was definitely closed
    assert not pid_exists(client._proc.pid)

    # no-op to call close again
    client.close()

    # Log was written
    assert os.path.exists(logpath)
    with open(logpath) as fil:
        assert len(fil.read()) > 0

    # Connection error on closed client
    with pytest.raises(skein.ConnectionError):
        client2.get_applications()

    # Connection error on connecting to missing driver
    with pytest.raises(skein.ConnectionError):
        skein.Client(address=client.address, security=security)
示例#2
0
def test_cli_driver_after_bad_driver_file(cmd, tmpdir, capsys):
    with set_skein_config(str(tmpdir)):
        run_command('config gencerts')
        driver_file = os.path.join(skein.properties.config_dir, 'driver')

        sock = socket.socket()
        sock.bind(('', 0))
        address = 'localhost:%d' % sock.getsockname()[1]

        # Find a PID that doesn't exist
        pid = 1234
        while pid_exists(pid):
            pid += 1
        _write_driver(address, pid)
        assert os.path.exists(driver_file)

        if cmd == 'start':
            run_command('driver start')
            out, err = capsys.readouterr()
            assert out
            assert 'Previous driver' in err
            assert os.path.exists(driver_file)

        run_command('driver stop')
        out, err = capsys.readouterr()
        assert not out
        assert not err
        assert not os.path.exists(driver_file)
示例#3
0
def test_client_closed_when_reference_dropped(security, kinit):
    client = skein.Client(security=security, log=False)
    ref = weakref.ref(client)

    pid = client._proc.pid

    del client
    assert ref() is None
    assert not pid_exists(pid)