예제 #1
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)
예제 #2
0
def test_redhat_install_package():
    """Test install package method for Red Hat distro."""
    client = MagicMock()
    redhat = RedHat()

    with patch('img_proof.ipa_utils.execute_ssh_command',
               MagicMock(return_value='')) as mocked:
        redhat.install_package(client, 'python')

    mocked.assert_called_once_with(
        client, "sudo sh -c 'dnf --assumeyes --nogpgcheck install python'")
예제 #3
0
def test_redhat_refresh():
    """Test refresh method for Red Hat distro."""
    client = MagicMock()
    redhat = RedHat()

    with patch('img_proof.ipa_utils.execute_ssh_command',
               MagicMock(return_value='Refresh finished!')) as mocked:
        output = redhat.repo_refresh(client)

    mocked.assert_called_once_with(client,
                                   "sudo sh -c 'dnf --assumeyes makecache'")
    assert output == 'Refresh finished!'
예제 #4
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")
예제 #5
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.'
예제 #6
0
def test_redhat_refresh_exception():
    """Test refresh method exception for Red Hat distro."""
    client = MagicMock()
    redhat = RedHat()

    with patch('img_proof.ipa_utils.execute_ssh_command',
               MagicMock(side_effect=Exception('ERROR!'))) as mocked:
        pytest.raises(IpaDistroException, redhat.repo_refresh, client)

    mocked.assert_called_once_with(client,
                                   "sudo sh -c 'dnf --assumeyes makecache'")