Class: Kitchen::Verifier::Salttox

Inherits:
Base
  • Object
show all
Defined in:
lib/kitchen/verifier/salttox.rb

Instance Method Summary collapse

Instance Method Details

#call(state) ⇒ Object



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
# File 'lib/kitchen/verifier/salttox.rb', line 23

def call(state)
  info("[#{name}] Verify on instance #{instance.name} with state=#{state}")
  root_path = (config[:windows] ? '%TEMP%\\kitchen' : '/tmp/kitchen')
  if ENV['KITCHEN_TESTS']
    ENV['KITCHEN_TESTS'].split(' ').each{|test| config[:tests].push(test)}
  end
  command = [
    'tox -c',
    File.join(root_path, config[:testingdir], 'tox.ini'),
    "-e #{instance.suite.name}",
    '--',
    '--sysinfo',
    '--output-columns=80',
    (config[:windows] ? "--names-file=#{root_path}\\testing\\tests\\whitelist.txt" : ''),
    (config[:transport] ? "--transport=#{config[:transport]}" : ''),
    (config[:verbose] ? '-v' : ''),
    (config[:run_destructive] ? "--run-destructive" : ''),
    (config[:coverage_xml] ? "--cov=salt/ --cov-report xml:#{config[:coverage_xml]}" : ''),
    (config[:xml] ? "--junitxml=#{config[:xml]}" : ''),
    config[:types].collect{|type| "--#{type}"}.join(' '),
    config[:tests].join(' '),
    '2>&1',
  ].join(' ')
  if config[:windows]
     command = "cmd.exe /c \"#{command}\" 2>&1"
  end
  info("Running Command: #{command}")
  instance.transport.connection(state) do |conn|
    begin
      if config[:windows]
        conn.execute('$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")')
        conn.execute("$env:PythonPath = [Environment]::ExpandEnvironmentVariables(\"#{root_path}\\testing\")")
      else
        conn.execute(sudo("chown -R $USER #{root_path}"))
      end
      conn.execute(sudo(command))
    ensure
      config[:save].each do |remote, local|
        unless config[:windows]
          conn.execute(sudo("chmod -R +r #{remote}"))
        end
        info("Copying #{remote} to #{local}")
        conn.download(remote, local)
      end
    end
  end
  debug("[#{name}] Verify completed.")
end