puppet_litmus 0.10.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2b4b8f9d03595ac86920511bc3ec0429c34e99ebb54fce2e0dd80bce3d233145
4
- data.tar.gz: c4a3bd340f4e215faa647111b6ba933d5669a43e4c06474ab4bc41766fb36235
3
+ metadata.gz: 28a5409c12ffc5d0ab3b083cabebff39be58c3ed41095cc9711a16f07f49852b
4
+ data.tar.gz: 9517425db215a6cbafdb1945260f09070dca8a550b2c511be0317c1c5097bac3
5
5
  SHA512:
6
- metadata.gz: 848d4c8ea4ff3b7b6e02f1404cbbd255d847a259fab02db44032b3982127c5c9a0358366557454f03a85645eb4e9a2ef35bc0e0da90d5fae2d68fb2094912b5d
7
- data.tar.gz: 85195c4df6ad10c37290acaba4d14cd4cb2d31950e8095a7afc5104e1a9d3050912dd4ff4a28b6bdcc90b3ff9cc7a956e5b0e1342bad4715ced75542ea0836c4
6
+ metadata.gz: 560edd1797551152c839db07af920345603d1a67d400301898b3e4b4841145892c50a0ffc18943c653712370cc1686612cb89503c6a8fc459524b803fcdc0bbf
7
+ data.tar.gz: 23c9cbf00d3f2af2343c1975b09eb5d43235d87b6cb32347a76db039d4f903aaa732b8ab7677eeeabea10ef08588e910032c2d9d9cf315a96b4aeef1cb8bd57c
@@ -61,6 +61,34 @@ module LitmusRakeHelper
61
61
 
62
62
  stdout
63
63
  end
64
+
65
+ # Builds all the modules in a specified module
66
+ #
67
+ # @param source_folder [String] the folder to get the modules from
68
+ # @return [Array] an array of module tar's
69
+ def build_modules_in_folder(source_folder)
70
+ require 'pdk/module/build'
71
+ folder_list = Dir.entries(source_folder).reject { |f| File.directory? f }
72
+ module_tars = []
73
+ folder_list.each do |folder|
74
+ file = File.new(File.join(source_folder, folder))
75
+ next if File.symlink?(file)
76
+
77
+ opts = {}
78
+ opts[:module_dir] = file.path
79
+ opts[:'target-dir'] = File.join(Dir.pwd, 'pkg')
80
+ opts[:force] = true
81
+ builder = PDK::Module::Build.new(opts)
82
+
83
+ # remove old build folder if exists, before we build afresh
84
+ FileUtils.rm_rf(builder.build_dir) if File.directory?(builder.build_dir)
85
+
86
+ # build_module
87
+ module_tar = builder.build
88
+ module_tars.push(File.new(module_tar))
89
+ end
90
+ module_tars
91
+ end
64
92
  end
65
93
 
66
94
  namespace :litmus do
@@ -75,11 +103,16 @@ namespace :litmus do
75
103
  end
76
104
 
77
105
  # Provisions a list of OSes from provision.yaml file e.g. 'bundle exec rake litmus:provision_list[default]'.
106
+ # @See https://github.com/puppetlabs/puppet_litmus/wiki/Overview-of-Litmus#provisioning-via-yaml
78
107
  #
79
108
  # @param :key [String] key that maps to a value for a provisioner and an image to be used for each OS provisioned.
80
109
  desc "provision list of machines from provision.yaml file. 'bundle exec rake 'litmus:provision_list[default]'"
81
110
  task :provision_list, [:key] do |_task, args|
111
+ raise 'Cannot find provision.yaml file' unless File.file?('./provision.yaml')
112
+
82
113
  provision_hash = YAML.load_file('./provision.yaml')
114
+ raise "No key #{args[:key]} in ./provision.yaml, see https://github.com/puppetlabs/puppet_litmus/wiki/Overview-of-Litmus#provisioning-via-yaml for examples" if provision_hash[args[:key]].nil?
115
+
83
116
  provisioner = provision_hash[args[:key]]['provisioner']
84
117
  inventory_vars = provision_hash[args[:key]]['vars']
85
118
  # Splat the params into environment variables to pass to the provision task but only in this runspace
@@ -188,6 +221,45 @@ namespace :litmus do
188
221
  end
189
222
  end
190
223
 
224
+ # Install the puppet modules from a source directory to nodes. It does not install dependencies.
225
+ #
226
+ # @param :source [String] source directory to look in (ignores symlinks) defaults do './spec/fixtures/modules'.
227
+ # @param :target_node_name [Array] nodes on which to install a puppet module for testing.
228
+ desc 'install_module - build and install module'
229
+ task :install_modules_from_directory, [:source, :target_node_name] do |_task, args|
230
+ inventory_hash = inventory_hash_from_inventory_file
231
+ target_nodes = find_targets(inventory_hash, args[:target_node_name])
232
+ if target_nodes.empty?
233
+ puts 'No targets found'
234
+ exit 0
235
+ end
236
+ source_folder = if args[:source].nil?
237
+ './spec/fixtures/modules'
238
+ else
239
+ File.expand_path(args[:source])
240
+ end
241
+ raise "Source folder doesnt exist #{source_folder}" unless File.directory?(source_folder)
242
+
243
+ module_tars = build_modules_in_folder(source_folder)
244
+ puts 'Building'
245
+ module_tars.each do |module_tar|
246
+ print "#{File.basename(module_tar)} "
247
+ end
248
+ include BoltSpec::Run
249
+ puts "\nSending"
250
+ module_tars.each do |module_tar|
251
+ upload_file(module_tar.path, "/tmp/#{File.basename(module_tar)}", target_nodes, options: {}, config: nil, inventory: inventory_hash)
252
+ print "#{File.basename(module_tar)} "
253
+ end
254
+ puts "\nInstalling"
255
+ module_tars.each do |module_tar|
256
+ # install_module
257
+ install_module_command = "puppet module install --force /tmp/#{File.basename(module_tar)}"
258
+ run_command(install_module_command, target_nodes, config: nil, inventory: inventory_hash)
259
+ print "#{File.basename(module_tar)} "
260
+ end
261
+ end
262
+
191
263
  # Install the puppet module under test on a collection of nodes
192
264
  #
193
265
  # @param :target_node_name [Array] nodes on which to install a puppet module for testing.
@@ -2,5 +2,5 @@
2
2
 
3
3
  # version of this gem
4
4
  module PuppetLitmus
5
- VERSION ||= '0.10.0'
5
+ VERSION ||= '0.11.0'
6
6
  end
File without changes
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'spec_helper'
4
4
  require 'rake'
5
-
5
+ # rubocop:disable RSpec/AnyInstance
6
6
  describe 'litmus rake tasks' do
7
7
  before(:all) do # rubocop:disable RSpec/BeforeAfterAll
8
8
  load File.expand_path('../../../lib/puppet_litmus/rake_tasks.rb', __dir__)
@@ -27,6 +27,25 @@ describe 'litmus rake tasks' do
27
27
  end
28
28
  end
29
29
 
30
+ context 'with litmus:install_modules_from_directory' do
31
+ let(:inventory_hash) { { 'groups' => [{ 'name' => 'ssh_nodes', 'nodes' => [{ 'name' => 'some.host' }] }] } }
32
+ let(:target_folder) { File.join(Dir.pwd, 'spec/fixtures/modules') }
33
+ let(:dummy_tar) { File.new('spec/data/doot.tar.gz') }
34
+
35
+ it 'happy path' do
36
+ stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
37
+ expect_any_instance_of(PuppetLitmus::InventoryManipulation).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
38
+ expect(File).to receive(:directory?).with(target_folder).and_return(true)
39
+ expect_any_instance_of(Object).to receive(:build_modules_in_folder).with(target_folder).and_return([dummy_tar])
40
+ expect(STDOUT).to receive(:puts).with('Building')
41
+ expect(STDOUT).to receive(:puts).with("\nSending")
42
+ expect_any_instance_of(Object).to receive(:upload_file).once
43
+ expect(STDOUT).to receive(:puts).with("\nInstalling")
44
+ expect_any_instance_of(Object).to receive(:run_command).once
45
+ Rake::Task['litmus:install_modules_from_directory'].invoke('./spec/fixtures/modules')
46
+ end
47
+ end
48
+
30
49
  context 'with litmus:provision_install task' do
31
50
  it 'happy path' do
32
51
  expect(Rake::Task['spec_prep']).to receive(:invoke).and_return('').once
@@ -38,7 +57,7 @@ describe 'litmus rake tasks' do
38
57
  end
39
58
 
40
59
  context 'with litmus:provision task' do
41
- it 'provisions' do
60
+ it 'happy path' do
42
61
  results = [{ 'node' => 'localhost',
43
62
  'target' => 'localhost',
44
63
  'action' => 'task',
@@ -47,9 +66,21 @@ describe 'litmus rake tasks' do
47
66
  'result' => { 'status' => 'ok', 'node_name' => 'localhost:2222' } }]
48
67
 
49
68
  allow(File).to receive(:directory?).with(any_args).and_return(true)
50
- allow_any_instance_of(BoltSpec::Run).to receive(:run_task).with(any_args).and_return(results) # rubocop:disable RSpec/AnyInstance
69
+ allow_any_instance_of(BoltSpec::Run).to receive(:run_task).with(any_args).and_return(results)
51
70
  expect(STDOUT).to receive(:puts).with('localhost:2222, centos:7')
52
71
  Rake::Task['litmus:provision'].invoke('docker', 'centos:7')
53
72
  end
54
73
  end
74
+
75
+ context 'with litmus:provision_list task' do
76
+ let(:provision_file) { './provision.yaml' }
77
+ let(:provision_hash) { { 'default' => { 'provisioner' => 'docker', 'images' => ['waffleimage/centos7'] } } }
78
+
79
+ it 'no key in provision file' do
80
+ allow(File).to receive(:file?).with(any_args).and_return(true)
81
+ expect(YAML).to receive(:load_file).with(provision_file).and_return(provision_hash)
82
+ expect { Rake::Task['litmus:provision_list'].invoke('deet') }.to raise_error(%r{deet})
83
+ end
84
+ end
55
85
  end
86
+ # rubocop:enable RSpec/AnyInstance
@@ -145,6 +145,7 @@ RSpec.describe PuppetLitmus::Serverspec do
145
145
  expect(dummy_class).to receive(:upload_file).with(local, remote, 'some.host', options: {}, config: nil, inventory: inventory_hash).and_return(result_success)
146
146
  expect { dummy_class.bolt_upload_file(local, remote) }.not_to raise_error
147
147
  end
148
+
148
149
  it 'does upload_file against localhost without error' do
149
150
  stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'localhost'))
150
151
  expect(File).to receive(:exist?).with('inventory.yaml').and_return(false)
@@ -165,6 +166,7 @@ RSpec.describe PuppetLitmus::Serverspec do
165
166
  expect(dummy_class).to receive(:upload_file).with(local, remote, 'some.host', options: {}, config: nil, inventory: inventory_hash).and_return(result_failure)
166
167
  expect { dummy_class.bolt_upload_file(local, remote) }.to raise_error(RuntimeError, %r{upload file failed})
167
168
  end
169
+
168
170
  it 'returns the exit code and error message when expecting failure' do
169
171
  stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
170
172
  expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
@@ -249,6 +251,7 @@ RSpec.describe PuppetLitmus::Serverspec do
249
251
  expect(dummy_class).to receive(:run_task).with(task_name, 'some.host', params, config: config_data, inventory: inventory_hash).and_return(result_unstructured_task_success)
250
252
  expect { dummy_class.run_bolt_task(task_name, params, opts: {}) }.not_to raise_error
251
253
  end
254
+
252
255
  it 'returns stdout for unstructured-data tasks' do
253
256
  stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
254
257
  expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
@@ -258,6 +261,7 @@ RSpec.describe PuppetLitmus::Serverspec do
258
261
  method_result = dummy_class.run_bolt_task(task_name, params, opts: {})
259
262
  expect(method_result.stdout).to eq('SUCCESS!')
260
263
  end
264
+
261
265
  it 'returns structured output for structured-data tasks' do
262
266
  stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
263
267
  expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
@@ -280,6 +284,7 @@ RSpec.describe PuppetLitmus::Serverspec do
280
284
  expect(dummy_class).to receive(:run_task).with(task_name, 'some.host', params, config: config_data, inventory: inventory_hash).and_return(result_failure)
281
285
  expect { dummy_class.run_bolt_task(task_name, params, opts: {}) }.to raise_error(RuntimeError, %r{task failed})
282
286
  end
287
+
283
288
  it 'returns the exit code and error message when expecting failure' do
284
289
  stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
285
290
  expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet_litmus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-26 00:00:00.000000000 Z
11
+ date: 2019-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bolt
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: 1.13.1
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: 1.29.1
22
+ version: 2.0.0
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: 1.13.1
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: 1.29.1
32
+ version: 2.0.0
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: pdk
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -70,6 +70,26 @@ dependencies:
70
70
  - - "<"
71
71
  - !ruby/object:Gem::Version
72
72
  version: 1.0.0
73
+ - !ruby/object:Gem::Dependency
74
+ name: docker-api
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '1.34'
80
+ - - "<"
81
+ - !ruby/object:Gem::Version
82
+ version: 2.0.0
83
+ type: :runtime
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '1.34'
90
+ - - "<"
91
+ - !ruby/object:Gem::Version
92
+ version: 2.0.0
73
93
  description: " Providing a simple command line tool for puppet content creators,
74
94
  to enable simple and complex test deployments.\n"
75
95
  email:
@@ -85,6 +105,7 @@ files:
85
105
  - lib/puppet_litmus/rake_tasks.rb
86
106
  - lib/puppet_litmus/serverspec.rb
87
107
  - lib/puppet_litmus/version.rb
108
+ - spec/data/doot.tar.gz
88
109
  - spec/data/inventory.yaml
89
110
  - spec/lib/puppet_litmus/inventory_manipulation_spec.rb
90
111
  - spec/lib/puppet_litmus/rake_tasks_spec.rb
@@ -122,4 +143,5 @@ test_files:
122
143
  - spec/lib/puppet_litmus/version_spec.rb
123
144
  - spec/lib/puppet_litmus/inventory_manipulation_spec.rb
124
145
  - spec/lib/puppet_litmus/serverspec_spec.rb
146
+ - spec/data/doot.tar.gz
125
147
  - spec/data/inventory.yaml