예제 #1
0
def test_redhat_get_stop_ssh_cmd():
    """Test Red Hat get stop ssh cmd method."""
    redhat = RedHat()

    redhat.init_system = 'systemd'
    assert redhat.get_stop_ssh_service_cmd() == 'systemctl stop sshd.service'

    redhat.init_system = 'init'
    assert redhat.get_stop_ssh_service_cmd() == 'service sshd stop'

    redhat.init_system = 'fake'
    with pytest.raises(IpaRedHatException) as error:
        redhat.get_stop_ssh_service_cmd()
    assert str(error.value) == \
        'The init system for this Red Hat system cannot be determined.'
예제 #2
0
def test_redhat_reboot_exception():
    """Test soft reboot method exception for Red Hat distro."""
    client = MagicMock()
    client.get_transport.side_effect = Exception('ERROR!')
    redhat = RedHat()
    redhat.init_system = 'systemd'

    with pytest.raises(IpaDistroException):
        redhat.reboot(client)
예제 #3
0
def test_redhat_reboot(mock_time):
    """Test soft reboot method for Red Hat distro."""
    client = MagicMock()
    channel = MagicMock()
    transport = MagicMock()
    transport.open_session.return_value = channel
    client.get_transport.return_value = transport
    redhat = RedHat()
    redhat.init_system = 'systemd'

    redhat.reboot(client)

    channel.exec_command.assert_called_once_with(
        "sudo sh -c '(sleep 1 && systemctl stop sshd.service "
        "&& shutdown -r now &)' && exit")