vanagon 0.3.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +13 -0
  3. data/README.md +175 -0
  4. data/bin/build +33 -0
  5. data/bin/devkit +22 -0
  6. data/bin/repo +26 -0
  7. data/bin/ship +15 -0
  8. data/lib/vanagon.rb +8 -0
  9. data/lib/vanagon/common.rb +2 -0
  10. data/lib/vanagon/common/pathname.rb +87 -0
  11. data/lib/vanagon/common/user.rb +25 -0
  12. data/lib/vanagon/component.rb +157 -0
  13. data/lib/vanagon/component/dsl.rb +307 -0
  14. data/lib/vanagon/component/source.rb +66 -0
  15. data/lib/vanagon/component/source/git.rb +60 -0
  16. data/lib/vanagon/component/source/http.rb +158 -0
  17. data/lib/vanagon/driver.rb +112 -0
  18. data/lib/vanagon/engine/base.rb +82 -0
  19. data/lib/vanagon/engine/docker.rb +40 -0
  20. data/lib/vanagon/engine/local.rb +40 -0
  21. data/lib/vanagon/engine/pooler.rb +85 -0
  22. data/lib/vanagon/errors.rb +28 -0
  23. data/lib/vanagon/extensions/string.rb +11 -0
  24. data/lib/vanagon/optparse.rb +62 -0
  25. data/lib/vanagon/platform.rb +245 -0
  26. data/lib/vanagon/platform/deb.rb +71 -0
  27. data/lib/vanagon/platform/dsl.rb +293 -0
  28. data/lib/vanagon/platform/osx.rb +100 -0
  29. data/lib/vanagon/platform/rpm.rb +76 -0
  30. data/lib/vanagon/platform/rpm/wrl.rb +39 -0
  31. data/lib/vanagon/platform/solaris_10.rb +182 -0
  32. data/lib/vanagon/platform/solaris_11.rb +138 -0
  33. data/lib/vanagon/platform/swix.rb +35 -0
  34. data/lib/vanagon/project.rb +251 -0
  35. data/lib/vanagon/project/dsl.rb +218 -0
  36. data/lib/vanagon/utilities.rb +299 -0
  37. data/spec/fixures/component/invalid-test-fixture.json +3 -0
  38. data/spec/fixures/component/mcollective.service +1 -0
  39. data/spec/fixures/component/test-fixture.json +4 -0
  40. data/spec/lib/vanagon/common/pathname_spec.rb +103 -0
  41. data/spec/lib/vanagon/common/user_spec.rb +36 -0
  42. data/spec/lib/vanagon/component/dsl_spec.rb +443 -0
  43. data/spec/lib/vanagon/component/source/git_spec.rb +19 -0
  44. data/spec/lib/vanagon/component/source/http_spec.rb +43 -0
  45. data/spec/lib/vanagon/component/source_spec.rb +99 -0
  46. data/spec/lib/vanagon/component_spec.rb +22 -0
  47. data/spec/lib/vanagon/engine/base_spec.rb +40 -0
  48. data/spec/lib/vanagon/engine/docker_spec.rb +40 -0
  49. data/spec/lib/vanagon/engine/pooler_spec.rb +54 -0
  50. data/spec/lib/vanagon/platform/deb_spec.rb +60 -0
  51. data/spec/lib/vanagon/platform/dsl_spec.rb +128 -0
  52. data/spec/lib/vanagon/platform/rpm_spec.rb +41 -0
  53. data/spec/lib/vanagon/platform/solaris_11_spec.rb +44 -0
  54. data/spec/lib/vanagon/platform_spec.rb +53 -0
  55. data/spec/lib/vanagon/project/dsl_spec.rb +203 -0
  56. data/spec/lib/vanagon/project_spec.rb +44 -0
  57. data/spec/lib/vanagon/utilities_spec.rb +140 -0
  58. data/templates/Makefile.erb +116 -0
  59. data/templates/deb/changelog.erb +5 -0
  60. data/templates/deb/conffiles.erb +3 -0
  61. data/templates/deb/control.erb +21 -0
  62. data/templates/deb/dirs.erb +3 -0
  63. data/templates/deb/docs.erb +1 -0
  64. data/templates/deb/install.erb +3 -0
  65. data/templates/deb/postinst.erb +46 -0
  66. data/templates/deb/postrm.erb +15 -0
  67. data/templates/deb/prerm.erb +17 -0
  68. data/templates/deb/rules.erb +25 -0
  69. data/templates/osx/postinstall.erb +24 -0
  70. data/templates/osx/preinstall.erb +19 -0
  71. data/templates/osx/project-installer.xml.erb +19 -0
  72. data/templates/rpm/project.spec.erb +217 -0
  73. data/templates/solaris/10/depend.erb +3 -0
  74. data/templates/solaris/10/pkginfo.erb +13 -0
  75. data/templates/solaris/10/postinstall.erb +37 -0
  76. data/templates/solaris/10/preinstall.erb +7 -0
  77. data/templates/solaris/10/preremove.erb +6 -0
  78. data/templates/solaris/10/proto.erb +5 -0
  79. data/templates/solaris/11/p5m.erb +73 -0
  80. metadata +172 -0
@@ -0,0 +1,41 @@
1
+ require 'vanagon/platform/rpm'
2
+
3
+ describe "Vanagon::Platform::RPM" do
4
+ let(:platforms) do
5
+ [
6
+ {
7
+ :name => "el-5-i386",
8
+ :os_name => "el",
9
+ :os_version => "5",
10
+ :architecture => "i386",
11
+ :output_dir => "el/5/products/i386",
12
+ :output_dir_with_target => "el/5/thing/i386",
13
+ },
14
+ {
15
+ :name => "fedora-21-x86_64",
16
+ :os_name => "fedora",
17
+ :os_version => "21",
18
+ :architecture => "x86_64",
19
+ :output_dir => "fedora/21/products/x86_64",
20
+ :output_dir_with_target => "fedora/21/thing/x86_64",
21
+ },
22
+ ]
23
+ end
24
+
25
+ describe "#output_dir" do
26
+ it "returns an output dir consistent with the packaging repo" do
27
+ platforms.each do |plat|
28
+ cur_plat = Vanagon::Platform::RPM.new(plat[:name])
29
+ expect(cur_plat.output_dir).to eq(plat[:output_dir])
30
+ end
31
+ end
32
+
33
+ it "adds the target repo in the right way" do
34
+ platforms.each do |plat|
35
+ cur_plat = Vanagon::Platform::RPM.new(plat[:name])
36
+ expect(cur_plat.output_dir('thing')).to eq(plat[:output_dir_with_target])
37
+ end
38
+ end
39
+ end
40
+ end
41
+
@@ -0,0 +1,44 @@
1
+ require 'vanagon/platform/solaris_11'
2
+
3
+ describe "Vanagon::Platform::Solaris_11" do
4
+ let(:platform) do
5
+ {
6
+ :name => 'solaris-11-i386',
7
+ :block => %Q[platform "solaris-11-i386" do |plat| end]
8
+ }
9
+ end
10
+
11
+ let(:versions) do
12
+ [
13
+ # Leading and trailing - stripped
14
+ { :original => "-1.2.3-", :final => "1.2.3" },
15
+
16
+ # Non-numeric stripped
17
+ { :original => "-1.2bcd.3aaz-", :final => "1.2.3" },
18
+
19
+ # Leading, non-singular zeroes stripped
20
+ { :original => "1.0.2.00123", :final => "1.0.2.123" },
21
+ { :original => "1.0000.2.00123", :final => "1.0.2.123" },
22
+ ]
23
+ end
24
+
25
+ describe '#ips_version' do
26
+ it 'strips invalid characters from the version' do
27
+ versions.each do |ver|
28
+ plat = Vanagon::Platform::DSL.new(platform[:name])
29
+ plat.instance_eval(platform[:block])
30
+ expect(plat._platform.ips_version(ver[:original], '1')).to eq("#{ver[:final]},5.11-1")
31
+ end
32
+ end
33
+
34
+ it 'handles the release field correctly' do
35
+ 1.upto(3) do |i|
36
+ versions.each do |ver|
37
+ plat = Vanagon::Platform::DSL.new(platform[:name])
38
+ plat.instance_eval(platform[:block])
39
+ expect(plat._platform.ips_version(ver[:original], i)).to eq("#{ver[:final]},5.11-#{i}")
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,53 @@
1
+ require 'vanagon/platform'
2
+
3
+ describe "Vanagon::Platform" do
4
+ let(:platforms) do
5
+ [
6
+ {
7
+ :name => "debian-6-i386",
8
+ :os_name => "debian",
9
+ :os_version => "6",
10
+ :architecture => "i386",
11
+ },
12
+ {
13
+ :name => "el-5-i386",
14
+ :os_name => "el",
15
+ :os_version => "5",
16
+ :architecture => "i386",
17
+ },
18
+ {
19
+ :name => "CumulusLinux-2.2-amd64",
20
+ :os_name => "CumulusLinux",
21
+ :os_version => "2.2",
22
+ :architecture => "amd64",
23
+ },
24
+ ]
25
+ end
26
+
27
+ describe "#os_name" do
28
+ it "returns the os_name for the platform" do
29
+ platforms.each do |plat|
30
+ cur_plat = Vanagon::Platform.new(plat[:name])
31
+ expect(cur_plat.os_name).to eq(plat[:os_name])
32
+ end
33
+ end
34
+ end
35
+
36
+ describe "#os_version" do
37
+ it "returns the the os_version for the platform" do
38
+ platforms.each do |plat|
39
+ cur_plat = Vanagon::Platform.new(plat[:name])
40
+ expect(cur_plat.os_version).to eq(plat[:os_version])
41
+ end
42
+ end
43
+ end
44
+
45
+ describe "#architecture" do
46
+ it "returns the architecture for the platform" do
47
+ platforms.each do |plat|
48
+ cur_plat = Vanagon::Platform.new(plat[:name])
49
+ expect(cur_plat.architecture).to eq(plat[:architecture])
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,203 @@
1
+ require 'vanagon/project/dsl'
2
+ require 'vanagon/driver'
3
+ require 'vanagon/common'
4
+
5
+ describe 'Vanagon::Project::DSL' do
6
+ let (:project_block) {
7
+ "project 'test-fixture' do |proj|
8
+ end" }
9
+ let (:configdir) { '/a/b/c' }
10
+
11
+ describe '#version_from_git' do
12
+ it 'sets the version based on the git describe' do
13
+ expect(Vanagon::Driver).to receive(:configdir).and_return(configdir)
14
+ proj = Vanagon::Project::DSL.new('test-fixture', {})
15
+ proj.instance_eval(project_block)
16
+ expect(Vanagon::Utilities).to receive(:git_version).with(File.expand_path('..', configdir)).and_return('1.2.3-1234')
17
+ proj.version_from_git
18
+ expect(proj._project.version).to eq('1.2.3.1234')
19
+ end
20
+ end
21
+
22
+ describe '#directory' do
23
+ it 'adds a directory to the list of directories' do
24
+ proj = Vanagon::Project::DSL.new('test-fixture', {})
25
+ proj.instance_eval(project_block)
26
+ proj.directory('/a/b/c/d', mode: '0755')
27
+ expect(proj._project.directories).to include(Vanagon::Common::Pathname.new('/a/b/c/d', mode: '0755'))
28
+ end
29
+ end
30
+
31
+ describe '#user' do
32
+ it 'sets a user for the project' do
33
+ proj = Vanagon::Project::DSL.new('test-fixture', {})
34
+ proj.instance_eval(project_block)
35
+ proj.user('test-user')
36
+ expect(proj._project.user).to eq(Vanagon::Common::User.new('test-user'))
37
+ end
38
+ end
39
+
40
+ describe '#target_repo' do
41
+ it 'sets the target_repo for the project' do
42
+ proj = Vanagon::Project::DSL.new('test-fixture', {})
43
+ proj.instance_eval(project_block)
44
+ proj.target_repo "pc1"
45
+ expect(proj._project.repo).to eq("pc1")
46
+ end
47
+ end
48
+
49
+ describe '#noarch' do
50
+ it 'sets noarch on the project to true' do
51
+ proj = Vanagon::Project::DSL.new('test-fixture', {})
52
+ proj.instance_eval(project_block)
53
+ proj.noarch
54
+ expect(proj._project.noarch).to eq(true)
55
+ end
56
+ end
57
+
58
+ describe '#identifier' do
59
+ it 'sets the identifier for the project' do
60
+ proj = Vanagon::Project::DSL.new('test-fixture', {})
61
+ proj.instance_eval(project_block)
62
+ proj.identifier "com.example"
63
+ expect(proj._project.identifier).to eq("com.example")
64
+ end
65
+ end
66
+
67
+ describe '#cleanup_during_build' do
68
+ it 'sets @cleanup to true' do
69
+ proj = Vanagon::Project::DSL.new('test-fixture', {})
70
+ proj.instance_eval(project_block)
71
+ proj.cleanup_during_build
72
+ expect(proj._project.cleanup).to eq(true)
73
+ end
74
+
75
+ it 'defaults to nil' do
76
+ proj = Vanagon::Project::DSL.new('test-fixture', {})
77
+ proj.instance_eval(project_block)
78
+ expect(proj._project.cleanup).to be_nil
79
+ end
80
+ end
81
+
82
+ describe "#write_version_file" do
83
+ let(:version_file) { '/opt/puppetlabs/puppet/VERSION' }
84
+
85
+ it 'sets version_file for the project' do
86
+ proj = Vanagon::Project::DSL.new('test-fixture', {})
87
+ proj.instance_eval(project_block)
88
+ proj.write_version_file(version_file)
89
+ expect(proj._project.version_file.path).to eq(version_file)
90
+ end
91
+ end
92
+
93
+ describe "#release" do
94
+ it 'sets the release for the project' do
95
+ proj = Vanagon::Project::DSL.new('test-fixture', {})
96
+ proj.instance_eval(project_block)
97
+ proj.release '12'
98
+ expect(proj._project.release).to eq('12')
99
+ end
100
+
101
+ it 'defaults to 1' do
102
+ proj = Vanagon::Project::DSL.new('test-fixture', {})
103
+ proj.instance_eval(project_block)
104
+ expect(proj._project.release).to eq('1')
105
+ end
106
+ end
107
+
108
+ describe "#provides" do
109
+ it 'adds the package provide to the list of provides' do
110
+ proj = Vanagon::Project::DSL.new('test-fixture', {})
111
+ proj.instance_eval(project_block)
112
+ proj.provides('thing1')
113
+ proj.provides('thing2')
114
+ expect(proj._project.get_provides.count).to eq(2)
115
+ expect(proj._project.get_provides.first.provide).to eq('thing1')
116
+ expect(proj._project.get_provides.last.provide).to eq('thing2')
117
+ end
118
+
119
+ it 'supports versioned provides' do
120
+ proj = Vanagon::Project::DSL.new('test-fixture', {})
121
+ proj.instance_eval(project_block)
122
+ proj.provides('thing1', '1.2.3')
123
+ expect(proj._project.get_provides.count).to eq(1)
124
+ expect(proj._project.get_provides.first.provide).to eq('thing1')
125
+ expect(proj._project.get_provides.first.version).to eq('1.2.3')
126
+ end
127
+
128
+ it 'gets rid of duplicates' do
129
+ proj = Vanagon::Project::DSL.new('test-fixture', {})
130
+ proj.instance_eval(project_block)
131
+ proj.provides('thing1', '1.2.3')
132
+ proj.provides('thing1', '1.2.3')
133
+ expect(proj._project.get_provides.count).to eq(1)
134
+ expect(proj._project.get_provides.first.provide).to eq('thing1')
135
+ expect(proj._project.get_provides.first.version).to eq('1.2.3')
136
+ end
137
+ end
138
+
139
+ describe "#replaces" do
140
+ it 'adds the package replacement to the list of replacements' do
141
+ proj = Vanagon::Project::DSL.new('test-fixture', {})
142
+ proj.instance_eval(project_block)
143
+ proj.replaces('thing1')
144
+ proj.replaces('thing2')
145
+ expect(proj._project.get_replaces.count).to eq(2)
146
+ expect(proj._project.get_replaces.first.replacement).to eq('thing1')
147
+ expect(proj._project.get_replaces.last.replacement).to eq('thing2')
148
+ end
149
+
150
+ it 'supports versioned replaces' do
151
+ proj = Vanagon::Project::DSL.new('test-fixture', {})
152
+ proj.instance_eval(project_block)
153
+ proj.replaces('thing1', '1.2.3')
154
+ expect(proj._project.get_replaces.count).to eq(1)
155
+ expect(proj._project.get_replaces.first.replacement).to eq('thing1')
156
+ expect(proj._project.get_replaces.first.version).to eq('1.2.3')
157
+ end
158
+
159
+ it 'gets rid of duplicates' do
160
+ proj = Vanagon::Project::DSL.new('test-fixture', {})
161
+ proj.instance_eval(project_block)
162
+ proj.replaces('thing1', '1.2.3')
163
+ proj.replaces('thing1', '1.2.3')
164
+ expect(proj._project.get_replaces.count).to eq(1)
165
+ expect(proj._project.get_replaces.first.replacement).to eq('thing1')
166
+ expect(proj._project.get_replaces.first.version).to eq('1.2.3')
167
+ end
168
+ end
169
+
170
+ describe "#component" do
171
+ let(:project_block) {
172
+ "project 'test-fixture' do |proj|
173
+ proj.component 'some-component'
174
+ end"
175
+ }
176
+
177
+ let(:component) { double(Vanagon::Component) }
178
+
179
+ before do
180
+ allow_any_instance_of(Vanagon::Project::DSL).to receive(:puts)
181
+ allow(Vanagon::Driver).to receive(:configdir).and_return(configdir)
182
+ allow(Vanagon::Component).to receive(:load_component).with('some-component', any_args).and_return(component)
183
+ end
184
+
185
+ it 'stores the component in the project if the included components set is empty' do
186
+ proj = Vanagon::Project::DSL.new('test-fixture', {}, [])
187
+ proj.instance_eval(project_block)
188
+ expect(proj._project.components).to include(component)
189
+ end
190
+
191
+ it 'stores the component in the project if the component name is listed in the included components set' do
192
+ proj = Vanagon::Project::DSL.new('test-fixture', {}, ['some-component'])
193
+ proj.instance_eval(project_block)
194
+ expect(proj._project.components).to include(component)
195
+ end
196
+
197
+ it 'does not store the component if the included components set is not empty and does not include the component name' do
198
+ proj = Vanagon::Project::DSL.new('test-fixture', {}, ['some-different-component'])
199
+ proj.instance_eval(project_block)
200
+ expect(proj._project.components).to_not include(component)
201
+ end
202
+ end
203
+ end
@@ -0,0 +1,44 @@
1
+ require 'vanagon/project'
2
+ require 'vanagon/driver'
3
+
4
+ describe 'Vanagon::Project' do
5
+ let(:component) { double(Vanagon::Component) }
6
+ let(:configdir) { '/a/b/c' }
7
+
8
+ let(:project_block) {
9
+ "project 'test-fixture' do |proj|
10
+ proj.component 'some-component'
11
+ end"
12
+ }
13
+
14
+ before do
15
+ allow_any_instance_of(Vanagon::Project::DSL).to receive(:puts)
16
+ allow(Vanagon::Driver).to receive(:configdir).and_return(configdir)
17
+ allow(Vanagon::Component).to receive(:load_component).with('some-component', any_args).and_return(component)
18
+ end
19
+
20
+ describe '#get_root_directories' do
21
+ let(:test_sets) do
22
+ [
23
+ {
24
+ :directories => ["/opt/puppetlabs/bin", "/etc/puppetlabs", "/var/log/puppetlabs", "/etc/puppetlabs/puppet", "/opt/puppetlabs"],
25
+ :results => ["/opt/puppetlabs", "/etc/puppetlabs", "/var/log/puppetlabs"],
26
+ },
27
+ {
28
+ :directories => ["/opt/puppetlabs/bin", "/etc/puppetlabs", "/var/log/puppetlabs", "/etc/puppetlabs/puppet", "/opt/puppetlabs/lib"],
29
+ :results => ["/opt/puppetlabs/bin", "/etc/puppetlabs", "/var/log/puppetlabs", "/opt/puppetlabs/lib"],
30
+ },
31
+ ]
32
+ end
33
+
34
+ it 'returns only the highest level directories' do
35
+ test_sets.each do |set|
36
+ expect(component).to receive(:directories).and_return([])
37
+ proj = Vanagon::Project::DSL.new('test-fixture', {}, [])
38
+ proj.instance_eval(project_block)
39
+ set[:directories].each {|dir| proj.directory dir }
40
+ expect(proj._project.get_root_directories.sort).to eq(set[:results].sort)
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,140 @@
1
+ require 'vanagon/utilities'
2
+ require 'tmpdir'
3
+
4
+ describe "Vanagon::Utilities" do
5
+ describe "#find_program_on_path" do
6
+ let(:command) { "thingie" }
7
+
8
+ it 'finds commands on the PATH' do
9
+ path_elems = ENV['PATH'].split(File::PATH_SEPARATOR)
10
+ path_elems.each_with_index do |path_elem, i|
11
+ expect(FileTest).to receive(:executable?).with(File.join(path_elem, command)).and_return(i == 0)
12
+ break
13
+ end
14
+
15
+ expect(Vanagon::Utilities.find_program_on_path(command)).to eq(File.join(path_elems.first, command))
16
+ end
17
+
18
+ it 'finds commands on the PATH' do
19
+ path_elems = ENV['PATH'].split(File::PATH_SEPARATOR)
20
+ path_elems.each_with_index do |path_elem, i|
21
+ expect(FileTest).to receive(:executable?).with(File.join(path_elem, command)).and_return(i == path_elems.length - 1)
22
+ end
23
+
24
+ expect(Vanagon::Utilities.find_program_on_path(command)).to eq(File.join(path_elems.last, command))
25
+ end
26
+
27
+ it 'raises an error if required is true and command is not found' do
28
+ ENV['PATH'].split(File::PATH_SEPARATOR).each do |path_elem|
29
+ expect(FileTest).to receive(:executable?).with(File.join(path_elem, command)).and_return(false)
30
+ end
31
+
32
+ expect { Vanagon::Utilities.find_program_on_path(command) }.to raise_error(RuntimeError)
33
+ end
34
+
35
+ it 'returns false if required is false and command is not found' do
36
+ ENV['PATH'].split(File::PATH_SEPARATOR).each do |path_elem|
37
+ expect(FileTest).to receive(:executable?).with(File.join(path_elem, command)).and_return(false)
38
+ end
39
+
40
+ expect(Vanagon::Utilities.find_program_on_path(command, false)).to be(false)
41
+ end
42
+ end
43
+
44
+ describe "#is_git_repo?" do
45
+ let(:dir) { Dir.mktmpdir }
46
+ after(:each) { FileUtils.rm_rf(dir) }
47
+
48
+ it "returns false if not in a git repo" do
49
+ expect(Vanagon::Utilities.is_git_repo?(dir)).to be(false)
50
+ end
51
+
52
+ it "returns true if in a git repo" do
53
+ Dir.chdir(dir) do
54
+ Vanagon::Utilities.git('init')
55
+ end
56
+
57
+ expect(Vanagon::Utilities.is_git_repo?(dir)).to be(true)
58
+ end
59
+ end
60
+
61
+ describe "#git_version" do
62
+ let(:dir) { Dir.mktmpdir }
63
+ after(:each) { FileUtils.rm_rf(dir) }
64
+
65
+ it "raises an exception if not in a git repo" do
66
+ expect { Vanagon::Utilities.git_version(dir) }.to raise_error(RuntimeError)
67
+ end
68
+
69
+ it "returns a git tag based version if there are tags in the repo" do
70
+ Dir.chdir(dir) do
71
+ Vanagon::Utilities.git('init')
72
+ Vanagon::Utilities.git('commit --allow-empty -m "testing this ish"')
73
+ Vanagon::Utilities.git('tag 1.2.3')
74
+ end
75
+
76
+ expect(Vanagon::Utilities.git_version(dir)).to eq('1.2.3')
77
+ end
78
+
79
+ it "returns empty string if there are no tags" do
80
+ Dir.chdir(dir) do
81
+ Vanagon::Utilities.git('init')
82
+ end
83
+
84
+ expect(Vanagon::Utilities.git_version(dir)).to be_empty
85
+ end
86
+ end
87
+
88
+ describe '#ssh_command' do
89
+ it 'adds the correct flags to the command if VANAGON_SSH_KEY is set' do
90
+ expect(Vanagon::Utilities).to receive(:find_program_on_path).with('ssh').and_return('/tmp/ssh')
91
+ ENV['VANAGON_SSH_KEY'] = '/a/b/c'
92
+ expect(Vanagon::Utilities.ssh_command).to include('/tmp/ssh -i /a/b/c')
93
+ ENV['VANAGON_SSH_KEY'] = nil
94
+ end
95
+
96
+ it 'returns just the path to ssh if VANAGON_SSH_KEY is not set' do
97
+ expect(Vanagon::Utilities).to receive(:find_program_on_path).with('ssh').and_return('/tmp/ssh')
98
+ expect(Vanagon::Utilities.ssh_command).to include('/tmp/ssh')
99
+ end
100
+
101
+ it 'sets the port to 22 when none is specified' do
102
+ expect(Vanagon::Utilities).to receive(:find_program_on_path).with('ssh').and_return('/tmp/ssh')
103
+ expect(Vanagon::Utilities.ssh_command).to include('-p 22')
104
+ end
105
+
106
+ it 'sets the port to 2222 when that is specified' do
107
+ expect(Vanagon::Utilities).to receive(:find_program_on_path).with('ssh').and_return('/tmp/ssh')
108
+ expect(Vanagon::Utilities.ssh_command(2222)).to include('-p 2222')
109
+ end
110
+
111
+ it 'disables strict host checking' do
112
+ expect(Vanagon::Utilities).to receive(:find_program_on_path).with('ssh').and_return('/tmp/ssh')
113
+ expect(Vanagon::Utilities.ssh_command).to include('-o StrictHostKeyChecking=no')
114
+ end
115
+
116
+ it 'sets known hosts file to /dev/null' do
117
+ expect(Vanagon::Utilities).to receive(:find_program_on_path).with('ssh').and_return('/tmp/ssh')
118
+ expect(Vanagon::Utilities.ssh_command).to include('-o UserKnownHostsFile=/dev/null')
119
+ end
120
+ end
121
+
122
+ describe '#retry_with_timeout' do
123
+ let (:tries) { 7 }
124
+ let (:timeout) { 2 }
125
+ let (:host) { 'abcd' }
126
+ let (:command) { 'echo' }
127
+ let (:port) { 1234 }
128
+
129
+ it 'raises a Vanagon::Error if the command fails n times' do
130
+ expect(Vanagon::Utilities).to receive(:remote_ssh_command).with(host, command, port).exactly(tries).times.and_raise(RuntimeError)
131
+ expect{ Vanagon::Utilities.retry_with_timeout(tries, timeout) { Vanagon::Utilities.remote_ssh_command(host, command, port) } }.to raise_error(Vanagon::Error)
132
+ end
133
+
134
+ it 'returns true if the command succeeds within n times' do
135
+ expect(Vanagon::Utilities).to receive(:remote_ssh_command).with(host, command, port).exactly(tries - 1).times.and_raise(RuntimeError)
136
+ expect(Vanagon::Utilities).to receive(:remote_ssh_command).with(host, command, port).exactly(1).times.and_return(true)
137
+ expect(Vanagon::Utilities.retry_with_timeout(tries, timeout) { Vanagon::Utilities.remote_ssh_command(host, command, port) }).to be(true)
138
+ end
139
+ end
140
+ end