cuken 0.1.13 → 0.1.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. data/.rvmrc +61 -0
  2. data/Gemfile +17 -15
  3. data/Gemfile.lock +55 -63
  4. data/VERSION +1 -1
  5. data/cuken.gems +46 -0
  6. data/cuken.gemspec +85 -31
  7. data/features/about.md +4 -0
  8. data/features/avagrant_steps/vagrant_steps.feature +13 -0
  9. data/features/chef_examples/cookbooks_cookbook.feature +1 -1
  10. data/features/chef_examples/cookbooks_metadata.feature +5 -5
  11. data/features/chef_examples/cookbooks_repo.feature +1 -1
  12. data/features/chef_examples/knife_admin_client.feature +12 -12
  13. data/features/chef_examples/knife_client_create.feature +1 -1
  14. data/features/chef_examples/zenoss_example/01_chef_server_setup.feature +1 -1
  15. data/features/chef_examples/zenoss_example/02_monitor_vm_setup.feature +1 -1
  16. data/features/chef_steps/cookbook_steps.feature +6 -16
  17. data/features/command_examples/commands.feature +3 -3
  18. data/features/command_examples/exit_statuses.feature +49 -0
  19. data/features/command_examples/file_system_commands.feature +128 -0
  20. data/features/command_examples/flushing.feature +24 -0
  21. data/features/command_examples/interactive.feature +57 -0
  22. data/features/command_examples/no_clobber.feature +41 -0
  23. data/features/command_examples/output.feature +205 -0
  24. data/features/command_steps/command_steps.feature +49 -42
  25. data/features/file_examples/files.feature +5 -5
  26. data/features/git_examples/git_clone.feature +33 -0
  27. data/features/ssh_examples/ssh.feature +11 -2
  28. data/features/step_definitions/cuken_steps.rb +3 -2
  29. data/features/support/env.rb +2 -1
  30. data/lib/cuken/all.rb +1 -0
  31. data/lib/cuken/api/aruba/api.rb +342 -0
  32. data/lib/cuken/api/aruba/hooks.rb +63 -0
  33. data/lib/cuken/api/aruba/process.rb +74 -0
  34. data/lib/cuken/api/aruba.rb +5 -0
  35. data/lib/cuken/api/chef/common.rb +8 -1
  36. data/lib/cuken/api/chef/cookbook.rb +31 -5
  37. data/lib/cuken/api/chef/knife.rb +3 -3
  38. data/lib/cuken/api/chef/role.rb +3 -3
  39. data/lib/cuken/api/chef.rb +98 -9
  40. data/lib/cuken/api/cmd.rb +8 -8
  41. data/lib/cuken/api/common.rb +11 -23
  42. data/lib/cuken/api/file.rb +38 -38
  43. data/lib/cuken/api/git/clone.rb +25 -0
  44. data/lib/cuken/api/git/common.rb +37 -0
  45. data/lib/cuken/api/git/remote.rb +16 -0
  46. data/lib/cuken/api/git/repository.rb +62 -0
  47. data/lib/cuken/api/git.rb +69 -0
  48. data/lib/cuken/api/rvm/common.rb +10 -0
  49. data/lib/cuken/api/rvm/gemsets.rb +33 -0
  50. data/lib/cuken/api/rvm/wip.rb +554 -0
  51. data/lib/cuken/api/rvm.rb +25 -479
  52. data/lib/cuken/api/ssh.rb +85 -4
  53. data/lib/cuken/api/vagrant/common.rb +7 -4
  54. data/lib/cuken/api/vagrant/v_m.rb +2 -2
  55. data/lib/cuken/api/vagrant.rb +3 -3
  56. data/lib/cuken/common.rb +3 -1
  57. data/lib/cuken/cucumber/chef/common.rb +3 -3
  58. data/lib/cuken/cucumber/chef/cookbook/action.rb +81 -0
  59. data/lib/cuken/cucumber/chef/cookbook/local.rb +71 -0
  60. data/lib/cuken/cucumber/chef/cookbook/remote.rb +37 -0
  61. data/lib/cuken/cucumber/chef/cookbook.rb +3 -140
  62. data/lib/cuken/cucumber/chef/cookbook_steps.rb +1 -1
  63. data/lib/cuken/cucumber/chef/deploy_steps.rb +1 -1
  64. data/lib/cuken/cucumber/chef/done_directory_steps.rb +2 -2
  65. data/lib/cuken/cucumber/chef/done_file_steps.rb +5 -5
  66. data/lib/cuken/cucumber/chef/knife.rb +1 -1
  67. data/lib/cuken/cucumber/chef.rb +1 -1
  68. data/lib/cuken/cucumber/cmd/execution.rb +34 -0
  69. data/lib/cuken/cucumber/cmd/exit_status.rb +30 -0
  70. data/lib/cuken/cucumber/cmd.rb +2 -36
  71. data/lib/cuken/cucumber/common.rb +42 -6
  72. data/lib/cuken/cucumber/file.rb +42 -37
  73. data/lib/cuken/cucumber/git/clone.rb +51 -0
  74. data/lib/cuken/cucumber/git/common.rb +36 -0
  75. data/lib/cuken/cucumber/git/local.rb +19 -0
  76. data/lib/cuken/cucumber/git/remote.rb +22 -0
  77. data/lib/cuken/cucumber/git.rb +26 -0
  78. data/lib/cuken/cucumber/output/all.rb +41 -0
  79. data/lib/cuken/cucumber/output/cmd.rb +46 -0
  80. data/lib/cuken/cucumber/output/stderr.rb +33 -0
  81. data/lib/cuken/cucumber/output/stdout.rb +34 -0
  82. data/lib/cuken/cucumber/rvm/common.rb +0 -0
  83. data/lib/cuken/cucumber/rvm/gemsets.rb +32 -0
  84. data/lib/cuken/cucumber/rvm/hooks.rb +0 -0
  85. data/lib/cuken/cucumber/rvm.rb +3 -1
  86. data/lib/cuken/cucumber/ssh/common.rb +51 -0
  87. data/lib/cuken/cucumber/ssh.rb +3 -35
  88. data/lib/cuken/cucumber/vagrant.rb +1 -1
  89. data/lib/cuken/git.rb +21 -0
  90. data/spec/api/rvm/gemsets/api_spec.rb +41 -0
  91. data/spec/api/rvm/gemsets/helper_spec.rb +19 -0
  92. data/spec/api/rvm_spec.rb +63 -15
  93. data/spec/api/vagrant/v_m/Vagrantfile +82 -0
  94. data/spec/api/vagrant/v_m/api_spec.rb +37 -0
  95. data/spec/spec_helper.rb +39 -0
  96. metadata +123 -45
  97. data/spec/cuken_spec.rb +0 -7
@@ -14,9 +14,25 @@
14
14
  # See the License for the specific language governing permissions and
15
15
  # limitations under the License.
16
16
  #
17
- require 'aruba/api' unless defined? ::Aruba::Api
17
+ #require 'aruba/api' unless defined? ::Aruba::Api
18
18
  require 'chef' unless defined? ::Chef
19
19
  require 'grit' unless defined? ::Grit
20
+ #
21
+ # Author:: Hedgehog (<hedgehogshiatus@gmail.com>)
22
+ # Copyright:: Copyright (c) 2011 Hedgehog.
23
+ #
24
+ # Licensed under the Apache License, Version 2.0 (the "License");
25
+ # you may not use this file except in compliance with the License.
26
+ # You may obtain a copy of the License at
27
+ #
28
+ # http://www.apache.org/licenses/LICENSE-2.0
29
+ #
30
+ # Unless required by applicable law or agreed to in writing, software
31
+ # distributed under the License is distributed on an "AS IS" BASIS,
32
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
33
+ # See the License for the specific language governing permissions and
34
+ # limitations under the License.
35
+ #
20
36
  require 'vagrant' unless defined? ::Vagrant
21
37
  require 'cuken/api/common'
22
38
  require 'cuken/api/chef/common'
@@ -30,6 +46,7 @@ module ::Cuken
30
46
  module Chef
31
47
 
32
48
  include ::Cuken::Api::Chef::Common
49
+ include ::Cuken::Api::Aruba::Api
33
50
 
34
51
  def append_cookbook_path(cookbook, lp, lrp)
35
52
  if lrp.exist?
@@ -70,28 +87,40 @@ module ::Cuken
70
87
  end
71
88
  end
72
89
 
73
- def chef_clone_repo(ckbk_path, cookbook = false, repo = chef.remote_chef_repo, type = {'branch' => 'master'})
74
- in_current_dir do
90
+ def chef_clone_repo(ckbk_path, cookbook = false, repo = chef.remote_chef_repo, type = {'branch' => 'master'}, deep_clone = true)
91
+ in_dir do
75
92
  pth = Pathname(ckbk_path).expand_path
76
- gritty = ::Grit::Git.new(current_dir)
93
+ gritty = ::Grit::Git.new((pth + '.git').to_s)
77
94
  announce_or_puts gritty.inspect
78
- clone_opts = {:quiet => false, :verbose => true, :progress => true}
95
+ clone_opts = {:depth => 1, :quiet => false, :verbose => true, :progress => true}
79
96
  type['branch'] = type['branch'].nil? ? '' : type['branch']
80
97
  type['tag'] = type['tag'].nil? ? '' : type['tag']
81
98
  type['ref'] = type['ref'].nil? ? '' : type['ref']
82
- clone_opts[:branch] = type['branch'].empty? ? 'master' : type['branch']
99
+ clone_opts[:depth] = 1 unless deep_clone
83
100
  if pth.directory?
84
101
  announce_or_puts "Pulling: #{repo} into #{pth}"
85
- res = gritty.pull(clone_opts, repo, pth.to_s)
102
+ FileUtils.cd(pth.to_s) do
103
+ res = gritty.pull(clone_opts, repo)
104
+ end
105
+ clone_opts[:branch] = type['branch'].empty? ? 'master' : type['branch']
86
106
  else
107
+ clone_opts[:branch] = type['branch'].empty? ? 'master' : type['branch']
87
108
  announce_or_puts "Cloning: #{repo} into #{pth}"
88
109
  res = gritty.clone(clone_opts, repo, pth.to_s)
110
+ Dir.chdir(pth.to_s) do
111
+ if ::File.exist?('.gitmodules')
112
+ cmd = "git submodule init"
113
+ announce_or_puts `#{cmd}`
114
+ cmd = "git submodule update"
115
+ announce_or_puts `#{cmd}`
116
+ end
117
+ end
89
118
  end
90
119
  clone_pull_error_check(res) if res
91
120
  update_cookbook_paths(pth, cookbook)
92
121
  unless chef.cookbooks_paths.empty? # is empty after cloning default chef-repo
93
122
  grotty = ::Grit::Git.new((pth + '.git').to_s)
94
- grotty.checkout( { :b => true }, clone_opts[:branch] )
123
+ grotty.checkout( { :B => clone_opts[:branch]||'master' } )
95
124
  if !type['tag'].empty? || !type['ref'].empty?
96
125
  grotty.checkout( { :B => true }, 'cuken', type['tag']||type['ref'] )
97
126
  else
@@ -102,6 +131,66 @@ module ::Cuken
102
131
  end
103
132
  end
104
133
 
134
+ def chef_submodule_repo(ckbk_path, cookbook = false, repo = chef.remote_chef_repo, type = {'branch' => 'master'}, deep_clone = true)
135
+ in_dir do
136
+ pth = (Pathname(chef.root_dir).expand_path)+ckbk_path
137
+ gritty = ::Grit::Git.new((pth + '.git').to_s)
138
+ announce_or_puts gritty.inspect
139
+ clone_opts = {:quiet => false, :verbose => true, :progress => true}
140
+ clone_opts[:depth] = 1 unless deep_clone
141
+ checkout = type['ref']||type['tag']||type['branch']||'master'
142
+ type['branch'] = type['branch'].nil? ? '' : type['branch']
143
+ type['tag'] = type['tag'].nil? ? '' : type['tag']
144
+ type['ref'] = type['ref'].nil? ? '' : type['ref']
145
+ res = nil
146
+ if pth.directory?
147
+ announce_or_puts "Updating submodule: #{repo} at #{pth}"
148
+ FileUtils.cd(pth.to_s) do
149
+ cmd = "git fetch"
150
+ res = `#{cmd}`
151
+ announce_or_puts res
152
+ end
153
+ clone_opts[:branch] = type['branch'].empty? ? 'master' : type['branch']
154
+ else
155
+ clone_opts[:branch] = type['branch'].empty? ? 'master' : type['branch']
156
+ announce_or_puts "Adding submodule: #{repo} at #{pth}"
157
+ FileUtils.cd(chef.root_dir) do
158
+ cmd = "git submodule add #{repo} #{pth.to_s}"
159
+ announce_or_puts `#{cmd}`
160
+ end
161
+ FileUtils.cd(pth.to_s) do
162
+ cmd = "git submodule init"
163
+ res = `#{cmd}`
164
+ announce_or_puts res
165
+ cmd = "git submodule update"
166
+ res = `#{cmd}`
167
+ announce_or_puts res
168
+ end
169
+ end
170
+ clone_pull_error_check(res) if res
171
+ update_cookbook_paths(pth, cookbook)
172
+ unless chef.cookbooks_paths.empty? # is empty after cloning default chef-repo
173
+ grotty = ::Grit::Git.new((pth + '.git').to_s)
174
+ cmd = "git submodule add #{repo} #{pth.to_s}"
175
+ announce_or_puts `#{cmd}`
176
+ FileUtils.cd(pth.to_s) do
177
+ cmd = "git submodule init"
178
+ res = `#{cmd}`
179
+ announce_or_puts res
180
+ cmd = "git submodule update"
181
+ res = `#{cmd}`
182
+ announce_or_puts res
183
+ if !type['tag'].empty? || !type['ref'].empty?
184
+ grotty.checkout( { :B => true }, 'cuken', type['tag']||type['ref'] )
185
+ else
186
+ grotty.checkout( { :B => true }, 'cuken' )
187
+ end
188
+ end
189
+ end
190
+ pth
191
+ end
192
+ end
193
+
105
194
  def run_knife_command(cmd, interactive=false)
106
195
  no_ckbk_pth_opt = ['cookbook delete', 'role from file'].each{|str| break true if cmd[/#{str}/]}
107
196
  no_ckbk_pth = chef.cookbooks_paths.empty?
@@ -112,7 +201,7 @@ module ::Cuken
112
201
  ckbk_pth_opt = true
113
202
  end
114
203
  ckbk_pth_opt = false if no_ckbk_pth_opt.is_a? TrueClass
115
- in_current_dir do
204
+ in_dir do
116
205
  unless chef.knife_config_file
117
206
  chef.knife_config_file = Pathname(chef.local_chef_repo).ascend { |d| h=d+'.chef'+'knife.rb'; break h if h.file? }
118
207
  end
data/lib/cuken/api/cmd.rb CHANGED
@@ -1,9 +1,9 @@
1
- require 'aruba/api' unless defined? Aruba::Api
1
+ #require 'aruba/api' unless defined? Aruba::Api
2
2
 
3
- module Cuken
4
- module Api
5
- module Cmd
6
-
7
- end
8
- end
9
- end
3
+ #module Cuken
4
+ # module Api
5
+ # module Cmd
6
+ #
7
+ # end
8
+ # end
9
+ #end
@@ -1,4 +1,5 @@
1
- require 'aruba/api' unless defined? Aruba::Api
1
+ require 'cuken/api/aruba'
2
+ World(Cuken::Api::Aruba::Api)
2
3
 
3
4
  module ::Cuken
4
5
  module Api
@@ -16,29 +17,16 @@ module ::Cuken
16
17
  end
17
18
  end
18
19
 
19
- end
20
- end
21
- end
22
-
23
- #
24
- # We strip ANSI code from output strings.
25
- #
26
- module ::Aruba
27
- class Process
28
- def remove_ansi_codes(str)
29
- str.gsub(/\e\[(\d+)m/, '')
30
- end
31
- def stdout
32
- wait_for_io do
33
- @out.rewind
34
- remove_ansi_codes(@out.read)
35
- end
36
- end
37
- def stderr
38
- wait_for_io do
39
- @err.rewind
40
- remove_ansi_codes(@err.read)
20
+ def clone_pull_error_check(res)
21
+ if repo = res[/Could not find Repository /]
22
+ raise RuntimeError, "Could not find Repository #{repo}", caller
23
+ end
24
+ if repo = res[/ERROR: (.*) doesn't exist. Did you enter it correctly?/,1]
25
+ raise RuntimeError, "ERROR: #{repo} doesn't exist. Did you enter it correctly? #{repo}", caller
26
+ end
41
27
  end
28
+
42
29
  end
43
30
  end
44
31
  end
32
+
@@ -1,4 +1,4 @@
1
- require 'aruba/api' unless defined? Aruba::Api
1
+ #require 'aruba/api' unless defined? Aruba::Api
2
2
  require 'etc'
3
3
 
4
4
  module Cuken
@@ -6,24 +6,24 @@ module Cuken
6
6
  module File
7
7
  include Etc
8
8
 
9
- def check_file_content(file, partial_content, expect_match, times = 1)
10
- regexp = regexp(partial_content)
11
- seen_count = 0
12
- prep_for_fs_check do
13
- content = IO.read(file)
14
- while (seen_count < times.to_i || content =~ regexp)do
15
- if content =~ regexp
16
- content = content.sub(regexp,'')
17
- seen_count+=1
18
- end
19
- end
20
- if expect_match
21
- seen_count.should == times.to_i
22
- else
23
- seen_count.should_not == times.to_i
24
- end
25
- end
26
- end
9
+ # def check_file_content(file, partial_content, expect_match, times = 1)
10
+ # regexp = regexp(partial_content)
11
+ # seen_count = 0
12
+ # prep_for_fs_check do
13
+ # content = IO.read(::File.expand_path(file))
14
+ # while (seen_count < times.to_i || content =~ regexp)do
15
+ # if content =~ regexp
16
+ # content = content.sub(regexp,'')
17
+ # seen_count+=1
18
+ # end
19
+ # end
20
+ # if expect_match
21
+ # seen_count.should == times.to_i
22
+ # else
23
+ # seen_count.should_not == times.to_i
24
+ # end
25
+ # end
26
+ # end
27
27
 
28
28
  def parse_mode(mode, octal=false)
29
29
  return mode.to_s if octal
@@ -35,21 +35,21 @@ module Cuken
35
35
  end
36
36
 
37
37
  def record_amtimes(filename)
38
- in_current_dir do
38
+ in_dir do
39
39
  @recorded_mtime = ::File.mtime(filename)
40
40
  @recorded_atime = ::File.atime(filename)
41
41
  end
42
42
  end
43
43
 
44
44
  def check_modes(expected_mode, filename, octal = false)
45
- in_current_dir do
45
+ in_dir do
46
46
  cstats = ::File.stat(filename)
47
47
  parse_mode(cstats.mode, octal).should match /#{expected_mode}\Z/# ].should_not be_nil
48
48
  end
49
49
  end
50
50
 
51
51
  def check_uid(dirname, owner)
52
- in_current_dir do
52
+ in_dir do
53
53
  uid = ::Etc.getpwnam(owner).uid
54
54
  cstats = ::File.stat(dirname)
55
55
  cstats.uid.should == uid
@@ -57,7 +57,7 @@ module Cuken
57
57
  end
58
58
 
59
59
  def check_amtime_change(filename, time_type)
60
- in_current_dir do
60
+ in_dir do
61
61
  case time_type
62
62
  when "m"
63
63
  current_mtime = ::File.mtime(filename)
@@ -70,9 +70,9 @@ module Cuken
70
70
  end
71
71
 
72
72
  def place_file(src, dst)
73
- dest = Pathname(dst).expand_path.realdirpath
73
+ dest = Pathname(dst).expand_path
74
74
  FileUtils.mkdir_p((dest+src).dirname.to_s)
75
- in_current_dir do
75
+ in_dir do
76
76
  opts = {:verbose => true, :preserve => true, :remove_destination => true}
77
77
  FileUtils.cp_r(src, (dest+src).to_s, opts).should be_nil
78
78
  FileUtils.compare_file(src, (dest+src).to_s).should be_true
@@ -82,22 +82,22 @@ module Cuken
82
82
  def place_folder_contents(dest_dir_name, src_dir_name)
83
83
  dest = Pathname(dest_dir_name).expand_path.realdirpath
84
84
  dest_parent = dest.dirname.to_s
85
- FileUtils.mkdir_p((dest+src_dir_name).to_s)
86
- in_current_dir do
85
+ ::FileUtils.mkdir_p((dest+src_dir_name).to_s)
86
+ in_dir do
87
87
  opts = {:verbose => true, :preserve => true, :remove_destination => true}
88
- FileUtils.cp_r(src_dir_name+'/.', dest.to_s, opts).should be_nil
88
+ ::FileUtils.cp_r(src_dir_name+'/.', dest.to_s, opts).should be_nil
89
89
  end
90
- Dir.glob("#{src_dir_name}/**/*").each do |fn|
91
- if File.file?(fn)
92
- fn2 = File.join(dest_parent, fn)
93
- FileUtils.compare_file(fn, fn2).should be_true
90
+ ::Dir.glob("#{src_dir_name}/**/*").each do |fn|
91
+ if ::File.file?(fn.to_s)
92
+ fn2 = ::File.join(dest_parent, fn)
93
+ ::FileUtils.compare_file(fn, fn2).should be_true if ::File.file?(fn2.to_s)
94
94
  end
95
95
  end
96
96
  end
97
97
 
98
98
  def check_placed_file_content(file, partial_content, expect_match)
99
99
  prep_for_placed_fs_check do
100
- content = IO.read(file)
100
+ content = IO.read(::File.expand_path(file))
101
101
  if expect_match
102
102
  content.should include partial_content
103
103
  else
@@ -115,9 +115,9 @@ module Cuken
115
115
  prep_for_placed_fs_check do
116
116
  paths.each do |path|
117
117
  if expect_presence
118
- ::File.should be_file(path)
118
+ Pathname(path).expand_path.should be_file
119
119
  else
120
- ::File.should_not be_file(path)
120
+ Pathname(path).expand_path.should_not be_file
121
121
  end
122
122
  end
123
123
  end
@@ -127,11 +127,11 @@ module Cuken
127
127
  prep_for_placed_fs_check do
128
128
  paths.each do |path|
129
129
  if expect_presence
130
- dest = Pathname(path).expand_path.realdirpath
130
+ dest = Pathname(path).expand_path
131
131
  Pathname(dest).mkpath
132
- Pathname(path).should be_directory
132
+ Pathname(path).expand_path.should be_directory
133
133
  else
134
- Pathname(path).should_not be_directory
134
+ Pathname(path).expand_path.should_not be_directory
135
135
  end
136
136
  end
137
137
  end
@@ -0,0 +1,25 @@
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 Git
20
+ module Clone
21
+
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,37 @@
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 Git
20
+ module Common
21
+
22
+ include ::Grit
23
+ ::Grit.debug = true
24
+ attr_accessor :git_uri,
25
+ :local_git_repo,
26
+ :remote_git_repo
27
+
28
+
29
+ def git
30
+ @remote_git_repo ||= "git://github.com/cookbooks/chef-repo.git"
31
+ @git ||= self
32
+ end
33
+
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,16 @@
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
+ #
@@ -0,0 +1,62 @@
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 Git
20
+ module Repository
21
+
22
+ def parse_to_repository_path(hsh)
23
+ case
24
+ when not(hsh['repo'].nil? || hsh['repo'].empty?)
25
+ ckbk = hsh['repo']
26
+ ckbk_src = "#{ckbk}"
27
+ when not(hsh['repository'].nil? || hsh['repository'].empty?)
28
+ ckbk = hsh['repository']
29
+ ckbk_src = "#{ckbk}"
30
+ else
31
+ src =""
32
+ end
33
+ return ckbk, ckbk_src
34
+ end
35
+
36
+ def check_repository_table_presence(table, expect_presence = true, curr_dir = current_dir)
37
+ table.hashes.each do |hsh|
38
+ ckbk, ckbk_src = parse_to_repository_path(hsh)
39
+ full_repo_src = ckbk
40
+ announce_or_puts(%{Looking for repository: #{full_repo_src}}) if @announce_env
41
+ check_repository_presence(full_repo_src, expect_presence, curr_dir)
42
+ end
43
+ end
44
+
45
+ def check_repository_presence(repo, expect_presence = true, curr_dir = current_dir)
46
+ in_dir(curr_dir) do |pn|
47
+ curr_path = Pathname(pn).basename.to_s
48
+ condition = Pathname(pn).exist?
49
+ given_repo = Pathname(repo).basename.to_s if repo
50
+ result = given_repo == curr_path
51
+ if condition && result
52
+ given_repo.should == curr_path
53
+ announce_or_puts(%{Found cookbook: #{pn}}) if @announce_env
54
+ end
55
+ end
56
+ end
57
+
58
+ end
59
+ end
60
+ end
61
+ end
62
+
@@ -0,0 +1,69 @@
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 'grit' unless defined? ::Grit
18
+ require 'cuken/api/common'
19
+ require 'cuken/api/git/common'
20
+ require 'cuken/api/git/clone'
21
+ require 'cuken/api/git/remote'
22
+ require 'cuken/api/git/repository'
23
+
24
+ module ::Cuken
25
+ module Api
26
+ module Git
27
+
28
+ include ::Cuken::Api::Git::Common
29
+ include ::Cuken::Api::Git::Clone
30
+ include ::Cuken::Api::Git::Repository
31
+ include ::Cuken::Api::Aruba::Api
32
+
33
+ #TODO: Refactor with chef_clone_repo method
34
+ def git_clone_repo(repo_path, repo = git.remote_git_repo, type = {'branch' => 'master'} , deep_clone = true)
35
+ in_dir do
36
+ pth = Pathname(repo_path).expand_path
37
+ gritty = ::Grit::Git.new((pth + '.git').to_s)
38
+ announce_or_puts gritty.inspect
39
+ clone_opts = {:quiet => false, :verbose => true, :progress => true}
40
+ clone_opts[:depth] = 1 unless deep_clone
41
+ type['branch'] = type['branch'].nil? ? '' : type['branch']
42
+ type['tag'] = type['tag'].nil? ? '' : type['tag']
43
+ type['ref'] = type['ref'].nil? ? '' : type['ref']
44
+ if pth.directory?
45
+ announce_or_puts "Pulling: #{repo} into #{pth}"
46
+ FileUtils.cd(pth.to_s) do
47
+ res = gritty.pull(clone_opts, repo)
48
+ end
49
+ clone_opts[:branch] = type['branch'].empty? ? 'master' : type['branch']
50
+ else
51
+ clone_opts[:branch] = type['branch'].empty? ? 'master' : type['branch']
52
+ announce_or_puts "Cloning: #{repo} into #{pth}"
53
+ res = gritty.clone(clone_opts, repo, pth.to_s)
54
+ end
55
+ clone_pull_error_check(res) if res
56
+ grotty = ::Grit::Git.new((pth + '.git').to_s)
57
+ grotty.checkout( { :B => clone_opts[:branch]||'master' } )
58
+ if !type['tag'].empty? || !type['ref'].empty?
59
+ grotty.checkout( { :B => true }, 'cuken', type['tag']||type['ref'] )
60
+ else
61
+ grotty.checkout( { :B => true }, 'cuken' )
62
+ end
63
+ pth
64
+ end
65
+ end
66
+
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,10 @@
1
+ module ::Cuken
2
+ module Api
3
+ module Rvm
4
+ module Common
5
+ end
6
+ end
7
+ end
8
+ end
9
+
10
+
@@ -0,0 +1,33 @@
1
+ module ::Cuken
2
+ module Api
3
+ module Rvm
4
+ module Gemsets
5
+
6
+ include ::Cuken::Api::Rvm::Common
7
+ #include ::Cuken::Api::Aruba::Api
8
+
9
+ def check_gemset_activation(gemset, expect_active = true)
10
+ if expect_active
11
+ rvm.current.environment_name.should match(gemset)
12
+ else
13
+ rvm.current.environment_name.should_not match(gemset)
14
+ end
15
+ end
16
+
17
+ def check_gemset_presence(gemsets, expect_presence = true)
18
+ if expect_presence
19
+ gemsets.each do |gs|
20
+ rvm.gemset.list.include?(gs).should be_true
21
+ end
22
+ else
23
+ gemsets.each do |gs|
24
+ pending "this is failing for some reason"
25
+ rvm.gemset.list.include?(gs).should be_false
26
+ end
27
+ end
28
+ end
29
+
30
+ end
31
+ end
32
+ end
33
+ end