Module: PDQTest::Instance

Defined in:
lib/pdqtest/instance.rb

Constant Summary collapse

TEST_DIR =
'/testcase'
@@keep_container =
false
@@active_container =
nil
@@image_name =
false

Class Method Summary collapse

Class Method Details

.get_active_containerObject



13
14
15
# File 'lib/pdqtest/instance.rb', line 13

def self.get_active_container
  @@active_container
end

.get_keep_containerObject



17
18
19
# File 'lib/pdqtest/instance.rb', line 17

def self.get_keep_container
  @@keep_container
end

.run(example = nil) ⇒ Object



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
# File 'lib/pdqtest/instance.rb', line 34

def self.run(example=nil)
  # needed to prevent timeouts from container.exec()
  Excon.defaults[:write_timeout] = 10000
  Excon.defaults[:read_timeout] = 10000
  status = true

  # remove reference to any previous test container
  @@active_container = nil

  if PDQTest::Puppet::find_examples().empty?
    Escort::Logger.output.puts "No acceptance tests found, annotate examples with #{PDQTest::Puppet::MAGIC_MARKER} to make some"
  else
    # process each supported OS
    test_platforms = @@image_name || Docker::acceptance_test_images
    Escort::Logger.output.puts "Acceptance test on #{test_platforms}..."
    test_platforms.each { |image_name|
      Escort::Logger.output.puts "--- start test with #{image_name} ---"
      @@active_container = PDQTest::Docker::new_container(TEST_DIR, image_name)
      Escort::Logger.output.puts "alive, running tests"
      status &= PDQTest::Puppet.run(@@active_container, example)

      if @@keep_container
        Escort::Logger.output.puts "finished build, container #{@@active_container.id} left on system"
        Escort::Logger.output.puts "  docker exec -ti #{@@active_container.id} bash "
      else
        PDQTest::Docker.cleanup_container(@@active_container)
        @@active_container = nil
      end

      Escort::Logger.output.puts "--- end test with #{image_name} (status: #{status})---"
    }
  end
  Escort::Logger.output.puts "overall acceptance test status=#{status}"
  status
end

.set_docker_image(image_name) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/pdqtest/instance.rb', line 25

def self.set_docker_image(image_name)
  @@image_name =
      if image_name
        Array(image_name.split(/,/))
      else
        false
      end
end

.set_keep_container(keep_container) ⇒ Object



21
22
23
# File 'lib/pdqtest/instance.rb', line 21

def self.set_keep_container(keep_container)
  @@keep_container = keep_container
end

.shellObject



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
# File 'lib/pdqtest/instance.rb', line 70

def self.shell
  # pick the first test platform to test on as our shell - want to do a specific one
  # just list it with --image-name
  image_name = (@@image_name || Docker::acceptance_test_images).first
  Escort::Logger.output.puts "Opening a shell in #{image_name}"
  @@active_container = PDQTest::Docker::new_container(TEST_DIR, image_name)

  # In theory I should be able to get something like the code below to
  # redirect all input streams and give a makeshift interactive shell, howeve
  # I'm damned if I get get this to do anything at all, so instead go the
  # easy way and start the container running, then use system() to redirect
  # all streams using the regular docker command.  Works a treat!
  # @@active_container.tap(&:start).attach(:tty => true)
  # @@active_container.exec('bash', tty: true).tap(&:start).attach( :tty => true, :stdin => $stdin) { |out, err|
  #   puts out
  #   puts err
  # }
  system("docker exec -ti #{@@active_container.id} bash")
  if @@keep_container
    Escort::Logger.output.puts "finished build, container #{@@active_container.id} left on system"
    Escort::Logger.output.puts "  docker exec -ti #{@@active_container.id} bash "
  else
      PDQTest::Docker.cleanup_container(@@active_container)
      @@active_container = nil
  end
end