cuken 0.1.11 → 0.1.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. data/Gemfile +1 -1
  2. data/Gemfile.lock +8 -8
  3. data/VERSION +1 -1
  4. data/cuken.gemspec +19 -5
  5. data/features/about.md +110 -27
  6. data/features/chef_examples/cookbooks_cookbook.feature +2 -2
  7. data/features/chef_examples/zenoss/01_chef_server_setup.feature +205 -0
  8. data/features/chef_examples/zenoss/02_monitor_vm_setup.feature +139 -0
  9. data/features/chef_examples/zenoss/03_monitor_chef_setup.feature +109 -0
  10. data/features/step_definitions/cuken_steps.rb +16 -0
  11. data/features/support/env.rb +1 -0
  12. data/lib/cuken/api/chef/common.rb +20 -0
  13. data/lib/cuken/api/chef/cookbook.rb +62 -1
  14. data/lib/cuken/api/chef/data_bag.rb +89 -0
  15. data/lib/cuken/api/chef/knife.rb +16 -0
  16. data/lib/cuken/api/chef/role.rb +71 -0
  17. data/lib/cuken/api/chef.rb +51 -9
  18. data/lib/cuken/api/file.rb +68 -0
  19. data/lib/cuken/api/vagrant/common.rb +85 -0
  20. data/lib/cuken/api/vagrant/v_m.rb +125 -0
  21. data/lib/cuken/api/vagrant.rb +83 -0
  22. data/lib/cuken/chef.rb +16 -0
  23. data/lib/cuken/cucumber/chef/common.rb +4 -0
  24. data/lib/cuken/cucumber/chef/cookbook.rb +16 -2
  25. data/lib/cuken/cucumber/chef/data_bag.rb +48 -16
  26. data/lib/cuken/cucumber/chef/role.rb +30 -0
  27. data/lib/cuken/cucumber/chef.rb +16 -5
  28. data/lib/cuken/cucumber/cmd.rb +16 -0
  29. data/lib/cuken/cucumber/common.rb +16 -0
  30. data/lib/cuken/cucumber/file.rb +52 -0
  31. data/lib/cuken/cucumber/git/hooks.rb +28 -0
  32. data/lib/cuken/cucumber/rvm.rb +16 -0
  33. data/lib/cuken/cucumber/ssh/hooks.rb +31 -0
  34. data/lib/cuken/cucumber/ssh.rb +16 -0
  35. data/lib/cuken/cucumber/vagrant/common.rb +93 -0
  36. data/lib/cuken/cucumber/vagrant/hooks.rb +35 -0
  37. data/lib/cuken/cucumber/vagrant.rb +26 -0
  38. data/lib/cuken/vagrant.rb +19 -0
  39. metadata +18 -4
@@ -0,0 +1,139 @@
1
+ @announce
2
+ Feature: Zenoss Monitoring
3
+ In order to launch a Zenoss server
4
+ As a admin/developer
5
+ I want to define the VM configuration via executable features
6
+
7
+ Background:
8
+ Given the Chef root directory "/tmp/chef" exists
9
+ And the state of VM "chef" is "running"
10
+ And I switch Vagrant environment
11
+ And the Chef root directory "/tmp/monitor" exists
12
+ And the state of VM "monitor" is not "running"
13
+
14
+ Scenario: Clone a Chef skeleton repository
15
+ Given the remote Chef repository "git://github.com/cookbooks/chef-repo.git"
16
+ When I clone the remote Chef repository branch "master" to "monitor"
17
+ And the local Chef repository exists
18
+ Then I place all in "monitor" in "/tmp/monitor"
19
+
20
+ Scenario: Migrate the previously generated private keys
21
+ Then I successfully run `cp /tmp/chef/.chef/monitor.pem /tmp/monitor/.chef`
22
+ And I successfully run `cp /tmp/chef/.chef/monitor.pem /tmp/monitor/mnt/etc`
23
+
24
+ Scenario: Create some shared Vagrant configuration details
25
+ Given the directory "hobos"
26
+ And the file "hobos/vm.bo" contains nothing
27
+ When I write to "hobos/vm.bo":
28
+ """
29
+ vm.customize do |cvm|
30
+ cvm.memory_size = 1024
31
+ cvm.vram_size = 12
32
+ cvm.cpu_count = 2
33
+ cvm.accelerate_3d_enabled = false
34
+ cvm.accelerate_2d_video_enabled = false
35
+ cvm.monitor_count = 1
36
+
37
+ cvm.bios.acpi_enabled = true
38
+ cvm.bios.io_apic_enabled = false
39
+
40
+ cvm.cpu.pae = true
41
+
42
+ cvm.hw_virt.enabled = false
43
+ cvm.hw_virt.nested_paging = false
44
+ # STORAGE
45
+ end
46
+ """
47
+ And I place "hobos/vm.bo" in "/tmp/monitor"
48
+
49
+ Scenario: Create the Monitor Node's Vagrantfile
50
+ Given the file "Vagrantfile" contains nothing
51
+ When I write to "Vagrantfile":
52
+ """
53
+ Vagrant::Config.run do |config|
54
+
55
+ @cc_root_path = File.dirname(File.absolute_path(__FILE__))
56
+ @cc_box_name = "monitor"
57
+ @cc_node_name = "monitor"
58
+ @cc_box_url = (Pathname(@cc_root_path) + 'lucid64.box').to_s
59
+ @cc_ip = "33.33.33.2"
60
+ @cc_http_port = 48625
61
+ @cc_ssh_port = 48624
62
+ @cc_chef_server_url = "http://33.33.33.254:4000"
63
+ @cc_host_mount = "#{@cc_root_path}/mnt"
64
+ @cc_chefserver_path = Pathname(@cc_root_path).parent + 'chef'
65
+ @cc_validation_key_path = "#{@cc_chefserver_path}/mnt/etc/validation.pem"
66
+
67
+ config.vm.define :monitor do |cfg|
68
+
69
+ cfg.send :eval, IO.read("#{@cc_root_path}/hobos/vm.bo")
70
+
71
+ cfg.vm.box = @cc_box_name
72
+ cfg.vm.box_url = @cc_box_url
73
+ cfg.vm.boot_mode = :vrdp # :vrdp (headless) or :gui
74
+
75
+ cfg.vm.network @cc_ip # host-only network IP
76
+ cfg.vm.forward_port "http", 80, @cc_http_port # Accessible outside the host-only network
77
+ cfg.vm.forward_port "ssh", 22, @cc_ssh_port, :auto => true
78
+
79
+ cfg.vm.share_folder("chef", "~/chef", "#{@cc_host_mount}/chef" )
80
+ cfg.vm.share_folder( "chef-client-etc", "/etc/chef", "#{@cc_host_mount}/etc", :nfs => false ) # name, /vm/path, /real/path
81
+
82
+ cfg.vm.provision :chef_server do |chef|
83
+ chef.log_level = :debug
84
+ chef.node_name = @cc_node_name
85
+ chef.chef_server_url = @cc_chef_server_url
86
+ chef.validation_key_path = @cc_validation_key_path
87
+ chef.validation_client_name = "chef-validator"
88
+ chef.client_key_path = "/etc/chef/monitor.pem"
89
+ end
90
+ end
91
+ end
92
+ """
93
+ And I place "Vagrantfile" in "/tmp/monitor"
94
+ And I run `bash -c 'cp ~/chef/vagrant/lucid64.box /tmp/monitor'`
95
+
96
+ Scenario: Configure Knife file for the Monitor's client certificate
97
+ Given the directory ".chef"
98
+ And a file named ".chef/knife.rb" with:
99
+ """
100
+ current_dir = File.dirname(__FILE__)
101
+ user = ENV['CHEF_USER'] || ENV['OPSCODE_USER'] || ENV['USER'] || `whoami`
102
+ org = ENV['CHEF_ORGNAME'] || 'Private'
103
+ email = ENV['CHEF_EMAIL'] || "#{user}@mailinator.com"
104
+ log_path = "#{current_dir}/../log"
105
+
106
+ node_name 'monitor'
107
+ chef_server_url "http://localhost:4000"
108
+ log_level :debug
109
+ log_location "#{log_path}/client_#{node_name}.log"
110
+ verbose_logging true
111
+ client_key "#{current_dir}/#{node_name}.pem"
112
+ cache_type 'BasicFile'
113
+ cache_options :path => "#{log_path}/checksums"
114
+ cookbook_path ["#{current_dir}/../cookbooks", "#{current_dir}/../site-cookbooks"]
115
+ cookbook_copyright user
116
+ cookbook_license "apachev2"
117
+ cookbook_email email
118
+
119
+ # Amazon Web Services:
120
+ knife[:aws_access_key_id] = ENV['AWS_ACCESS_KEY'] if ENV['AWS_ACCESS_KEY']
121
+ knife[:aws_secret_access_key] = ENV['AWS_SECRET_KEY'] if ENV['AWS_SECRET_KEY']
122
+
123
+ # Rackspace:
124
+ knife[:rackspace_api_key] = ENV['RS_API_KEY'] if ENV['RS_API_KEY']
125
+ knife[:rackspace_api_username] = ENV['RS_API_USERNAME'] if ENV['RS_API_USERNAME']
126
+
127
+ # Slicehost
128
+ knife[:slicehost_password] = ENV['SH_PASSWORD'] if ENV['SH_PASSWORD']
129
+
130
+ # Terremark
131
+ knife[:terremark_password] = ENV['TM_PASSWORD'] if ENV['TM_PASSWORD']
132
+ knife[:terremark_username] = ENV['TM_USERNAME'] if ENV['TM_USERNAME']
133
+ knife[:terremark_service] = ENV['TM_SERVICE'] if ENV['TM_SERVICE']
134
+
135
+ """
136
+ And I place ".chef/knife.rb" in "/tmp/monitor"
137
+ And I place ".chef/knife.rb" in "/tmp/monitor/mnt/chef"
138
+
139
+
@@ -0,0 +1,109 @@
1
+ @announce
2
+ Feature: Zenoss Monitoring
3
+ In order to launch a Zenoss server
4
+ As a admin/developer
5
+ I want to define the Chef configuration via executable features
6
+
7
+ Background:
8
+ Given the Chef root directory "/tmp/chef" exists
9
+ And the state of VM "chef" is "running"
10
+ And I switch Vagrant environment
11
+ And the Chef root directory "/tmp/monitor" exists
12
+ And the state of VM "monitor" is not "running"
13
+
14
+ Scenario: Download Cookbooks from one Cookbooks URI
15
+ Given the remote Cookbooks URI "git://github.com/cookbooks/"
16
+ When I clone the Cookbooks:
17
+ | cookbook | branch | tag | ref | destination |
18
+ | apt | master | | | monitor/cookbooks/apt |
19
+ | openssh | master | | 9a8ce8ce44 | monitor/cookbooks/openssh |
20
+ | openssl | master | | | monitor/cookbooks/openssl |
21
+ | yum | master | | | monitor/cookbooks/yum |
22
+ And these local Cookbooks exist:
23
+ | cookbook |
24
+ | apt |
25
+ | openssh |
26
+ | openssl |
27
+ | yum |
28
+ Then I place all in "monitor" in "/tmp/monitor"
29
+
30
+ Scenario: Download Site-Cookbooks from another Cookbooks URI
31
+ Given the remote Cookbooks URI "git@github.com:hedgehog/"
32
+ When I clone the Cookbooks:
33
+ | cookbook | branch | destination |
34
+ | zenoss | qa | monitor/site-cookbooks/zenoss |
35
+ And these local Cookbooks exist:
36
+ | site-cookbook |
37
+ | zenoss |
38
+ Then I place all in "monitor" in "/tmp/monitor"
39
+
40
+ Scenario: Load Roles from Cookbooks
41
+ Given the Chef root directory "/tmp/monitor" exists
42
+ And a Cookbooks path "/tmp/monitor/cookbooks/"
43
+ And a Cookbooks path "/tmp/monitor/site-cookbooks/"
44
+ And the Knife file "/tmp/monitor/.chef/knife.rb"
45
+ When I load the Cookbook Roles:
46
+ | site-cookbook | role |
47
+ | zenoss | Class_Server-SSH-Linux.rb |
48
+ | zenoss | Class_Server-SSH-Linux-MySQL.rb |
49
+ | zenoss | Location_Austin.rb |
50
+ | zenoss | Location_Seattle.rb |
51
+ | zenoss | ZenossServer.rb |
52
+ Then these Roles exist:
53
+ | role |
54
+ | ServerSSHLinux |
55
+ | ServerSSHLinuxMySQL |
56
+ | Austin |
57
+ | Seattle |
58
+ | ZenossServer |
59
+
60
+ Scenario: Load Data Bag from Cookbooks
61
+ Given the Chef root directory "/tmp/monitor" exists
62
+ And a Cookbooks path "/tmp/monitor/cookbooks/"
63
+ And a Cookbooks path "/tmp/monitor/site-cookbooks/"
64
+ And I create the Data Bag "users"
65
+ When I add these Cookbook Data Bag items:
66
+ | site-cookbook | data_bag | item |
67
+ | zenoss | users | Zenoss_User.json |
68
+ | zenoss | users | Zenoss_Readonly_User.json |
69
+ Then these Data Bags exist:
70
+ | data_bag |
71
+ | users |
72
+ And these Data Bags contain:
73
+ | data_bag | item |
74
+ | users | readonly |
75
+ | users | zenossadmin |
76
+
77
+ Scenario: Build Node Run Lists
78
+ Given the Chef root directory "/tmp/monitor" exists
79
+ And the Node "monitor" exists
80
+ When I add these Roles to the Nodes:
81
+ | node | role |
82
+ | monitor | ZenossServer |
83
+
84
+ Scenario: Upload the Cookbooks
85
+ Given the Chef root directory "/tmp/monitor" exists
86
+ When I load the Cookbooks:
87
+ | cookbook | site-cookbook |
88
+ | apt | |
89
+ | openssh | |
90
+ | openssl | |
91
+ | | zenoss |
92
+ | yum | |
93
+ Then these remote Cookbooks exist:
94
+ | cookbook | site-cookbook |
95
+ | apt | |
96
+ | openssh | |
97
+ | openssl | |
98
+ | | zenoss |
99
+ | yum | |
100
+
101
+ @cosmic
102
+ Scenario: Launch the Vagrant VM Monitor
103
+ Given the state of VM "monitor" is not "running"
104
+ And the Chef root directory "/tmp/monitor" exists
105
+ And the Vagrantfile "/tmp/monitor/Vagrantfile" exists
106
+ When I launch the VM "monitor"
107
+ Then the state of VM "monitor" is "running"
108
+
109
+
@@ -1,3 +1,19 @@
1
+ #
2
+ # Author:: Hedgehog (<hedgehogshiatus@gmail.com>)
3
+ # Copyright:: Copyright (c) 2011 Hedgehog.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
1
17
  Given /^the Gem "([^\"]*)" has been required$/ do |gem|
2
18
  Gem.loaded_specs.key?(gem).should be_true
3
19
  end
@@ -12,5 +12,6 @@ require 'cuken/ssh'
12
12
  require 'cuken/cmd'
13
13
  require 'cuken/file'
14
14
  require 'cuken/chef'
15
+ require 'cuken/vagrant'
15
16
 
16
17
  require 'rspec/expectations'
@@ -68,6 +68,21 @@ module ::Cuken
68
68
  'knife '
69
69
  end
70
70
 
71
+ def run_knife(argv=[])
72
+ argv << '--config' << chef.knife_config_file.to_s
73
+ with_args *argv do
74
+ ::Chef::Application::Knife.new.run
75
+ end
76
+ ::Chef::Knife.cuken
77
+ end
78
+
79
+ def knife_config_file_error_handling
80
+ unless chef.knife_config_file && Pathname(chef.knife_config_file).exist?
81
+ chef.knife_config_file = Pathname(chef.local_chef_repo).ascend { |d| h=d+'.chef'+'knife.rb'; break h if h.file? }
82
+ end
83
+ raise(RuntimeError, "chef.knife_config_file is required", caller) unless chef.knife_config_file
84
+ end
85
+
71
86
  def knife_debug
72
87
  @knife_debug ||= true
73
88
  end
@@ -116,6 +131,11 @@ module ::Cuken
116
131
  end
117
132
  end
118
133
 
134
+ def check_chef_root_presence(directory, expect_presence = true)
135
+ chef.root_dir = directory
136
+ check_placed_directory_presence([chef.root_dir], expect_presence)
137
+ end
138
+
119
139
  end
120
140
  end
121
141
  end
@@ -1,3 +1,19 @@
1
+ #
2
+ # Author:: Hedgehog (<hedgehogshiatus@gmail.com>)
3
+ # Copyright:: Copyright (c) 2011 Hedgehog.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
1
17
  module ::Cuken
2
18
  module Api
3
19
  module Chef
@@ -17,7 +33,7 @@ module ::Cuken
17
33
  return ckbk, ckbk_src
18
34
  end
19
35
 
20
- def check_cookbooks_table_presence(table, expect_presence = true)
36
+ def check_cookbook_table_presence(table, expect_presence = true)
21
37
  table.hashes.each do |hsh|
22
38
  ckbk, ckbk_src = parse_to_cookbooks_path(hsh)
23
39
  full_cookbook_src = find_path_in_cookbook_folders(ckbk, ckbk_src, ckbk)
@@ -26,6 +42,19 @@ module ::Cuken
26
42
  end
27
43
  end
28
44
 
45
+ def check_remote_cookbook_table_presence(table, expect_presence = true)
46
+ books = cookbooks_list
47
+ table.hashes.each do |hsh|
48
+ if expect_presence
49
+ books.should include(hsh['cookbook']) if not (hsh['cookbook'].nil? || hsh['cookbook'].empty?)
50
+ books.should include(hsh['site-cookbook']) if not (hsh['site-cookbook'].nil? || hsh['site-cookbook'].empty?)
51
+ else
52
+ books.should_not include(hsh['cookbook']) if not (hsh['cookbook'].nil? || hsh['cookbook'].empty?)
53
+ books.should_not include(hsh['site-cookbook']) if not (hsh['site-cookbook'].nil? || hsh['site-cookbook'].empty?)
54
+ end
55
+ end
56
+ end
57
+
29
58
  def find_path_in_cookbook_folders(ckbk, ckbk_src, path_fragment1, path_fagment2='')
30
59
  verify_cookbook_folders
31
60
  full_data_bag_src = nil
@@ -74,6 +103,38 @@ module ::Cuken
74
103
  end
75
104
  end
76
105
 
106
+ def cookbooks_load(table)
107
+ table.hashes.each do |hsh|
108
+ ckbk, ckbk_src = parse_to_cookbooks_path(hsh)
109
+ full_cookbook_src = find_path_in_cookbook_folders(ckbk, ckbk_src, ckbk)
110
+ cookbook_load(ckbk)
111
+ end
112
+ end
113
+
114
+ def cookbook_load(ckbk)
115
+
116
+ knife_config_file_error_handling()
117
+
118
+ ckbk_pth = nil
119
+ in_chef_root do
120
+ ckbk_pth = unless chef.cookbooks_paths.empty?
121
+ (chef.cookbooks_paths.collect { |pn| pn.expand_path.to_s }).join(':')
122
+ end
123
+ end
124
+
125
+ argv = ['cookbook', 'upload', ckbk]
126
+ ( argv << '--cookbook-path' << ckbk_pth ) if ckbk_pth
127
+ run_knife(argv)
128
+ end
129
+
130
+ def cookbooks_list
131
+
132
+ knife_config_file_error_handling()
133
+
134
+ argv = ['cookbook', 'list']
135
+ run_knife(argv)
136
+ end
137
+
77
138
  end
78
139
  end
79
140
  end
@@ -0,0 +1,89 @@
1
+ #
2
+ # Author:: Hedgehog (<hedgehogshiatus@gmail.com>)
3
+ # Copyright:: Copyright (c) 2011 Hedgehog.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+ module ::Cuken
18
+ module Api
19
+ module Chef
20
+ module DataBag
21
+
22
+ include ::Cuken::Api::Common
23
+
24
+ def load_data_bag_item_table(table)
25
+ table.hashes.each do |hsh|
26
+ data_bag_load(hsh)
27
+ end
28
+ end
29
+
30
+ def check_data_bag_table_presence(table, expect_presence = true)
31
+ bags = data_bag_list
32
+ table.hashes.each do |hsh|
33
+ if expect_presence
34
+ bags.should include(hsh['data_bag'])
35
+ else
36
+ bags.should include(hsh['data_bag'])
37
+ end
38
+ end
39
+ end
40
+
41
+ def check_data_bag_content_table(table, expect_match = true)
42
+ table.hashes.each do |hsh|
43
+ items = data_bag_show(hsh['data_bag'])
44
+ if expect_match
45
+ items.should include(hsh['item'])
46
+ else
47
+ items.should_not include(hsh['item'])
48
+ end
49
+ end
50
+ end
51
+
52
+ def data_bag_create(data_bag_name)
53
+
54
+ knife_config_file_error_handling()
55
+
56
+ argv = ['data', 'bag', 'create', data_bag_name]
57
+ run_knife(argv)
58
+ end
59
+
60
+ def data_bag_load(hsh)
61
+
62
+ knife_config_file_error_handling()
63
+
64
+ ckbk, ckbk_src = parse_to_cookbooks_path(hsh)
65
+ full_data_bag_src = find_path_in_cookbook_folders(ckbk, ckbk_src, ckbk, "data_bags/#{hsh['item']}")
66
+ argv = ['data', 'bag', 'from', 'file', hsh[:data_bag], full_data_bag_src]
67
+ run_knife(argv)
68
+ end
69
+
70
+ def data_bag_list
71
+
72
+ knife_config_file_error_handling()
73
+
74
+ argv = ['data', 'bag', 'list']
75
+ run_knife(argv)
76
+ end
77
+
78
+ def data_bag_show(data_bag)
79
+
80
+ knife_config_file_error_handling()
81
+
82
+ argv = ['data', 'bag', 'show', data_bag]
83
+ run_knife(argv)
84
+ end
85
+
86
+ end
87
+ end
88
+ end
89
+ end
@@ -1,3 +1,19 @@
1
+ #
2
+ # Author:: Hedgehog (<hedgehogshiatus@gmail.com>)
3
+ # Copyright:: Copyright (c) 2011 Hedgehog.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
1
17
  require 'chef/application/knife'
2
18
 
3
19
  module ::Cuken
@@ -0,0 +1,71 @@
1
+ #
2
+ # Author:: Hedgehog (<hedgehogshiatus@gmail.com>)
3
+ # Copyright:: Copyright (c) 2011 Hedgehog.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+ module ::Cuken
18
+ module Api
19
+ module Chef
20
+ module Role
21
+
22
+ include ::Cuken::Api::Common
23
+
24
+ def load_role_table(table)
25
+ in_chef_root do
26
+ table.hashes.each do |hsh|
27
+ case
28
+ when not(hsh['cookbook'].nil? || hsh['cookbook'].empty?)
29
+ src = "cookbooks/#{hsh['cookbook']}/roles/#{hsh['role']}"
30
+ when not(hsh['site-cookbook'].nil? || hsh['site-cookbook'].empty?)
31
+ src = "site-cookbooks/#{hsh['site-cookbook']}/roles/#{hsh['role']}"
32
+ else
33
+ src =""
34
+ end
35
+ role_load(src)
36
+ end
37
+ end
38
+ end
39
+
40
+ def role_load(src)
41
+
42
+ knife_config_file_error_handling()
43
+
44
+ argv = ['role', 'from', 'file', src]
45
+ run_knife(argv)
46
+ end
47
+
48
+ def role_list
49
+
50
+ knife_config_file_error_handling()
51
+
52
+ argv = ['role', 'list']
53
+ run_knife(argv)
54
+ end
55
+
56
+ def check_role_table_presence(table, expect_presence = true)
57
+ roles = role_list
58
+ table.hashes.each do |hsh|
59
+ if expect_presence
60
+ roles.should include(hsh['role'])
61
+ else
62
+ roles.should_not include(hsh['role'])
63
+ end
64
+ end
65
+ end
66
+
67
+ end
68
+ end
69
+ end
70
+ end
71
+
@@ -1,11 +1,29 @@
1
- require 'aruba/api' unless defined? Aruba::Api
2
- require 'chef' unless defined? Chef
3
- require 'grit' unless defined? Grit
4
- require 'vagrant' unless defined? Vagrant
1
+ #
2
+ # Author:: Hedgehog (<hedgehogshiatus@gmail.com>)
3
+ # Copyright:: Copyright (c) 2011 Hedgehog.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+ require 'aruba/api' unless defined? ::Aruba::Api
18
+ require 'chef' unless defined? ::Chef
19
+ require 'grit' unless defined? ::Grit
20
+ require 'vagrant' unless defined? ::Vagrant
5
21
  require 'cuken/api/common'
6
22
  require 'cuken/api/chef/common'
7
23
  require 'cuken/api/chef/cookbook'
8
24
  require 'cuken/api/chef/knife'
25
+ require 'cuken/api/chef/role'
26
+ require 'cuken/api/chef/data_bag'
9
27
 
10
28
  module ::Cuken
11
29
  module Api
@@ -43,10 +61,14 @@ module ::Cuken
43
61
  end
44
62
  end
45
63
 
46
- def clone_pull_error_check(repo, res)
47
- if res[/Could not find Repository /]
48
- raise RuntimeError, "Could not find Cookbook in Repository #{repo}", caller
64
+ def clone_pull_error_check(res)
65
+ if repo = res[/Could not find Repository /]
66
+ raise RuntimeError, "Could not find Repository #{repo}", caller
49
67
  end
68
+ if repo = res[/ERROR: (.*) doesn't exist. Did you enter it correctly?/,1]
69
+ raise RuntimeError, "ERROR: #{repo} doesn't exist. Did you enter it correctly? #{repo}", caller
70
+ end
71
+
50
72
  end
51
73
 
52
74
  def chef_clone_repo(ckbk_path, cookbook = false, repo = chef.remote_chef_repo, type = {'branch' => 'master'})
@@ -55,9 +77,10 @@ module ::Cuken
55
77
  gritty = ::Grit::Git.new(current_dir)
56
78
  announce_or_puts gritty.inspect
57
79
  clone_opts = {:quiet => false, :verbose => true, :progress => true}
58
- clone_opts[:branch] = type['branch'].empty? ? 'master' : type['branch']
80
+ type['branch'] = type['branch'].nil? ? '' : type['branch']
59
81
  type['tag'] = type['tag'].nil? ? '' : type['tag']
60
82
  type['ref'] = type['ref'].nil? ? '' : type['ref']
83
+ clone_opts[:branch] = type['branch'].empty? ? 'master' : type['branch']
61
84
  if pth.directory?
62
85
  announce_or_puts "Pulling: #{repo} into #{pth}"
63
86
  res = gritty.pull(clone_opts, repo, pth.to_s)
@@ -65,7 +88,7 @@ module ::Cuken
65
88
  announce_or_puts "Cloning: #{repo} into #{pth}"
66
89
  res = gritty.clone(clone_opts, repo, pth.to_s)
67
90
  end
68
- clone_pull_error_check(repo, res) if res
91
+ clone_pull_error_check(res) if res
69
92
  update_cookbook_paths(pth, cookbook)
70
93
  unless chef.cookbooks_paths.empty? # is empty after cloning default chef-repo
71
94
  grotty = ::Grit::Git.new((pth + '.git').to_s)
@@ -175,3 +198,22 @@ module ::Cuken
175
198
  end
176
199
  end
177
200
  end
201
+
202
+ class ::Chef
203
+ class Knife
204
+ class << self
205
+ attr_accessor :cuken
206
+ end
207
+ private
208
+ def output(data)
209
+ ::Chef::Knife.cuken = data
210
+ end
211
+ module Core
212
+ class GenericPresenter
213
+ def format_cookbook_list_for_display(data)
214
+ ::Chef::Knife.cuken = data
215
+ end
216
+ end
217
+ end
218
+ end
219
+ end