beaker 2.7.1 → 2.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +8 -8
  2. data/HISTORY.md +121 -2
  3. data/lib/beaker/dsl.rb +2 -2
  4. data/lib/beaker/dsl/helpers.rb +13 -1429
  5. data/lib/beaker/dsl/helpers/facter_helpers.rb +48 -0
  6. data/lib/beaker/dsl/helpers/hiera_helpers.rb +71 -0
  7. data/lib/beaker/dsl/helpers/host_helpers.rb +506 -0
  8. data/lib/beaker/dsl/helpers/puppet_helpers.rb +698 -0
  9. data/lib/beaker/dsl/helpers/tk_helpers.rb +101 -0
  10. data/lib/beaker/dsl/helpers/web_helpers.rb +115 -0
  11. data/lib/beaker/dsl/install_utils.rb +8 -1570
  12. data/lib/beaker/dsl/install_utils/ezbake_utils.rb +256 -0
  13. data/lib/beaker/dsl/install_utils/module_utils.rb +237 -0
  14. data/lib/beaker/dsl/install_utils/pe_utils.rb +518 -0
  15. data/lib/beaker/dsl/install_utils/puppet_utils.rb +722 -0
  16. data/lib/beaker/dsl/outcomes.rb +0 -4
  17. data/lib/beaker/dsl/roles.rb +0 -3
  18. data/lib/beaker/dsl/structure.rb +127 -4
  19. data/lib/beaker/dsl/wrappers.rb +0 -4
  20. data/lib/beaker/host.rb +23 -0
  21. data/lib/beaker/host/unix/pkg.rb +4 -4
  22. data/lib/beaker/host_prebuilt_steps.rb +11 -5
  23. data/lib/beaker/hypervisor/vagrant.rb +1 -0
  24. data/lib/beaker/hypervisor/vmpooler.rb +38 -0
  25. data/lib/beaker/logger.rb +10 -4
  26. data/lib/beaker/network_manager.rb +5 -4
  27. data/lib/beaker/options/command_line_parser.rb +7 -0
  28. data/lib/beaker/shared.rb +2 -1
  29. data/lib/beaker/shared/semvar.rb +41 -0
  30. data/lib/beaker/test_suite.rb +20 -6
  31. data/lib/beaker/version.rb +1 -1
  32. data/spec/beaker/dsl/helpers/facter_helpers_spec.rb +59 -0
  33. data/spec/beaker/dsl/helpers/hiera_helpers_spec.rb +96 -0
  34. data/spec/beaker/dsl/helpers/host_helpers_spec.rb +413 -0
  35. data/spec/beaker/dsl/{helpers_spec.rb → helpers/puppet_helpers_spec.rb} +2 -611
  36. data/spec/beaker/dsl/helpers/tk_helpers_spec.rb +83 -0
  37. data/spec/beaker/dsl/helpers/web_helpers_spec.rb +60 -0
  38. data/spec/beaker/dsl/install_utils/module_utils_spec.rb +241 -0
  39. data/spec/beaker/dsl/install_utils/pe_utils_spec.rb +475 -0
  40. data/spec/beaker/dsl/install_utils/puppet_utils_spec.rb +523 -0
  41. data/spec/beaker/dsl/structure_spec.rb +108 -0
  42. data/spec/beaker/host_prebuilt_steps_spec.rb +44 -0
  43. data/spec/beaker/host_spec.rb +41 -0
  44. data/spec/beaker/hypervisor/vagrant_spec.rb +2 -1
  45. data/spec/beaker/logger_spec.rb +9 -2
  46. data/spec/beaker/network_manager_spec.rb +7 -1
  47. data/spec/beaker/options/command_line_parser_spec.rb +3 -2
  48. data/spec/beaker/shared/semvar_spec.rb +36 -0
  49. data/spec/beaker/test_suite_spec.rb +48 -0
  50. data/spec/mocks.rb +10 -0
  51. metadata +23 -5
  52. data/lib/beaker/dsl/ezbake_utils.rb +0 -259
  53. data/spec/beaker/dsl/install_utils_spec.rb +0 -1242
@@ -1,259 +0,0 @@
1
- require 'beaker/dsl/install_utils'
2
- require 'fileutils'
3
-
4
- module Beaker
5
- module DSL
6
- # This module contains methods to assist in installing projects from source
7
- # that use ezbake for packaging.
8
- #
9
- # @api dsl
10
- module EZBakeUtils
11
-
12
- # @!group Public DSL Methods
13
-
14
- # Installs leiningen project with given name and version on remote host.
15
- #
16
- # @param [Host] host A single remote host on which to install the
17
- # specified leiningen project.
18
- # @api dsl
19
- def install_from_ezbake host
20
- ezbake_validate_support host
21
- ezbake_tools_available?
22
- install_ezbake_tarball_on_host host
23
- ezbake_installsh host, "service"
24
- end
25
-
26
- # Installs termini with given name and version on remote host.
27
- #
28
- # @param [Host] host A single remote host on which to install the
29
- # specified leiningen project.
30
- # @api dsl
31
- def install_termini_from_ezbake host
32
- ezbake_validate_support host
33
- ezbake_tools_available?
34
- install_ezbake_tarball_on_host host
35
- ezbake_installsh host, "termini"
36
- end
37
-
38
- # Install a development version of ezbake into the local m2 repository
39
- #
40
- # This can be useful if you want to work on a development branch of
41
- # ezbake that hasn't been released yet. Ensure your project dependencies
42
- # in your development branch include a reference to the -SNAPSHOT
43
- # version of the project for it to successfully pickup a pre-shipped
44
- # version of ezbake.
45
- #
46
- # @param url [String] git url
47
- # @param branch [String] git branch
48
- # @api dsl
49
- def ezbake_dev_build url = "git@github.com:puppetlabs/ezbake.git",
50
- branch = "master"
51
- ezbake_dir = 'tmp/ezbake'
52
- conditionally_clone url, ezbake_dir, branch
53
- lp = ezbake_lein_prefix
54
-
55
- Dir.chdir(ezbake_dir) do
56
- ezbake_local_cmd "#{lp} install",
57
- :throw_on_failure => true
58
- end
59
- end
60
-
61
- # @!endgroup
62
-
63
- class << self
64
- attr_accessor :config
65
- end
66
-
67
- # @!group Private helpers
68
-
69
- # Test for support in one place
70
- #
71
- # @param [Host] host host to check for support
72
- # @raise [RuntimeError] if OS is not supported
73
- # @api private
74
- def ezbake_validate_support host
75
- variant, version, _, _ = host['platform'].to_array
76
- unless variant =~ /^(fedora|el|centos|debian|ubuntu)$/
77
- raise RuntimeError,
78
- "No support for #{variant} within ezbake_utils ..."
79
- end
80
- end
81
-
82
- # Build, copy & unpack tarball on remote host
83
- #
84
- # @param [Host] host installation destination
85
- # @api private
86
- def install_ezbake_tarball_on_host host
87
- if not ezbake_config
88
- ezbake_stage
89
- end
90
-
91
- # Skip installation if the remote directory exists
92
- result = on host, "test -d #{ezbake_install_dir}", :acceptable_exit_codes => [0, 1]
93
- return if result.exit_code == 0
94
-
95
- ezbake_staging_dir = File.join('target', 'staging')
96
- Dir.chdir(ezbake_staging_dir) do
97
- ezbake_local_cmd 'rake package:tar'
98
- end
99
-
100
- local_tarball = ezbake_staging_dir + "/pkg/" + ezbake_install_name + ".tar.gz"
101
- remote_tarball = ezbake_install_dir + ".tar.gz"
102
- scp_to host, local_tarball, remote_tarball
103
-
104
- # untar tarball on host
105
- on host, "tar -xzf " + remote_tarball
106
-
107
- # Check to ensure directory exists
108
- on host, "test -d #{ezbake_install_dir}"
109
- end
110
-
111
- LOCAL_COMMANDS_REQUIRED = [
112
- ['leiningen', 'lein --version', nil],
113
- ['lein-pprint', 'lein with-profile ci pprint :version',
114
- 'Must have lein-pprint installed under the :ci profile.'],
115
- ['java', 'java -version', nil],
116
- ['git', 'git --version', nil],
117
- ['rake', 'rake --version', nil],
118
- ]
119
-
120
- # Checks given host for the tools necessary to perform
121
- # install_from_ezbake.
122
- #
123
- # @raise [RuntimeError] if tool is not found
124
- # @api private
125
- def ezbake_tools_available?
126
- LOCAL_COMMANDS_REQUIRED.each do |software_name, command, additional_error_message|
127
- if not system command
128
- error_message = "Must have #{software_name} installed on development system.\n"
129
- if additional_error_message
130
- error_message += additional_error_message
131
- end
132
- raise RuntimeError, error_message
133
- end
134
- end
135
- end
136
-
137
- # Return the ezbake config.
138
- #
139
- # @return [Hash] configuration for ezbake, usually from ezbake.rb
140
- # @api private
141
- def ezbake_config
142
- EZBakeUtils.config
143
- end
144
-
145
- # Returns a leiningen prefix with local m2 repo capability
146
- #
147
- # @return [String] lein prefix command that uses a local build
148
- # m2 repository.
149
- # @api private
150
- def ezbake_lein_prefix
151
- # Get the absolute path to the local repo
152
- m2_repo = File.join(Dir.pwd, 'tmp', 'm2-local')
153
-
154
- 'lein update-in : assoc :local-repo "\"' + m2_repo + '\"" --'
155
- end
156
-
157
- # Prepares a staging directory for the specified project.
158
- #
159
- # @api private
160
- def ezbake_stage
161
- # Install the PuppetDB jar into the local repository
162
- ezbake_local_cmd "#{ezbake_lein_prefix} install",
163
- :throw_on_failure => true
164
-
165
- # Run ezbake stage
166
- ezbake_local_cmd "#{ezbake_lein_prefix} with-profile ezbake ezbake stage",
167
- :throw_on_failure => true
168
-
169
- # Boostrap packaging, and grab configuration info from project
170
- staging_dir = File.join('target','staging')
171
- Dir.chdir(staging_dir) do
172
- ezbake_local_cmd 'rake package:bootstrap'
173
-
174
- load 'ezbake.rb'
175
- ezbake = EZBake::Config
176
- ezbake[:package_version] = `echo -n $(rake pl:print_build_param[ref] | tail -n 1)`
177
- EZBakeUtils.config = ezbake
178
- end
179
- end
180
-
181
- # Executes a local command using system, logging the prepared command
182
- #
183
- # @param [String] cmd command to execute
184
- # @param [Hash] opts options
185
- # @option opts [bool] :throw_on_failure If true, throws an
186
- # exception if the exit code is non-zero. Defaults to false.
187
- # @return [bool] true if exit == 0 false if otherwise
188
- # @raise [RuntimeError] if :throw_on_failure is true and
189
- # command fails
190
- # @api private
191
- def ezbake_local_cmd cmd, opts={}
192
- opts = {
193
- :throw_on_failure => false,
194
- }.merge(opts)
195
-
196
- logger.notify "localhost $ #{cmd}"
197
- result = system cmd
198
- if opts[:throw_on_failure] && result == false
199
- raise RuntimeError, "Command failure #{cmd}"
200
- end
201
- result
202
- end
203
-
204
- # Retrieve the tarball installation name. This is the name of
205
- # the tarball without the .tar.gz extension, and the name of the
206
- # path where it will unpack to.
207
- #
208
- # @return [String] name of the tarball and directory
209
- # @api private
210
- def ezbake_install_name
211
- ezbake = ezbake_config
212
- project_package_version = ezbake[:package_version]
213
- project_name = ezbake[:project]
214
- "%s-%s" % [ project_name, project_package_version ]
215
- end
216
-
217
- # Returns the full path to the installed software on the remote host.
218
- #
219
- # This only returns the path, it doesn't work out if its installed or
220
- # not.
221
- #
222
- # @return [String] path to the installation dir
223
- # @api private
224
- def ezbake_install_dir
225
- "/root/#{ezbake_install_name}"
226
- end
227
-
228
- # A helper that wraps the execution of install.sh in the proper
229
- # ezbake installation directory.
230
- #
231
- # @param [Host] host Host to run install.sh on
232
- # @param [String] task Task to execute with install.sh
233
- # @api private
234
- def ezbake_installsh host, task=""
235
- on host, "cd #{ezbake_install_dir}; bash install.sh #{task}"
236
- end
237
-
238
- # Only clone from given git URI if there is no existing git clone at the
239
- # given local_path location.
240
- #
241
- # @param [String] upstream_uri git URI
242
- # @param [String] local_path path to conditionally install to
243
- # @param [String] branch to checkout
244
- # @api private
245
- def conditionally_clone upstream_uri, local_path, branch="origin/HEAD"
246
- if ezbake_local_cmd "git --work-tree=#{local_path} --git-dir=#{local_path}/.git status"
247
- ezbake_local_cmd "git --work-tree=#{local_path} --git-dir=#{local_path}/.git fetch origin"
248
- ezbake_local_cmd "git --work-tree=#{local_path} --git-dir=#{local_path}/.git checkout #{branch}"
249
- else
250
- parent_dir = File.dirname(local_path)
251
- FileUtils.mkdir_p(parent_dir)
252
- ezbake_local_cmd "git clone #{upstream_uri} #{local_path}"
253
- ezbake_local_cmd "git --work-tree=#{local_path} --git-dir=#{local_path}/.git checkout #{branch}"
254
- end
255
- end
256
-
257
- end
258
- end
259
- end
@@ -1,1242 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class ClassMixedWithDSLInstallUtils
4
- include Beaker::DSL::InstallUtils
5
- include Beaker::DSL::Wrappers
6
- include Beaker::DSL::Helpers
7
- include Beaker::DSL::Structure
8
- include Beaker::DSL::Roles
9
- include Beaker::DSL::Patterns
10
-
11
- def logger
12
- @logger ||= RSpec::Mocks::Double.new('logger').as_null_object
13
- end
14
- end
15
-
16
- describe ClassMixedWithDSLInstallUtils do
17
- let(:presets) { Beaker::Options::Presets.new }
18
- let(:opts) { presets.presets.merge(presets.env_vars) }
19
- let(:basic_hosts) { make_hosts( { :pe_ver => '3.0',
20
- :platform => 'linux',
21
- :roles => [ 'agent' ] }, 4 ) }
22
- let(:hosts) { basic_hosts[0][:roles] = ['master', 'database', 'dashboard']
23
- basic_hosts[1][:platform] = 'windows'
24
- basic_hosts[2][:platform] = 'osx-10.9-x86_64'
25
- basic_hosts[3][:platform] = 'eos'
26
- basic_hosts }
27
- let(:hosts_sorted) { [ hosts[1], hosts[0], hosts[2], hosts[3] ] }
28
- let(:winhost) { make_host( 'winhost', { :platform => 'windows',
29
- :pe_ver => '3.0',
30
- :working_dir => '/tmp' } ) }
31
- let(:machost) { make_host( 'machost', { :platform => 'osx-10.9-x86_64',
32
- :pe_ver => '3.0',
33
- :working_dir => '/tmp' } ) }
34
- let(:unixhost) { make_host( 'unixhost', { :platform => 'linux',
35
- :pe_ver => '3.0',
36
- :working_dir => '/tmp',
37
- :dist => 'puppet-enterprise-3.1.0-rc0-230-g36c9e5c-debian-7-i386' } ) }
38
- let(:eoshost) { make_host( 'eoshost', { :platform => 'eos',
39
- :pe_ver => '3.0',
40
- :working_dir => '/tmp',
41
- :dist => 'puppet-enterprise-3.7.1-rc0-78-gffc958f-eos-4-i386' } ) }
42
-
43
-
44
- context 'extract_repo_info_from' do
45
- [{ :protocol => 'git', :path => 'git://github.com/puppetlabs/project.git' },
46
- { :protocol => 'ssh', :path => 'git@github.com:puppetlabs/project.git' },
47
- { :protocol => 'https', :path => 'https://github.com:puppetlabs/project' },
48
- { :protocol => 'file', :path => 'file:///home/example/project' }
49
- ].each do |type|
50
- it "handles #{ type[:protocol] } uris" do
51
- uri = "#{ type[:path] }#master"
52
- repo_info = subject.extract_repo_info_from uri
53
- expect( repo_info[:name] ).to be == 'project'
54
- expect( repo_info[:path] ).to be == type[:path]
55
- expect( repo_info[:rev] ).to be == 'master'
56
- end
57
- end
58
- end
59
-
60
- context 'order_packages' do
61
- it 'orders facter, hiera before puppet, before anything else' do
62
- named_repos = [
63
- { :name => 'puppet_plugin' }, { :name => 'puppet' }, { :name => 'facter' }
64
- ]
65
- ordered_repos = subject.order_packages named_repos
66
- expect( ordered_repos[0][:name] ).to be == 'facter'
67
- expect( ordered_repos[1][:name] ).to be == 'puppet'
68
- expect( ordered_repos[2][:name] ).to be == 'puppet_plugin'
69
- end
70
- end
71
-
72
- context 'find_git_repo_versions' do
73
- it 'returns a hash of :name => version' do
74
- host = double( 'Host' )
75
- repository = { :name => 'name' }
76
- path = '/path/to/repo'
77
- cmd = 'cd /path/to/repo/name && git describe || true'
78
- logger = double.as_null_object
79
-
80
- expect( subject ).to receive( :logger ).and_return( logger )
81
- expect( subject ).to receive( :on ).with( host, cmd ).and_yield
82
- expect( subject ).to receive( :stdout ).and_return( '2' )
83
-
84
- version = subject.find_git_repo_versions( host, path, repository )
85
-
86
- expect( version ).to be == { 'name' => '2' }
87
- end
88
- end
89
-
90
- context 'install_from_git' do
91
- it 'does a ton of stuff it probably shouldnt' do
92
- repo = { :name => 'puppet',
93
- :path => 'git://my.server.net/puppet.git',
94
- :rev => 'master' }
95
- path = '/path/to/repos'
96
- host = { 'platform' => 'debian' }
97
- logger = double.as_null_object
98
-
99
- expect( subject ).to receive( :logger ).exactly( 3 ).times.and_return( logger )
100
- expect( subject ).to receive( :on ).exactly( 4 ).times
101
-
102
- subject.install_from_git( host, path, repo )
103
- end
104
-
105
- it 'allows a checkout depth of 1' do
106
- repo = { :name => 'puppet',
107
- :path => 'git://my.server.net/puppet.git',
108
- :rev => 'master',
109
- :depth => 1 }
110
-
111
- path = '/path/to/repos'
112
- cmd = "test -d #{path}/#{repo[:name]} || git clone --branch #{repo[:rev]} --depth #{repo[:depth]} #{repo[:path]} #{path}/#{repo[:name]}"
113
- host = { 'platform' => 'debian' }
114
- logger = double.as_null_object
115
- expect( subject ).to receive( :logger ).exactly( 3 ).times.and_return( logger )
116
- expect( subject ).to receive( :on ).with( host,"test -d #{path} || mkdir -p #{path}").exactly( 1 ).times
117
- # this is the the command we want to test
118
- expect( subject ).to receive( :on ).with( host, cmd ).exactly( 1 ).times
119
- expect( subject ).to receive( :on ).with( host, "cd #{path}/#{repo[:name]} && git remote rm origin && git remote add origin #{repo[:path]} && git fetch origin +refs/pull/*:refs/remotes/origin/pr/* +refs/heads/*:refs/remotes/origin/* && git clean -fdx && git checkout -f #{repo[:rev]}" ).exactly( 1 ).times
120
- expect( subject ).to receive( :on ).with( host, "cd #{path}/#{repo[:name]} && if [ -f install.rb ]; then ruby ./install.rb ; else true; fi" ).exactly( 1 ).times
121
-
122
- subject.install_from_git( host, path, repo )
123
- end
124
-
125
- it 'allows a checkout depth with a rev from a specific branch' do
126
- repo = { :name => 'puppet',
127
- :path => 'git://my.server.net/puppet.git',
128
- :rev => 'a2340acddadfeafd234230faf',
129
- :depth => 50,
130
- :depth_branch => 'master' }
131
-
132
- path = '/path/to/repos'
133
- cmd = "test -d #{path}/#{repo[:name]} || git clone --branch #{repo[:depth_branch]} --depth #{repo[:depth]} #{repo[:path]} #{path}/#{repo[:name]}"
134
- host = { 'platform' => 'debian' }
135
- logger = double.as_null_object
136
- expect( subject ).to receive( :logger ).exactly( 3 ).times.and_return( logger )
137
- expect( subject ).to receive( :on ).with( host,"test -d #{path} || mkdir -p #{path}").exactly( 1 ).times
138
- # this is the the command we want to test
139
- expect( subject ).to receive( :on ).with( host, cmd ).exactly( 1 ).times
140
- expect( subject ).to receive( :on ).with( host, "cd #{path}/#{repo[:name]} && git remote rm origin && git remote add origin #{repo[:path]} && git fetch origin +refs/pull/*:refs/remotes/origin/pr/* +refs/heads/*:refs/remotes/origin/* && git clean -fdx && git checkout -f #{repo[:rev]}" ).exactly( 1 ).times
141
- expect( subject ).to receive( :on ).with( host, "cd #{path}/#{repo[:name]} && if [ -f install.rb ]; then ruby ./install.rb ; else true; fi" ).exactly( 1 ).times
142
-
143
- subject.install_from_git( host, path, repo )
144
- end
145
- end
146
-
147
- describe 'sorted_hosts' do
148
- it 'can reorder so that the master comes first' do
149
- allow( subject ).to receive( :hosts ).and_return( hosts_sorted )
150
- expect( subject.sorted_hosts ).to be === hosts
151
- end
152
-
153
- it 'leaves correctly ordered hosts alone' do
154
- allow( subject ).to receive( :hosts ).and_return( hosts )
155
- expect( subject.sorted_hosts ).to be === hosts
156
- end
157
-
158
- it 'does not allow nil entries' do
159
- allow( subject ).to receive( :options ).and_return( { :masterless => true } )
160
- masterless_host = [basic_hosts[0]]
161
- allow( subject ).to receive( :hosts ).and_return( masterless_host )
162
- expect( subject.sorted_hosts ).to be === masterless_host
163
- end
164
- end
165
-
166
- describe 'installer_cmd' do
167
-
168
- it 'generates a windows PE install command for a windows host' do
169
- winhost['dist'] = 'puppet-enterprise-3.0'
170
- allow( subject ).to receive( :hosts ).and_return( [ hosts[1], hosts[0], hosts[2], winhost ] )
171
- expect( subject.installer_cmd( winhost, {} ) ).to be === "cd /tmp && cmd /C 'start /w msiexec.exe /qn /L*V tmp.log /i puppet-enterprise-3.0.msi PUPPET_MASTER_SERVER=vm1 PUPPET_AGENT_CERTNAME=winhost'"
172
- end
173
-
174
- it 'generates a unix PE install command for a unix host' do
175
- the_host = unixhost.dup
176
- the_host['pe_installer'] = 'puppet-enterprise-installer'
177
- expect( subject.installer_cmd( the_host, {} ) ).to be === "cd /tmp/puppet-enterprise-3.1.0-rc0-230-g36c9e5c-debian-7-i386 && ./puppet-enterprise-installer -a /tmp/answers"
178
- end
179
-
180
- it 'generates a unix PE frictionless install command for a unix host with role "frictionless"' do
181
- allow( subject ).to receive( :version_is_less ).and_return( false )
182
- allow( subject ).to receive( :master ).and_return( 'testmaster' )
183
- the_host = unixhost.dup
184
- the_host['pe_installer'] = 'puppet-enterprise-installer'
185
- the_host['roles'] = ['frictionless']
186
- expect( subject.installer_cmd( the_host, {} ) ).to be === "cd /tmp && curl --tlsv1 -kO https://testmaster:8140/packages/3.0/install.bash && bash install.bash"
187
- end
188
-
189
- it 'generates a unix PE frictionless install command for a unix host with role "frictionless" and "frictionless_options"' do
190
- allow( subject ).to receive( :version_is_less ).and_return( false )
191
- allow( subject ).to receive( :master ).and_return( 'testmaster' )
192
- the_host = unixhost.dup
193
- the_host['pe_installer'] = 'puppet-enterprise-installer'
194
- the_host['roles'] = ['frictionless']
195
- the_host['frictionless_options'] = { 'main' => { 'dns_alt_names' => 'puppet' } }
196
- expect( subject.installer_cmd( the_host, {} ) ).to be === "cd /tmp && curl --tlsv1 -kO https://testmaster:8140/packages/3.0/install.bash && bash install.bash main:dns_alt_names=puppet"
197
- end
198
-
199
- it 'generates a osx PE install command for a osx host' do
200
- the_host = machost.dup
201
- the_host['pe_installer'] = 'puppet-enterprise-installer'
202
- expect( subject.installer_cmd( the_host, {} ) ).to be === "cd /tmp && hdiutil attach .dmg && installer -pkg /Volumes/puppet-enterprise-3.0/puppet-enterprise-installer-3.0.pkg -target /"
203
- end
204
-
205
- it 'generates an EOS PE install command for an EOS host' do
206
- the_host = eoshost.dup
207
- commands = ['enable', "extension puppet-enterprise-#{the_host['pe_ver']}-#{the_host['platform']}.swix"]
208
- command = commands.join("\n")
209
- expect( subject.installer_cmd( the_host, {} ) ).to be === "Cli -c '#{command}'"
210
- end
211
-
212
- it 'generates a unix PE install command in verbose for a unix host when pe_debug is enabled' do
213
- the_host = unixhost.dup
214
- the_host['pe_installer'] = 'puppet-enterprise-installer'
215
- the_host[:pe_debug] = true
216
- expect( subject.installer_cmd( the_host, {} ) ).to be === "cd /tmp/puppet-enterprise-3.1.0-rc0-230-g36c9e5c-debian-7-i386 && ./puppet-enterprise-installer -D -a /tmp/answers"
217
- end
218
-
219
- it 'generates a osx PE install command in verbose for a osx host when pe_debug is enabled' do
220
- the_host = machost.dup
221
- the_host['pe_installer'] = 'puppet-enterprise-installer'
222
- the_host[:pe_debug] = true
223
- expect( subject.installer_cmd( the_host, {} ) ).to be === "cd /tmp && hdiutil attach .dmg && installer -verboseR -pkg /Volumes/puppet-enterprise-3.0/puppet-enterprise-installer-3.0.pkg -target /"
224
- end
225
-
226
- it 'generates a unix PE frictionless install command in verbose for a unix host with role "frictionless" and pe_debug is enabled' do
227
- allow( subject ).to receive( :version_is_less ).and_return( false )
228
- allow( subject ).to receive( :master ).and_return( 'testmaster' )
229
- the_host = unixhost.dup
230
- the_host['pe_installer'] = 'puppet-enterprise-installer'
231
- the_host['roles'] = ['frictionless']
232
- the_host[:pe_debug] = true
233
- expect( subject.installer_cmd( the_host, {} ) ).to be === "cd /tmp && curl --tlsv1 -kO https://testmaster:8140/packages/3.0/install.bash && bash -x install.bash"
234
- end
235
-
236
- end
237
-
238
-
239
- describe 'fetch_puppet' do
240
-
241
- it 'can push a local PE .tar.gz to a host and unpack it' do
242
- allow( File ).to receive( :directory? ).and_return( true ) #is local
243
- allow( File ).to receive( :exists? ).and_return( true ) #is a .tar.gz
244
- unixhost['pe_dir'] = '/local/file/path'
245
- allow( subject ).to receive( :scp_to ).and_return( true )
246
-
247
- path = unixhost['pe_dir']
248
- filename = "#{ unixhost['dist'] }"
249
- extension = '.tar.gz'
250
- expect( subject ).to receive( :scp_to ).with( unixhost, "#{ path }/#{ filename }#{ extension }", "#{ unixhost['working_dir'] }/#{ filename }#{ extension }" ).once
251
- expect( subject ).to receive( :on ).with( unixhost, /gunzip/ ).once
252
- expect( subject ).to receive( :on ).with( unixhost, /tar -xvf/ ).once
253
- subject.fetch_puppet( [unixhost], {} )
254
- end
255
-
256
- it 'can download a PE .tar from a URL to a host and unpack it' do
257
- allow( File ).to receive( :directory? ).and_return( false ) #is not local
258
- allow( subject ).to receive( :link_exists? ) do |arg|
259
- if arg =~ /.tar.gz/ #there is no .tar.gz link, only a .tar
260
- false
261
- else
262
- true
263
- end
264
- end
265
- allow( subject ).to receive( :on ).and_return( true )
266
-
267
- path = unixhost['pe_dir']
268
- filename = "#{ unixhost['dist'] }"
269
- extension = '.tar'
270
- expect( subject ).to receive( :on ).with( unixhost, "cd #{ unixhost['working_dir'] }; curl #{ path }/#{ filename }#{ extension } | tar -xvf -" ).once
271
- subject.fetch_puppet( [unixhost], {} )
272
- end
273
-
274
- it 'can download a PE .tar.gz from a URL to a host and unpack it' do
275
- allow( File ).to receive( :directory? ).and_return( false ) #is not local
276
- allow( subject ).to receive( :link_exists? ).and_return( true ) #is a tar.gz
277
- allow( subject ).to receive( :on ).and_return( true )
278
-
279
- path = unixhost['pe_dir']
280
- filename = "#{ unixhost['dist'] }"
281
- extension = '.tar.gz'
282
- expect( subject ).to receive( :on ).with( unixhost, "cd #{ unixhost['working_dir'] }; curl #{ path }/#{ filename }#{ extension } | gunzip | tar -xvf -" ).once
283
- subject.fetch_puppet( [unixhost], {} )
284
- end
285
-
286
- it 'can download a PE .swix from a URL to an EOS host and unpack it' do
287
- allow( File ).to receive( :directory? ).and_return( false ) #is not local
288
- allow( subject ).to receive( :link_exists? ).and_return( true ) #is a tar.gz
289
- allow( subject ).to receive( :on ).and_return( true )
290
-
291
- path = eoshost['pe_dir']
292
- filename = "#{ eoshost['dist'] }"
293
- extension = '.swix'
294
- commands = ['enable', "copy #{path}/#{filename}#{extension} extension:"]
295
- command = commands.join("\n")
296
- expect( subject ).to receive( :on ).with( eoshost, "Cli -c '#{command}'" ).once
297
- subject.fetch_puppet( [eoshost], {} )
298
- end
299
-
300
- it 'can push a local PE package to a windows host' do
301
- allow( File ).to receive( :directory? ).and_return( true ) #is local
302
- allow( File ).to receive( :exists? ).and_return( true ) #is present
303
- winhost['dist'] = 'puppet-enterprise-3.0'
304
- allow( subject ).to receive( :scp_to ).and_return( true )
305
-
306
- path = winhost['pe_dir']
307
- filename = "puppet-enterprise-#{ winhost['pe_ver'] }"
308
- extension = '.msi'
309
- expect( subject ).to receive( :scp_to ).with( winhost, "#{ path }/#{ filename }#{ extension }", "#{ winhost['working_dir'] }/#{ filename }#{ extension }" ).once
310
- subject.fetch_puppet( [winhost], {} )
311
-
312
- end
313
-
314
- it 'can download a PE dmg from a URL to a mac host' do
315
- allow( File ).to receive( :directory? ).and_return( false ) #is not local
316
- allow( subject ).to receive( :link_exists? ).and_return( true ) #is not local
317
- allow( subject ).to receive( :on ).and_return( true )
318
-
319
- path = machost['pe_dir']
320
- filename = "#{ machost['dist'] }"
321
- extension = '.dmg'
322
- expect( subject ).to receive( :on ).with( machost, "cd #{ machost['working_dir'] }; curl -O #{ path }/#{ filename }#{ extension }" ).once
323
- subject.fetch_puppet( [machost], {} )
324
- end
325
-
326
- it 'can push a PE dmg to a mac host' do
327
- allow( File ).to receive( :directory? ).and_return( true ) #is local
328
- allow( File ).to receive( :exists? ).and_return( true ) #is present
329
- allow( subject ).to receive( :scp_to ).and_return( true )
330
-
331
- path = machost['pe_dir']
332
- filename = "#{ machost['dist'] }"
333
- extension = '.dmg'
334
- expect( subject ).to receive( :scp_to ).with( machost, "#{ path }/#{ filename }#{ extension }", "#{ machost['working_dir'] }/#{ filename }#{ extension }" ).once
335
- subject.fetch_puppet( [machost], {} )
336
- end
337
-
338
- it "does nothing for a frictionless agent for PE >= 3.2.0" do
339
- unixhost['roles'] << 'frictionless'
340
- unixhost['pe_ver'] = '3.2.0'
341
-
342
- expect( subject).to_not receive(:scp_to)
343
- expect( subject).to_not receive(:on)
344
- allow( subject ).to receive(:version_is_less).with('3.2.0', '3.2.0').and_return(false)
345
- subject.fetch_puppet( [unixhost], {} )
346
- end
347
- end
348
-
349
- describe 'do_install' do
350
- it 'can perform a simple installation' do
351
- allow( subject ).to receive( :on ).and_return( Beaker::Result.new( {}, '' ) )
352
- allow( subject ).to receive( :fetch_puppet ).and_return( true )
353
- allow( subject ).to receive( :create_remote_file ).and_return( true )
354
- allow( subject ).to receive( :sign_certificate_for ).and_return( true )
355
- allow( subject ).to receive( :stop_agent_on ).and_return( true )
356
- allow( subject ).to receive( :sleep_until_puppetdb_started ).and_return( true )
357
- allow( subject ).to receive( :version_is_less ).with('3.0', '4.0').and_return( true )
358
- allow( subject ).to receive( :version_is_less ).with('3.0', '3.4').and_return( true )
359
- allow( subject ).to receive( :version_is_less ).with('3.0', '3.0').and_return( false )
360
- allow( subject ).to receive( :version_is_less ).with('3.0', '3.4').and_return( true )
361
- allow( subject ).to receive( :wait_for_host_in_dashboard ).and_return( true )
362
- allow( subject ).to receive( :puppet_agent ) do |arg|
363
- "puppet agent #{arg}"
364
- end
365
- allow( subject ).to receive( :puppet ) do |arg|
366
- "puppet #{arg}"
367
- end
368
-
369
- allow( subject ).to receive( :hosts ).and_return( hosts )
370
- #create answers file per-host, except windows
371
- expect( subject ).to receive( :create_remote_file ).with( hosts[0], /answers/, /q/ ).once
372
- #run installer on all hosts
373
- expect( subject ).to receive( :on ).with( hosts[0], /puppet-enterprise-installer/ ).once
374
- expect( subject ).to receive( :on ).with( hosts[1], /msiexec.exe/ ).once
375
- expect( subject ).to receive( :on ).with( hosts[2], / hdiutil attach puppet-enterprise-3.0-osx-10.9-x86_64.dmg && installer -pkg \/Volumes\/puppet-enterprise-3.0\/puppet-enterprise-installer-3.0.pkg -target \// ).once
376
- expect( subject ).to receive( :on ).with( hosts[3], /^Cli/ ).once
377
- #does extra mac/EOS specific commands
378
- expect( subject ).to receive( :on ).with( hosts[2], /puppet config set server/ ).once
379
- expect( subject ).to receive( :on ).with( hosts[3], /puppet config set server/ ).once
380
- expect( subject ).to receive( :on ).with( hosts[2], /puppet config set certname/ ).once
381
- expect( subject ).to receive( :on ).with( hosts[3], /puppet config set certname/ ).once
382
- expect( subject ).to receive( :on ).with( hosts[2], /puppet agent -t/, :acceptable_exit_codes => [1] ).once
383
- expect( subject ).to receive( :on ).with( hosts[3], /puppet agent -t/, :acceptable_exit_codes => [0, 1] ).once
384
- #sign certificate per-host
385
- expect( subject ).to receive( :sign_certificate_for ).with( hosts[0] ).once
386
- expect( subject ).to receive( :sign_certificate_for ).with( hosts[1] ).once
387
- expect( subject ).to receive( :sign_certificate_for ).with( hosts[2] ).once
388
- expect( subject ).to receive( :sign_certificate_for ).with( hosts[3] ).once
389
- #stop puppet agent on all hosts
390
- expect( subject ).to receive( :stop_agent_on ).with( hosts[0] ).once
391
- expect( subject ).to receive( :stop_agent_on ).with( hosts[1] ).once
392
- expect( subject ).to receive( :stop_agent_on ).with( hosts[2] ).once
393
- expect( subject ).to receive( :stop_agent_on ).with( hosts[3] ).once
394
- #wait for puppetdb to start
395
- expect( subject ).to receive( :sleep_until_puppetdb_started ).with( hosts[0] ).once
396
- #run each puppet agent once
397
- expect( subject ).to receive( :on ).with( hosts[0], /puppet agent -t/, :acceptable_exit_codes => [0,2] ).once
398
- expect( subject ).to receive( :on ).with( hosts[1], /puppet agent -t/, :acceptable_exit_codes => [0,2] ).once
399
- expect( subject ).to receive( :on ).with( hosts[2], /puppet agent -t/, :acceptable_exit_codes => [0,2] ).once
400
- expect( subject ).to receive( :on ).with( hosts[3], /puppet agent -t/, :acceptable_exit_codes => [0,2] ).once
401
- #run rake task on dashboard
402
- expect( subject ).to receive( :on ).with( hosts[0], /\/opt\/puppet\/bin\/rake -sf \/opt\/puppet\/share\/puppet-dashboard\/Rakefile .* RAILS_ENV=production/ ).once
403
- #wait for all hosts to appear in the dashboard
404
- #run puppet agent now that installation is complete
405
- expect( subject ).to receive( :on ).with( hosts, /puppet agent/, :acceptable_exit_codes => [0,2] ).once
406
- subject.do_install( hosts, opts )
407
- end
408
-
409
- it 'can perform a masterless installation' do
410
- hosts = make_hosts({
411
- :pe_ver => '3.0',
412
- :roles => ['agent']
413
- }, 1)
414
-
415
- allow( subject ).to receive( :hosts ).and_return( hosts )
416
- allow( subject ).to receive( :options ).and_return({ :masterless => true })
417
- allow( subject ).to receive( :on ).and_return( Beaker::Result.new( {}, '' ) )
418
- allow( subject ).to receive( :fetch_puppet ).and_return( true )
419
- allow( subject ).to receive( :create_remote_file ).and_return( true )
420
- allow( subject ).to receive( :stop_agent_on ).and_return( true )
421
- allow( subject ).to receive( :version_is_less ).with(anything, '3.2.0').exactly(hosts.length + 1).times.and_return( false )
422
-
423
- expect( subject ).to receive( :on ).with( hosts[0], /puppet-enterprise-installer/ ).once
424
- expect( subject ).to receive( :create_remote_file ).with( hosts[0], /answers/, /q/ ).once
425
- expect( subject ).to_not receive( :sign_certificate_for )
426
- expect( subject ).to receive( :stop_agent_on ).with( hosts[0] ).once
427
- expect( subject ).to_not receive( :sleep_until_puppetdb_started )
428
- expect( subject ).to_not receive( :wait_for_host_in_dashboard )
429
- expect( subject ).to_not receive( :on ).with( hosts[0], /puppet agent -t/, :acceptable_exit_codes => [0,2] )
430
- subject.do_install( hosts, opts)
431
- end
432
- end
433
-
434
- describe 'do_higgs_install' do
435
-
436
- before :each do
437
- my_time = double( "time double" )
438
- allow( my_time ).to receive( :strftime ).and_return( "2014-07-01_15.27.53" )
439
- allow( Time ).to receive( :new ).and_return( my_time )
440
-
441
- hosts[0]['working_dir'] = "tmp/2014-07-01_15.27.53"
442
- hosts[0]['dist'] = 'dist'
443
- hosts[0]['pe_installer'] = 'pe-installer'
444
- allow( hosts[0] ).to receive( :tmpdir ).and_return( "/tmp/2014-07-01_15.27.53" )
445
-
446
- @fail_result = Beaker::Result.new( {}, '' )
447
- @fail_result.stdout = "No match here"
448
- @success_result = Beaker::Result.new( {}, '' )
449
- @success_result.stdout = "Please go to https://website in your browser to continue installation"
450
- end
451
-
452
- it 'can perform a simple installation' do
453
- allow( subject ).to receive( :fetch_puppet ).and_return( true )
454
- allow( subject ).to receive( :sleep ).and_return( true )
455
-
456
- allow( subject ).to receive( :hosts ).and_return( hosts )
457
-
458
- #run higgs installer command
459
- expect( subject ).to receive( :on ).with( hosts[0],
460
- "cd /tmp/2014-07-01_15.27.53/puppet-enterprise-3.0-linux ; nohup ./pe-installer <<<Y > higgs_2014-07-01_15.27.53.log 2>&1 &",
461
- opts ).once
462
- #check to see if the higgs installation has proceeded correctly, works on second check
463
- expect( subject ).to receive( :on ).with( hosts[0], /cat #{hosts[0]['higgs_file']}/, { :acceptable_exit_codes => 0..255 }).and_return( @fail_result, @success_result )
464
- subject.do_higgs_install( hosts[0], opts )
465
- end
466
-
467
- it 'fails out after checking installation log 10 times' do
468
- allow( subject ).to receive( :fetch_puppet ).and_return( true )
469
- allow( subject ).to receive( :sleep ).and_return( true )
470
-
471
- allow( subject ).to receive( :hosts ).and_return( hosts )
472
-
473
- #run higgs installer command
474
- expect( subject ).to receive( :on ).with( hosts[0],
475
- "cd /tmp/2014-07-01_15.27.53/puppet-enterprise-3.0-linux ; nohup ./pe-installer <<<Y > higgs_2014-07-01_15.27.53.log 2>&1 &",
476
- opts ).once
477
- #check to see if the higgs installation has proceeded correctly, works on second check
478
- expect( subject ).to receive( :on ).with( hosts[0], /cat #{hosts[0]['higgs_file']}/, { :acceptable_exit_codes => 0..255 }).exactly(10).times.and_return( @fail_result )
479
- expect{ subject.do_higgs_install( hosts[0], opts ) }.to raise_error
480
- end
481
-
482
- end
483
-
484
- describe '#install_puppet' do
485
- let(:hosts) do
486
- make_hosts({:platform => platform })
487
- end
488
-
489
- before do
490
- allow( subject ).to receive(:hosts).and_return(hosts)
491
- allow( subject ).to receive(:on).and_return(Beaker::Result.new({},''))
492
- end
493
- context 'on el-6' do
494
- let(:platform) { "el-6-i386" }
495
- it 'installs' do
496
- expect(subject).to receive(:on).with(hosts[0], /puppetlabs-release-el-6\.noarch\.rpm/)
497
- expect(subject).to receive(:on).with(hosts[0], 'yum install -y puppet')
498
- subject.install_puppet
499
- end
500
- it 'installs specific version of puppet when passed :version' do
501
- expect(subject).to receive(:on).with(hosts[0], 'yum install -y puppet-3000')
502
- subject.install_puppet( :version => '3000' )
503
- end
504
- it 'can install specific versions of puppets dependencies' do
505
- expect(subject).to receive(:on).with(hosts[0], 'yum install -y puppet-3000')
506
- expect(subject).to receive(:on).with(hosts[0], 'yum install -y hiera-2001')
507
- expect(subject).to receive(:on).with(hosts[0], 'yum install -y facter-1999')
508
- subject.install_puppet( :version => '3000', :facter_version => '1999', :hiera_version => '2001' )
509
- end
510
- end
511
- context 'on el-5' do
512
- let(:platform) { "el-5-i386" }
513
- it 'installs' do
514
- expect(subject).to receive(:on).with(hosts[0], /puppetlabs-release-el-5\.noarch\.rpm/)
515
- expect(subject).to receive(:on).with(hosts[0], 'yum install -y puppet')
516
- subject.install_puppet
517
- end
518
- end
519
- context 'on fedora' do
520
- let(:platform) { "fedora-18-x86_84" }
521
- it 'installs' do
522
- expect(subject).to receive(:on).with(hosts[0], /puppetlabs-release-fedora-18\.noarch\.rpm/)
523
- expect(subject).to receive(:on).with(hosts[0], 'yum install -y puppet')
524
- subject.install_puppet
525
- end
526
- end
527
- context 'on debian' do
528
- let(:platform) { "debian-7-amd64" }
529
- it 'installs latest if given no version info' do
530
- expect(subject).to receive(:on).with(hosts[0], /puppetlabs-release-\$\(lsb_release -c -s\)\.deb/)
531
- expect(subject).to receive(:on).with(hosts[0], 'dpkg -i puppetlabs-release-$(lsb_release -c -s).deb')
532
- expect(subject).to receive(:on).with(hosts[0], 'apt-get update')
533
- expect(subject).to receive(:on).with(hosts[0], 'apt-get install -y puppet')
534
- subject.install_puppet
535
- end
536
- it 'installs specific version of puppet when passed :version' do
537
- expect(subject).to receive(:on).with(hosts[0], 'apt-get install -y puppet=3000-1puppetlabs1')
538
- subject.install_puppet( :version => '3000' )
539
- end
540
- it 'can install specific versions of puppets dependencies' do
541
- expect(subject).to receive(:on).with(hosts[0], 'apt-get install -y puppet=3000-1puppetlabs1')
542
- expect(subject).to receive(:on).with(hosts[0], 'apt-get install -y hiera=2001-1puppetlabs1')
543
- expect(subject).to receive(:on).with(hosts[0], 'apt-get install -y facter=1999-1puppetlabs1')
544
- subject.install_puppet( :version => '3000', :facter_version => '1999', :hiera_version => '2001' )
545
- end
546
- end
547
- context 'on windows' do
548
- let(:platform) { "windows-2008r2-i386" }
549
- it 'installs specific version of puppet when passed :version' do
550
- allow(subject).to receive(:link_exists?).and_return( true )
551
- expect(subject).to receive(:on).with(hosts[0], 'curl -O http://downloads.puppetlabs.com/windows/puppet-3000.msi')
552
- expect(subject).to receive(:on).with(hosts[0], " echo 'export PATH=$PATH:\"/cygdrive/c/Program Files (x86)/Puppet Labs/Puppet/bin\":\"/cygdrive/c/Program Files/Puppet Labs/Puppet/bin\"' > /etc/bash.bashrc ")
553
- expect(subject).to receive(:on).with(hosts[0], 'cmd /C \'start /w msiexec.exe /qn /i puppet-3000.msi\'')
554
- subject.install_puppet(:version => '3000')
555
- end
556
- it 'installs from custom url when passed :win_download_url' do
557
- allow(subject).to receive(:link_exists?).and_return( true )
558
- expect(subject).to receive(:on).with(hosts[0], 'curl -O http://nightlies.puppetlabs.com/puppet-latest/repos/windows/puppet-3000.msi')
559
- expect(subject).to receive(:on).with(hosts[0], 'cmd /C \'start /w msiexec.exe /qn /i puppet-3000.msi\'')
560
- subject.install_puppet( :version => '3000', :win_download_url => 'http://nightlies.puppetlabs.com/puppet-latest/repos/windows' )
561
- end
562
- end
563
- describe 'on unsupported platforms' do
564
- let(:platform) { 'solaris-11-x86_64' }
565
- let(:host) { make_host('henry', :platform => 'solaris-11-x86_64') }
566
- let(:hosts) { [host] }
567
- it 'by default raises an error' do
568
- expect(subject).to_not receive(:on)
569
- expect { subject.install_puppet }.to raise_error(/unsupported platform/)
570
- end
571
- it 'falls back to installing from gem when given :default_action => "gem_install"' do
572
- result = double
573
- gem_env_string = '{"RubyGems Environment": [ {"GEM PATHS": [], "EXECUTABLE DIRECTORY": "/does/not/exist" } ] }'
574
- allow( result ).to receive(:stdout).and_return gem_env_string
575
- allow(subject).to receive(:on).with(host, /gem environment/).and_return result
576
- expect(subject).to receive(:on).with(host, /gem install/)
577
- subject.install_puppet :default_action => 'gem_install'
578
- end
579
- end
580
- end
581
-
582
- describe 'configure_puppet_on' do
583
- before do
584
- allow(subject).to receive(:on).and_return(Beaker::Result.new({},''))
585
- end
586
- context 'on debian' do
587
- let(:platform) { 'debian-7-amd64' }
588
- let(:host) { make_host('testbox.test.local', :platform => 'debian-7-amd64') }
589
- it 'it sets the puppet.conf file to the provided config' do
590
- config = { 'main' => {'server' => 'testbox.test.local'} }
591
- expect(subject).to receive(:on).with(host, "echo \"[main]\nserver=testbox.test.local\n\n\" > #{host.puppet['config']}")
592
- subject.configure_puppet_on(host, config)
593
- end
594
- end
595
- context 'on windows' do
596
- let(:platform) { 'windows-2008R2-amd64' }
597
- let(:host) { make_host('testbox.test.local', :platform => 'windows-2008R2-amd64') }
598
- it 'it sets the puppet.conf file to the provided config' do
599
- config = { 'main' => {'server' => 'testbox.test.local'} }
600
- expect(subject).to receive(:on) do |host, command|
601
- expect(command.command).to eq('powershell.exe')
602
- expect(command.args).to eq(["-ExecutionPolicy Bypass", "-InputFormat None", "-NoLogo", "-NoProfile", "-NonInteractive", "-Command $text = \\\"[main]`nserver=testbox.test.local`n`n\\\"; Set-Content -path '#{host.puppet['config']}' -value $text"])
603
- end
604
- subject.configure_puppet_on(host, config)
605
- end
606
- end
607
- end
608
-
609
- describe 'configure_puppet' do
610
- let(:hosts) do
611
- make_hosts({:platform => platform })
612
- end
613
-
614
- before do
615
- allow( subject ).to receive(:hosts).and_return(hosts)
616
- allow( subject ).to receive(:on).and_return(Beaker::Result.new({},''))
617
- end
618
- context 'on debian' do
619
- let(:platform) { 'debian-7-amd64' }
620
- it 'it sets the puppet.conf file to the provided config' do
621
- config = { 'main' => {'server' => 'testbox.test.local'} }
622
- expect(subject).to receive(:on).with(hosts[0], "echo \"[main]\nserver=testbox.test.local\n\n\" > #{hosts[0].puppet['config']}")
623
- subject.configure_puppet(config)
624
- end
625
- end
626
- context 'on windows' do
627
- let(:platform) { 'windows-2008R2-amd64' }
628
- it 'it sets the puppet.conf file to the provided config' do
629
- config = { 'main' => {'server' => 'testbox.test.local'} }
630
- expect(subject).to receive(:on) do |host, command|
631
- expect(command.command).to eq('powershell.exe')
632
- expect(command.args).to eq(["-ExecutionPolicy Bypass", "-InputFormat None", "-NoLogo", "-NoProfile", "-NonInteractive", "-Command $text = \\\"[main]`nserver=testbox.test.local`n`n\\\"; Set-Content -path '#{host.puppet['config']}' -value $text"])
633
- end
634
- subject.configure_puppet(config)
635
- end
636
- end
637
- end
638
-
639
- describe '#add_system32_hosts_entry' do
640
- before do
641
- allow( subject ).to receive(:on).and_return(Beaker::Result.new({},''))
642
- end
643
- context 'on debian' do
644
- let(:platform) { 'debian-7-amd64' }
645
- let(:host) { make_host('testbox.test.local', :platform => 'debian-7-amd64') }
646
- it 'logs message - nothing to do on this host' do
647
- expect( Beaker::Command ).to receive( :new ).never
648
-
649
- expect {
650
- subject.add_system32_hosts_entry(host, {})
651
- }.to raise_error
652
- end
653
- end
654
- context 'on windows' do
655
- let(:platform) { 'windows-2008R2-amd64' }
656
- let(:host) { make_host('testbox.test.local', :platform => 'windows-2008R2-amd64') }
657
- it 'it add an entry into the /etc/hosts file' do
658
- entry = { 'ip' => '23.251.154.122', 'name' => 'forge.puppetlabs.com' }
659
- expect(subject).to receive(:on) do |host, command|
660
- expect(command.command).to eq('powershell.exe')
661
- expect(command.args).to eq(["-ExecutionPolicy Bypass", "-InputFormat None", "-NoLogo", "-NoProfile", "-NonInteractive", "-Command $text = \\\"23.251.154.122`t`tforge.puppetlabs.com\\\"; Add-Content -path 'C:\\Windows\\System32\\Drivers\\etc\\hosts' -value $text"])
662
- end
663
-
664
-
665
- subject.add_system32_hosts_entry(host, entry)
666
- end
667
- end
668
- end
669
-
670
- describe 'install_pe' do
671
-
672
- it 'calls do_install with sorted hosts' do
673
- allow( subject ).to receive( :options ).and_return( {} )
674
- allow( subject ).to receive( :hosts ).and_return( hosts_sorted )
675
- allow( subject ).to receive( :do_install ).and_return( true )
676
- expect( subject ).to receive( :do_install ).with( hosts, {} )
677
- subject.install_pe
678
- end
679
-
680
- it 'fills in missing pe_ver' do
681
- hosts.each do |h|
682
- h['pe_ver'] = nil
683
- end
684
- allow( Beaker::Options::PEVersionScraper ).to receive( :load_pe_version ).and_return( '2.8' )
685
- allow( subject ).to receive( :hosts ).and_return( hosts_sorted )
686
- allow( subject ).to receive( :options ).and_return( {} )
687
- allow( subject ).to receive( :do_install ).and_return( true )
688
- expect( subject ).to receive( :do_install ).with( hosts, {} )
689
- subject.install_pe
690
- hosts.each do |h|
691
- expect( h['pe_ver'] ).to be === '2.8'
692
- end
693
- end
694
- end
695
-
696
- describe 'install_higgs' do
697
- it 'fills in missing pe_ver' do
698
- hosts[0]['pe_ver'] = nil
699
- allow( Beaker::Options::PEVersionScraper ).to receive( :load_pe_version ).and_return( '2.8' )
700
- allow( subject ).to receive( :hosts ).and_return( [ hosts[1], hosts[0], hosts[2] ] )
701
- allow( subject ).to receive( :options ).and_return( {} )
702
- allow( subject ).to receive( :do_higgs_install ).and_return( true )
703
- expect( subject ).to receive( :do_higgs_install ).with( hosts[0], {} )
704
- subject.install_higgs
705
- expect( hosts[0]['pe_ver'] ).to be === '2.8'
706
- end
707
-
708
- end
709
-
710
- describe 'upgrade_pe' do
711
-
712
- it 'calls puppet-enterprise-upgrader for pre 3.0 upgrades' do
713
- allow( Beaker::Options::PEVersionScraper ).to receive( :load_pe_version ).and_return( '2.8' )
714
- allow( Beaker::Options::PEVersionScraper ).to receive( :load_pe_version_win ).and_return( '2.8' )
715
- the_hosts = [ hosts[0].dup, hosts[1].dup, hosts[2].dup ]
716
- allow( subject ).to receive( :hosts ).and_return( the_hosts )
717
- allow( subject ).to receive( :options ).and_return( {} )
718
- allow( subject ).to receive( :version_is_less ).with('3.0', '3.4.0').and_return( true )
719
- allow( subject ).to receive( :version_is_less ).with('2.8', '3.0').and_return( true )
720
- version = version_win = '2.8'
721
- path = "/path/to/upgradepkg"
722
- expect( subject ).to receive( :do_install ).with( the_hosts, {:type=>:upgrade, :set_console_password=>true} )
723
- subject.upgrade_pe( path )
724
- the_hosts.each do |h|
725
- expect( h['pe_installer'] ).to be === 'puppet-enterprise-upgrader'
726
- end
727
- end
728
-
729
- it 'uses standard upgrader for post 3.0 upgrades' do
730
- allow( Beaker::Options::PEVersionScraper ).to receive( :load_pe_version ).and_return( '3.1' )
731
- allow( Beaker::Options::PEVersionScraper ).to receive( :load_pe_version_win ).and_return( '3.1' )
732
- the_hosts = [ hosts[0].dup, hosts[1].dup, hosts[2].dup ]
733
- allow( subject ).to receive( :hosts ).and_return( the_hosts )
734
- allow( subject ).to receive( :options ).and_return( {} )
735
- allow( subject ).to receive( :version_is_less ).with('3.0', '3.4.0').and_return( true )
736
- allow( subject ).to receive( :version_is_less ).with('3.1', '3.0').and_return( false )
737
- version = version_win = '3.1'
738
- path = "/path/to/upgradepkg"
739
- expect( subject ).to receive( :do_install ).with( the_hosts, {:type=>:upgrade, :set_console_password=>true} )
740
- subject.upgrade_pe( path )
741
- the_hosts.each do |h|
742
- expect( h['pe_installer'] ).to be nil
743
- end
744
- end
745
-
746
- it 'updates pe_ver post upgrade' do
747
- allow( Beaker::Options::PEVersionScraper ).to receive( :load_pe_version ).and_return( '2.8' )
748
- allow( Beaker::Options::PEVersionScraper ).to receive( :load_pe_version_win ).and_return( '2.8' )
749
- the_hosts = [ hosts[0].dup, hosts[1].dup, hosts[2].dup ]
750
- allow( subject ).to receive( :hosts ).and_return( the_hosts )
751
- allow( subject ).to receive( :options ).and_return( {} )
752
- allow( subject ).to receive( :version_is_less ).with('3.0', '3.4.0').and_return( true )
753
- allow( subject ).to receive( :version_is_less ).with('2.8', '3.0').and_return( true )
754
- version = version_win = '2.8'
755
- path = "/path/to/upgradepkg"
756
- expect( subject ).to receive( :do_install ).with( the_hosts, {:type=>:upgrade, :set_console_password=>true} )
757
- subject.upgrade_pe( path )
758
- the_hosts.each do |h|
759
- expect( h['pe_ver'] ).to be === '2.8'
760
- end
761
- end
762
-
763
- end
764
-
765
-
766
- def fetch_allows
767
- allow(subject).to receive( :logger ) { logger }
768
- end
769
-
770
- describe "#fetch_http_file" do
771
- let( :logger) { double("Beaker::Logger", :notify => nil , :debug => nil ) }
772
-
773
- before do
774
- fetch_allows
775
- end
776
-
777
- describe "given valid arguments" do
778
-
779
- it "returns its second and third arguments concatenated." do
780
- create_files(['destdir/name'])
781
- result = subject.fetch_http_file "http://beaker.tool/", "name", "destdir"
782
- expect(result).to eq("destdir/name")
783
- end
784
-
785
- end
786
-
787
- end
788
-
789
- describe "#fetch_http_dir" do
790
- let( :logger) { double("Beaker::Logger", :notify => nil , :debug => nil ) }
791
- let( :result) { double(:each_line => []) }
792
-
793
- before do
794
- fetch_allows
795
- end
796
-
797
- describe "given valid arguments" do
798
-
799
- it "returns basename of first argument concatenated to second." do
800
- expect(subject).to receive(:`).with(/^wget.*/).ordered { result }
801
- expect($?).to receive(:to_i).and_return(0)
802
- result = subject.fetch_http_dir "http://beaker.tool/beep", "destdir"
803
- expect(result).to eq("destdir/beep")
804
- end
805
-
806
- end
807
-
808
- end
809
-
810
- describe "#install_puppetlabs_release_repo" do
811
- let( :platform ) { Beaker::Platform.new('solaris-7-i386') }
812
- let( :host ) do
813
- FakeHost.create('fakevm', platform.to_s)
814
- end
815
-
816
- before do
817
- allow(subject).to receive(:options) { opts }
818
- end
819
-
820
- describe "When host is unsupported platform" do
821
- let( :platform ) { Beaker::Platform.new('solaris-7-i386') }
822
-
823
- it "raises an exception." do
824
- expect{
825
- subject.install_puppetlabs_release_repo host
826
- }.to raise_error(RuntimeError, /No repository installation step for/)
827
- end
828
- end
829
-
830
- describe "When host is a debian-like platform" do
831
- let( :platform ) { Beaker::Platform.new('debian-7-i386') }
832
-
833
- it "downloads a deb file, installs, and updates the apt cache." do
834
- expect(subject).to receive(:on).with( host, /wget .*/ ).ordered
835
- expect(subject).to receive(:on).with( host, /dpkg .*/ ).ordered
836
- expect(subject).to receive(:on).with( host, "apt-get update" ).ordered
837
- subject.install_puppetlabs_release_repo host
838
- end
839
-
840
- end
841
-
842
- describe "When host is a redhat-like platform" do
843
- let( :platform ) { Beaker::Platform.new('el-7-i386') }
844
-
845
- it "installs an rpm" do
846
- expect(subject).to receive(:on).with( host, /rpm .*/ ).ordered
847
- subject.install_puppetlabs_release_repo host
848
- end
849
-
850
- end
851
-
852
- end
853
-
854
- RSpec.shared_examples "install-dev-repo" do
855
- let( :repo_config ) { "repoconfig" }
856
- let( :repo_dir ) { "repodir" }
857
-
858
- before do
859
- allow(subject).to receive(:fetch_http_file) { repo_config }
860
- allow(subject).to receive(:fetch_http_dir) { repo_dir }
861
- allow(subject).to receive(:on).with(host, "apt-get update") { }
862
- allow(subject).to receive(:options) { opts }
863
- allow(subject).to receive(:link_exists?) { true }
864
- end
865
-
866
- it "scp's files to SUT then modifies them with find-and-sed 2-hit combo" do
867
- expect(subject).to receive(:on).with( host, /^mkdir -p .*$/ ).ordered
868
- expect(subject).to receive(:scp_to).with( host, repo_config, /.*/ ).ordered
869
- expect(subject).to receive(:scp_to).with( host, repo_dir, /.*/ ).ordered
870
- expect(subject).to receive(:on).with( host, /^find .* sed .*/ ).ordered
871
- subject.install_puppetlabs_dev_repo host, package_name, package_version
872
- end
873
-
874
- end
875
-
876
- describe "#install_puppetlabs_dev_repo" do
877
- let( :package_name ) { "puppet" }
878
- let( :package_version ) { "7.5.6" }
879
- let( :host ) do
880
- FakeHost.create('fakvm', platform.to_s, opts)
881
- end
882
-
883
- describe "When host is unsupported platform" do
884
- let( :platform ) { Beaker::Platform.new('solaris-7-i386') }
885
-
886
- it "raises an exception." do
887
- expect(subject).to receive(:on).with( host, /^mkdir -p .*$/ ).ordered
888
- allow(subject).to receive(:options) { opts }
889
- expect{
890
- subject.install_puppetlabs_dev_repo host, package_name, package_version
891
- }.to raise_error(RuntimeError, /No repository installation step for/)
892
- end
893
-
894
- end
895
-
896
- describe "When host is a debian-like platform" do
897
- let( :platform ) { Beaker::Platform.new('debian-7-i386') }
898
- include_examples "install-dev-repo"
899
- end
900
-
901
- describe "When host is a redhat-like platform" do
902
- let( :platform ) { Beaker::Platform.new('el-7-i386') }
903
- include_examples "install-dev-repo"
904
- end
905
-
906
- end
907
-
908
- describe '#install_packages_from_local_dev_repo' do
909
- let( :package_name ) { 'puppet-agent' }
910
- let( :platform ) { @platform || 'other' }
911
- let( :host ) do
912
- FakeHost.create('fakvm', platform, opts)
913
- end
914
-
915
- it 'sets the find command correctly for el-based systems' do
916
- @platform = 'el-1-3'
917
- expect( subject ).to receive( :on ).with( host, /\*\.rpm.+rpm\s-ivh/ )
918
- subject.install_packages_from_local_dev_repo( host, package_name )
919
- end
920
-
921
- it 'sets the find command correctly for debian-based systems' do
922
- @platform = 'debian-1-3'
923
- expect( subject ).to receive( :on ).with( host, /\*\.deb.+dpkg\s-i/ )
924
- subject.install_packages_from_local_dev_repo( host, package_name )
925
- end
926
-
927
- it 'fails correctly for systems not accounted for' do
928
- @platform = 'eos-1-3'
929
- expect{ subject.install_packages_from_local_dev_repo( host, package_name ) }.to raise_error RuntimeError
930
- end
931
-
932
- end
933
-
934
- describe '#install_puppetagent_dev_repo' do
935
-
936
- it 'raises an exception when host platform is unsupported' do
937
- platform = Object.new()
938
- allow(platform).to receive(:to_array) { ['ptan', '5', 'x4']}
939
- host = basic_hosts.first
940
- host['platform'] = platform
941
- opts = { :version => '0.1.0' }
942
- allow( subject ).to receive( :options ).and_return( {} )
943
-
944
- expect{
945
- subject.install_puppetagent_dev_repo( host, opts )
946
- }.to raise_error(RuntimeError, /No repository installation step for/)
947
- end
948
-
949
- it 'runs the correct install for el-based platforms' do
950
- platform = Object.new()
951
- allow(platform).to receive(:to_array) { ['el', '5', 'x4']}
952
- host = basic_hosts.first
953
- host['platform'] = platform
954
- opts = { :version => '0.1.0' }
955
- allow( subject ).to receive( :options ).and_return( {} )
956
-
957
- expect(subject).to receive(:fetch_http_file).once.with(/\/el\//, /-agent-/, /el/)
958
- expect(subject).to receive(:scp_to).once.with(host, /-agent-/, "/root")
959
- expect(subject).to receive(:on).once.with(host, /rpm\ -ivh/)
960
-
961
- subject.install_puppetagent_dev_repo( host, opts )
962
- end
963
-
964
- it 'runs the correct install for debian-based platforms' do
965
- platform = Object.new()
966
- allow(platform).to receive(:to_array) { ['debian', '5', 'x4']}
967
- host = basic_hosts.first
968
- host['platform'] = platform
969
- opts = { :version => '0.1.0' }
970
- allow( subject ).to receive( :options ).and_return( {} )
971
-
972
- expect(subject).to receive(:fetch_http_file).once.with(/\/deb\//, /-agent_/, /deb/)
973
- expect(subject).to receive(:scp_to).once.with(host, /-agent_/, "/root")
974
- expect(subject).to receive(:on).ordered.with(host, /dpkg\ -i\ --force-all/)
975
- expect(subject).to receive(:on).ordered.with(host, /apt-get\ update/)
976
-
977
- subject.install_puppetagent_dev_repo( host, opts )
978
- end
979
-
980
- it 'runs the correct install for windows platforms' do
981
- platform = Object.new()
982
- allow(platform).to receive(:to_array) { ['windows', '5', 'x64']}
983
- host = basic_hosts.first
984
- host['platform'] = platform
985
- opts = { :version => '0.1.0' }
986
- allow( subject ).to receive( :options ).and_return( {} )
987
- mock_echo = Object.new()
988
- allow( mock_echo ).to receive( :raw_output ).and_return( " " )
989
-
990
- expect(subject).to receive(:fetch_http_file).once.with(/\/windows$/, 'puppet-agent-x64.msi', /\/windows$/)
991
- expect(subject).to receive(:scp_to).once.with(host, /\/puppet-agent-x64.msi$/, /cygpath/)
992
- expect(subject).to receive(:on).ordered.with(host, /echo/).and_return(mock_echo)
993
- expect(subject).to receive(:on).ordered.with(host, anything)
994
-
995
- subject.install_puppetagent_dev_repo( host, opts )
996
- end
997
-
998
- it 'allows you to override the local copy directory' do
999
- platform = Object.new()
1000
- allow(platform).to receive(:to_array) { ['debian', '5', 'x4']}
1001
- host = basic_hosts.first
1002
- host['platform'] = platform
1003
- opts = { :version => '0.1.0', :copy_base_local => 'face' }
1004
- allow( subject ).to receive( :options ).and_return( {} )
1005
-
1006
- expect(subject).to receive(:fetch_http_file).once.with(/\/deb\//, /-agent_/, /face/)
1007
- expect(subject).to receive(:scp_to).once.with(host, /face/, "/root")
1008
- expect(subject).to receive(:on).ordered.with(host, /dpkg\ -i\ --force-all/)
1009
- expect(subject).to receive(:on).ordered.with(host, /apt-get\ update/)
1010
-
1011
- subject.install_puppetagent_dev_repo( host, opts )
1012
- end
1013
-
1014
- it 'allows you to override the external copy directory' do
1015
- platform = Object.new()
1016
- allow(platform).to receive(:to_array) { ['debian', '5', 'x4']}
1017
- host = basic_hosts.first
1018
- host['platform'] = platform
1019
- opts = { :version => '0.1.0', :copy_dir_external => 'muppetsB' }
1020
- allow( subject ).to receive( :options ).and_return( {} )
1021
-
1022
- expect(subject).to receive(:fetch_http_file).once.with(/\/deb\//, /-agent_/, /deb/)
1023
- expect(subject).to receive(:scp_to).once.with(host, /-agent_/, /muppetsB/)
1024
- expect(subject).to receive(:on).ordered.with(host, /dpkg\ -i\ --force-all/)
1025
- expect(subject).to receive(:on).ordered.with(host, /apt-get\ update/)
1026
-
1027
- subject.install_puppetagent_dev_repo( host, opts )
1028
- end
1029
-
1030
- end
1031
-
1032
- describe '#install_dev_puppet_module_on' do
1033
- context 'having set allow( a ).to receive forge' do
1034
- it 'stubs the forge on the host' do
1035
- master = hosts.first
1036
- allow( subject ).to receive( :options ).and_return( {:forge_host => 'ahost.com'} )
1037
-
1038
- expect( subject ).to receive( :with_forge_stubbed_on )
1039
-
1040
- subject.install_dev_puppet_module_on( master, {:source => '/module', :module_name => 'test'} )
1041
- end
1042
-
1043
- it 'installs via #install_puppet_module_via_pmt' do
1044
- master = hosts.first
1045
- allow( subject ).to receive( :options ).and_return( {:forge_host => 'ahost.com'} )
1046
- allow( subject ).to receive( :with_forge_stubbed_on ).and_yield
1047
-
1048
- expect( subject ).to receive( :install_puppet_module_via_pmt_on )
1049
-
1050
- subject.install_dev_puppet_module_on( master, {:source => '/module', :module_name => 'test'} )
1051
- end
1052
- end
1053
- context 'without allow( a ).to receive forge (default)' do
1054
- it 'calls copy_module_to to get the module on the SUT' do
1055
- master = hosts.first
1056
- allow( subject ).to receive( :options ).and_return( {} )
1057
-
1058
- expect( subject ).to receive( :copy_module_to )
1059
-
1060
- subject.install_dev_puppet_module_on( master, {:source => '/module', :module_name => 'test'} )
1061
- end
1062
- end
1063
- end
1064
-
1065
- describe '#install_dev_puppet_module' do
1066
- it 'delegates to #install_dev_puppet_module_on with the hosts list' do
1067
- allow( subject ).to receive( :hosts ).and_return( hosts )
1068
- allow( subject ).to receive( :options ).and_return( {} )
1069
-
1070
- hosts.each do |host|
1071
- expect( subject ).to receive( :install_dev_puppet_module_on ).
1072
- with( host, {:source => '/module', :module_name => 'test'})
1073
- end
1074
-
1075
- subject.install_dev_puppet_module( {:source => '/module', :module_name => 'test'} )
1076
- end
1077
- end
1078
-
1079
- describe '#install_puppet_module_via_pmt_on' do
1080
- it 'installs module via puppet module tool' do
1081
- allow( subject ).to receive( :hosts ).and_return( hosts )
1082
- master = hosts.first
1083
-
1084
-
1085
- expect( subject ).to receive( :puppet ).with('module install test ', {}).once
1086
-
1087
- subject.install_puppet_module_via_pmt_on( master, {:module_name => 'test'} )
1088
- end
1089
-
1090
- it 'takes the trace option and passes it down correctly' do
1091
- allow( subject ).to receive( :hosts ).and_return( hosts )
1092
- master = hosts.first
1093
- trace_opts = { :trace => nil }
1094
- master['default_module_install_opts'] = trace_opts
1095
-
1096
- expect( subject ).to receive( :puppet ).with('module install test ', trace_opts).once
1097
-
1098
- subject.install_puppet_module_via_pmt_on( master, {:module_name => 'test'} )
1099
- end
1100
- end
1101
-
1102
- describe '#install_puppet_module_via_pmt' do
1103
- it 'delegates to #install_puppet_module_via_pmt with the hosts list' do
1104
- allow( subject ).to receive( :hosts ).and_return( hosts )
1105
-
1106
- expect( subject ).to receive( :install_puppet_module_via_pmt_on ).with( hosts, {:source => '/module', :module_name => 'test'}).once
1107
-
1108
- subject.install_puppet_module_via_pmt( {:source => '/module', :module_name => 'test'} )
1109
- end
1110
- end
1111
-
1112
- describe 'copy_module_to' do
1113
- let(:ignore_list) { Beaker::DSL::InstallUtils::PUPPET_MODULE_INSTALL_IGNORE }
1114
- let(:source){ File.expand_path('./')}
1115
- let(:target){'/etc/puppetlabs/puppet/modules/testmodule'}
1116
- let(:module_parse_name){'testmodule'}
1117
-
1118
- shared_examples 'copy_module_to' do |opts|
1119
- it{
1120
- host = double("host")
1121
- allow( host ).to receive(:[]).with('distmoduledir').and_return('/etc/puppetlabs/puppet/modules')
1122
- result = double
1123
- stdout = target.split('/')[0..-2].join('/') + "\n"
1124
- allow( result ).to receive(:stdout).and_return( stdout )
1125
- expect( subject ).to receive(:on).with(host, "echo #{File.dirname(target)}" ).and_return(result )
1126
- allow( Dir ).to receive(:getpwd).and_return(source)
1127
-
1128
- allow( subject ).to receive(:parse_for_moduleroot).and_return(source)
1129
- if module_parse_name
1130
- allow( subject ).to receive(:parse_for_modulename).with(any_args()).and_return(module_parse_name)
1131
- else
1132
- expect( subject).to_not receive(:parse_for_modulename)
1133
- end
1134
-
1135
- allow( File ).to receive(:exists?).with(any_args()).and_return(false)
1136
- allow( File ).to receive(:directory?).with(any_args()).and_return(false)
1137
-
1138
- expect( subject ).to receive(:scp_to).with(host,source, File.dirname(target), {:ignore => ignore_list})
1139
- expect( subject ).to receive(:on).with(host, "mv #{File.join(File.dirname(target), File.basename(source))} #{target}")
1140
- if opts.nil?
1141
- subject.copy_module_to(host)
1142
- else
1143
- subject.copy_module_to(host,opts)
1144
- end
1145
- }
1146
- end
1147
-
1148
- describe 'should call scp with the correct info, with only providing host' do
1149
- let(:target){'/etc/puppetlabs/puppet/modules/testmodule'}
1150
-
1151
- it_should_behave_like 'copy_module_to', :module_name => 'testmodule'
1152
- end
1153
-
1154
- describe 'should call scp with the correct info, when specifying the modulename' do
1155
- let(:target){'/etc/puppetlabs/puppet/modules/bogusmodule'}
1156
- let(:module_parse_name){false}
1157
- it_should_behave_like 'copy_module_to', {:module_name =>'bogusmodule'}
1158
- end
1159
-
1160
- describe 'should call scp with the correct info, when specifying the target to a different path' do
1161
- target = '/opt/shared/puppet/modules'
1162
- let(:target){"#{target}/testmodule"}
1163
- it_should_behave_like 'copy_module_to', {:target_module_path => target, :module_name => 'testmodule'}
1164
- end
1165
-
1166
- describe 'should accept multiple hosts when' do
1167
- it 'used in a default manner' do
1168
- allow( subject ).to receive( :build_ignore_list ).and_return( [] )
1169
- allow( subject ).to receive( :parse_for_modulename ).and_return( [nil, 'modulename'] )
1170
- allow( subject ).to receive( :on ).and_return( double.as_null_object )
1171
- hosts = [{}, {}]
1172
-
1173
- expect( subject ).to receive( :scp_to ).twice
1174
- subject.copy_module_to( hosts )
1175
- end
1176
- end
1177
- end
1178
-
1179
- describe 'split_author_modulename' do
1180
- it 'should return a correct modulename' do
1181
- result = subject.split_author_modulename('myname-test_43_module')
1182
- expect(result[:author]).to eq('myname')
1183
- expect(result[:module]).to eq('test_43_module')
1184
- end
1185
- end
1186
-
1187
- describe 'get_module_name' do
1188
- it 'should return an array of author and modulename' do
1189
- expect(subject.get_module_name('myname-test_43_module')).to eq(['myname', 'test_43_module'])
1190
- end
1191
- it 'should return nil for invalid names' do
1192
- expect(subject.get_module_name('myname-')).to eq(nil)
1193
- end
1194
- end
1195
-
1196
- describe 'parse_for_modulename' do
1197
- directory = '/testfilepath/myname-testmodule'
1198
- it 'should return name from metadata.json' do
1199
- allow( File ).to receive(:exists?).with("#{directory}/metadata.json").and_return(true)
1200
- allow( File ).to receive(:read).with("#{directory}/metadata.json").and_return(" {\"name\":\"myname-testmodule\"} ")
1201
- expect( subject.logger ).to receive(:debug).with("Attempting to parse Modulename from metadata.json")
1202
- expect(subject.logger).to_not receive(:debug).with('Unable to determine name, returning null')
1203
- expect(subject.parse_for_modulename(directory)).to eq(['myname', 'testmodule'])
1204
- end
1205
- it 'should return name from Modulefile' do
1206
- allow( File ).to receive(:exists?).with("#{directory}/metadata.json").and_return(false)
1207
- allow( File ).to receive(:exists?).with("#{directory}/Modulefile").and_return(true)
1208
- allow( File ).to receive(:read).with("#{directory}/Modulefile").and_return("name 'myname-testmodule' \nauthor 'myname'")
1209
- expect( subject.logger ).to receive(:debug).with("Attempting to parse Modulename from Modulefile")
1210
- expect(subject.logger).to_not receive(:debug).with("Unable to determine name, returning null")
1211
- expect(subject.parse_for_modulename(directory)).to eq(['myname', 'testmodule'])
1212
- end
1213
- end
1214
-
1215
- describe 'parse_for_module_root' do
1216
- directory = '/testfilepath/myname-testmodule'
1217
- describe 'stops searching when either' do
1218
- it 'finds a Modulefile' do
1219
- allow( File ).to receive(:exists?).and_return(false)
1220
- allow( File ).to receive(:exists?).with("#{directory}/Modulefile").and_return(true)
1221
-
1222
- expect( subject.logger ).to_not receive(:debug).with("At root, can't parse for another directory")
1223
- expect( subject.logger ).to receive(:debug).with("No Modulefile or metadata.json found at #{directory}/acceptance, moving up")
1224
- expect(subject.parse_for_moduleroot("#{directory}/acceptance")).to eq(directory)
1225
- end
1226
- it 'finds a metadata.json file' do
1227
- allow( File ).to receive(:exists?).and_return(false)
1228
- allow( File ).to receive(:exists?).with("#{directory}/metadata.json").and_return(true)
1229
-
1230
- expect( subject.logger ).to_not receive(:debug).with("At root, can't parse for another directory")
1231
- expect( subject.logger ).to receive(:debug).with("No Modulefile or metadata.json found at #{directory}/acceptance, moving up")
1232
- expect(subject.parse_for_moduleroot("#{directory}/acceptance")).to eq(directory)
1233
- end
1234
- end
1235
- it 'should recersively go up the directory to find the module files' do
1236
- allow( File ).to receive(:exists?).and_return(false)
1237
- expect( subject.logger ).to receive(:debug).with("No Modulefile or metadata.json found at #{directory}, moving up")
1238
- expect( subject.logger ).to receive(:error).with("At root, can't parse for another directory")
1239
- expect(subject.parse_for_moduleroot(directory)).to eq(nil)
1240
- end
1241
- end
1242
- end