calamares_partitioning.pm 7.06 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
# Copyright (C) 2016-2018 Harald Sitter <sitter@kde.org>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of
# the License or (at your option) version 3 or any later version
# accepted by the membership of KDE e.V. (or its successor approved
# by the membership of KDE e.V.), which shall act as a proxy
# defined in Section 14 of version 3 of the license.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

use base "livetest_neon";
use strict;
use testapi;
use autotest 'query_isotovideo'; # to access mouse commands directly

my $user = $testapi::username;
my $password = $testapi::password;

sub cala_setup_geoip {
    select_console 'log-console';
    {
        assert_script_run 'wget ' . data_url('geoip_service_calamares.rb'),  16;
        script_sudo 'systemd-run ruby `pwd`/geoip_service_calamares.rb', 16;
    }
    select_console 'x11';
}

sub cala_welcome {
    assert_screen 'calamares-installer-welcome', 30;
    assert_and_click 'calamares-installer-next';
}

sub cala_keyboard {
    assert_screen "calamares-installer-keyboard", 16;
    assert_and_click "calamares-installer-next";
}

sub cala_show {
    assert_screen 'calamares-installer-show', 16;
}

sub cala_close {
    assert_and_click 'calamares-installer-restart-checkbox';
    assert_and_click 'calamares-installer-close';
}

sub cala_timezone {
    # Timezone has 75% fuzzyness as timezone is geoip'd so its fairly divergent.
    # Also, starting here only the top section of the window gets matched as
    # the bottom part with the buttons now has a progressbar and status
    # text which is non-deterministic.
    # NB: we give way more leeway on the new needle appearing as disk IO can
    #   cause quite a bit of slowdown and ubiquity's transition policy is
    #   fairly weird when moving away from the disk page.
    assert_screen 'calamares-installer-timezone', 60;
    assert_and_click 'calamares-installer-next';
}

sub cala_user {
    assert_screen 'calamares-installer-user', 16;
    type_string $user;
    assert_screen 'calamares-installer-user-user', 16;
    send_key 'tab'; # username field
    send_key 'tab'; # hostname field
    send_key 'tab'; # 1st password field
    type_string $password;
    send_key 'tab'; # 2nd password field
    type_string $password;
    # all fields filled (not matching hostname field)
    assert_screen 'calamares-installer-user-complete', 16;
79
    assert_and_click 'calamares-installer-install';
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
}

sub run_partioning {
    my ($code) = @_;

    assert_and_click 'calamares-installer-icon';

    cala_welcome;
    cala_timezone;
    cala_keyboard;

    assert_screen 'calamares-installer-disk', 16;
    $code->();

    cala_user;
    cala_show;
    cala_close;

    # wait for kpmcore helper to quit
    sleep 16;
}

sub run {
    my ($self) = shift;
    $self->boot;

    $testapi::username = 'neon';
    $testapi::password = '';

    cala_setup_geoip;

    select_console 'log-console';
    {
        assert_script_run 'wget ' . data_url('calamares_partitioning_only.rb'),  16;
        assert_script_sudo 'ruby `pwd`/calamares_partitioning_only.rb', 16;
    }
    select_console 'x11';

118 119
    $self->maybe_switch_offline;

120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
    # First erase and do a standard partitioning
    run_partioning sub {
        assert_and_click 'calamares-installer-disk-erase';
        assert_screen 'calamares-installer-disk-erase-selected';
        assert_and_click 'calamares-installer-next';
    };

    # Now let's replace root.
    run_partioning sub {
        assert_and_click 'calamares-installer-disk-replace';
        assert_and_click 'calamares-installer-disk-replace-select';
        assert_screen 'calamares-installer-disk-replace-selected';
        assert_and_click 'calamares-installer-next';
    };

    # Along side the other one.
    run_partioning sub {
        assert_and_click 'calamares-installer-disk-alongside';
        assert_and_click 'calamares-installer-disk-alongside-select';

        # Next adjust the spacing a bit.

        # cheeky way of getting the click area and calculating the center(
        # i.e. click point)
        my $needle = assert_screen 'calamares-installer-disk-alongside-adjust';
        my $area = $needle->{area}->[-1];
        my $x = int($area->{x} + $area->{w} / 2);
        my $y = int($area->{y} + $area->{h} / 2);

        # This has some sleeps mixed in to make sure the app registers the
        # event.
        mouse_set($x, $y);
        # mouse down
        query_isotovideo('backend_mouse_button', {button => 'left', bstate => 1});
        sleep 1;
        # move to the left
        mouse_set($x - 150, $y);
        sleep 1;
        # mouse up
        query_isotovideo('backend_mouse_button', {button => 'left', bstate => 0});
        # move it away again, lest it screws up needles via hover focus
        mouse_hide;

        assert_and_click 'calamares-installer-disk-alongside-selected';
        assert_and_click 'calamares-installer-next';
    };

    # Manually partition the shebang.
    run_partioning sub {
        assert_and_click 'calamares-installer-disk-manual';
        assert_and_click 'calamares-installer-next';
        assert_and_click 'calamares-installer-disk-manual-new-table';
172
        assert_and_click 'calamares-installer-disk-manual-new-gpt-ok';
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
        assert_screen 'calamares-installer-disk-manual-clean';
        assert_and_click 'calamares-installer-disk-manual-free-space';
        assert_and_click 'calamares-installer-disk-manual-create';

        assert_screen 'calamares-installer-disk-manual-create-dialog';
        send_key 'tab'; # fsystem
        send_key 'tab'; # encrypt?
        send_key 'tab'; # mountpoint
        type_string '/';
        # click ok
        assert_and_click 'calamares-installer-disk-manual-create-dialog';
        assert_screen 'calamares-installer-disk-manual-new-ext4-root';
        assert_and_click 'calamares-installer-next';
        assert_and_click 'calamares-installer-disk-manual-no-esp';
    };
}

sub upload_calamares_logs {
    # Uploads end up in wok/ulogs/
    # Older calamari used this path:
    upload_logs '/home/neon/.cache/Calamares/calamares/Calamares.log', failok => 1;
    # Newer this one:
    upload_logs '/home/neon/.cache/Calamares/session.log', failok => 1;
    # Even newer:
    upload_logs '/home/neon/.cache/calamares/session.log', failok => 1;
}

sub post_fail_hook {
    my ($self) = shift;
    $self->SUPER::post_fail_hook;
    $self->upload_calamares_logs;
}

sub test_flags {
    # without anything - rollback to 'lastgood' snapshot if failed
    # 'fatal' - whole test suite is in danger if this fails
    # 'milestone' - after this test succeeds, update 'lastgood'
    # 'important' - if this fails, set the overall state to 'fail'
    return { important => 1, fatal => 1 };
}

1;