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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
# File 'lib/kitchen/verifier/nox.rb', line 30
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
noxenv = instance.suite.name
if config[:pytest]
noxenv = "pytest"
tests = config[:tests].join(' ')
else
noxenv = "runtests"
tests = config[:tests].collect{|test| "-n #{test}"}.join(' ')
end
noxenv = "#{noxenv}-#{config[:transport] ? config[:transport] : 'zeromq'}"
if ENV['NOX_SESSION']
noxenv = "#{noxenv}-#{ENV['NOX_SESSION']}"
end
suite = instance.suite.name.gsub('py', '').gsub('2', '2.7')
noxenv = "#{noxenv}-#{suite}(coverage=#{config[:coverage] ? 'True' : 'False'})"
if config[:enable_filenames] and ENV['CHANGE_TARGET'] and ENV['BRANCH_NAME']
require 'git'
repo = Git.open(Dir.pwd)
config[:from_filenames] = repo.diff("origin/#{ENV['CHANGE_TARGET']}",
"origin/#{ENV['BRANCH_NAME']}").name_status.keys.select{|file| file.end_with?('.py')}
end
if config[:junitxml]
junitxml = File.join(root_path, config[:testingdir], 'artifacts', 'xml-unittests-output')
if config[:pytest]
junitxml = "--junitxml=#{File.join(junitxml, 'test-results.xml')}"
else
junitxml = "--xml=#{junitxml}"
end
end
save = {
"#{File.join(root_path, config[:testingdir], 'artifacts')}" => "#{Dir.pwd}/"
}
save.merge!(config[:save])
command = [
'nox',
"-f #{File.join(root_path, config[:testingdir], 'noxfile.py')}",
(config[:windows] ? "-e #{noxenv}" : "-e '#{noxenv}'"),
'--',
"--output-columns=#{config[:output_columns]}",
(config[:sysinfo] ? '--sysinfo' : ''),
(config[:junitxml] ? junitxml : ''),
(config[:windows] ? "--names-file=#{root_path}\\testing\\tests\\whitelist.txt" : ''),
(config[:verbose] ? '-vv' : '-v'),
(config[:run_destructive] ? "--run-destructive" : ''),
(config[:ssh_tests] ? "--ssh-tests" : ''),
(config[:proxy_tests] ? "--proxy-tests" : ''),
config[:passthrough_opts].join(' '),
(config[:from_filenames].any? ? "--from-filenames=#{config[:from_filenames].join(',')}" : ''),
tests,
].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
begin
conn.execute(sudo("chown -R $USER #{root_path}"))
rescue => e
error("Failed to chown #{root_path} :: #{e}")
end
end
begin
conn.execute(sudo(command))
rescue => e
info("Verify command failed :: #{e}")
end
ensure
save.each do |remote, local|
unless config[:windows]
begin
conn.execute(sudo("chmod -R +r #{remote}"))
rescue => e
error("Failed to chown #{remote} :: #{e}")
end
end
begin
info("Copying #{remote} to #{local}")
conn.download(remote, local)
rescue => e
error("Failed to copy #{remote} to #{local} :: #{e}")
end
end
end
end
debug("[#{name}] Verify completed.")
end
|