示例#1
0
def test_upstart_system(mocker):
    process_mock = MagicMock()
    process_mock.communicate.return_value = ('stop', '', )
    process_mock.returncode = 0
    popen_mock = mocker.patch('subprocess.Popen', return_value=process_mock)

    mount_efs.start_watchdog('init')

    assert 2 == popen_mock.call_count
    assert '/sbin/start' in popen_mock.call_args[0][0]
示例#2
0
def test_supervisor_system_watchdog_status(mocker):
    process_mock = MagicMock()
    process_mock.communicate.return_value = ('RUNNING', '', )
    process_mock.returncode = 0
    popen_mock = mocker.patch('subprocess.Popen', return_value=process_mock)

    mount_efs.start_watchdog('supervisord')

    utils.assert_called_once(popen_mock)
    assert 'supervisorctl' in popen_mock.call_args[0][0]
    assert 'status' in popen_mock.call_args[0][0]
示例#3
0
def test_systemd_system(mocker):
    call_mock = mocker.patch('subprocess.call', return_value=1)
    popen_mock = mocker.patch('subprocess.Popen')

    mount_efs.start_watchdog('systemd')

    utils.assert_called_once(call_mock)
    assert 'systemctl' in call_mock.call_args[0][0]
    assert 'is-active' in call_mock.call_args[0][0]
    utils.assert_called_once(popen_mock)
    assert 'systemctl' in popen_mock.call_args[0][0]
    assert 'start' in popen_mock.call_args[0][0]
示例#4
0
def test_systemd_system(mocker):
    call_mock = mocker.patch("subprocess.call", return_value=1)
    popen_mock = mocker.patch("subprocess.Popen")

    mount_efs.start_watchdog("systemd")

    utils.assert_called_once(call_mock)
    assert "systemctl" in call_mock.call_args[0][0]
    assert "is-active" in call_mock.call_args[0][0]
    utils.assert_called_once(popen_mock)
    assert "systemctl" in popen_mock.call_args[0][0]
    assert "start" in popen_mock.call_args[0][0]
示例#5
0
def test_upstart_system(mocker):
    process_mock = MagicMock()
    process_mock.communicate.return_value = (
        "stop",
        "",
    )
    process_mock.returncode = 0
    popen_mock = mocker.patch("subprocess.Popen", return_value=process_mock)

    mount_efs.start_watchdog("init")

    assert 2 == popen_mock.call_count
    assert "/sbin/start" in popen_mock.call_args[0][0]
示例#6
0
def test_launchd_system(mocker):
    process_mock = MagicMock()
    process_mock.communicate.return_value = (
        "stop",
        "",
    )
    process_mock.returncode = 0
    popen_mock = mocker.patch("subprocess.Popen", return_value=process_mock)
    mocker.patch("os.path.exists", return_value=True)

    mount_efs.start_watchdog("launchd")

    assert 2 == popen_mock.call_count
    assert "sudo" in popen_mock.call_args[0][0]
    assert "launchctl" in popen_mock.call_args[0][0]
    assert "load" in popen_mock.call_args[0][0]
示例#7
0
def test_launchd_system(mocker):
    process_mock = MagicMock()
    process_mock.communicate.return_value = (
        'stop',
        '',
    )
    process_mock.returncode = 0
    popen_mock = mocker.patch('subprocess.Popen', return_value=process_mock)
    mocker.patch('os.path.exists', return_value=True)

    mount_efs.start_watchdog('launchd')

    assert 2 == popen_mock.call_count
    assert 'sudo' in popen_mock.call_args[0][0]
    assert 'launchctl' in popen_mock.call_args[0][0]
    assert 'load' in popen_mock.call_args[0][0]
示例#8
0
def test_unknown_system(mocker):
    popen_mock = mocker.patch('subprocess.Popen')

    mount_efs.start_watchdog('unknown')

    utils.assert_not_called(popen_mock)