Manual test suite: use more precise data when comparing image size.
[tails.git] / features / step_definitions / snapshots.rb
blob83a6e9689c45e4115f337aa797647751fe0c3304
1 def checkpoints
2   {
3     'tails-greeter' => {
4       :description => "I have started Tails from DVD without network and stopped at Tails Greeter's login screen",
5       :parent_checkpoint => nil,
6       :steps => [
7         'the network is unplugged',
8         'I start the computer',
9         'the computer boots Tails'
10       ],
11     },
13     'no-network-logged-in' => {
14       :description => "I have started Tails from DVD without network and logged in",
15       :parent_checkpoint => "tails-greeter",
16       :steps => [
17         'I log in to a new session',
18       ],
19     },
21     'with-network-logged-in' => {
22       :description => "I have started Tails from DVD and logged in and the network is connected",
23       :parent_checkpoint => "no-network-logged-in",
24       :steps => [
25         'the network is plugged',
26         'Tor is ready',
27         'all notifications have disappeared',
28         'available upgrades have been checked',
29       ],
30     },
32     'no-network-bridge-mode' => {
33       :temporary => true,
34       :description => "I have started Tails from DVD without network and logged in with bridge mode enabled",
35       :parent_checkpoint => "tails-greeter",
36       :steps => [
37         'I enable the specific Tor configuration option',
38         'I log in to a new session',
39         'all notifications have disappeared',
40       ],
41     },
43     'no-network-logged-in-sudo-passwd' => {
44       :temporary => true,
45       :description => "I have started Tails from DVD without network and logged in with an administration password",
46       :parent_checkpoint => "tails-greeter",
47       :steps => [
48         'I set an administration password',
49         'I log in to a new session',
50       ],
51     },
53     'with-network-logged-in-sudo-passwd' => {
54       :temporary => true,
55       :description => "I have started Tails from DVD and logged in with an administration password and the network is connected",
56       :parent_checkpoint => "no-network-logged-in-sudo-passwd",
57       :steps => [
58         'the network is plugged',
59         'Tor is ready',
60         'all notifications have disappeared',
61         'available upgrades have been checked',
62       ],
63     },
65     'usb-install-tails-greeter' => {
66       :description => "I have started Tails without network from a USB drive without a persistent partition and stopped at Tails Greeter's login screen",
67       :parent_checkpoint => nil,
68       :steps => [
69         'I create a 7200 MiB disk named "__internal"',
70         'I plug USB drive "__internal"',
71         'I write the Tails USB image to disk "__internal"',
72         'I start Tails from USB drive "__internal" with network unplugged',
73         'the boot device has safe access rights',
74         'Tails is running from USB drive "__internal"',
75         'there is no persistence partition on USB drive "__internal"',
76         'process "udev-watchdog" is running',
77         'udev-watchdog is monitoring the correct device',
78       ],
79     },
81     'usb-install-logged-in' => {
82       :description => "I have started Tails without network from a USB drive without a persistent partition and logged in",
83       :parent_checkpoint => 'usb-install-tails-greeter',
84       :steps => [
85         'I log in to a new session',
86       ],
87     },
89     'usb-install-with-persistence-tails-greeter' => {
90       :description => "I have started Tails without network from a USB drive with a persistent partition and stopped at Tails Greeter's login screen",
91       :parent_checkpoint => 'usb-install-logged-in',
92       :steps => [
93         'I create a persistent partition',
94         'a Tails persistence partition exists on USB drive "__internal"',
95         'I shutdown Tails and wait for the computer to power off',
96         'I start Tails from USB drive "__internal" with network unplugged',
97         'the boot device has safe access rights',
98         'Tails is running from USB drive "__internal"',
99         'process "udev-watchdog" is running',
100         'udev-watchdog is monitoring the correct device',
101       ],
102     },
104     'usb-install-with-persistence-logged-in' => {
105       :description => "I have started Tails without network from a USB drive with a persistent partition enabled and logged in",
106       :parent_checkpoint => 'usb-install-with-persistence-tails-greeter',
107       :steps => [
108         'I enable persistence',
109         'I log in to a new session',
110         'all persistence presets are enabled',
111         'all persistent filesystems have safe access rights',
112         'all persistence configuration files have safe access rights',
113         'all persistent directories have safe access rights',
114       ],
115     },
117     'usb-install-with-persistence-logged-in-with-administration-password' => {
118       :description => "I have started Tails without network from a USB drive with a persistent partition enabled and logged in with an administration password",
119       :parent_checkpoint => 'usb-install-with-persistence-tails-greeter',
120       :steps => [
121         'I enable persistence',
122         'I set an administration password',
123         'I log in to a new session',
124         'all persistence presets are enabled',
125         'all persistent filesystems have safe access rights',
126         'all persistence configuration files have safe access rights',
127         'all persistent directories have safe access rights',
128       ],
129     },
130   }
133 def reach_checkpoint(name)
134   scenario_indent = " "*4
135   step_indent = " "*6
137   step "a computer"
138   if VM.snapshot_exists?(name)
139     $vm.restore_snapshot(name)
140     post_snapshot_restore_hook
141   else
142     checkpoint = checkpoints[name]
143     checkpoint_description = checkpoint[:description]
144     parent_checkpoint = checkpoint[:parent_checkpoint]
145     steps = checkpoint[:steps]
146     if parent_checkpoint
147       if VM.snapshot_exists?(parent_checkpoint)
148         $vm.restore_snapshot(parent_checkpoint)
149       else
150         reach_checkpoint(parent_checkpoint)
151       end
152       post_snapshot_restore_hook
153     end
154     debug_log(scenario_indent + "Checkpoint: #{checkpoint_description}",
155               color: :white, timestamp: false)
156     step_action = "Given"
157     if parent_checkpoint
158       parent_description = checkpoints[parent_checkpoint][:description]
159       debug_log(step_indent + "#{step_action} #{parent_description}",
160                 color: :green, timestamp: false)
161       step_action = "And"
162     end
163     steps.each do |s|
164       begin
165         step(s)
166       rescue Exception => e
167         debug_log(scenario_indent +
168                   "Step failed while creating checkpoint: #{s}",
169                   color: :red, timestamp: false)
170         raise e
171       end
172       debug_log(step_indent + "#{step_action} #{s}",
173                 color: :green, timestamp: false)
174       step_action = "And"
175     end
176     $vm.save_snapshot(name)
177   end
180 # For each checkpoint we generate a step to reach it.
181 checkpoints.each do |name, desc|
182   step_regex = Regexp.new("^#{Regexp.escape(desc[:description])}$")
183   Given step_regex do
184     reach_checkpoint(name)
185   end