-
Notifications
You must be signed in to change notification settings - Fork 283
/
Copy pathy2snapper_common.pm
269 lines (206 loc) · 7.76 KB
/
y2snapper_common.pm
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
79
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
118
119
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
172
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
=head1 y2snapper_common.pm
Library for creating snapshot by using YaST2 snapper.
=cut
package y2snapper_common;
use strict;
use warnings;
use testapi;
use utils;
use version_utils;
use YaST::workarounds;
use Utils::Logging 'export_logs';
=head2 y2snapper_select_current_conf
y2snapper_select_current_conf($ncurses);
Select Current Configuration on Snapshots screen
C<$ncurses> is used to check if it is ncurses.
=cut
sub y2snapper_select_current_conf {
my ($self, $ncurses) = @_;
$ncurses //= 0;
if ($ncurses) {
send_key_until_needlematch 'yast2_snapper-current_configuration_root', 'tab';
send_key 'down'; # Expand test configuration selection box
send_key 'down'; # Select test configuration
send_key 'ret'; # Apply selection
send_key 'tab';
}
else {
send_key 'shift-tab'; # Focus Current Configuration selection box
send_key 'down'; # Select test configuration
}
}
=head2 y2snapper_close_snapper_module
y2snapper_close_snapper_module($ncurses);
Close snapper module
C<$ncurses> is used to check if it is ncurses.
=cut
sub y2snapper_close_snapper_module {
my ($self, $ncurses) = @_;
$ncurses //= 0;
if ($ncurses) {
send_key_until_needlematch 'yast2_snapper-close', 'tab';
send_key 'ret';
}
else {
assert_and_click 'yast2_snapper-close';
}
wait_still_screen 3;
}
=head2 y2snapper_adding_new_snapper_conf
y2snapper_adding_new_snapper_conf();
Setup another snapper config for /test (creating previously a subvolume for it)
It allows to have more control over diffs amongs snapshots.
=cut
sub y2snapper_adding_new_snapper_conf {
assert_script_run("btrfs subvolume create /test");
# we only allow certain snapshots to be labeled snapperd_data_t, see poo#168583
assert_script_run("semanage fcontext -a -t 'snapperd_data_t' -s system_u '/test(/.*)?'") if has_selinux;
assert_script_run("snapper -c test create-config /test");
assert_script_run('snapper -c test set-config TIMELINE_CREATE=no TIMELINE_MIN_AGE=0');
assert_script_run('snapper -c test get-config');
assert_script_run('snapper -c test cleanup timeline');
}
=head2 y2snapper_create_snapshot
y2snapper_create_snapshot($name);
Helper to create a snapper snapshot. C<$name> is the name of snapshot.
=cut
sub y2snapper_create_snapshot {
my $self = shift;
my $name = shift || "Awesome Snapshot";
# Open the 'C'reate dialog and wait until it is there
send_key "alt-c";
assert_screen 'yast2_snapper-createsnapshotdialog', 100;
# Fill the form and finish by pressing the 'O'k-button
type_string $name;
wait_screen_change { send_key "alt-u" };
type_string "a=1,b=2";
save_screenshot;
send_key "alt-o";
}
=head2 y2snapper_new_snapshot
y2snapper_new_snapshot($ncurses);
Create a new snapshot.
C<$ncurses> is used to check if it is ncurses. In ncurses it needs to focus to snapshots list manually.
=cut
sub y2snapper_new_snapshot {
my ($self, $ncurses) = @_;
$ncurses //= 0;
assert_screen 'yast2_snapper-snapshots', 100;
$self->y2snapper_select_current_conf($ncurses);
assert_screen 'yast2_snapper-empty-list';
# Create a new snapshot
$self->y2snapper_create_snapshot;
# Have to focus to Snapshots list manually in ncurses
if ($ncurses) {
send_key_until_needlematch 'yast2_snapper-focus-in-snapshots', 'tab';
}
else {
apply_workaround_poo124652([qw(yast2_snapper-new_snapshot yast2_snapper-new_snapshot_selected)], 10) if (is_sle('>=15-SP4'));
}
# Make sure the snapshot is listed in the main window
send_key_until_needlematch([qw(yast2_snapper-new_snapshot yast2_snapper-new_snapshot_selected)], 'pgdn');
$self->y2snapper_close_snapper_module($ncurses);
}
=head2 y2snapper_apply_filesystem_changes
y2snapper_apply_filesystem_changes();
Performs any modification in filesystem and at least include some change
under /test, which is the subvolume for testing.
=cut
sub y2snapper_apply_filesystem_changes {
assert_script_run('echo "hello world in snapper conf /root" > /hello_root.txt');
assert_script_run('echo "hello world in snapper conf /test" > /test/hello_test.txt');
}
=head2 y2snapper_show_changes_and_delete
y2snapper_show_changes_and_delete($ncurses);
Show changes of snapshot and delete it.
Use C<$ncurses> to check if it is ncurses. Select in ncurses the first subvolume (root) in the tree and expand it.
=cut
sub y2snapper_show_changes_and_delete {
my ($self, $ncurses) = @_;
$ncurses //= 0;
assert_screen 'yast2_snapper-snapshots', 100;
$self->y2snapper_select_current_conf($ncurses);
send_key_until_needlematch 'yast2_snapper-new_snapshot_selected', 'tab';
# Press Show Changes
send_key "alt-s";
wait_still_screen(2, 4);
is_sle('>=15-SP4') ? apply_workaround_poo124652('yast2_snapper-unselected_testdata') : assert_screen('yast2_snapper-unselected_testdata');
if ($ncurses) {
# Select 1. subvolume (root) in the tree and expand it
wait_screen_change { send_key "ret" };
wait_screen_change { send_key "end" };
}
else {
wait_screen_change { send_key "tab" };
wait_screen_change { send_key "spc" };
}
assert_screen 'yast2_snapper-selected_testdata';
# Close the dialog and make sure it is closed
send_key 'alt-c';
# Dele't'e the snapshot
if ($ncurses) {
send_key_until_needlematch 'yast2_snapper-delete', 'tab';
send_key 'ret';
}
else {
send_key "alt-t";
}
assert_screen 'yast2_snapper-confirm_delete';
send_key "alt-y";
is_sle('>=15-SP4') ? apply_workaround_poo124652('yast2_snapper-empty-list') : assert_screen('yast2_snapper-empty-list');
}
=head2 y2snapper_clean_and_quit
y2snapper_clean_and_quit($module_name,$ncurses);
C<$module_name> is YaST2 module yast2-snapper.
Quit yast2-snapper and clean up the test data.
=cut
sub y2snapper_clean_and_quit {
my ($self, $module_name, $ncurses) = @_;
# Ensure yast2-snapper is not busy anymore
wait_still_screen 30;
$self->y2snapper_close_snapper_module($ncurses);
if (defined($module_name)) {
wait_serial("$module_name-0", 240) || die "yast2 snapper failed";
}
else {
# Wait until root gnome terminal is focussed, delete the directory and close window
assert_screen('root-gnome-terminal', timeout => 180);
}
script_run 'rm /hello_root.txt';
script_run 'snapper -c test delete-config';
script_run 'rm -rf /test/*';
script_run "ls";
unless ($ncurses) {
enter_cmd "exit"; # root
wait_still_screen(1);
enter_cmd "exit"; # user
wait_still_screen(1);
}
}
=head2 y2snapper_failure_analysis
y2snapper_failure_analysis();
Analyse failure and upload logs.
=cut
sub y2snapper_failure_analysis {
my ($self) = @_;
# snapper actions can put the system under quite some load so we want to
# give some more time, e.g. for login in the consoles
my $factor = 30;
my $previous_timeout_scale = get_var('TIMEOUT_SCALE', 1);
set_var('TIMEOUT_SCALE', $previous_timeout_scale * $factor);
select_console('log-console', await_console => 0);
my $additional_sleep_time = 10;
sleep $additional_sleep_time;
export_logs;
# Upload y2log for analysis if yast2 snapper fails
upload_y2logs;
save_screenshot;
diag('check if at least snapper low-level commands still work');
script_run('snapper ls');
diag('Collect a backtrace from potentially running snapperd, e.g. for bsc#1032831');
script_run('pidof snapperd && gdb --batch -q -ex "thread apply all bt" -ex q /usr/sbin/snapperd $(pidof snapperd) |& tee /tmp/snapperd_bt_all.log');
upload_logs '/tmp/snapperd_bt_all.log';
set_var('TIMEOUT_SCALE', $previous_timeout_scale);
enter_cmd "exit";
}
1;