toft 0.0.6 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/Gemfile.lock +34 -26
  2. data/Rakefile +1 -0
  3. data/features/chef.feature +8 -0
  4. data/features/node.feature +4 -0
  5. data/features/puppet.feature +49 -0
  6. data/features/step_definitions/centos/checks.rb +9 -0
  7. data/features/step_definitions/node.rb +8 -1
  8. data/features/step_definitions/puppet.rb +15 -0
  9. data/features/support/env.rb +6 -2
  10. data/fixtures/chef/cookbooks/test/recipes/data_bag.rb +9 -0
  11. data/fixtures/chef/data_bags/bag1/item1.json +4 -0
  12. data/fixtures/chef/data_bags/bag1/item2.json +4 -0
  13. data/fixtures/chef/data_bags/bag2/item1.json +4 -0
  14. data/fixtures/chef/data_bags/bag2/item2.json +4 -0
  15. data/fixtures/puppet/conf/fileserver.conf +3 -0
  16. data/fixtures/puppet/conf/puppet.conf +15 -0
  17. data/fixtures/puppet/conf/puppet_exec.conf +9 -0
  18. data/fixtures/puppet/conf/puppet_fileserver.conf +8 -0
  19. data/fixtures/puppet/conf/puppet_modules.conf +7 -0
  20. data/fixtures/puppet/conf/puppet_template.conf +8 -0
  21. data/fixtures/puppet/manifests/fileserver/conf/test_fileserver +1 -0
  22. data/fixtures/puppet/manifests/nodes/test_node.pp +26 -0
  23. data/fixtures/puppet/manifests/site.pp +1 -0
  24. data/fixtures/puppet/manifests/templates/template_test +2 -0
  25. data/fixtures/puppet/manifests/test.pp +8 -0
  26. data/fixtures/puppet/manifests/test_fileserver.pp +14 -0
  27. data/fixtures/puppet/manifests/test_install.pp +5 -0
  28. data/fixtures/puppet/manifests/test_module.pp +5 -0
  29. data/fixtures/puppet/manifests/test_service.pp +11 -0
  30. data/fixtures/puppet/manifests/test_template.pp +12 -0
  31. data/fixtures/puppet/modules/test_module/manifests/init.pp +8 -0
  32. data/lib/toft/chef/chef_runner.rb +9 -1
  33. data/lib/toft/node.rb +34 -9
  34. data/lib/toft/puppet/puppet_runner.rb +38 -0
  35. data/lib/toft/version.rb +1 -1
  36. data/lib/toft.rb +3 -2
  37. data/scripts/bin/centos/lxc-prepare-host +6 -0
  38. data/scripts/bin/centos/provision_vagrant +11 -0
  39. data/scripts/bin/share/lxc-create-centos-image +30 -2
  40. data/scripts/bin/ubuntu/lxc-create-ubuntu-image +20 -10
  41. data/scripts/bin/ubuntu/lxc-prepare-host +0 -2
  42. data/scripts/bin/ubuntu/provision_vagrant +9 -0
  43. data/spec/toft/{chef_attributes_spec.rb → chef/chef_attributes_spec.rb} +0 -0
  44. data/spec/toft/{chef_runner_spec.rb → chef/chef_runner_spec.rb} +1 -1
  45. data/spec/toft/node_spec.rb +18 -0
  46. data/spec/toft/puppet/puppet_runner_spec.rb +26 -0
  47. metadata +45 -10
data/Gemfile.lock CHANGED
@@ -1,54 +1,62 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- toft (0.0.6)
4
+ toft (0.0.11)
5
5
  net-ssh
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
10
  archive-tar-minitar (0.5.2)
11
+ arr-pm (0.0.7)
12
+ cabin (> 0)
13
+ backports (2.3.0)
11
14
  builder (3.0.0)
12
- cucumber (1.1.0)
15
+ cabin (0.4.4)
16
+ json
17
+ childprocess (0.3.2)
18
+ ffi (~> 1.0.6)
19
+ clamp (0.4.0)
20
+ cucumber (1.2.0)
13
21
  builder (>= 2.1.2)
14
- diff-lcs (>= 1.1.2)
15
- gherkin (~> 2.5.0)
22
+ diff-lcs (>= 1.1.3)
23
+ gherkin (~> 2.10.0)
16
24
  json (>= 1.4.6)
17
- term-ansicolor (>= 1.0.6)
18
25
  diff-lcs (1.1.3)
19
26
  erubis (2.7.0)
20
- ffi (1.0.9)
21
- fpm (0.3.10)
27
+ ffi (1.0.11)
28
+ fpm (0.4.6)
29
+ arr-pm (~> 0.0.7)
30
+ backports (= 2.3.0)
31
+ cabin (~> 0.4.3)
32
+ clamp
22
33
  json
23
- gherkin (2.5.1)
34
+ gherkin (2.10.0)
24
35
  json (>= 1.4.6)
25
36
  i18n (0.6.0)
26
37
  json (1.5.4)
38
+ log4r (1.1.10)
27
39
  net-scp (1.0.4)
28
40
  net-ssh (>= 1.99.1)
29
- net-ssh (2.1.4)
30
- rake (0.9.2)
31
- rspec (2.6.0)
32
- rspec-core (~> 2.6.0)
33
- rspec-expectations (~> 2.6.0)
34
- rspec-mocks (~> 2.6.0)
35
- rspec-core (2.6.4)
36
- rspec-expectations (2.6.0)
37
- diff-lcs (~> 1.1.2)
38
- rspec-mocks (2.6.0)
39
- term-ansicolor (1.0.6)
40
- thor (0.14.6)
41
- vagrant (0.8.7)
41
+ net-ssh (2.2.2)
42
+ rake (0.9.2.2)
43
+ rspec (2.10.0)
44
+ rspec-core (~> 2.10.0)
45
+ rspec-expectations (~> 2.10.0)
46
+ rspec-mocks (~> 2.10.0)
47
+ rspec-core (2.10.0)
48
+ rspec-expectations (2.10.0)
49
+ diff-lcs (~> 1.1.3)
50
+ rspec-mocks (2.10.1)
51
+ vagrant (1.0.3)
42
52
  archive-tar-minitar (= 0.5.2)
53
+ childprocess (~> 0.3.1)
43
54
  erubis (~> 2.7.0)
44
55
  i18n (~> 0.6.0)
45
56
  json (~> 1.5.1)
57
+ log4r (~> 1.1.9)
46
58
  net-scp (~> 1.0.4)
47
- net-ssh (~> 2.1.4)
48
- thor (~> 0.14.6)
49
- virtualbox (~> 0.9.1)
50
- virtualbox (0.9.2)
51
- ffi (~> 1.0.9)
59
+ net-ssh (~> 2.2.2)
52
60
 
53
61
  PLATFORMS
54
62
  ruby
data/Rakefile CHANGED
@@ -103,6 +103,7 @@ eos
103
103
  -d sudo \
104
104
  -d bind-utils \
105
105
  -d bridge-utils \
106
+ -d dhclient \
106
107
  -d dhcp \
107
108
  -d bind \
108
109
  -d ntp \
@@ -57,6 +57,14 @@ Scenario: Attributes table should override attributes in json file
57
57
  Then Node "n1" should have file or directory "/tmp/stub/two_two"
58
58
  Then Node "n1" should have file or directory "/tmp/stub/three"
59
59
 
60
+ Scenario: Run chef recipe with data bags
61
+ Given I have a clean running node n1
62
+ When I run "recipe[test::data_bag]" on node "n1"
63
+ Then Node "n1" should have file or directory "/tmp/stub/bag1item1"
64
+ Then Node "n1" should have file or directory "/tmp/stub/bag1item2"
65
+ Then Node "n1" should have file or directory "/tmp/stub/bag2item1"
66
+ Then Node "n1" should have file or directory "/tmp/stub/bag2item2"
67
+
60
68
  Scenario: Run non-exist recipe
61
69
 
62
70
  Scenario: Run non-exist role
@@ -35,3 +35,7 @@ Scenario: Create or destroy node
35
35
  When I destroy node "n2"
36
36
  Then There should be 1 nodes in the environment
37
37
 
38
+ Scenario: Change hostname used internally for a specific host
39
+ Given I have a clean running node n1
40
+ And I change the internal hostname for "n1" to "correct.puppet.com"
41
+ Then the result of running ssh command "hostname" on "n1" should contain "correct.puppet.com"
@@ -0,0 +1,49 @@
1
+ Feature: Puppet support
2
+
3
+ Scenario: Run Puppet manifest on nodes
4
+ Given I have a clean running node n1
5
+ When I run puppet manifest "manifests/test.pp" on node "n1"
6
+ Then Node "n1" should have file or directory "/tmp/puppet_test"
7
+
8
+ Scenario: Run puppet manifest with included nodes
9
+ Given I have a clean running node n1
10
+ And I change the internal hostname for "n1" to "correct.puppet.com"
11
+ And I run puppet manifest "manifests/site.pp" on node "n1"
12
+ Then Node "n1" should have file or directory "/tmp/puppet_test_correct"
13
+ And Node "n1" should have file or directory "/tmp/puppet_test_default"
14
+ And Node "n1" should have not file or directory "/tmp/puppet_test_incorrect"
15
+
16
+ Scenario: Run puppet manifest with modules
17
+ Given I have a clean running node n1
18
+ When I run puppet manifest "manifests/test_module.pp" with config file "puppet_modules.conf" on node "n1"
19
+ Then Node "n1" should have file or directory "/tmp/puppet_test_module"
20
+
21
+ Scenario: Run puppet manifest with static files being served by fileserver
22
+ Given I have a clean running node n1
23
+ When I run puppet manifest "manifests/test_fileserver.pp" with config file "puppet_fileserver.conf" on node "n1"
24
+ Then Node "n1" should have file or directory "/tmp/puppet_test_fileserver"
25
+
26
+ Scenario: Run puppet manifest with template dir configuration
27
+ Given I have a clean running node n1
28
+ When I run puppet manifest "manifests/test_template.pp" with config file "puppet_template.conf" on node "n1"
29
+ Then Node "n1" should have file or directory "/tmp/puppet_test_template"
30
+
31
+ Scenario: Check that package was installed on centos box
32
+ Given I have a clean running node n1
33
+ When I run puppet manifest "manifests/test_install.pp" on node "n1"
34
+ Then Node "n1" should have package "zip" installed in the centos box
35
+
36
+ Scenario: Check that service is running on centos box
37
+ Given I have a clean running node n1
38
+ When I run puppet manifest "manifests/test_service.pp" on node "n1"
39
+ Then Node "n1" should have service "named" running in the centos box
40
+
41
+ Scenario: Run puppet manifest overriding conf settings
42
+ Given I have a clean running node n1
43
+ And node "n1" has the configuration settings:
44
+ |key|value|
45
+ |modulepath|/tmp/toft-puppet-tmp/modules|
46
+ When I run puppet manifest "manifests/test_module.pp" on node "n1"
47
+ Then Node "n1" should have file or directory "/tmp/puppet_test_module"
48
+
49
+
@@ -0,0 +1,9 @@
1
+ Then /^Node "([^"]*)" should have package "([^"]*)" installed in the centos box$/ do |node, package|
2
+ result = find(node).run_ssh("rpm -qa #{package}")
3
+ result.stdout.should include(package)
4
+ end
5
+
6
+ Then /^Node "([^"]*)" should have service "([^"]*)" running in the centos box$/ do |node, service|
7
+ result = find(node).run_ssh("ps -ef | grep -v grep | grep #{service} | wc -l")
8
+ result.stdout.strip!.should == "1"
9
+ end
@@ -53,6 +53,13 @@ When /^I remove cname "([^"]*)" from "([^"]*)"$/ do |cname, node|
53
53
  find(node).remove_cname cname
54
54
  end
55
55
 
56
+ When /^I change the internal hostname for "([^"]*)" to "([^"]*)"$/ do |node_hostname, internal_hostname|
57
+ r = find(node_hostname)
58
+ r.run_ssh("hostname #{internal_hostname}")
59
+ r.run_ssh("echo 127.0.0.1 #{internal_hostname} >> /etc/hosts")
60
+ end
61
+
62
+
56
63
  Then /^Hostname of Node "([^"]*)" should match its name$/ do |node|
57
64
  find(node).hostname.should == node
58
- end
65
+ end
@@ -0,0 +1,15 @@
1
+ When /^I run puppet manifest "([^"]*)" on node "([^"]*)"$/ do |run_list, node|
2
+ find(node).run_puppet run_list
3
+ end
4
+
5
+ When /^I run puppet manifest "([^"]*)" with config file "([^"]*)" on node "([^"]*)"$/ do |run_list, conf_file, node|
6
+ find(node).run_puppet(run_list, :conf_file => conf_file)
7
+ end
8
+
9
+ When /^node "([^"]*)" has the configuration settings:$/ do |node, table|
10
+ r = find(node)
11
+ r.run_ssh("echo '[user]' >> /etc/puppet/puppet.conf")
12
+ table.hashes.each do |hash|
13
+ r.run_ssh("echo '#{hash[:key]} = #{hash[:value]}' >> /etc/puppet/puppet.conf")
14
+ end
15
+ end
@@ -3,7 +3,9 @@ require 'rspec/expectations'
3
3
  require 'toft'
4
4
 
5
5
  CHEF_FIXTURE_PATH = File.dirname(__FILE__) + '/../../fixtures/chef'
6
- CONTAINER_TYPE = "natty"
6
+ PUPPET_FIXTURE_PATH = File.dirname(__FILE__) + '/../../fixtures/puppet'
7
+
8
+ CONTAINER_TYPE = "centos-6"
7
9
 
8
10
  World(Toft)
9
11
 
@@ -13,10 +15,12 @@ n1 = create_node "n1", {:ip => "192.168.20.2", :type => CONTAINER_TYPE}
13
15
  Before do
14
16
  Toft.cookbook_path = CHEF_FIXTURE_PATH + '/cookbooks'
15
17
  Toft.role_path = CHEF_FIXTURE_PATH + '/roles'
18
+ Toft.data_bag_path = CHEF_FIXTURE_PATH + '/data_bags'
19
+ Toft.manifest_path = PUPPET_FIXTURE_PATH
16
20
 
17
21
  @n1 = n1
18
22
  end
19
23
 
20
24
  at_exit do
21
25
  n1.destroy
22
- end
26
+ end
@@ -0,0 +1,9 @@
1
+ %w{bag1 bag2}.each do |bag_name|
2
+ %w{item1 item2}.each do |item_name|
3
+ item = data_bag_item(bag_name, item_name)
4
+ directory "/tmp/stub/#{item['value']}" do
5
+ action :create
6
+ recursive true
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,4 @@
1
+ {
2
+ "id": "item1",
3
+ "value": "bag1item1"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "id": "item2",
3
+ "value": "bag1item2"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "id": "item1",
3
+ "value": "bag2item1"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "id": "item2",
3
+ "value": "bag2item2"
4
+ }
@@ -0,0 +1,3 @@
1
+ [conf]
2
+ path /tmp/toft-puppet-tmp/manifests/fileserver/conf
3
+ allow *
@@ -0,0 +1,15 @@
1
+ [main]
2
+ modulepath = /tmp/puppet/modules
3
+ templatedir = /tmp/puppet/manifests/templates
4
+ node_terminus = exec
5
+ external_nodes = /tmp/puppet/tools/extnode.pl
6
+ fileserverconfig = /tmp/puppet/conf/fileserver.conf
7
+ logdir = /var/log/puppet
8
+ vardir = /var/lib/puppet
9
+ ssldir = /var/lib/puppet/ssl
10
+ rundir = /var/run/puppet
11
+ report = true
12
+ server = puppet.dev.int.realestate.com.au
13
+ reportserver = puppet.dev.int.realestate.com.au
14
+ diff = diff
15
+ diff_args = -u
@@ -0,0 +1,9 @@
1
+ [main]
2
+ node_terminus = exec
3
+ external_nodes = /tmp/puppet/tools/extnode.pl
4
+
5
+ logdir = /var/log/puppet
6
+ vardir = /var/lib/puppet
7
+ ssldir = /var/lib/puppet/ssl
8
+ rundir = /var/run/puppet
9
+ report = true
@@ -0,0 +1,8 @@
1
+ [main]
2
+ fileserverconfig = /tmp/toft-puppet-tmp/conf/fileserver.conf
3
+
4
+ logdir = /var/log/puppet
5
+ vardir = /var/lib/puppet
6
+ ssldir = /var/lib/puppet/ssl
7
+ rundir = /var/run/puppet
8
+ report = true
@@ -0,0 +1,7 @@
1
+ [main]
2
+ modulepath = /tmp/toft-puppet-tmp/modules
3
+
4
+ logdir = /var/log/puppet
5
+ vardir = /var/lib/puppet
6
+ ssldir = /var/lib/puppet/ssl
7
+ rundir = /var/run/puppet
@@ -0,0 +1,8 @@
1
+ [main]
2
+ templatedir = /tmp/toft-puppet-tmp/manifests/templates
3
+
4
+ logdir = /var/log/puppet
5
+ vardir = /var/lib/puppet
6
+ ssldir = /var/lib/puppet/ssl
7
+ rundir = /var/run/puppet
8
+ report = true
@@ -0,0 +1 @@
1
+ This is a test for the fileserver config
@@ -0,0 +1,26 @@
1
+ node /^correct.*/ inherits default_node {
2
+
3
+ file { "/tmp/puppet_test_correct":
4
+ ensure => present,
5
+ mode => '0666',
6
+ }
7
+
8
+ }
9
+
10
+ node /^incorrect.*/ inherits default_node {
11
+
12
+ file { "/tmp/puppet_test_incorrect":
13
+ ensure => present,
14
+ mode => '0666',
15
+ }
16
+
17
+ }
18
+
19
+ node default_node {
20
+
21
+ file { "/tmp/puppet_test_default":
22
+ ensure => present,
23
+ mode => '0666',
24
+ }
25
+
26
+ }
@@ -0,0 +1 @@
1
+ import "nodes/*.pp"
@@ -0,0 +1,2 @@
1
+ This is a test for the template config
2
+ Here is the variable <%= variable %>
@@ -0,0 +1,8 @@
1
+ class { 'test': }
2
+
3
+ class test {
4
+ file { "/tmp/puppet_test":
5
+ ensure => present,
6
+ mode => '0666',
7
+ }
8
+ }
@@ -0,0 +1,14 @@
1
+ class { 'test': }
2
+
3
+ class test {
4
+ file { "test_fileserver":
5
+ path => "/tmp/puppet_test_fileserver",
6
+ owner => "root",
7
+ group => "root",
8
+ mode => 0440,
9
+ source => "puppet:///conf/test_fileserver",
10
+ }
11
+ }
12
+
13
+
14
+
@@ -0,0 +1,5 @@
1
+ class { 'test': }
2
+
3
+ class test {
4
+ package { "zip": ensure => installed }
5
+ }
@@ -0,0 +1,5 @@
1
+ class { 'test': }
2
+
3
+ class test {
4
+ include test_module
5
+ }
@@ -0,0 +1,11 @@
1
+ class { 'test': }
2
+
3
+ class test {
4
+ package { "bind": ensure => installed }
5
+
6
+ service { "named":
7
+ enable => true,
8
+ ensure => running,
9
+ require => Package["bind"],
10
+ }
11
+ }
@@ -0,0 +1,12 @@
1
+ class { 'test': }
2
+
3
+ class test {
4
+
5
+ $variable = "BLAH"
6
+
7
+ file { "/tmp/puppet_test_template":
8
+ ensure => present,
9
+ mode => '0666',
10
+ content => template(template_test)
11
+ }
12
+ }
@@ -0,0 +1,8 @@
1
+ class test_module {
2
+
3
+ file { "/tmp/puppet_test_module":
4
+ ensure => present,
5
+ mode => '0666',
6
+ }
7
+
8
+ }
@@ -9,6 +9,7 @@ module Toft
9
9
  DEST_CHEF_TMP = "/tmp/toft-chef-tmp"
10
10
  DEST_COOKBOOK_PATH = "#{DEST_CHEF_TMP}/cookbooks"
11
11
  DEST_ROLE_PATH = "#{DEST_CHEF_TMP}/roles"
12
+ DEST_DATA_BAG_PATH = "#{DEST_CHEF_TMP}/data_bags"
12
13
  DEST_CHEF_SOLO_PATH = "#{DEST_CHEF_TMP}/solo.rb"
13
14
  DEST_CHEF_JSON_PATH = "#{DEST_CHEF_TMP}/solo.json"
14
15
 
@@ -43,18 +44,25 @@ module Toft
43
44
  mkdir_p "#{@root_dir}#{DEST_CHEF_TMP}"
44
45
  cp_r Toft.cookbook_path, "#{@root_dir}#{DEST_COOKBOOK_PATH}"
45
46
  cp_r Toft.role_path, "#{@root_dir}#{DEST_ROLE_PATH}" unless roles_missing?
47
+ cp_r Toft.data_bag_path, "#{@root_dir}#{DEST_DATA_BAG_PATH}" unless data_bags_missing?
46
48
  end
47
49
 
48
50
  def roles_missing?
49
51
  Toft.role_path.blank?
50
52
  end
51
53
 
54
+ def data_bags_missing?
55
+ Toft.data_bag_path.blank?
56
+ end
57
+
52
58
  def generate_solo_rb
59
+ mkdir_p "#{@root_dir}/tmp/chef-file-cache"
53
60
  solo = <<-EOF
54
61
  file_cache_path "/tmp/chef-file-cache"
55
62
  cookbook_path ["#{DEST_COOKBOOK_PATH}"]
56
63
  EOF
57
64
  solo += "role_path [\"#{DEST_ROLE_PATH}\"]" unless roles_missing?
65
+ solo += "\ndata_bag_path \"#{DEST_DATA_BAG_PATH}\"" unless data_bags_missing?
58
66
 
59
67
  File.open("#{@root_dir}#{DEST_CHEF_SOLO_PATH}", 'w') do |f|
60
68
  f.write(solo);
@@ -74,4 +82,4 @@ cookbook_path ["#{DEST_COOKBOOK_PATH}"]
74
82
  end
75
83
  end
76
84
  end
77
- end
85
+ end
data/lib/toft/node.rb CHANGED
@@ -36,7 +36,7 @@ CQWv13UgQjiHgQILXSb7xdzpWK1wpDoqIEWQugRyPQDeZhPWVbB4Lg==
36
36
  -----END RSA PRIVATE KEY-----
37
37
  EOF
38
38
 
39
- TIMOUT_IN_SECONDS = 60
39
+ TIMEOUT_IN_SECONDS = 120
40
40
  TRY_INTERVAL = 0.5
41
41
 
42
42
  include Observable
@@ -54,6 +54,11 @@ CQWv13UgQjiHgQILXSb7xdzpWK1wpDoqIEWQugRyPQDeZhPWVbB4Lg==
54
54
  @chef_runner = Toft::Chef::ChefRunner.new("#{rootfs}") do |chef_command|
55
55
  run_ssh chef_command
56
56
  end
57
+
58
+ @puppet_runner = options[:runner]
59
+ @puppet_runner ||= Toft::Puppet::PuppetRunner.new("#{rootfs}") do |puppet_command|
60
+ run_ssh puppet_command
61
+ end
57
62
  end
58
63
 
59
64
  def hostname
@@ -65,6 +70,7 @@ CQWv13UgQjiHgQILXSb7xdzpWK1wpDoqIEWQugRyPQDeZhPWVbB4Lg==
65
70
  end
66
71
 
67
72
  def start
73
+ puts "Starting host node..."
68
74
  cmd "lxc-start -n #{@hostname} -d" # system + sudo lxc-start does not work on centos-6, but back-quote does(no clue on why)
69
75
  cmd! "lxc-wait -n #{@hostname} -s RUNNING"
70
76
  wait_ssh_ready
@@ -135,6 +141,10 @@ CQWv13UgQjiHgQILXSb7xdzpWK1wpDoqIEWQugRyPQDeZhPWVbB4Lg==
135
141
  @chef_runner.run run_list, params
136
142
  end
137
143
 
144
+ def run_puppet(run_list, params = {})
145
+ @puppet_runner.run run_list, params
146
+ end
147
+
138
148
  def file(path)
139
149
  FileChecker.new(rootfs, path)
140
150
  end
@@ -149,31 +159,46 @@ CQWv13UgQjiHgQILXSb7xdzpWK1wpDoqIEWQugRyPQDeZhPWVbB4Lg==
149
159
  end
150
160
 
151
161
  def wait_sshd_running
152
- while true
162
+ wait_for do
153
163
  netstat = cmd("lxc-netstat --name #{@hostname} -ta")
154
164
  return if netstat =~ /ssh/
155
165
  end
156
166
  end
157
167
 
158
168
  def wait_remote_host_reachable
159
- max_try = TIMOUT_IN_SECONDS / TRY_INTERVAL
160
- try = 0
161
- while try < max_try
169
+ wait_for do
162
170
  begin
163
- break if Ping.pingecho fqdn, 0.1
171
+ return if Ping.pingecho fqdn, 0.1
164
172
  rescue Exception
165
173
  # fix the strange pingcho exception
166
174
  end
167
- sleep TRY_INTERVAL
168
- try += 1
169
175
  end
170
176
  raise RuntimeError, "Remote machine not responding." if try >= max_try
171
177
  end
172
178
 
179
+ def wait_for
180
+ return if !block_given?
181
+ max_try = TIMEOUT_IN_SECONDS / TRY_INTERVAL
182
+ try = 0
183
+ while try < max_try
184
+ output_progress
185
+ yield
186
+ sleep TRY_INTERVAL
187
+ try += 1
188
+ end
189
+ end
190
+
191
+ def output_progress
192
+ print "."
193
+ STDOUT.flush
194
+ end
195
+
173
196
  def wait_ssh_ready
197
+ print "Waiting for host sshd ready"
174
198
  wait_sshd_running
199
+ print "\nWaiting for host to be reachable"
175
200
  wait_remote_host_reachable
176
- puts "SSH connection on '#{@hostname}/#{@ip}' is ready..."
201
+ puts "\nSSH connection on '#{@hostname}/#{@ip}' is ready."
177
202
  end
178
203
 
179
204
  def generate_lxc_config
@@ -0,0 +1,38 @@
1
+ require 'fileutils'
2
+
3
+ module Toft
4
+ module Puppet
5
+ class PuppetRunner
6
+ include FileUtils
7
+
8
+ DEST_PUPPET_TMP = "/tmp/toft-puppet-tmp"
9
+ DEST_CONF_PATH = "/etc/puppet/puppet.conf"
10
+
11
+ def initialize(root_dir, &command_runner)
12
+ @root_dir = root_dir
13
+ @command_runner = command_runner
14
+ end
15
+
16
+ def run(run_list, params = {})
17
+ copy_puppet_material
18
+ copy_conf_file(params[:conf_file]) if params[:conf_file]
19
+ @command_runner.call "puppet apply #{DEST_PUPPET_TMP}/#{run_list}"
20
+ end
21
+
22
+ private
23
+
24
+ def copy_conf_file(conf_file)
25
+ @command_runner.call "cp #{DEST_PUPPET_TMP}/conf/#{conf_file} #{DEST_CONF_PATH}"
26
+ end
27
+
28
+ def copy_puppet_material
29
+ raise ArgumentError, "Toft.manifest_path can not be empty!" if Toft.manifest_path.blank?
30
+ rm_rf "#{@root_dir}#{DEST_PUPPET_TMP}"
31
+ mkdir_p "#{@root_dir}#{DEST_PUPPET_TMP}"
32
+
33
+ cp_r "#{Toft.manifest_path}/.", "#{@root_dir}#{DEST_PUPPET_TMP}"
34
+ end
35
+
36
+ end
37
+ end
38
+ end
data/lib/toft/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Toft
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.11"
3
3
  end
data/lib/toft.rb CHANGED
@@ -2,13 +2,14 @@ require 'toft/node_controller'
2
2
  require 'toft/file_checker'
3
3
  require 'toft/chef/chef_attributes'
4
4
  require 'toft/chef/chef_runner'
5
+ require 'toft/puppet/puppet_runner'
5
6
 
6
7
  module Toft
7
8
  DYNAMIC_IP = "0.0.0.0"
8
9
  DOMAIN = "foo"
9
10
 
10
11
  class << self
11
- attr_accessor :cookbook_path, :role_path
12
+ attr_accessor :manifest_path, :cookbook_path, :role_path, :data_bag_path
12
13
  end
13
14
 
14
15
  def create_node(hostname, options = {})
@@ -35,4 +36,4 @@ class String
35
36
  def blank?
36
37
  empty?
37
38
  end
38
- end
39
+ end
@@ -6,6 +6,12 @@ if [ ! "$username" = "root" ]; then
6
6
  exit 1
7
7
  fi
8
8
 
9
+ # sudo yum -y install wget
10
+ # wget http://dl.dropbox.com/u/43220259/toft-lxc-0.0.6.noarch.rpm
11
+ # sudo yum erase -y dhclient
12
+ # sudo yum install -y --nogpgcheck toft-lxc-0.0.6.noarch.rpm
13
+ # sudo yum install -y bind dhcp dhclient bridge-utils
14
+
9
15
  gateway_ip="192.168.20.1"
10
16
  subnet="192.168.20.0"
11
17
  netmask="255.255.255.0"
@@ -0,0 +1,11 @@
1
+ cd /vagrant
2
+ sudo yum -y install wget
3
+ wget http://dl.dropbox.com/u/43220259/toft-lxc-0.0.6.noarch.rpm
4
+ sudo yum erase -y dhclient
5
+ sudo yum install -y --nogpgcheck toft-lxc-0.0.6.noarch.rpm
6
+ sudo yum install -y bind dhcp dhclient bridge-utils
7
+ sudo ./scripts/bin/centos/lxc-prepare-host
8
+ sudo yum install -y ruby ruby-devel ruby-docs ruby-ri ruby-irb ruby-rdoc rubygems
9
+ sudo gem install bundler --no-ri --no-rdoc
10
+ sudo bundle install
11
+ sudo cp natty-i386-puppet.tar.gz /var/cache/lxc/natty-i386.tar.gz
@@ -1,7 +1,7 @@
1
1
  #!/bin/bash
2
2
 
3
3
  if [ $# -eq 0 ]; then
4
- echo "Usage: `basename $0` <centos-6|centos-5|centos-4>"
4
+ echo "Usage: `basename $0` <centos-6>"
5
5
  exit 1
6
6
  fi
7
7
 
@@ -30,8 +30,12 @@ fi
30
30
 
31
31
  # clean the cache dir
32
32
  rm -rf $cache/$suite-$arch
33
+ mkdir -p $cache/$suite-$arch
33
34
 
34
35
  # install latest rinse
36
+ if [ -f /etc/redhat-release ]; then # on centos
37
+ yum install -y perl perl-CPAN perl-libwww-perl
38
+ fi
35
39
  if [[ ! `type rinse` ]]; then
36
40
  echo "Rinse does not exist. Installing..."
37
41
  (cd /tmp && \
@@ -42,9 +46,33 @@ if [[ ! `type rinse` ]]; then
42
46
  fi
43
47
 
44
48
  # create centos image using rinse
49
+ epel_arch=$arch
50
+ if [ "$arch" == "amd64" ]; then
51
+ epel_arch="x86_64"
52
+ fi
45
53
  cat <<EOF > /tmp/after_post_install
54
+ ## chef rpms
46
55
  chroot $cache/$suite-$arch rpm -Uvh http://rbel.co/rbel6
47
- chroot $cache/$suite-$arch yum -y install tar man sudo bind-utils openssh-server openssh-clients rubygem-chef
56
+ ## ruby-shadow and other libs that puppet requires
57
+ chroot $cache/$suite-$arch rpm -Uvh http://download.fedoraproject.org/pub/epel/6/$epel_arch/epel-release-6-5.noarch.rpm
58
+ ## puppet repo
59
+ cat <<EOFF > $cache/$suite-$arch/etc/yum.repos.d/puppet.repo
60
+ [puppetlabs]
61
+ name=Puppet Labs Packages
62
+ baseurl=http://yum.puppetlabs.com/el/\\\$releasever/products/\\\$basearch/
63
+ enabled=1
64
+ gpgcheck=1
65
+ gpgkey=http://yum.puppetlabs.com/RPM-GPG-KEY-puppetlabs
66
+
67
+ [puppetlabs-deps]
68
+ name=Puppet Labs Packages Dependency
69
+ baseurl=http://yum.puppetlabs.com/el/\\\$releasever/dependencies/\\\$basearch/
70
+ enabled=1
71
+ gpgcheck=1
72
+ gpgkey=http://yum.puppetlabs.com/RPM-GPG-KEY-puppetlabs
73
+ EOFF
74
+ chroot $cache/$suite-$arch yum -y install tar man sudo bind-utils openssh-server openssh-clients rubygem-chef puppet
75
+ chroot $cache/$suite-$arch yum clean all
48
76
  EOF
49
77
  chmod +x /tmp/after_post_install
50
78
 
@@ -1,7 +1,7 @@
1
1
  #!/bin/bash
2
2
 
3
3
  if [ $# -eq 0 ]; then
4
- echo "Usage: `basename $0` <lenny|lucid|natty>"
4
+ echo "Usage: `basename $0` <lenny|lucid|natty|oneiric>"
5
5
  exit 1
6
6
  fi
7
7
 
@@ -30,27 +30,25 @@ fi
30
30
 
31
31
  # clean the cache dir
32
32
  rm -rf $cache/$suite-$arch
33
+ mkdir -p $cache/$suite-$arch
34
+
33
35
 
34
36
  lenny_packages=ifupdown,locales,libui-dialog-perl,netbase,net-tools,dialog,apt,apt-utils,resolvconf,iproute,inetutils-ping,dnsutils,dhcp3-client,ssh,lsb-release,wget,gpgv,gnupg,sudo,ruby,rubygems1.8,ruby-dev,libopenssl-ruby,build-essential,ssl-cert
37
+ squeeze_packages=$lenny_packages
35
38
  lucid_packages=dialog,apt,apt-utils,resolvconf,iproute,inetutils-ping,dnsutils,dhcp3-client,ssh,lsb-release,wget,gpgv,gnupg,sudo,ruby,rubygems1.8,ruby-dev,libopenssl-ruby,build-essential,ssl-cert
36
39
  natty_packages=dialog,apt,apt-utils,resolvconf,iproute,inetutils-ping,dnsutils,isc-dhcp-client,isc-dhcp-common,ssh,lsb-release,gnupg,netbase,lxcguest,sudo,ruby,rubygems1.8,ruby-dev,libruby,build-essential,wget,ssl-cert
37
- # check the mini ubuntu was not already downloaded
38
- rm -rf "$cache/$suite-$arch"
39
- mkdir -p "$cache/$suite-$arch"
40
- if [ $? -ne 0 ]; then
41
- echo "Failed to create '$cache/$suite-$arch' directory"
42
- exit 1
43
- fi
40
+ oneiric_packages=$natty_packages
44
41
 
45
42
  # download a mini ubuntu into a cache
43
+ apt-get install -y debootstrap
46
44
  echo "Downloading ubuntu minimal ..."
47
45
  eval "packages=\$${suite}_packages"
48
46
  cmd="debootstrap --verbose --variant=minbase --components=main,universe --arch=$arch --include=$packages $suite $cache/$suite-$arch"
49
47
  echo $cmd
50
48
  eval $cmd
51
49
  if [ $? -ne 0 ]; then
52
- echo "Failed to download the rootfs, aborting."
53
- exit 1
50
+ echo "Failed to download the rootfs, aborting."
51
+ exit 1
54
52
  fi
55
53
 
56
54
  echo "Download complete."
@@ -71,6 +69,18 @@ apt-get install chef --force-yes -qy
71
69
  EOF
72
70
  chroot "$cache/$suite-$arch" bash /tmp/install-chef-ubuntu.sh
73
71
 
72
+ # install puppet
73
+ cat <<EOF > "$cache/$suite-$arch/tmp/install-puppet-ubuntu.sh"
74
+ echo -e "deb http://apt.puppetlabs.com/ $suite main\ndeb-src http://apt.puppetlabs.com/ $suite main" >> /etc/apt/sources.list.d/puppet.list
75
+ apt-key adv --keyserver keyserver.ubuntu.com --recv 4BD6EC30
76
+ apt-get update
77
+ apt-get install -y puppet
78
+ EOF
79
+ chroot "$cache/$suite-$arch" bash /tmp/install-puppet-ubuntu.sh
80
+
81
+ #clean apt caches
82
+ rm -rf $cache/$suite-$arch/var/cache/apt
83
+
74
84
  # compress root image
75
85
  echo "Packaging rootfs ..."
76
86
  (cd $cache/$suite-$arch && tar --exclude=$suite-$arch.tar.gz -zcf $suite-$arch.tar.gz .)
@@ -8,7 +8,6 @@ fi
8
8
 
9
9
  OS=`cat /etc/issue | cut -f 1 -d " " -s`
10
10
 
11
-
12
11
  gateway_ip="192.168.20.1"
13
12
  subnet="192.168.20.0"
14
13
  netmask="255.255.255.0"
@@ -189,4 +188,3 @@ subnet $subnet netmask $netmask {
189
188
  }
190
189
  EOF
191
190
  sudo /etc/init.d/$dhcp_daemon restart
192
-
@@ -0,0 +1,9 @@
1
+ cd /vagrant
2
+ wget http://dl.dropbox.com/u/43220259/toft-lxc_0.0.6_all.deb
3
+ sudo apt-get -y remove apparmor
4
+ sudo dpkg -i toft-lxc_0.0.6_all.deb
5
+ sudo apt-get -fy install
6
+ sudo ./scripts/bin/ubuntu/lxc-prepare-host
7
+ sudo gem install bundler --no-ri --no-rdoc
8
+ sudo bundle install
9
+ sudo cp natty-i386.tar.gz /var/cache/lxc/
@@ -31,4 +31,4 @@ describe "ChefRunner" do
31
31
  lambda { cf.run "run list" }.should raise_error RuntimeError
32
32
  end
33
33
 
34
- end
34
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Node" do
4
+
5
+ describe 'run_puppet' do
6
+
7
+ it 'should run block with puppet runner' do
8
+ puppet_runner = mock Toft::Puppet::PuppetRunner.class
9
+ puppet_runner.should_receive(:run).with('manifest', {})
10
+
11
+ node = Toft::Node.new("my_host", {:runner => puppet_runner})
12
+ node.run_puppet('manifest')
13
+
14
+ end
15
+
16
+ end
17
+
18
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe "PuppetRunner" do
4
+
5
+ it "should run puppet apply to manifest" do
6
+ Toft.manifest_path = "#{PROJECT_ROOT}/fixtures/puppet/manifests"
7
+ runner = Toft::Puppet::PuppetRunner.new("whatever") do |command|
8
+ command.include?("puppet apply").should be_true
9
+ end
10
+ lambda { runner.run "test" }.should_not raise_error
11
+ end
12
+
13
+ it "should throw exception if manifest path not set" do
14
+ Toft.manifest_path = ""
15
+ runner = Toft::Puppet::PuppetRunner.new "whatever"
16
+ lambda { runner.run "test" }.should raise_error ArgumentError, "Toft.manifest_path can not be empty!"
17
+ end
18
+
19
+
20
+ it "should throw exception if cookbook not exist" do
21
+ Toft.manifest_path = "non-exist-manifest"
22
+ cf = Toft::Puppet::PuppetRunner.new "whatever"
23
+ lambda { cf.run "test" }.should raise_error RuntimeError
24
+ end
25
+
26
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toft
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 9
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 6
10
- version: 0.0.6
9
+ - 11
10
+ version: 0.0.11
11
11
  platform: ruby
12
12
  authors:
13
13
  - Huang Liang
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-11-04 00:00:00 Z
18
+ date: 2012-05-16 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rspec
@@ -103,7 +103,7 @@ dependencies:
103
103
  version: "0"
104
104
  type: :runtime
105
105
  version_requirements: *id006
106
- description: toft currently support testing chef, shell scripts using cucumber on lxc on ubuntu
106
+ description: toft currently support testing chef, puppet, shell scripts using cucumber on lxc on ubuntu
107
107
  email:
108
108
  - exceedhl@gmail.com
109
109
  executables: []
@@ -120,17 +120,42 @@ files:
120
120
  - features/chef.feature
121
121
  - features/command.feature
122
122
  - features/node.feature
123
+ - features/puppet.feature
124
+ - features/step_definitions/centos/checks.rb
123
125
  - features/step_definitions/checker.rb
124
126
  - features/step_definitions/chef.rb
125
127
  - features/step_definitions/command.rb
126
128
  - features/step_definitions/node.rb
129
+ - features/step_definitions/puppet.rb
127
130
  - features/support/env.rb
128
131
  - fixtures/chef/attributes.json
129
132
  - fixtures/chef/cookbooks/test/attributes/default.rb
130
133
  - fixtures/chef/cookbooks/test/recipes/attribute.rb
134
+ - fixtures/chef/cookbooks/test/recipes/data_bag.rb
131
135
  - fixtures/chef/cookbooks/test/recipes/default.rb
132
136
  - fixtures/chef/cookbooks/test/recipes/role.rb
137
+ - fixtures/chef/data_bags/bag1/item1.json
138
+ - fixtures/chef/data_bags/bag1/item2.json
139
+ - fixtures/chef/data_bags/bag2/item1.json
140
+ - fixtures/chef/data_bags/bag2/item2.json
133
141
  - fixtures/chef/roles/test.rb
142
+ - fixtures/puppet/conf/fileserver.conf
143
+ - fixtures/puppet/conf/puppet.conf
144
+ - fixtures/puppet/conf/puppet_exec.conf
145
+ - fixtures/puppet/conf/puppet_fileserver.conf
146
+ - fixtures/puppet/conf/puppet_modules.conf
147
+ - fixtures/puppet/conf/puppet_template.conf
148
+ - fixtures/puppet/manifests/fileserver/conf/test_fileserver
149
+ - fixtures/puppet/manifests/nodes/test_node.pp
150
+ - fixtures/puppet/manifests/site.pp
151
+ - fixtures/puppet/manifests/templates/template_test
152
+ - fixtures/puppet/manifests/test.pp
153
+ - fixtures/puppet/manifests/test_fileserver.pp
154
+ - fixtures/puppet/manifests/test_install.pp
155
+ - fixtures/puppet/manifests/test_module.pp
156
+ - fixtures/puppet/manifests/test_service.pp
157
+ - fixtures/puppet/manifests/test_template.pp
158
+ - fixtures/puppet/modules/test_module/manifests/init.pp
134
159
  - lib/toft.rb
135
160
  - lib/toft/chef/chef_attributes.rb
136
161
  - lib/toft/chef/chef_runner.rb
@@ -138,12 +163,15 @@ files:
138
163
  - lib/toft/file_checker.rb
139
164
  - lib/toft/node.rb
140
165
  - lib/toft/node_controller.rb
166
+ - lib/toft/puppet/puppet_runner.rb
141
167
  - lib/toft/version.rb
142
168
  - scripts/bin/centos/lxc-prepare-host
169
+ - scripts/bin/centos/provision_vagrant
143
170
  - scripts/bin/share/install-chef-ubuntu.sh
144
171
  - scripts/bin/share/lxc-create-centos-image
145
172
  - scripts/bin/ubuntu/lxc-create-ubuntu-image
146
173
  - scripts/bin/ubuntu/lxc-prepare-host
174
+ - scripts/bin/ubuntu/provision_vagrant
147
175
  - scripts/lxc-templates/files/rc.local
148
176
  - scripts/lxc-templates/lxc-centos-6
149
177
  - scripts/lxc-templates/lxc-lenny
@@ -151,8 +179,10 @@ files:
151
179
  - scripts/lxc-templates/lxc-natty
152
180
  - spec/fixtures/illegal_syntax.json
153
181
  - spec/spec_helper.rb
154
- - spec/toft/chef_attributes_spec.rb
155
- - spec/toft/chef_runner_spec.rb
182
+ - spec/toft/chef/chef_attributes_spec.rb
183
+ - spec/toft/chef/chef_runner_spec.rb
184
+ - spec/toft/node_spec.rb
185
+ - spec/toft/puppet/puppet_runner_spec.rb
156
186
  homepage: https://github.com/exceedhl/toft
157
187
  licenses: []
158
188
 
@@ -185,18 +215,23 @@ rubyforge_project: toft
185
215
  rubygems_version: 1.8.6
186
216
  signing_key:
187
217
  specification_version: 3
188
- summary: toft aims to help test infrastructure code such as chef
218
+ summary: toft aims to help test infrastructure code such as chef, puppet
189
219
  test_files:
190
220
  - features/checker.feature
191
221
  - features/chef.feature
192
222
  - features/command.feature
193
223
  - features/node.feature
224
+ - features/puppet.feature
225
+ - features/step_definitions/centos/checks.rb
194
226
  - features/step_definitions/checker.rb
195
227
  - features/step_definitions/chef.rb
196
228
  - features/step_definitions/command.rb
197
229
  - features/step_definitions/node.rb
230
+ - features/step_definitions/puppet.rb
198
231
  - features/support/env.rb
199
232
  - spec/fixtures/illegal_syntax.json
200
233
  - spec/spec_helper.rb
201
- - spec/toft/chef_attributes_spec.rb
202
- - spec/toft/chef_runner_spec.rb
234
+ - spec/toft/chef/chef_attributes_spec.rb
235
+ - spec/toft/chef/chef_runner_spec.rb
236
+ - spec/toft/node_spec.rb
237
+ - spec/toft/puppet/puppet_runner_spec.rb