Module: PDQTest::Instance
- Defined in:
- lib/pdqtest/instance.rb
Constant Summary collapse
- @@keep_container =
false
- @@active_container =
nil
- @@image_name =
false
- @@privileged =
false
- @@inplace =
false
Class Method Summary collapse
- .get_acceptance_test_images ⇒ Object
- .get_active_container ⇒ Object
- .get_inplace ⇒ Object
- .get_keep_container ⇒ Object
- .get_privileged ⇒ Object
- .run(example = nil) ⇒ Object
- .set_docker_image(image_name) ⇒ Object
- .set_inplace(inplace) ⇒ Object
- .set_keep_container(keep_container) ⇒ Object
- .set_privileged(privileged) ⇒ Object
- .shell ⇒ Object
Class Method Details
.get_acceptance_test_images ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/pdqtest/instance.rb', line 53 def self.get_acceptance_test_images test_platforms = @@image_name || PDQTest::Docker.acceptance_test_images filtered_test_platforms = test_platforms.reject do |image_name| reject = false if Util.is_windows if image_name !~ /windows/ $logger.info "Skipping test image #{image_name} (requires Linux)" reject = true end else if image_name =~ /windows/ $logger.info "Skipping test image #{image_name} (requires Windows)" reject = true end end reject end filtered_test_platforms end |
.get_active_container ⇒ Object
15 16 17 |
# File 'lib/pdqtest/instance.rb', line 15 def self.get_active_container @@active_container end |
.get_inplace ⇒ Object
48 49 50 |
# File 'lib/pdqtest/instance.rb', line 48 def self.get_inplace() @@inplace end |
.get_keep_container ⇒ Object
19 20 21 |
# File 'lib/pdqtest/instance.rb', line 19 def self.get_keep_container @@keep_container end |
.get_privileged ⇒ Object
40 41 42 |
# File 'lib/pdqtest/instance.rb', line 40 def self.get_privileged @@privileged end |
.run(example = nil) ⇒ Object
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 |
# File 'lib/pdqtest/instance.rb', line 75 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? $logger.info "No acceptance tests found, annotate examples with #{PDQTest::Puppet.setting(:magic_marker)} to make some" else # process each supported OS and figure out what controller container to use if @@inplace test_platforms = [PDQTest::Inplace::INPLACE_IMAGE] cc = PDQTest::Inplace else test_platforms = get_acceptance_test_images.uniq cc = PDQTest::Docker end test_platforms.each { |image_name| $logger.info "--- start test with #{image_name} ---" @@active_container = cc.new_container(image_name, @@privileged) $logger.info "alive, running tests" status &= PDQTest::Puppet.run(cc, @@active_container, example) if @@keep_container && ! @@inplace $logger.info "finished build, container #{@@active_container.id} left on system" $logger.info " docker exec -ti #{@@active_container.id} #{Util.shell} " else cc.cleanup_container(@@active_container) @@active_container = nil end $logger.info "--- end test with #{image_name} (status: #{status})---" } end $logger.info "overall acceptance test status=#{status}" status end |
.set_docker_image(image_name) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/pdqtest/instance.rb', line 27 def self.set_docker_image(image_name) @@image_name = if image_name Array(image_name.split(/,/)) else false end end |
.set_inplace(inplace) ⇒ Object
44 45 46 |
# File 'lib/pdqtest/instance.rb', line 44 def self.set_inplace(inplace) @@inplace = inplace end |
.set_keep_container(keep_container) ⇒ Object
23 24 25 |
# File 'lib/pdqtest/instance.rb', line 23 def self.set_keep_container(keep_container) @@keep_container = keep_container end |
.set_privileged(privileged) ⇒ Object
36 37 38 |
# File 'lib/pdqtest/instance.rb', line 36 def self.set_privileged(privileged) @@privileged = privileged end |
.shell ⇒ Object
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 |
# File 'lib/pdqtest/instance.rb', line 117 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 $logger.info "Opening a shell in #{image_name}" @@active_container = PDQTest::Docker::new_container(image_name, @@privileged) # Shell is always executed with docker - if you want a new shell for # in-place, your already in it ;-) PDQTest::Execution.exec(PDQTest::Docker, @@active_container, PDQTest::Puppet.setup) # 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} #{Util.shell}") if @@keep_container $logger.info "finished build, container #{@@active_container.id} left on system" $logger.info " docker exec -ti #{@@active_container.id} #{Util.shell} " else PDQTest::Docker.cleanup_container(@@active_container) @@active_container = nil end end |