summaryrefslogtreecommitdiffstats
path: root/cucumber/features/step_definitions/snapshots.rb
blob: 956b9ccf3071f2def6729159b80cdb25309060fa (plain)
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
def checkpoints
  {
    'boot-d-i' => {
      :description => "I have started Debian Installer and stopped at the Tasksel prompt",
      :parent_checkpoint => nil,
      :steps => [
	'I create a 8 GiB disk named "'+JOB_NAME+'"',
	'I plug ide drive "'+JOB_NAME+'"',
	'I accept that the machine is slooooow',
	'I start the computer',
	'I boot to the d-i splash screen',
      ],
    },

    'boot-d-i-to-tasksel' => {
      :description => "I have started Debian Installer and stopped at the Tasksel prompt",
      :parent_checkpoint => 'boot-d-i',
      :steps => [
	'I accept that the machine is slooooow',
	'I select text mode and wait for the remote shell',
	'in text mode I select British English',
	'in text mode I accept the hostname, using "example.com" as the domain',
	'in text mode I set the root password to "rootme"',
	'in text mode I set the password for "Philip Hands" to be "verysecret"',
	'in text mode I select full-disk, single-filesystem partitioning',
	'in text mode I note that the Base system is being installed',
	'in text mode I accept the default mirror',
	'in text mode I ignore Popcon',
	'in text mode we reach the Tasksel prompt',
      ],
    },

    'boot-g-i-to-tasksel' => {
      :description => "I have started GUI Debian Installer and stopped at the Tasksel prompt",
      :parent_checkpoint => 'boot-d-i',
      :steps => [
	'I create a 8 GiB disk named "'+JOB_NAME+'"',
	'I plug ide drive "'+JOB_NAME+'"',
	'I accept that the machine is slooooow',
	'I select gui mode and wait for the remote shell',
	'in gui mode I select British English',
	'in gui mode I accept the hostname, using "example.com" as the domain',
	'in gui mode I set the root password to "rootme"',
	'in gui mode I set the password for "Philip Hands" to be "verysecret"',
	'in gui mode I select full-disk, single-filesystem partitioning',
	'in gui mode I note that the Base system is being installed',
	'in gui mode I accept the default mirror',
	'in gui mode I ignore Popcon',
	'in gui mode we reach the Tasksel prompt',
      ],
    },

    'debian-console-install' => {
      :description => "I install a non-GUI Debian system, in text mode",
      :parent_checkpoint => 'boot-d-i-to-tasksel',
      :steps => [
	'I accept that the machine is slooooow',
	'in text mode I unset the Desktop task',
	'in text mode I wait while the bulk of the packages are installed',
	'in text mode I install GRUB',
	'in text mode I allow reboot after the install is complete',
	'I wait for the reboot',
	'I power off the computer',
	'the computer is set to boot from ide drive "'+JOB_NAME+'"',
      ],
    },

    'debian-gui-console-install' => {
      :description => "I install a non-GUI Debian system, in gui mode",
      :parent_checkpoint => 'boot-g-i-to-tasksel',
      :steps => [
	'I accept that the machine is slooooow',
	'in gui mode I unset the Desktop task',
	'in gui mode I wait while the bulk of the packages are installed',
	'in gui mode I install GRUB',
	'in gui mode I allow reboot after the install is complete',
	'I wait for the reboot',
	'I power off the computer',
	'the computer is set to boot from ide drive "'+JOB_NAME+'"',
      ],
    },

    'debian-minimal-install' => {
      :description => "I install a Minimal Debian system, in text mode",
      :parent_checkpoint => 'boot-d-i-to-tasksel',
      :steps => [
	'I accept that the machine is slooooow',
	'in text mode I unset the Desktop and Print tasks',
	'in text mode I wait while the bulk of the packages are installed',
	'in text mode I install GRUB',
	'in text mode I allow reboot after the install is complete',
	'I wait for the reboot',
	'I power off the computer',
	'the computer is set to boot from ide drive "'+JOB_NAME+'"',
      ],
    },

    'debian-gui-minimal-install' => {
      :description => "I install a Minimal Debian system, in gui mode",
      :parent_checkpoint => 'boot-g-i-to-tasksel',
      :steps => [
	'I accept that the machine is slooooow',
	'in gui mode I unset the Desktop and Print tasks',
	'in gui mode I wait while the bulk of the packages are installed',
	'in gui mode I install GRUB',
	'in gui mode I allow reboot after the install is complete',
	'I wait for the reboot',
	'I power off the computer',
	'the computer is set to boot from ide drive "'+JOB_NAME+'"',
      ],
    },

    'debian-gnome-install' => {
      :description => "I install a Gnome Desktop Debian system, in text mode",
      :parent_checkpoint => 'boot-d-i-to-tasksel',
      :steps => [
	'I accept that the machine is slooooow',
	'in text mode I select the Gnome Desktop task',
	'in text mode I wait while the bulk of the packages are installed',
	'in text mode I install GRUB',
	'in text mode I allow reboot after the install is complete',
	'I wait for the reboot',
	'I power off the computer',
	'the computer is set to boot from ide drive "'+JOB_NAME+'"',
      ],
    },

    'debian-gui-gnome-install' => {
      :description => "I install a Gnome Desktop Debian system, in gui mode",
      :parent_checkpoint => 'boot-g-i-to-tasksel',
      :steps => [
	'I accept that the machine is slooooow',
	'in gui mode I select the Gnome Desktop task',
	'in gui mode I wait while the bulk of the packages are installed',
	'in gui mode I install GRUB',
	'in gui mode I allow reboot after the install is complete',
	'I wait for the reboot',
	'I power off the computer',
	'the computer is set to boot from ide drive "'+JOB_NAME+'"',
      ],
    },

    'debian-xfce-install' => {
      :description => "I install a XFCE Desktop Debian system, in text mode",
      :parent_checkpoint => 'boot-d-i-to-tasksel',
      :steps => [
	'I accept that the machine is slooooow',
	'in text mode I select the XFCE Desktop task',
	'in text mode I wait while the bulk of the packages are installed',
	'in text mode I install GRUB',
	'in text mode I allow reboot after the install is complete',
	'I wait for the reboot',
	'I power off the computer',
	'the computer is set to boot from ide drive "'+JOB_NAME+'"',
      ],
    },

    'debian-gui-xfce-install' => {
      :description => "I install a XFCE Desktop Debian system, in gui mode",
      :parent_checkpoint => 'boot-g-i-to-tasksel',
      :steps => [
	'I accept that the machine is slooooow',
	'in gui mode I select the XFCE Desktop task',
	'in gui mode I wait while the bulk of the packages are installed',
	'in gui mode I install GRUB',
	'in gui mode I allow reboot after the install is complete',
	'I wait for the reboot',
	'I power off the computer',
	'the computer is set to boot from ide drive "'+JOB_NAME+'"',
      ],
    },
  }
end

def live_screenshot()
  debug_log("debug: publishing live screenshot.")
  screen_capture = @screen.capture
  p = screen_capture.getFilename
  if File.exist?(p)
    s = ENV['WORKSPACE']
    s_path = "#{s}/screenshot.png"
    FileUtils.mv(p, s_path)
    convert = IO.popen(['convert',
                      s_path, '-adaptive-resize', '128x96', "#{s}/screenshot-thumb.png",
                      :err => ['/dev/null', 'w'],
                     ])
  end
end

def reach_checkpoint(name)
  scenario_indent = " "*4
  step_indent = " "*6

  step "a computer"
  live_screenshot
  if VM.snapshot_exists?(name)
    $vm.restore_snapshot(name)
    post_snapshot_restore_hook
  else
    checkpoint = checkpoints[name]
    checkpoint_description = checkpoint[:description]
    parent_checkpoint = checkpoint[:parent_checkpoint]
    steps = checkpoint[:steps]
    if parent_checkpoint
      if VM.snapshot_exists?(parent_checkpoint)
        $vm.restore_snapshot(parent_checkpoint)
      else
        reach_checkpoint(parent_checkpoint)
      end
      post_snapshot_restore_hook
    end
    debug_log(scenario_indent + "Checkpoint: #{checkpoint_description}",
              :color => :white)
    step_action = "Given"
    if parent_checkpoint
      parent_description = checkpoints[parent_checkpoint][:description]
      debug_log(step_indent + "#{step_action} #{parent_description}",
                :color => :green)
      step_action = "And"
    end
    steps.each do |s|
      begin
        step(s)
      rescue Exception => e
        debug_log(scenario_indent +
                  "Step failed while creating checkpoint: #{s}",
                  :color => :red)
        live_screenshot
        raise e
      end
      live_screenshot
      debug_log(step_indent + "#{step_action} #{s}", :color => :green)
      step_action = "And"
    end
    $vm.save_snapshot(name)
  end
  live_screenshot
end

# For each checkpoint we generate a step to reach it.
checkpoints.each do |name, desc|
  step_regex = Regexp.new("^#{Regexp.escape(desc[:description])}$")
  Given step_regex do
    reach_checkpoint(name)
  end
end