cucumber-chef 2.1.0.rc.11 → 2.1.0.rc.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,187 +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-2013 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::Chef::Helpers::Container
23
-
24
- ################################################################################
25
-
26
- def load_containers
27
- logger.debug { "Reading '#{Cucumber::Chef.containers_bin}'." }
28
- @containers = ((Marshal.load(IO.read(Cucumber::Chef.containers_bin)) rescue Hash.new) || Hash.new)
29
-
30
- logger.info { "-" * 8 }
31
- @containers.each do |key, value|
32
- logger.info { "LOAD CONTAINER: #{key.inspect} => #{value.inspect}" }
33
- end
34
- end
35
-
36
- ################################################################################
37
-
38
- def save_containers
39
- logger.debug { "Writing '#{Cucumber::Chef.containers_bin}'." }
40
- logger.info { "-" * 8 }
41
- @containers.each do |key, value|
42
- logger.info { "SAVE CONTAINER: #{key.inspect} => #{value.inspect}" }
43
- end
44
-
45
- File.open(Cucumber::Chef.containers_bin, 'w') do |f|
46
- f.puts(Marshal.dump(@containers))
47
- end
48
- end
49
-
50
- ################################################################################
51
-
52
- def container_create(name, distro, release, arch)
53
- unless container_exists?(name)
54
- cache_rootfs = container_cache_root(name, distro, release, arch)
55
- if !File.exists?(cache_rootfs)
56
- logger.warn { "'#{name}' has triggered building the lxc file cache for '#{distro}'." }
57
- logger.warn { "This one time process per distro can take up to 10 minutes or longer depending on the test lab." }
58
- end
59
-
60
- command_run_local(container_create_command(name, distro, release, arch))
61
-
62
- commands = Array.new
63
-
64
- # install omnibus into the distro/release file cache if it's not already there
65
- omnibus_chef_client = File.join("/", "opt", "chef", "bin", "chef-client")
66
- omnibus_cache = File.join(cache_rootfs, omnibus_chef_client)
67
- logger.info { "looking for omnibus cache in #{omnibus_cache}" }
68
- if !File.exists?(omnibus_cache)
69
- case distro.downcase
70
- when "ubuntu" then
71
- commands << "chroot #{cache_rootfs} /bin/bash -c 'apt-get -y --force-yes install wget'"
72
- when "fedora" then
73
- commands << "yum --nogpgcheck --installroot=#{cache_rootfs} -y install wget openssh-server"
74
- end
75
- commands << "chroot #{cache_rootfs} /bin/bash -c 'locale-gen en_US'"
76
- commands << "chroot #{cache_rootfs} /bin/bash -c 'wget http://www.opscode.com/chef/install.sh'"
77
- commands << "chroot #{cache_rootfs} /bin/bash -c 'bash install.sh -v #{Cucumber::Chef::Config.chef[:version]}'"
78
- if distro.downcase == "fedora"
79
- commands << "chroot #{cache_rootfs} /bin/bash -c 'rpm -Uvh --nodeps /tmp/*rpm'"
80
- end
81
- commands << "lxc-destroy -n #{name}"
82
- commands << container_create_command(name, distro, release, arch)
83
- end
84
-
85
- commands << <<-EOH
86
- mkdir -vp #{File.join(container_root(name), Cucumber::Chef.lxc_user_home_dir, ".ssh")}
87
- chmod 0700 #{File.join(container_root(name), Cucumber::Chef.lxc_user_home_dir, ".ssh")}
88
- cat #{File.join(Cucumber::Chef.lab_user_home_dir, ".ssh", "id_rsa.pub")} | tee -a #{File.join(container_root(name), Cucumber::Chef.lxc_user_home_dir, ".ssh", "authorized_keys")}
89
-
90
- rm -vf #{File.join(container_root(name), "etc", "motd")}
91
- cp -v /etc/motd #{File.join(container_root(name), "etc", "motd")}
92
- echo ' You are now logged in to the "#{name}" container!\n' | tee -a #{File.join(container_root(name), "etc", "motd")}
93
- echo '127.0.0.1 #{name}.#{Cucumber::Chef::Config.test_lab[:tld]} #{name}' | tee -a #{File.join(container_root(name), "etc", "hosts")}
94
- echo '#{name}.test-lab' | tee #{File.join(container_root(name), "etc", "hostname")}
95
- EOH
96
-
97
- command_run_local(commands.join("\n"))
98
- end
99
- container_start(name)
100
- end
101
-
102
- def container_destroy(name)
103
- if container_exists?(name)
104
- chef_server_node_destroy(name)
105
- chef_server_client_destroy(name)
106
- container_stop(name)
107
- command_run_local("lxc-destroy -n #{name}")
108
- logger.info { "Destroyed container '#{name}'." }
109
- end
110
- end
111
-
112
- ################################################################################
113
-
114
- def container_start(name)
115
- status = command_run_local("lxc-info -n #{name}").output
116
- if status.include?("STOPPED")
117
- command_run_local("lxc-start -d -n #{name}")
118
- end
119
- end
120
-
121
- def container_stop(name)
122
- status = command_run_local("lxc-info -n #{name}").output
123
- if status.include?("RUNNING")
124
- command_run_local("lxc-stop -n #{name}")
125
- end
126
- end
127
-
128
- ################################################################################
129
-
130
- def container_running?(name)
131
- status = command_run_local("lxc-info -n #{name}").output
132
- status.include?("RUNNING")
133
- end
134
-
135
- ################################################################################
136
-
137
- def container_config_network(name)
138
- lxc_network_config = File.join("/etc/lxc", name)
139
- File.open(lxc_network_config, 'w') do |f|
140
- f.puts(Cucumber::Chef.generate_do_not_edit_warning("LXC Container Configuration"))
141
- f.puts("")
142
- f.puts("lxc.network.type = veth")
143
- f.puts("lxc.network.flags = up")
144
- f.puts("lxc.network.link = br0")
145
- f.puts("lxc.network.name = eth0")
146
- f.puts("lxc.network.hwaddr = #{@containers[name][:mac]}")
147
- f.puts("lxc.network.ipv4 = 0.0.0.0")
148
- end
149
- end
150
-
151
- ################################################################################
152
-
153
- def containers
154
- command_run_local("lxc-ls 2>&1").split("\n").uniq
155
- end
156
-
157
- def container_exists?(name)
158
- (File.directory?(container_root(name)) ? true : false)
159
- end
160
-
161
- def container_root(name)
162
- File.join("/", "var", "lib", "lxc", name, "rootfs")
163
- end
164
-
165
- def container_cache_root(name, distro, release, arch)
166
- case distro.downcase
167
- when "ubuntu" then
168
- cache_root = File.join("/", "var", "cache", "lxc", release, "rootfs-#{arch}")
169
- when "fedora" then
170
- cache_root = File.join("/", "var", "cache", "lxc", distro, arch, release, "rootfs")
171
- end
172
- end
173
-
174
- def container_create_command(name, distro, release, arch)
175
- case distro.downcase
176
- when "ubuntu" then
177
- "DEBIAN_FRONTEND=noninteractive lxc-create -n #{name} -f /etc/lxc/#{name} -t #{distro} -- --release #{release} --arch #{arch}"
178
- when "fedora" then
179
- "lxc-create -n #{name} -f /etc/lxc/#{name} -t #{distro} -- --release #{release}"
180
- end
181
- end
182
-
183
- ################################################################################
184
-
185
- end
186
-
187
- ################################################################################
@@ -1,35 +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-2013 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::Chef::Helpers::MiniTest
23
-
24
- def enable_minitest(name)
25
- @chef_client_attributes[:run_list].unshift("recipe[minitest-handler]")
26
- end
27
-
28
- def run_minitests(name)
29
- chef_run = chef_run_client(name, "-l info")
30
- test_result = chef_run.drop_while {|e| e !~ /^# Running tests/}.take_while {|e| e !~ /^[.*] INFO/}
31
- puts test_result
32
- test_result
33
- end
34
-
35
- end
@@ -1,115 +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-2013 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::Chef::Helpers::Server
23
-
24
- ################################################################################
25
-
26
- def server_init(name)
27
- @containers[name] ||= Hash.new
28
- @containers[name][:chef_client] = nil
29
- end
30
-
31
- ################################################################################
32
-
33
- def server_delete(name)
34
- @containers.delete(name)
35
- end
36
-
37
- ################################################################################
38
-
39
- def server_set_attributes(name, attributes={})
40
- @containers[name].merge!(attributes)
41
- end
42
-
43
- ################################################################################
44
-
45
- def server_create(name)
46
- server_init(name)
47
-
48
- # if this is a new or non-persistent container destroy it
49
- server_destroy(name) if !@containers[name][:persist]
50
-
51
- attributes = @containers[name]
52
- @containers[name] = {
53
- :ip => generate_ip,
54
- :mac => generate_mac,
55
- :persist => true,
56
- :distro => "ubuntu",
57
- :release => "lucid",
58
- :arch => detect_arch(attributes[:distro] || "ubuntu")
59
- }.merge(attributes)
60
-
61
- if server_running?(name)
62
- logger.info { "Container '#{name}' is already running." }
63
- else
64
- logger.info { "Please wait, creating container {#{name.inspect} => #{server_tag(name)}}." }
65
- bm = ::Benchmark.realtime do
66
- test_lab_config_dhcpd
67
- container_config_network(name)
68
- container_create(name, @containers[name][:distro], @containers[name][:release], @containers[name][:arch])
69
- end
70
- logger.info { "Container '#{name}' creation took %0.4f seconds." % bm }
71
-
72
- bm = ::Benchmark.realtime do
73
- ZTK::TCPSocketCheck.new(:host => @containers[name][:ip], :port => 22).wait
74
- end
75
- logger.info { "Container '#{name}' SSHD responded after %0.4f seconds." % bm }
76
- end
77
-
78
- save_containers
79
- end
80
-
81
- ################################################################################
82
-
83
- def server_destroy(name)
84
- container_destroy(name)
85
- test_lab_config_dhcpd
86
- end
87
-
88
- ################################################################################
89
-
90
- def server_running?(name)
91
- container_running?(name)
92
- end
93
-
94
- ################################################################################
95
-
96
- def server_tag(name)
97
- @containers[name].inspect.to_s
98
- end
99
-
100
- ################################################################################
101
-
102
- def detect_arch(distro)
103
- case distro.downcase
104
- when "ubuntu" then
105
- ((RUBY_PLATFORM =~ /x86_64/) ? "amd64" : "i386")
106
- when "fedora" then
107
- ((RUBY_PLATFORM =~ /x86_64/) ? "amd64" : "i686")
108
- end
109
- end
110
-
111
- ################################################################################
112
-
113
- end
114
-
115
- ################################################################################
@@ -1,52 +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-2013 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::Chef::Helpers::TestLab
23
-
24
- ################################################################################
25
-
26
- def test_lab_config_dhcpd
27
- dhcpd_config = File.join("/etc/dhcp/test-lab.conf")
28
- File.open(dhcpd_config, 'w') do |f|
29
- f.puts(Cucumber::Chef.generate_do_not_edit_warning("DHCPD Configuration"))
30
- @containers.each do |key, value|
31
- next if [:mac, :ip].any?{ |z| value[z].nil? }
32
-
33
- f.puts
34
- f.puts("host #{key} {")
35
- f.puts(" hardware ethernet #{value[:mac]};")
36
- f.puts(" fixed-address #{value[:ip]};")
37
- f.puts(" ddns-hostname \"#{key}\";")
38
- f.puts("}")
39
- end
40
- f.flush
41
- f.close
42
- end
43
-
44
- command_run_local("service isc-dhcp-server restart")
45
- command_run_local("service bind9 restart")
46
- end
47
-
48
- ################################################################################
49
-
50
- end
51
-
52
- ################################################################################
@@ -1,71 +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-2013 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::Chef::Helpers::Utility
23
-
24
- ################################################################################
25
-
26
- def logger
27
- Cucumber::Chef.logger
28
- end
29
-
30
- ################################################################################
31
-
32
- def generate_ip
33
- octets = [ 192..192,
34
- 168..168,
35
- 0..254,
36
- 1..254 ]
37
- ip = Array.new
38
- for x in 1..4 do
39
- ip << octets[x-1].to_a[rand(octets[x-1].count)].to_s
40
- end
41
- ip.join(".")
42
- end
43
-
44
- ################################################################################
45
-
46
- def generate_mac
47
- digits = [ %w(0),
48
- %w(0),
49
- %w(0),
50
- %w(0),
51
- %w(5),
52
- %w(e),
53
- %w(0 1 2 3 4 5 6 7 8 9 a b c d e f),
54
- %w(0 1 2 3 4 5 6 7 8 9 a b c d e f),
55
- %w(5 6 7 8 9 a b c d e f),
56
- %w(3 4 5 6 7 8 9 a b c d e f),
57
- %w(0 1 2 3 4 5 6 7 8 9 a b c d e f),
58
- %w(0 1 2 3 4 5 6 7 8 9 a b c d e f) ]
59
- mac = ""
60
- for x in 1..12 do
61
- mac += digits[x-1][rand(digits[x-1].count)]
62
- mac += ":" if (x.modulo(2) == 0) && (x != 12)
63
- end
64
- mac
65
- end
66
-
67
- ################################################################################
68
-
69
- end
70
-
71
- ################################################################################
@@ -1,50 +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-2013 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
- # This module includes all of the helper methods meant to drive step
26
- # definitions.
27
- module Helpers
28
-
29
- require 'cucumber/chef/helpers/chef_client'
30
- require 'cucumber/chef/helpers/chef_server'
31
- require 'cucumber/chef/helpers/command'
32
- require 'cucumber/chef/helpers/container'
33
- require 'cucumber/chef/helpers/server'
34
- require 'cucumber/chef/helpers/test_lab'
35
- require 'cucumber/chef/helpers/utility'
36
-
37
- def self.included(base)
38
- base.send(:include, ::Cucumber::Chef::Helpers::ChefClient)
39
- base.send(:include, ::Cucumber::Chef::Helpers::ChefServer)
40
- base.send(:include, ::Cucumber::Chef::Helpers::Command)
41
- base.send(:include, ::Cucumber::Chef::Helpers::Container)
42
- base.send(:include, ::Cucumber::Chef::Helpers::Server)
43
- base.send(:include, ::Cucumber::Chef::Helpers::TestLab)
44
- base.send(:include, ::Cucumber::Chef::Helpers::Utility)
45
- end
46
-
47
- end
48
-
49
- end
50
- end