cucumber-chef 2.0.4 → 2.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,90 +0,0 @@
1
- ################################################################################
2
- #
3
- # Author: Stephen Nelson-Smith <stephen@atalanta-systems.com>
4
- # Author: Zachary Patten <zachary@jovelabs.com>
5
- # Copyright: Copyright (c) 2011-2012 Atalanta Systems Ltd
6
- # License: Apache License, Version 2.0
7
- #
8
- # Licensed under the Apache License, Version 2.0 (the "License");
9
- # you may not use this file except in compliance with the License.
10
- # You may obtain a copy of the License at
11
- #
12
- # http://www.apache.org/licenses/LICENSE-2.0
13
- #
14
- # Unless required by applicable law or agreed to in writing, software
15
- # distributed under the License is distributed on an "AS IS" BASIS,
16
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
- # See the License for the specific language governing permissions and
18
- # limitations under the License.
19
- #
20
- ################################################################################
21
-
22
-
23
- module Cucumber
24
- module Chef
25
-
26
- class LoggerError < Error; end
27
-
28
- class Logger < ::Logger
29
-
30
- SEVERITIES = Severity.constants.inject([]) {|arr,c| arr[Severity.const_get(c)] = c; arr}
31
-
32
- ################################################################################
33
-
34
- def initialize(file=nil)
35
- if file.nil?
36
- config_path = File.join(Cucumber::Chef.locate_parent(".chef"), ".cucumber-chef")
37
- FileUtils.mkdir_p(config_path)
38
- file = File.join(config_path, "cucumber-chef.log")
39
- end
40
-
41
- #super(file, 7, (1024 * 1024))
42
- super(file)
43
- set_log_level
44
- end
45
-
46
- ################################################################################
47
-
48
- def parse_caller(at)
49
- if /^(.+?):(\d+)(?::in `(.*)')?/ =~ at
50
- file = Regexp.last_match[1]
51
- line = Regexp.last_match[2]
52
- method = Regexp.last_match[3]
53
- "#{File.basename(file)}:#{line}:#{method} | "
54
- else
55
- ""
56
- end
57
- end
58
-
59
- ################################################################################
60
-
61
- def add(severity, message = nil, progname = nil, &block)
62
- return if (@level > severity)
63
-
64
- called_by = parse_caller(caller[1])
65
-
66
- msg = (block && block.call)
67
- return if (msg.nil? || msg.strip.empty?)
68
- message = [message, progname, msg].delete_if{|i| i == nil}.join(": ")
69
- message = "%19s.%06d | %5s | %5s | %s%s\n" % [Time.now.utc.strftime("%Y-%m-%d %H:%M:%S"), Time.now.utc.usec, Process.pid.to_s, SEVERITIES[severity], called_by, message]
70
-
71
- @logdev.write(message)
72
-
73
- true
74
- end
75
-
76
- ################################################################################
77
-
78
- def set_log_level(level="INFO")
79
- log_level = (ENV['LOG_LEVEL'] || level)
80
- self.level = Cucumber::Chef::Logger.const_get(log_level.to_s.upcase)
81
- end
82
-
83
- ################################################################################
84
-
85
- end
86
-
87
- end
88
- end
89
-
90
- ################################################################################
@@ -1,190 +0,0 @@
1
- ################################################################################
2
- #
3
- # Author: Stephen Nelson-Smith <stephen@atalanta-systems.com>
4
- # Author: Zachary Patten <zachary@jovelabs.com>
5
- # Copyright: Copyright (c) 2011-2012 Atalanta Systems Ltd
6
- # License: Apache License, Version 2.0
7
- #
8
- # Licensed under the Apache License, Version 2.0 (the "License");
9
- # you may not use this file except in compliance with the License.
10
- # You may obtain a copy of the License at
11
- #
12
- # http://www.apache.org/licenses/LICENSE-2.0
13
- #
14
- # Unless required by applicable law or agreed to in writing, software
15
- # distributed under the License is distributed on an "AS IS" BASIS,
16
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
- # See the License for the specific language governing permissions and
18
- # limitations under the License.
19
- #
20
- ################################################################################
21
-
22
- module Cucumber
23
- module Chef
24
-
25
- class SSHError < Error; end
26
-
27
- class SSH
28
- attr_accessor :stdout, :stderr, :stdin, :config
29
-
30
- ################################################################################
31
-
32
- def initialize(stdout=STDOUT, stderr=STDERR, stdin=STDIN)
33
- @stdout, @stderr, @stdin = stdout, stderr, stdin
34
- @stdout.sync = true if @stdout.respond_to?(:sync=)
35
-
36
- @config = Hash.new(nil)
37
- end
38
-
39
- ################################################################################
40
-
41
- def console
42
- $logger.debug { "config(#{@config.inspect})" }
43
-
44
- command = [ "ssh" ]
45
- command << [ "-q" ]
46
- command << [ "-o", "UserKnownHostsFile=/dev/null" ]
47
- command << [ "-o", "StrictHostKeyChecking=no" ]
48
- command << [ "-o", "KeepAlive=yes" ]
49
- command << [ "-o", "ServerAliveInterval=60" ]
50
- command << [ "-i", @config[:identity_file] ] if @config[:identity_file]
51
- command << [ "-o", "ProxyCommand=\"#{proxy_command}\"" ] if @config[:proxy]
52
- command << "#{@config[:ssh_user]}@#{@config[:host]}"
53
- command = command.flatten.compact.join(" ")
54
- $logger.info { "command(#{command})" }
55
- Kernel.exec(command)
56
- end
57
-
58
- ################################################################################
59
-
60
- def exec(command, options={})
61
- @ssh ||= Net::SSH.start(@config[:host], @config[:ssh_user], ssh_options)
62
-
63
- options = { :silence => false }.merge(options)
64
- silence = options[:silence]
65
- output = ""
66
-
67
- $logger.debug { "config(#{@config.inspect})" }
68
- $logger.debug { "options(#{options.inspect})" }
69
- $logger.info { "command(#{command})" }
70
- channel = @ssh.open_channel do |chan|
71
- $logger.debug { "channel opened" }
72
- chan.exec(command) do |ch, success|
73
- raise SSHError, "Could not execute '#{command}'." unless success
74
-
75
- ch.on_data do |c, data|
76
- output += data
77
- $logger.debug { data.chomp.strip }
78
- @stdout.print(data) if !silence
79
- end
80
-
81
- ch.on_extended_data do |c, type, data|
82
- output += data
83
- $logger.debug { data.chomp.strip }
84
- @stderr.print(data) if !silence
85
- end
86
-
87
- end
88
- end
89
- channel.wait
90
- $logger.debug { "channel closed" }
91
-
92
- output
93
- end
94
-
95
- ################################################################################
96
-
97
- def upload(local, remote)
98
- @sftp ||= Net::SFTP.start(@config[:host], @config[:ssh_user], ssh_options)
99
-
100
- $logger.debug { "config(#{@config.inspect})" }
101
- $logger.info { "parameters(#{local},#{remote})" }
102
- @sftp.upload!(local.to_s, remote.to_s) do |event, uploader, *args|
103
- case event
104
- when :open
105
- $logger.info { "upload(#{args[0].local} -> #{args[0].remote})" }
106
- when :close
107
- $logger.debug { "close(#{args[0].remote})" }
108
- when :mkdir
109
- $logger.debug { "mkdir(#{args[0]})" }
110
- when :put
111
- $logger.debug { "put(#{args[0].remote}, size #{args[2].size} bytes, offset #{args[1]})" }
112
- when :finish
113
- $logger.info { "finish" }
114
- end
115
- end
116
- end
117
-
118
- ################################################################################
119
-
120
- def download(remote, local)
121
- @sftp ||= Net::SFTP.start(@config[:host], @config[:ssh_user], ssh_options)
122
-
123
- $logger.debug { "config(#{@config.inspect})" }
124
- $logger.info { "parameters(#{remote},#{local})" }
125
- @sftp.download!(remote.to_s, local.to_s) do |event, downloader, *args|
126
- case event
127
- when :open
128
- $logger.info { "download(#{args[0].remote} -> #{args[0].local})" }
129
- when :close
130
- $logger.debug { "close(#{args[0].local})" }
131
- when :mkdir
132
- $logger.debug { "mkdir(#{args[0]})" }
133
- when :get
134
- $logger.debug { "get(#{args[0].remote}, size #{args[2].size} bytes, offset #{args[1]})" }
135
- when :finish
136
- $logger.info { "finish" }
137
- end
138
- end
139
- end
140
-
141
-
142
- ################################################################################
143
- private
144
- ################################################################################
145
-
146
- def proxy_command
147
- $logger.debug { "config(#{@config.inspect})" }
148
-
149
- if !@config[:identity_file]
150
- message = "You must specify an identity file in order to SSH proxy."
151
- $logger.fatal { message }
152
- raise SSHError, message
153
- end
154
-
155
- command = ["ssh"]
156
- command << [ "-q" ]
157
- command << [ "-o", "UserKnownHostsFile=/dev/null" ]
158
- command << [ "-o", "StrictHostKeyChecking=no" ]
159
- command << [ "-o", "KeepAlive=yes" ]
160
- command << [ "-o", "ServerAliveInterval=60" ]
161
- command << [ "-i", @config[:proxy_identity_file] ] if @config[:proxy_identity_file]
162
- command << "#{@config[:proxy_ssh_user]}@#{@config[:proxy_host]}"
163
- command << "nc %h %p"
164
- command = command.flatten.compact.join(" ")
165
- $logger.debug { "command(#{command})" }
166
- command
167
- end
168
-
169
- ################################################################################
170
-
171
- def ssh_options
172
- $logger.debug { "config(#{@config.inspect})" }
173
- options = {}
174
- options.merge!(:password => @config[:ssh_password]) if @config[:ssh_password]
175
- options.merge!(:keys => @config[:identity_file]) if @config[:identity_file]
176
- options.merge!(:timeout => @config[:timeout]) if @config[:timeout]
177
- options.merge!(:user_known_hosts_file => '/dev/null') if !@config[:host_key_verify]
178
- options.merge!(:proxy => Net::SSH::Proxy::Command.new(proxy_command)) if @config[:proxy]
179
- $logger.debug { "options(#{options.inspect})" }
180
- options
181
- end
182
-
183
- ################################################################################
184
-
185
- end
186
-
187
- end
188
- end
189
-
190
- ################################################################################
@@ -1,83 +0,0 @@
1
- ################################################################################
2
- #
3
- # Author: Stephen Nelson-Smith <stephen@atalanta-systems.com>
4
- # Author: Zachary Patten <zachary@jovelabs.com>
5
- # Copyright: Copyright (c) 2011-2012 Atalanta Systems Ltd
6
- # License: Apache License, Version 2.0
7
- #
8
- # Licensed under the Apache License, Version 2.0 (the "License");
9
- # you may not use this file except in compliance with the License.
10
- # You may obtain a copy of the License at
11
- #
12
- # http://www.apache.org/licenses/LICENSE-2.0
13
- #
14
- # Unless required by applicable law or agreed to in writing, software
15
- # distributed under the License is distributed on an "AS IS" BASIS,
16
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
- # See the License for the specific language governing permissions and
18
- # limitations under the License.
19
- #
20
- ################################################################################
21
-
22
- module Cucumber
23
- module Chef
24
-
25
- class TCPSocketError < Error; end
26
-
27
- class TCPSocket
28
-
29
- ################################################################################
30
-
31
- def initialize(host, port, data=nil)
32
- @host, @port, @data = host, port, data
33
-
34
- if !host
35
- message = "You must supply a host!"
36
- $logger.fatal { message } if $logger
37
- raise TCPSocketError, message
38
- end
39
-
40
- if !port
41
- message = "You must supply a port!"
42
- $logger.fatal { message } if $logger
43
- raise TCPSocketError, message
44
- end
45
- end
46
-
47
- ################################################################################
48
-
49
- def ready?
50
- socket = ::TCPSocket.new(@host, @port)
51
-
52
- if @data.nil?
53
- $logger.debug { "read(#{@host}:#{@port})" } if $logger
54
- ((::IO.select([socket], nil, nil, 5) && socket.gets) ? true : false)
55
- else
56
- $logger.debug { "write(#{@host}:#{@port}, '#{@data}')" } if $logger
57
- ((::IO.select(nil, [socket], nil, 5) && socket.write(@data)) ? true : false)
58
- end
59
-
60
- rescue Errno::ETIMEDOUT, Errno::ECONNREFUSED, Errno::EHOSTUNREACH => e
61
- $logger.debug { "#{@host}:#{@port} - #{e.message}" } if $logger
62
- false
63
- ensure
64
- (socket && socket.close)
65
- end
66
-
67
- ################################################################################
68
-
69
- def wait
70
- begin
71
- success = ready?
72
- sleep(1)
73
- end until success
74
- end
75
-
76
- ################################################################################
77
-
78
- end
79
-
80
- end
81
- end
82
-
83
- ################################################################################
@@ -1,57 +0,0 @@
1
- ################################################################################
2
- #
3
- # Author: Stephen Nelson-Smith <stephen@atalanta-systems.com>
4
- # Author: Zachary Patten <zachary@jovelabs.com>
5
- # Copyright: Copyright (c) 2011-2012 Atalanta Systems Ltd
6
- # License: Apache License, Version 2.0
7
- #
8
- # Licensed under the Apache License, Version 2.0 (the "License");
9
- # you may not use this file except in compliance with the License.
10
- # You may obtain a copy of the License at
11
- #
12
- # http://www.apache.org/licenses/LICENSE-2.0
13
- #
14
- # Unless required by applicable law or agreed to in writing, software
15
- # distributed under the License is distributed on an "AS IS" BASIS,
16
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
- # See the License for the specific language governing permissions and
18
- # limitations under the License.
19
- #
20
- ################################################################################
21
-
22
- module Cucumber
23
- module Chef
24
-
25
- class TemplateError < Error; end
26
-
27
- class Template
28
-
29
- ################################################################################
30
-
31
- def self.render(template, context=nil)
32
- self.render_template(self.load_template(template), context)
33
- end
34
-
35
-
36
- ################################################################################
37
- private
38
- ################################################################################
39
-
40
- def self.load_template(template)
41
- IO.read(template).chomp
42
- end
43
-
44
- ################################################################################
45
-
46
- def self.render_template(template, context)
47
- Erubis::Eruby.new(template).evaluate(:config => context)
48
- end
49
-
50
- ################################################################################
51
-
52
- end
53
-
54
- end
55
- end
56
-
57
- ################################################################################
@@ -1,103 +0,0 @@
1
- ################################################################################
2
- #
3
- # Author: Stephen Nelson-Smith <stephen@atalanta-systems.com>
4
- # Author: Zachary Patten <zachary@jovelabs.com>
5
- # Copyright: Copyright (c) 2011-2012 Atalanta Systems Ltd
6
- # License: Apache License, Version 2.0
7
- #
8
- # Licensed under the Apache License, Version 2.0 (the "License");
9
- # you may not use this file except in compliance with the License.
10
- # You may obtain a copy of the License at
11
- #
12
- # http://www.apache.org/licenses/LICENSE-2.0
13
- #
14
- # Unless required by applicable law or agreed to in writing, software
15
- # distributed under the License is distributed on an "AS IS" BASIS,
16
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
- # See the License for the specific language governing permissions and
18
- # limitations under the License.
19
- #
20
- ################################################################################
21
-
22
- module Cucumber
23
- module Chef
24
-
25
- class TestRunnerError < Error; end
26
-
27
- class TestRunner
28
-
29
- ################################################################################
30
-
31
- def initialize(features_path, stdout=STDOUT, stderr=STDERR, stdin=STDIN)
32
- @features_path = features_path
33
- @stdout, @stderr, @stdin = stdout, stderr, stdin
34
- @stdout.sync = true if @stdout.respond_to?(:sync=)
35
-
36
- @test_lab = Cucumber::Chef::TestLab.new(@stdout, @stderr, @stdin)
37
-
38
- @ssh = Cucumber::Chef::SSH.new(@stdout, @stderr, @stdin)
39
- @ssh.config[:host] = @test_lab.labs_running.first.public_ip_address
40
- @ssh.config[:ssh_user] = "ubuntu"
41
- @ssh.config[:identity_file] = Cucumber::Chef.locate(:file, ".cucumber-chef", "id_rsa-#{@ssh.config[:ssh_user]}")
42
-
43
- @stdout.puts("Cucumber-Chef Test Runner Initalized!")
44
- end
45
-
46
- ################################################################################
47
-
48
- def run(destroy, *args)
49
- reset_project
50
- upload_project
51
-
52
- @stdout.puts("Executing Cucumber-Chef Test Runner")
53
- remote_path = File.join("/", "home", "ubuntu", "features")
54
- cucumber_options = args.flatten.compact.join(" ")
55
- env = ( destroy ? "DESTROY=1" : nil )
56
- command = [ "cd #{remote_path}", "&&", "sudo", env, "cucumber", cucumber_options, "--exclude support/cookbooks", "--exclude support/roles", "--exclude support/data_bags", "--exclude support/keys", "." ].flatten.compact.join(" ")
57
-
58
- @ssh.exec(command)
59
- end
60
-
61
-
62
- ################################################################################
63
- private
64
- ################################################################################
65
-
66
- def reset_project
67
- @stdout.print("Cleaning up any previous test runs...")
68
- Cucumber::Chef.spinner do
69
- remote_path = File.join("/", "home", "ubuntu", "features")
70
-
71
- command = "rm -rf #{remote_path}"
72
- @ssh.exec(command, :silence => true)
73
- end
74
- @stdout.print("done.\n")
75
- end
76
-
77
- ################################################################################
78
-
79
- def upload_project
80
- @stdout.print("Uploading files required for this test run...")
81
- Cucumber::Chef.spinner do
82
- local_path = File.join(@features_path)
83
- remote_path = File.join("/", "home", "ubuntu", "features")
84
- @ssh.upload(local_path, remote_path)
85
-
86
- root_path = Cucumber::Chef.locate_parent(".chef")
87
- cucumber_config_file = File.expand_path(File.join(root_path, "cucumber.yml"))
88
- if File.exists?(cucumber_config_file)
89
- remote_file = File.join(remote_path, File.basename(cucumber_config_file))
90
- @ssh.upload(cucumber_config_file, remote_file)
91
- end
92
- end
93
- @stdout.print("done.\n")
94
- end
95
-
96
- ################################################################################
97
-
98
- end
99
-
100
- end
101
- end
102
-
103
- ################################################################################