cucumber-chef 1.0.3 → 2.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. data/.gitignore +8 -35
  2. data/.rspec +1 -0
  3. data/.rvmrc.template +2 -0
  4. data/.travis.yml +22 -0
  5. data/Gemfile +2 -15
  6. data/LICENSE +202 -201
  7. data/NOTICE +9 -0
  8. data/README.md +696 -92
  9. data/Rakefile +39 -25
  10. data/TODO.md +28 -0
  11. data/bin/cc-knife +32 -0
  12. data/bin/cucumber-chef +409 -79
  13. data/chef_repo/cookbooks/cucumber-chef/LICENSE +202 -0
  14. data/chef_repo/cookbooks/cucumber-chef/README.md +69 -0
  15. data/chef_repo/cookbooks/cucumber-chef/attributes/default.rb +27 -0
  16. data/chef_repo/cookbooks/cucumber-chef/metadata.rb +13 -0
  17. data/chef_repo/cookbooks/cucumber-chef/recipes/default.rb +23 -0
  18. data/chef_repo/cookbooks/cucumber-chef/recipes/lxc.rb +315 -0
  19. data/chef_repo/cookbooks/cucumber-chef/recipes/test_lab.rb +146 -0
  20. data/chef_repo/cookbooks/cucumber-chef/templates/default/db-168-192.erb +15 -0
  21. data/chef_repo/cookbooks/cucumber-chef/templates/default/db-test-lab.erb +15 -0
  22. data/chef_repo/cookbooks/cucumber-chef/templates/default/dhcpd-conf.erb +44 -0
  23. data/chef_repo/cookbooks/cucumber-chef/templates/default/gemrc.erb +10 -0
  24. data/{cookbooks/cucumber-chef/files/default/cucumber-net → chef_repo/cookbooks/cucumber-chef/templates/default/lxc-initializer-config.erb} +1 -1
  25. data/chef_repo/cookbooks/cucumber-chef/templates/default/lxc-install-chef.erb +3 -0
  26. data/chef_repo/cookbooks/cucumber-chef/templates/default/motd.erb +10 -0
  27. data/chef_repo/cookbooks/cucumber-chef/templates/default/named-conf-local.erb +25 -0
  28. data/{cookbooks/cucumber-chef/files/default/permissive-ssh-config → chef_repo/cookbooks/cucumber-chef/templates/default/ssh-config.erb} +3 -1
  29. data/chef_repo/roles/test_lab.rb +24 -0
  30. data/cucumber-chef.gemspec +50 -123
  31. data/examples/README.md +7 -0
  32. data/examples/users_add.feature +51 -0
  33. data/examples/users_auto_remove.feature +50 -0
  34. data/features/support/env.rb +3 -2
  35. data/lib/cucumber/chef/bootstrap.rb +94 -0
  36. data/lib/cucumber/chef/command.rb +78 -0
  37. data/lib/cucumber/chef/config.rb +143 -93
  38. data/lib/cucumber/chef/helpers/chef_client.rb +87 -0
  39. data/lib/cucumber/chef/helpers/chef_server.rb +90 -0
  40. data/lib/cucumber/chef/helpers/command.rb +57 -0
  41. data/lib/cucumber/chef/helpers/container.rb +154 -0
  42. data/lib/cucumber/chef/helpers/minitest.rb +35 -0
  43. data/lib/cucumber/chef/helpers/server.rb +81 -0
  44. data/lib/cucumber/chef/helpers/test_lab.rb +46 -0
  45. data/lib/cucumber/chef/helpers/utility.rb +73 -0
  46. data/lib/cucumber/chef/helpers.rb +56 -0
  47. data/lib/cucumber/chef/logger.rb +90 -0
  48. data/lib/cucumber/chef/provisioner.rb +275 -69
  49. data/lib/cucumber/chef/ssh.rb +190 -0
  50. data/lib/cucumber/chef/steps/chef_steps.rb +32 -0
  51. data/lib/cucumber/chef/steps/minitest_steps.rb +29 -0
  52. data/lib/cucumber/chef/steps/provision_steps.rb +60 -0
  53. data/lib/cucumber/chef/steps/ssh_steps.rb +95 -0
  54. data/lib/cucumber/chef/steps.rb +27 -0
  55. data/lib/cucumber/chef/tcp_socket.rb +83 -0
  56. data/lib/cucumber/chef/template.rb +57 -0
  57. data/lib/cucumber/chef/templates/bootstrap/ubuntu-precise-test-lab.erb +99 -0
  58. data/lib/cucumber/chef/templates/cucumber/env.rb +56 -0
  59. data/lib/cucumber/chef/templates/cucumber/example_feature.erb +49 -0
  60. data/lib/cucumber/chef/templates/cucumber/example_steps.erb +11 -0
  61. data/lib/cucumber/chef/templates/cucumber/readme-data_bags.erb +1 -0
  62. data/lib/cucumber/chef/templates/cucumber/readme-keys.erb +1 -0
  63. data/lib/cucumber/chef/templates/cucumber/readme-roles.erb +1 -0
  64. data/lib/cucumber/chef/templates/cucumber/readme.erb +18 -0
  65. data/lib/cucumber/chef/templates/cucumber-chef/config-rb.erb +33 -0
  66. data/lib/cucumber/chef/templates/cucumber-chef/cucumber-yml.erb +2 -0
  67. data/lib/cucumber/chef/templates/cucumber-chef/knife-rb.erb +18 -0
  68. data/lib/cucumber/chef/test_lab.rb +308 -52
  69. data/lib/cucumber/chef/test_runner.rb +86 -15
  70. data/lib/cucumber/chef/utility.rb +128 -0
  71. data/lib/cucumber/chef/version.rb +30 -1
  72. data/lib/cucumber/chef.rb +53 -20
  73. data/lib/cucumber-chef.rb +24 -1
  74. data/spec/cucumber/chef/config_spec.rb +144 -78
  75. data/spec/cucumber/chef/provisioner_spec.rb +60 -16
  76. data/spec/cucumber/chef/test_lab_spec.rb +62 -19
  77. data/spec/spec_helper.rb +30 -26
  78. data/todo.org +17 -0
  79. metadata +267 -163
  80. data/.document +0 -5
  81. data/VERSION +0 -1
  82. data/cookbooks/cucumber-chef/README.rdoc +0 -8
  83. data/cookbooks/cucumber-chef/files/default/add-git-identity +0 -2
  84. data/cookbooks/cucumber-chef/files/default/controller-first-boot +0 -1
  85. data/cookbooks/cucumber-chef/files/default/cucumber-private-key +0 -27
  86. data/cookbooks/cucumber-chef/files/default/cucumber-run_list +0 -1
  87. data/cookbooks/cucumber-chef/files/default/git-private-key +0 -27
  88. data/cookbooks/cucumber-chef/files/default/install-chef +0 -1
  89. data/cookbooks/cucumber-chef/files/default/lxc-controller-network-config +0 -5
  90. data/cookbooks/cucumber-chef/files/default/lxc-lucid-chef +0 -378
  91. data/cookbooks/cucumber-chef/metadata.rb +0 -6
  92. data/cookbooks/cucumber-chef/recipes/controller.rb +0 -51
  93. data/cookbooks/cucumber-chef/recipes/lxc.rb +0 -35
  94. data/cookbooks/cucumber-chef/recipes/test_lab.rb +0 -23
  95. data/cookbooks/cucumber-chef/recipes/testrunner.rb +0 -46
  96. data/cookbooks/cucumber-chef/roles/controller.rb +0 -7
  97. data/cookbooks/cucumber-chef/roles/test_lab_test.rb +0 -9
  98. data/cookbooks/cucumber-chef/templates/default/controller-client.erb +0 -5
  99. data/cookbooks/cucumber-chef/templates/default/lxc-lucid-chef +0 -385
  100. data/lib/cucumber/chef/handy.rb +0 -90
  101. data/lib/cucumber/chef/templates/controller.erb +0 -35
  102. data/lib/cucumber/chef/templates/env.rb +0 -16
  103. data/lib/cucumber/chef/templates/example_feature.erb +0 -11
  104. data/lib/cucumber/chef/templates/example_step.erb +0 -19
  105. data/lib/cucumber/chef/templates/readme.erb +0 -14
  106. data/lib/cucumber/chef/templates/ubuntu10.04-gems.erb +0 -43
  107. data/lib/cucumber/ec2_server_create.rb +0 -99
  108. data/website/website.html +0 -385
@@ -0,0 +1,57 @@
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::Chef::Helpers::Command
23
+
24
+ ################################################################################
25
+
26
+ def command_run_remote(name, command, expected_exit_code=0)
27
+ output = %x(ssh #{name} '#{command}' 2>&1)
28
+ raise "command_run_remote(#{command}) failed (#{$?})" if ($? != expected_exit_code)
29
+ output
30
+ # rescue RuntimeError => e
31
+ # if $? == 65280
32
+ # puts "Exit Code #{$?}: Retrying..."
33
+ # retry
34
+ # end
35
+ end
36
+
37
+ ################################################################################
38
+
39
+ def command_run_chroot(name, command, expected_exit_code=0)
40
+ output = %x(chroot #{container_root(name)} /bin/bash -c '#{command}' 2>&1)
41
+ raise "command_run_chroot(#{command}) failed (#{$?})" if ($? != expected_exit_code)
42
+ output
43
+ end
44
+
45
+ ################################################################################
46
+
47
+ def command_run_local(command, expected_exit_code=0)
48
+ output = %x(#{command} 2>&1)
49
+ raise "command_run_local(#{command}) failed (#{$?})" if ($? != expected_exit_code)
50
+ output
51
+ end
52
+
53
+ ################################################################################
54
+
55
+ end
56
+
57
+ ################################################################################
@@ -0,0 +1,154 @@
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::Chef::Helpers::Container
23
+
24
+ ################################################################################
25
+
26
+ def container_create(name, distro, release, arch)
27
+ unless container_exists?(name)
28
+ cache_rootfs = container_cache_root(name, distro, release, arch)
29
+ log(name, "has triggered first time lxc distro cache build; this will take a while") if !File.exists?(cache_rootfs)
30
+
31
+ command_run_local(container_create_command(name, distro, release, arch))
32
+
33
+ # install omnibus into the distro/release file cache if it's not already there
34
+ omnibus_chef_client = File.join("/", "opt", "opscode", "bin", "chef-client")
35
+ if !File.exists?(File.join(cache_rootfs, omnibus_chef_client))
36
+ case distro.downcase
37
+ when "ubuntu":
38
+ %x(chroot #{cache_rootfs} /bin/bash -c 'apt-get -y --force-yes install wget' 2>&1)
39
+ when "fedora":
40
+ %x( yum --nogpgcheck --installroot=#{cache_rootfs} -y install wget openssh-server )
41
+ end
42
+ %x( chroot #{cache_rootfs} /bin/bash -c 'wget http://opscode.com/chef/install.sh -O - | bash' 2>&1 )
43
+ if distro.downcase == "fedora"
44
+ %x( chroot #{cache_rootfs} /bin/bash -c 'rpm -Uvh --nodeps /tmp/*rpm' 2>&1 )
45
+ end
46
+ command_run_local("lxc-destroy -n #{name} 2>&1")
47
+ command_run_local(container_create_command(name, distro, release, arch))
48
+ end
49
+
50
+ command_run_local("mkdir -p #{container_root(name)}/root/.ssh")
51
+ command_run_local("chmod 0755 #{container_root(name)}/root/.ssh")
52
+ command_run_local("cat /root/.ssh/id_rsa.pub | tee -a #{container_root(name)}/root/.ssh/authorized_keys")
53
+ command_run_local("cat /home/ubuntu/.ssh/id_rsa.pub | tee -a #{container_root(name)}/root/.ssh/authorized_keys")
54
+
55
+ command_run_local("mkdir -p #{container_root(name)}/home/ubuntu/.ssh")
56
+ command_run_local("chmod 0755 #{container_root(name)}/home/ubuntu/.ssh")
57
+ command_run_local("cat /root/.ssh/id_rsa.pub | tee -a #{container_root(name)}/home/ubuntu/.ssh/authorized_keys")
58
+ command_run_local("cat /home/ubuntu/.ssh/id_rsa.pub | tee -a #{container_root(name)}/home/ubuntu/.ssh/authorized_keys")
59
+ command_run_local("chown -R ubuntu:ubuntu #{container_root(name)}/home/ubuntu/.ssh")
60
+
61
+ command_run_local("rm #{container_root(name)}/etc/motd")
62
+ command_run_local("cp /etc/motd #{container_root(name)}/etc/motd")
63
+ command_run_local("echo \" You are now logged in to the LXC '#{name}'\\n\" >> #{container_root(name)}/etc/motd")
64
+ command_run_local("sed -i \"s/localhost #{name}/#{name}.test-lab #{name} localhost/\" #{container_root(name)}/etc/hosts")
65
+ command_run_local("echo \"#{name}.test-lab\" | tee #{container_root(name)}/etc/hostname")
66
+ end
67
+ container_start(name)
68
+ end
69
+
70
+ def container_destroy(name)
71
+ if container_exists?(name)
72
+ container_stop(name)
73
+ command_run_local("lxc-destroy -n #{name} 2>&1")
74
+ chef_server_node_destroy(name)
75
+ chef_server_client_destroy(name)
76
+ end
77
+ end
78
+
79
+ ################################################################################
80
+
81
+ def container_start(name)
82
+ status = command_run_local("lxc-info -n #{name} 2>&1")
83
+ if status.include?("STOPPED")
84
+ command_run_local("lxc-start -d -n #{name}")
85
+ end
86
+ end
87
+
88
+ def container_stop(name)
89
+ status = command_run_local("lxc-info -n #{name} 2>&1")
90
+ if status.include?("RUNNING")
91
+ command_run_local("lxc-stop -n #{name}")
92
+ end
93
+ end
94
+
95
+ ################################################################################
96
+
97
+ def container_running?(name)
98
+ status = command_run_local("lxc-info -n #{name} 2>&1")
99
+ status.include?("RUNNING")
100
+ end
101
+
102
+ ################################################################################
103
+
104
+ def container_config_network(name)
105
+ lxc_network_config = File.join("/etc/lxc", name)
106
+ File.open(lxc_network_config, 'w') do |f|
107
+ f.puts(Cucumber::Chef.generate_do_not_edit_warning("LXC Container Configuration"))
108
+ f.puts("")
109
+ f.puts("lxc.network.type = veth")
110
+ f.puts("lxc.network.flags = up")
111
+ f.puts("lxc.network.link = br0")
112
+ f.puts("lxc.network.name = eth0")
113
+ f.puts("lxc.network.hwaddr = #{$servers[name][:mac]}")
114
+ f.puts("lxc.network.ipv4 = 0.0.0.0")
115
+ end
116
+ end
117
+
118
+ ################################################################################
119
+
120
+ def containers
121
+ command_run_local("lxc-ls 2>&1").split("\n").uniq
122
+ end
123
+
124
+ def container_exists?(name)
125
+ (File.directory?(container_root(name)) ? true : false)
126
+ end
127
+
128
+ def container_root(name)
129
+ File.join("/", "var", "lib", "lxc", name, "rootfs")
130
+ end
131
+
132
+ def container_cache_root(name, distro, release, arch)
133
+ case distro.downcase
134
+ when "ubuntu":
135
+ cache_root = File.join("/", "var", "cache", "lxc", release, "rootfs-#{arch}")
136
+ when "fedora":
137
+ cache_root = File.join("/", "var", "cache", "lxc", distro, arch, release, "rootfs")
138
+ end
139
+ end
140
+
141
+ def container_create_command(name, distro, release, arch)
142
+ case distro.downcase
143
+ when "ubuntu":
144
+ "lxc-create -n #{name} -f /etc/lxc/#{name} -t #{distro} -- --release #{release} --arch #{arch}"
145
+ when "fedora":
146
+ "lxc-create -n #{name} -f /etc/lxc/#{name} -t #{distro} -- --release #{release}"
147
+ end
148
+ end
149
+
150
+ ################################################################################
151
+
152
+ end
153
+
154
+ ################################################################################
@@ -0,0 +1,35 @@
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::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
@@ -0,0 +1,81 @@
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::Chef::Helpers::Server
23
+
24
+ ################################################################################
25
+
26
+ def detect_arch(distro)
27
+ case distro.downcase
28
+ when "ubuntu":
29
+ ((RUBY_PLATFORM =~ /x86_64/) ? "amd64" : "i386")
30
+ when "fedora":
31
+ ((RUBY_PLATFORM =~ /x86_64/) ? "amd64" : "i686")
32
+ end
33
+ end
34
+
35
+ def server_create(name, attributes={})
36
+ if ((attributes[:persist] && $servers[name]) || ($servers[name] && $servers[name][:persist]))
37
+ attributes = $servers[name]
38
+ else
39
+ server_destroy(name) if (container_exists?(name) && (ENV['DESTROY'] == "1"))
40
+ attributes = { :ip => generate_ip,
41
+ :mac => generate_mac,
42
+ :persist => true,
43
+ :distro => "ubuntu",
44
+ :release => "lucid",
45
+ :arch => detect_arch(attributes[:distro] || "ubuntu") }.merge(attributes)
46
+ end
47
+ $servers = ($servers || Hash.new(nil)).merge(name => attributes)
48
+ $current_server = $servers[name][:ip]
49
+ if !server_running?(name)
50
+ log(name, "is being provisioned") if $servers[name]
51
+
52
+ test_lab_config_dhcpd
53
+ container_config_network(name)
54
+ container_create(name, $servers[name][:distro], $servers[name][:release], $servers[name][:arch])
55
+ Cucumber::Chef::TCPSocket.new($servers[name][:ip], 22).wait
56
+ end
57
+ end
58
+
59
+ def server_destroy(name)
60
+ log(name, "is being destroyed") if $servers[name]
61
+
62
+ container_destroy(name)
63
+ end
64
+
65
+ ################################################################################
66
+
67
+ def server_running?(name)
68
+ container_running?(name)
69
+ end
70
+
71
+ ################################################################################
72
+
73
+ def servers
74
+ containers
75
+ end
76
+
77
+ ################################################################################
78
+
79
+ end
80
+
81
+ ################################################################################
@@ -0,0 +1,46 @@
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::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
+ $servers.each do |key, value|
31
+ f.puts
32
+ f.puts("host #{key} {")
33
+ f.puts(" hardware ethernet #{value[:mac]};")
34
+ f.puts(" fixed-address #{value[:ip]};")
35
+ f.puts(" ddns-hostname \"#{key}\";")
36
+ f.puts("}")
37
+ end
38
+ end
39
+ command_run_local("/etc/init.d/isc-dhcp-server restart")
40
+ end
41
+
42
+ ################################################################################
43
+
44
+ end
45
+
46
+ ################################################################################
@@ -0,0 +1,73 @@
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::Chef::Helpers::Utility
23
+
24
+ ################################################################################
25
+
26
+ def log(name, message)
27
+ STDOUT.puts("\033[34m >>> \033[1m#{name}\033[0m\033[34m #{message}\033[0m")
28
+ STDOUT.flush if STDOUT.respond_to?(:flush)
29
+ end
30
+
31
+ ################################################################################
32
+
33
+ def generate_ip
34
+ octets = [ 192..192,
35
+ 168..168,
36
+ 0..254,
37
+ 1..254 ]
38
+ ip = ""
39
+ for x in 1..4 do
40
+ ip += octets[x-1].to_a[rand(octets[x-1].count)].to_s
41
+ ip += "." if x != 4
42
+ end
43
+ ip
44
+ end
45
+
46
+ ################################################################################
47
+
48
+ def generate_mac
49
+ digits = [ %w( 0 ),
50
+ %w( 0 ),
51
+ %w( 0 ),
52
+ %w( 0 ),
53
+ %w( 5 ),
54
+ %w( e ),
55
+ %w( 0 1 2 3 4 5 6 7 8 9 a b c d e f ),
56
+ %w( 0 1 2 3 4 5 6 7 8 9 a b c d e f ),
57
+ %w( 5 6 7 8 9 a b c d e f ),
58
+ %w( 3 4 5 6 7 8 9 a b c d e f ),
59
+ %w( 0 1 2 3 4 5 6 7 8 9 a b c d e f ),
60
+ %w( 0 1 2 3 4 5 6 7 8 9 a b c d e f ) ]
61
+ mac = ""
62
+ for x in 1..12 do
63
+ mac += digits[x-1][rand(digits[x-1].count)]
64
+ mac += ":" if (x.modulo(2) == 0) && (x != 12)
65
+ end
66
+ mac
67
+ end
68
+
69
+ ################################################################################
70
+
71
+ end
72
+
73
+ ################################################################################
@@ -0,0 +1,56 @@
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
+ module Helpers
26
+
27
+ ################################################################################
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
+ ################################################################################
38
+
39
+ def self.included(base)
40
+ base.send(:include, Cucumber::Chef::Helpers::ChefClient)
41
+ base.send(:include, Cucumber::Chef::Helpers::ChefServer)
42
+ base.send(:include, Cucumber::Chef::Helpers::Command)
43
+ base.send(:include, Cucumber::Chef::Helpers::Container)
44
+ base.send(:include, Cucumber::Chef::Helpers::Server)
45
+ base.send(:include, Cucumber::Chef::Helpers::TestLab)
46
+ base.send(:include, Cucumber::Chef::Helpers::Utility)
47
+ end
48
+
49
+ ################################################################################
50
+
51
+ end
52
+
53
+ end
54
+ end
55
+
56
+ ################################################################################
@@ -0,0 +1,90 @@
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
+ ################################################################################