Exemple #1
0
def test_get_no_such_service(mocker):
    from ideascube.serveradmin.systemd import Manager, NoSuchUnit

    mocker.patch(
        'ideascube.serveradmin.systemd.dbus.SystemBus', side_effect=FakeBus)

    manager = Manager()

    with pytest.raises(NoSuchUnit):
        manager.get_service('foobar')
Exemple #2
0
def test_deactivate_service(mocker):
    from ideascube.serveradmin.systemd import Manager

    mocker.patch(
        'ideascube.serveradmin.systemd.dbus.SystemBus', side_effect=FakeBus)
    mocker.patch(
        'ideascube.serveradmin.systemd.subprocess.Popen', side_effect=FakePopen)
    mocker.patch(
        'ideascube.serveradmin.systemd.subprocess.PIPE', side_effect=StringIO)

    manager = Manager()
    manager.deactivate('NetworkManager.service')
Exemple #3
0
def test_restart_service(mocker):
    from ideascube.serveradmin.systemd import Manager

    mocker.patch(
        'ideascube.serveradmin.systemd.dbus.SystemBus', side_effect=FakeBus)
    mocker.patch(
        'ideascube.serveradmin.systemd.subprocess.Popen', side_effect=FakePopen)
    mocker.patch(
        'ideascube.serveradmin.systemd.subprocess.PIPE', side_effect=BytesIO)

    manager = Manager()
    manager.restart('NetworkManager.service')
Exemple #4
0
def test_restart_service(mocker):
    from ideascube.serveradmin.systemd import Manager

    mocker.patch('ideascube.serveradmin.systemd.dbus.SystemBus',
                 side_effect=FakeBus)
    mocker.patch('ideascube.serveradmin.systemd.subprocess.Popen',
                 side_effect=FakePopen)
    mocker.patch('ideascube.serveradmin.systemd.subprocess.PIPE',
                 side_effect=BytesIO)

    manager = Manager()
    manager.restart('NetworkManager.service')
Exemple #5
0
def test_get_service(mocker):
    from ideascube.serveradmin.systemd import Manager

    mocker.patch(
        'ideascube.serveradmin.systemd.dbus.SystemBus', side_effect=FakeBus)

    manager = Manager()

    service = manager.get_service('NetworkManager.service')
    assert service.LoadState == 'loaded'
    assert service.ActiveState == 'active'
    assert service.active

    service = manager.get_service('NetworkManager')
    assert service.LoadState == 'loaded'
    assert service.ActiveState == 'active'
    assert service.active
Exemple #6
0
def test_failed_to_deactivate_service(mocker):
    from ideascube.serveradmin.systemd import Manager, UnitManagementError

    mocker.patch('ideascube.serveradmin.systemd.dbus.SystemBus',
                 side_effect=FakeBus)
    mocker.patch('ideascube.serveradmin.systemd.subprocess.Popen',
                 side_effect=FailingPopen)
    mocker.patch('ideascube.serveradmin.systemd.subprocess.PIPE',
                 side_effect=BytesIO)

    manager = Manager()

    with pytest.raises(UnitManagementError) as e:
        manager.deactivate('NetworkManager.service')

    assert str(
        e.value) == ('Could not disable NetworkManager.service: Oh Noes!')
Exemple #7
0
def test_failed_to_deactivate_service(mocker):
    from ideascube.serveradmin.systemd import Manager, UnitManagementError

    mocker.patch(
        'ideascube.serveradmin.systemd.dbus.SystemBus', side_effect=FakeBus)
    mocker.patch(
        'ideascube.serveradmin.systemd.subprocess.Popen',
        side_effect=FailingPopen)
    mocker.patch(
        'ideascube.serveradmin.systemd.subprocess.PIPE', side_effect=StringIO)

    manager = Manager()

    with pytest.raises(UnitManagementError) as e:
        manager.deactivate('NetworkManager.service')

    assert str(e.value) == (
        'Could not disable NetworkManager.service: Oh Noes!')