Exemplo n.º 1
0
def test_watchdog_clean():
    with mock.patch.dict('os.environ'):
        intf = Systemd()
        os.environ['WATCHDOG_USEC'] = '5000000'
        os.environ['WATCHDOG_PID'] = str(os.getpid())
        intf.watchdog_clean()
        assert 'WATCHDOG_USEC' not in os.environ
        assert 'WATCHDOG_PID' not in os.environ
Exemplo n.º 2
0
def test_known_available(tmpdir):
    addr = tmpdir.join('known')
    s = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM | socket.SOCK_CLOEXEC)
    s.bind(str(addr))
    try:
        intf = Systemd(str(addr))
        intf.available()
    finally:
        s.close()
Exemplo n.º 3
0
def test_watchdog_period():
    with mock.patch.dict('os.environ'):
        intf = Systemd()
        os.environ.pop('WATCHDOG_USEC', None)
        assert intf.watchdog_period() is None
        os.environ['WATCHDOG_USEC'] = '5000000'
        assert intf.watchdog_period() == 5
        os.environ['WATCHDOG_PID'] = '1'
        assert intf.watchdog_period() is None
Exemplo n.º 4
0
def test_available(mock_sock):
    intf = Systemd()
    intf.available()
Exemplo n.º 5
0
def test_notify_not():
    intf = Systemd()
    intf.notify('foo')
    intf.notify(b'foo')
Exemplo n.º 6
0
def test_available_ioerror(tmpdir):
    with mock.patch.dict('os.environ'):
        os.environ['NOTIFY_SOCKET'] = str(tmpdir.join('FOO'))
        intf = Systemd()
        with pytest.raises(RuntimeError):
            intf.available()
Exemplo n.º 7
0
def test_available_invalid():
    with mock.patch.dict('os.environ'):
        os.environ['NOTIFY_SOCKET'] = 'FOO'
        intf = Systemd()
        with pytest.raises(RuntimeError):
            intf.available()
Exemplo n.º 8
0
def test_available_undefined():
    intf = Systemd()
    with pytest.raises(RuntimeError):
        intf.available()
Exemplo n.º 9
0
def test_main_pid(mock_sock):
    intf = Systemd()
    intf.main_pid(10)
    assert mock_sock.recv(64) == b'MAINPID=10'
    intf.main_pid()
    assert mock_sock.recv(64) == ('MAINPID=%d' % os.getpid()).encode('ascii')
Exemplo n.º 10
0
def test_watchdog_reset(mock_sock):
    intf = Systemd()
    intf.watchdog_reset(3)
    assert mock_sock.recv(64) == b'WATCHDOG_USEC=3000000'
Exemplo n.º 11
0
def test_watchdog_ping(mock_sock):
    intf = Systemd()
    intf.watchdog_ping()
    assert mock_sock.recv(64) == b'WATCHDOG=1'
Exemplo n.º 12
0
def test_extend_timeout(mock_sock):
    intf = Systemd()
    intf.extend_timeout(5)
    assert mock_sock.recv(64) == b'EXTEND_TIMEOUT_USEC=5000000'
Exemplo n.º 13
0
def test_stopping(mock_sock):
    intf = Systemd()
    intf.stopping()
    assert mock_sock.recv(64) == b'STOPPING=1'
Exemplo n.º 14
0
def test_reloading(mock_sock):
    intf = Systemd()
    intf.reloading()
    assert mock_sock.recv(64) == b'RELOADING=1'
Exemplo n.º 15
0
def test_abstract_ready(mock_abstract_sock):
    intf = Systemd()
    intf.ready()
    assert mock_abstract_sock.recv(64) == b'READY=1'
Exemplo n.º 16
0
def test_available(mock_sock):
    intf = Systemd()
    intf.notify('foo')
    assert mock_sock.recv(64) == b'foo'
    intf.notify(b'bar')
    assert mock_sock.recv(64) == b'bar'