Module: PDQTest::Inplace

Defined in:
lib/pdqtest/inplace.rb

Constant Summary collapse

INPLACE_IMAGE =
"__INPLACE__"
@@enable =
false

Class Method Summary collapse

Class Method Details

._exec_real(container, real_c) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/pdqtest/inplace.rb', line 21

def self._exec_real(container, real_c)
  res = {}
  res[:OUT]    = []
  res[:ERR]    = []
  res[:STATUS] = 0
  $logger.debug("exec_real: running inplace command: #{real_c}")
  if @@enable
    # OMG ruby... https://dmerej.info/blog/post/why-i-dont-like-ruby/
    stdout, stderr, status = Open3.capture3(
      Util.clean_env, *real_c, unsetenv_others: true
    )

    res[:STATUS] = status.exitstatus
    res[:OUT] = stdout.split("\n")
    res[:ERR] = stderr.split("\n")
  else
    $logger.info "didn't run command, reason: DISABLED"
  end
  $logger.debug("...result: #{res[:STATUS]}")

  res
end

.cleanup_container(container) ⇒ Object



54
55
56
# File 'lib/pdqtest/inplace.rb', line 54

def self.cleanup_container(container)
  FileUtils.rm_rf Docker.test_dir
end

.idObject



44
45
46
# File 'lib/pdqtest/inplace.rb', line 44

def self.id
  INPLACE_IMAGE
end

.new_container(image_name, privileged) ⇒ Object



48
49
50
51
52
# File 'lib/pdqtest/inplace.rb', line 48

def self.new_container(image_name, privileged)
  FileUtils.rm_rf Docker.test_dir if Dir.exist? Docker.test_dir

  FileUtils.cp_r(File.join(Dir.pwd, "."), Docker.test_dir)
end

.set_enable(enable) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/pdqtest/inplace.rb', line 8

def self.set_enable(enable)
  if enable
    $logger.warn <<~END
      PDQTest run with --inplace --inplace-enable will run Puppet on 
      *this* computer! 
  
      You have 5 seconds to abort, press ctrl+c now
    END
    sleep(5)
  end
  @@enable = enable
end