summaryrefslogtreecommitdiffstats
path: root/features/step_definitions/apt.rb
blob: a54920540a486b5b5d5d2007c27a0007ca698050 (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
require 'uri'

Given /^the only hosts in APT sources are "([^"]*)"$/ do |hosts_str|
  next if @skip_steps_while_restoring_background
  hosts = hosts_str.split(',')
  @vm.file_content("/etc/apt/sources.list /etc/apt/sources.list.d/*").chomp.each_line { |line|
    next if ! line.start_with? "deb"
    source_host = URI(line.split[1]).host
    if !hosts.include?(source_host)
      raise "Bad APT source '#{line}'"
    end
  }
end

When /^I update APT using apt-get$/ do
  next if @skip_steps_while_restoring_background
  Timeout::timeout(30*60) do
    cmd = @vm.execute("echo #{@sudo_password} | " +
                      "sudo -S apt-get update", $live_user)
    if !cmd.success?
      STDERR.puts cmd.stderr
    end
  end
end

Then /^I should be able to install a package using apt-get$/ do
  next if @skip_steps_while_restoring_background
  package = "cowsay"
  Timeout::timeout(120) do
    cmd = @vm.execute("echo #{@sudo_password} | " +
                      "sudo -S apt-get install #{package}", $live_user)
    if !cmd.success?
      STDERR.puts cmd.stderr
    end
  end
  step "package \"#{package}\" is installed"
end

When /^I update APT using Synaptic$/ do
  next if @skip_steps_while_restoring_background
  # Upon start the interface will be frozen while Synaptic loads the
  # package list. Since the frozen GUI is so similar to the unfrozen
  # one there's no easy way to reliably wait for the latter. Hence we
  # spam reload until it's performed, which is easier to detect.
  try_for(60, :msg => "Failed to reload the package list in Synaptic") {
    @screen.type("r", Sikuli::KeyModifier.CTRL)
    @screen.find('SynapticReloadPrompt.png')
  }
  @screen.waitVanish('SynapticReloadPrompt.png', 30*60)
end

Then /^I should be able to install a package using Synaptic$/ do
  next if @skip_steps_while_restoring_background
  package = "cowsay"
  # We do this after a Reload, so the interface will be frozen until
  # the package list has been loaded
  try_for(60, :msg => "Failed to open the Synaptic 'Find' window") {
    @screen.type("f", Sikuli::KeyModifier.CTRL)  # Find key
    @screen.find('SynapticSearch.png')
  }
  @screen.type(package + Sikuli::Key.ENTER)
  @screen.wait_and_click('SynapticCowsaySearchResult.png', 20)
  sleep 5
  @screen.type("i", Sikuli::KeyModifier.CTRL)    # Mark for installation
  sleep 5
  @screen.type("p", Sikuli::KeyModifier.CTRL)    # Apply
  @screen.wait('SynapticApplyPrompt.png', 60)
  @screen.type("a", Sikuli::KeyModifier.ALT)     # Verify apply
  @screen.wait('SynapticChangesAppliedPrompt.png', 120)
  step "package \"#{package}\" is installed"
end

When /^I start Synaptic$/ do
  next if @skip_steps_while_restoring_background
  @screen.wait_and_click("GnomeApplicationsMenu.png", 10)
  @screen.wait_and_click("GnomeApplicationsSystem.png", 10)
  @screen.wait_and_click("GnomeApplicationsAdministration.png", 10)
  @screen.wait_and_click("GnomeApplicationsSynaptic.png", 20)
  deal_with_polkit_prompt('SynapticPolicyKitAuthPrompt.png', @sudo_password)
end