simp-beaker-helpers 1.5.5 → 1.5.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1ba9384c22def9cd5c3e88c7298533a61e9d8277
4
- data.tar.gz: 4e7cba748d9a2cb2293c0eddc5cc021d636dcf7a
3
+ metadata.gz: 8f3ff792835639c1d173825e4d7ad5a29e0340a3
4
+ data.tar.gz: 88c6466aa066ec0cb670de639329dad0f72c5870
5
5
  SHA512:
6
- metadata.gz: 9bdb0cb88a262d8e2cfc44ce412a7d1b4de292db036fc503a7e4776259aa49f15e892255857b9f7ab7bb3624ff238938fa32b9b58ed3678bb8d5b4893c97059b
7
- data.tar.gz: f206d78e24d4f5a46dc13d4369c45c9fa2cff961da229c198d9e041776bdf2960369f780116831dff9ecf6e96229cf4613b4cedd30833459c019ed67d3d9ce0e
6
+ metadata.gz: 3d302c7b7af35a327f39e1b8dc8e6958fa73a7afb918a12f4d4078b9b12ae1251da15cf62a6592626ea385c31d741cda1ed935e00e77c7353e1726b699fe1439
7
+ data.tar.gz: d3999f5dc684959e1a188a21c93d30583dc7f5a097b132187c229d1720cf6eca74231a4d1e25b9cbb7d12e4c8d5d6599cafc82659e2f2a0778cf9b0df7003c35
data/Gemfile CHANGED
@@ -17,6 +17,7 @@ group :system_tests do
17
17
  gem 'pry'
18
18
  gem 'beaker'
19
19
  gem 'beaker-rspec'
20
+ gem 'vagrant-wrapper'
20
21
  # NOTE: Workaround because net-ssh 2.10 is busting beaker
21
22
  # lib/ruby/1.9.1/socket.rb:251:in `tcp': wrong number of arguments (5 for 4) (ArgumentError)
22
23
  gem 'net-ssh', '~> 2.9.0'
data/README.md CHANGED
@@ -21,6 +21,7 @@ Methods to assist beaker acceptance tests for SIMP.
21
21
  * [`pfact_on`](#pfact_on)
22
22
  * [`pluginsync_on`](#pluginsync_on)
23
23
  * Hiera
24
+ * [`write_hieradata_to`](#write_hieradata_to)
24
25
  * [`set_hieradata_on`](#set_hieradata_on)
25
26
  * [`clear_temp_hieradata`](#clear_temp_hieradata)
26
27
  6. [Environment variables](#environment-variables)
@@ -232,18 +233,30 @@ Simulates a `pluginsync` (useful for deploying custom facts) on given SUTs.
232
233
 
233
234
  `pluginsync_on( suts = hosts )`
234
235
 
236
+ #### `write_hieradata_to`
237
+
238
+ Writes a YAML file in the Hiera :datadir of a Beaker::Host.
239
+
240
+ **NOTE**: This is useless unless Hiera is configured to use the data file.
241
+ `Beaker::DSL::Helpers::Hiera#write_hiera_config_on` from [beaker-hiera](https://github.com/puppetlabs/beaker-hiera) may be used to configure Hiera.
242
+
243
+ `write_hieradata_to(host, hieradata, terminus = 'default')`
244
+
245
+ - **`host`** = _(Array,String,Symbol)_ One or more hosts to act upon
246
+ - **`hieradata`** = _(Hash)_ The full hiera data structure to write to the system
247
+ - **`terminus`** = _(String)_ The file basename minus the file extension in which to write the Hiera data
235
248
 
236
249
  #### `set_hieradata_on`
237
250
 
238
- Set the hiera data file on the provided host to the passed data structure
251
+ Writes a YAML file in the Hiera :datdir of a Beaker::Host, then configures the host to use that file exclusively.
239
252
 
240
- **NOTE**: This is authoritative; you cannot mix this with other hieradata copies
253
+ **NOTE**: This is authoritative; you cannot mix this with other Hiera data sources.
241
254
 
242
- `set_hieradata_on(host, hieradata, data_file='default')`
255
+ `set_hieradata_on(host, hieradata, terminus = 'default')`
243
256
 
244
257
  - **`host`** = _(Array,String,Symbol)_ One or more hosts to act upon
245
258
  - **`hieradata`** = _(Hash)_ The full hiera data structure to write to the system
246
- - **`data_file`** = _(String)_ The filename (not path) of the hiera data
259
+ - **`terminus`** = _(String)_ The file basename minus the file extension in which to write the Hiera data
247
260
 
248
261
  #### `clear_temp_hieradata`
249
262
 
@@ -1,7 +1,7 @@
1
1
  module Simp; end
2
2
 
3
3
  module Simp::BeakerHelpers
4
- VERSION = '1.5.5'
4
+ VERSION = '1.5.6'
5
5
 
6
6
  # use the `puppet fact` face to look up facts on an SUT
7
7
  def pfact_on(sut, fact_name)
@@ -289,6 +289,10 @@ DEFAULT_KERNEL_TITLE=`/sbin/grubby --info=\\\${DEFAULT_KERNEL_INFO} | grep -m1 t
289
289
  def fix_errata_on( suts = hosts )
290
290
 
291
291
  suts.each do |sut|
292
+ # We need to be able to flip between server and client without issue
293
+ on sut, 'puppet resource group puppet gid=52'
294
+ on sut, 'puppet resource user puppet comment="Puppet" gid="52" uid="52" home="/var/lib/puppet" managehome=true'
295
+
292
296
  # SIMP uses structured facts, therefore stringify_facts must be disabled
293
297
  unless ENV['BEAKER_stringify_facts'] == 'yes'
294
298
  on sut, 'puppet config set stringify_facts false'
@@ -440,51 +444,62 @@ done
440
444
  end
441
445
 
442
446
 
443
- # Set the hiera data file on the provided host to the passed data structure
447
+ # Writes a YAML file in the Hiera :datadir of a Beaker::Host.
444
448
  #
445
- # Note: This is authoritative, you cannot mix this with other hieradata copies
449
+ # @note This is useless unless Hiera is configured to use the data file.
450
+ # @see `Beaker::DSL::Helpers::Hiera#write_hiera_config_on`
446
451
  #
447
- # @param[sut, Array<Host>, String, Symbol] One or more hosts to act upon.
452
+ # @param sut [Array<Host>, String, Symbol] One or more hosts to act upon.
448
453
  #
449
- # @param[heradata, Hash || String] The full hiera data structure to write to the system.
454
+ # @param heradata [Hash, String] The full hiera data structure to write to
455
+ # the system.
450
456
  #
451
- # @param[data_file, String] The filename (not path) of the hiera data
452
- # YAML file to write to the system.
457
+ # @param terminus [String] The basename of the YAML file minus the extension
458
+ # to write to the system.
453
459
  #
454
- # @param[hiera_config, Array<String>] The hiera config array to write
455
- # to the system. Must contain the
456
- # Data_file name as one element.
457
- def set_hieradata_on(sut, hieradata, data_file='default')
458
- # Keep a record of all temporary directories that are created
459
- #
460
- # Should be cleaned by calling `clear_temp_hiera data` in after(:all)
461
- #
462
- # Omit this call to be able to delve into the hiera data that is
463
- # being created
464
- @temp_hieradata_dirs = @temp_hieradata_dirs || []
465
-
460
+ # @return [Nil]
461
+ #
462
+ # @note This creates a tempdir on the host machine which should be removed
463
+ # using `#clear_temp_hieradata` in the `after(:all)` hook. It may also be
464
+ # retained for debugging purposes.
465
+ #
466
+ def write_hieradata_to(sut, hieradata, terminus = 'default')
467
+ @temp_hieradata_dirs ||= []
466
468
  data_dir = Dir.mktmpdir('hieradata')
467
469
  @temp_hieradata_dirs << data_dir
468
470
 
469
- fh = File.open(File.join(data_dir,"#{data_file}.yaml"),'w')
470
- if hieradata.kind_of? String
471
+ fh = File.open(File.join(data_dir, "#{terminus}.yaml"), 'w')
472
+ if hieradata.is_a?(String)
471
473
  fh.puts(hieradata)
472
474
  else
473
475
  fh.puts(hieradata.to_yaml)
474
476
  end
475
-
476
477
  fh.close
477
478
 
478
- # If there is already a directory on the system, the SCP below will
479
- # add the local directory to the existing directory instead of
480
- # replacing the contents.
481
- apply_manifest_on(
482
- sut,
483
- "file { '#{hiera_datadir(sut)}': ensure => 'absent', force => true, recurse => true }"
484
- )
479
+ apply_manifest_on sut, "file { '#{hiera_datadir(sut)}': ensure => 'directory', force => true }"
480
+ copy_hiera_data_to sut, File.join(data_dir, "#{terminus}.yaml")
481
+ end
482
+
485
483
 
486
- copy_hiera_data_to(sut, data_dir)
487
- write_hiera_config_on(sut, Array(data_file))
484
+ # Write the provided data structure to Hiera's :datadir and configure Hiera to
485
+ # use that data exclusively.
486
+ #
487
+ # @note This is authoritative. It manages both Hiera data and configuration,
488
+ # so it may not be used with other Hiera data sources.
489
+ #
490
+ # @param sut [Array<Host>, String, Symbol] One or more hosts to act upon.
491
+ #
492
+ # @param heradata [Hash, String] The full hiera data structure to write to
493
+ # the system.
494
+ #
495
+ # @param terminus [String] The basename of the YAML file minus the extension
496
+ # to write to the system.
497
+ #
498
+ # @return [Nil]
499
+ #
500
+ def set_hieradata_on(sut, hieradata, terminus = 'default')
501
+ write_hieradata_to sut, hieradata, terminus
502
+ write_hiera_config_on sut, Array(terminus)
488
503
  end
489
504
 
490
505
 
@@ -0,0 +1,57 @@
1
+ require 'spec_helper_acceptance'
2
+
3
+ hosts.each do |host|
4
+ describe '#set_hieradata_on' do
5
+ context 'when passed a YAML string' do
6
+ before(:all) { set_hieradata_on(host, "---\n") }
7
+ after(:all) { on(host, "rm -rf #{host.puppet['hiera_config']} #{hiera_datadir(host)}") }
8
+
9
+ it 'creates the datadir' do
10
+ on host, "test -d #{hiera_datadir(host)}"
11
+ end
12
+
13
+ it 'writes to the configuration file' do
14
+ stdout = on(host, "cat #{host.puppet['hiera_config']}").stdout
15
+ expect(stdout).to match(":hierarchy:\n- default")
16
+ end
17
+
18
+ it 'writes the correct contents to the correct file' do
19
+ stdout = on(host, "cat #{hiera_datadir(host)}/default.yaml").stdout
20
+ expect(stdout).to eq("---\n")
21
+ end
22
+ end
23
+
24
+ context 'when passed a hash' do
25
+ before(:all) { set_hieradata_on(host, { 'foo' => 'bar' }) }
26
+ after(:all) { on(host, "rm -rf #{host.puppet['hiera_config']} #{hiera_datadir(host)}") }
27
+
28
+ it 'creates the datadir' do
29
+ on host, "test -d #{hiera_datadir(host)}"
30
+ end
31
+
32
+ it 'writes the correct contents to the correct file' do
33
+ stdout = on(host, "cat #{hiera_datadir(host)}/default.yaml").stdout
34
+ expect(stdout).to eq("---\nfoo: bar\n")
35
+ end
36
+ end
37
+
38
+ context 'when the terminus is set' do
39
+ before(:all) { set_hieradata_on(host, "---\n", 'not-default') }
40
+ after(:all) { on(host, "rm -rf #{host.puppet['hiera_config']} #{hiera_datadir(host)}") }
41
+
42
+ it 'creates the datadir' do
43
+ on host, "test -d #{hiera_datadir(host)}"
44
+ end
45
+
46
+ it 'writes the correct hierarchy to the configuration file' do
47
+ stdout = on(host, "cat #{host.puppet['hiera_config']}").stdout
48
+ expect(stdout).to match(":hierarchy:\n- not-default")
49
+ end
50
+
51
+ it 'writes the correct contents to the correct file' do
52
+ stdout = on(host, "cat #{hiera_datadir(host)}/not-default.yaml").stdout
53
+ expect(stdout).to eq("---\n")
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper_acceptance'
2
+
3
+ hosts.each do |host|
4
+ describe '#write_hieradata_to' do
5
+ context 'when passed a YAML string' do
6
+ before(:all) { set_hieradata_on(host, "---\n") }
7
+ after(:all) { on(host, "rm -rf #{hiera_datadir(host)}") }
8
+
9
+ it 'creates the datadir' do
10
+ on host, "test -d #{hiera_datadir(host)}"
11
+ end
12
+
13
+ it 'writes the correct contents to the correct file' do
14
+ stdout = on(host, "cat #{hiera_datadir(host)}/default.yaml").stdout
15
+ expect(stdout).to eq("---\n")
16
+ end
17
+ end
18
+
19
+ context 'when passed a hash' do
20
+ before(:all) { set_hieradata_on(host, { 'foo' => 'bar' }) }
21
+ after(:all) { on(host, "rm -rf #{hiera_datadir(host)}") }
22
+
23
+ it 'creates the datadir' do
24
+ on host, "test -d #{hiera_datadir(host)}"
25
+ end
26
+
27
+ it 'writes the correct contents to the correct file' do
28
+ stdout = on(host, "cat #{hiera_datadir(host)}/default.yaml").stdout
29
+ expect(stdout).to eq("---\nfoo: bar\n")
30
+ end
31
+ end
32
+
33
+ context 'when the terminus is set' do
34
+ before(:all) { set_hieradata_on(host, "---\n", 'not-default') }
35
+ after(:all) { on(host, "rm -rf #{hiera_datadir(host)}") }
36
+
37
+ it 'creates the datadir' do
38
+ on host, "test -d #{hiera_datadir(host)}"
39
+ end
40
+
41
+ it 'writes the correct contents to the correct file' do
42
+ stdout = on(host, "cat #{hiera_datadir(host)}/not-default.yaml").stdout
43
+ expect(stdout).to eq("---\n")
44
+ end
45
+ end
46
+ end
47
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simp-beaker-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.5
4
+ version: 1.5.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Tessmer
@@ -9,20 +9,20 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-07-27 00:00:00.000000000 Z
12
+ date: 2016-09-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: beaker
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "~>"
18
+ - - ~>
19
19
  - !ruby/object:Gem::Version
20
20
  version: '2'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - "~>"
25
+ - - ~>
26
26
  - !ruby/object:Gem::Version
27
27
  version: '2'
28
28
  description: |2
@@ -32,10 +32,10 @@ executables: []
32
32
  extensions: []
33
33
  extra_rdoc_files: []
34
34
  files:
35
- - ".fixtures.yml"
36
- - ".gitignore"
37
- - ".rspec"
38
- - ".travis.yml"
35
+ - .fixtures.yml
36
+ - .gitignore
37
+ - .rspec
38
+ - .travis.yml
39
39
  - Gemfile
40
40
  - LICENSE
41
41
  - README.md
@@ -53,6 +53,8 @@ files:
53
53
  - spec/acceptance/nodesets/centos-combined-x64.yaml
54
54
  - spec/acceptance/nodesets/default.yml
55
55
  - spec/acceptance/pki_tests_spec.rb
56
+ - spec/acceptance/set_hieradata_on_spec.rb
57
+ - spec/acceptance/write_hieradata_to_spec.rb
56
58
  - spec/spec_helper_acceptance.rb
57
59
  homepage: https://github.com/simp/rubygem-simp-beaker-helpers
58
60
  licenses:
@@ -65,12 +67,12 @@ require_paths:
65
67
  - lib
66
68
  required_ruby_version: !ruby/object:Gem::Requirement
67
69
  requirements:
68
- - - ">="
70
+ - - '>='
69
71
  - !ruby/object:Gem::Version
70
72
  version: '0'
71
73
  required_rubygems_version: !ruby/object:Gem::Requirement
72
74
  requirements:
73
- - - ">="
75
+ - - '>='
74
76
  - !ruby/object:Gem::Version
75
77
  version: '0'
76
78
  requirements: []
@@ -86,4 +88,6 @@ test_files:
86
88
  - spec/acceptance/nodesets/centos-combined-x64.yaml
87
89
  - spec/acceptance/nodesets/default.yml
88
90
  - spec/acceptance/pki_tests_spec.rb
91
+ - spec/acceptance/set_hieradata_on_spec.rb
92
+ - spec/acceptance/write_hieradata_to_spec.rb
89
93
  - spec/spec_helper_acceptance.rb