simp-beaker-helpers 1.11.0 → 1.11.1

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: 595569d32fa2838087255deae0d053e768bf419795f2ba6e5dc2eba10a36a925
4
- data.tar.gz: 42b829bc3b86cabbfe51034f02e65d4bfea6e05e66f7a5d0fc21a9d19a29614b
3
+ metadata.gz: de20d90d702274ad89d7c0f4971cf392e7b9810dd81c19d2a18713e2094c2e8e
4
+ data.tar.gz: 98364f3ad80cb62f625e5b83fbe284e4b303a99e09bf2227d22f9e3adbf40603
5
5
  SHA512:
6
- metadata.gz: c4e100cfb8b50c78604d4731498cc4508cd6ed5e396da7d6b426a6f3f2250f7aa5048a059d8ef52a8bc0ec8d40c4842e6eb8dccdd8dd8206cb48b33c413ade23
7
- data.tar.gz: 3efbd63c6dff000c2de7fca7fef88afcf390249d7b17610ed5ee29b0b4a3a137c043a4dce520b74342693192e5e991feb6285b8f4984dea891ff045daf271549
6
+ metadata.gz: d94eb890371b09ce7f2bcaa315dc6fe723228364a5186a0d363d4f56a14a4c744e171307d53251abe23460290aabd96b6124f82d30e8f79bd350ff6b6a2ac599
7
+ data.tar.gz: 1cd900c931008350da80b0b13856538d01afcac2a9c912a7d546953321069ed3f4e915ab2b59052c1f413d651ce5bcc307cc3bf46d13b0d56c6edc4556e7dc69
data/CHANGELOG.md CHANGED
@@ -1,4 +1,11 @@
1
- ### 1.11.0 / 2018-09-09
1
+ ### 1.11.1 / 2018-10-03
2
+ * Deprecate the 'terminus' parameter in 'write_hieradata_to' and 'set_hieradata_on'
3
+ * Add 'copy_hiera_data_to' method to replace the one from beaker-hiera
4
+ * Add 'hiera_datadir' method to replace the one from beaker-hiera
5
+ * Change InSpec to use the 'reporter' option instead of 'format'
6
+ * Update the SSG to point to the new ComplianceAsCode repository
7
+
8
+ ### 1.11.0 / 2018-10-01
2
9
  * Add support for Beaker 4
3
10
 
4
11
  ### 1.10.14 / 2018-08-01
@@ -83,9 +83,7 @@ module Simp::BeakerHelpers
83
83
 
84
84
  # Returns the modulepath on the SUT, as an Array
85
85
  def puppet_modulepath_on(sut, environment='production')
86
- on(
87
- sut, "puppet config print --section main modulepath --environment #{environment} 2>/dev/null"
88
- ).output.lines.last.strip.split(':')
86
+ sut.puppet['modulepath'].split(':')
89
87
  end
90
88
 
91
89
  # Return the path to the 'spec/fixtures' directory
@@ -607,15 +605,15 @@ done
607
605
  # Writes a YAML file in the Hiera :datadir of a Beaker::Host.
608
606
  #
609
607
  # @note This is useless unless Hiera is configured to use the data file.
610
- # @see `Beaker::DSL::Helpers::Hiera#write_hiera_config_on`
608
+ # @see `#write_hiera_config_on`
611
609
  #
612
610
  # @param sut [Array<Host>, String, Symbol] One or more hosts to act upon.
613
611
  #
614
- # @param heradata [Hash, String] The full hiera data structure to write to
612
+ # @param hieradata [Hash, String] The full hiera data structure to write to
615
613
  # the system.
616
614
  #
617
- # @param terminus [String] The basename of the YAML file minus the extension
618
- # to write to the system.
615
+ # @param terminus [String] DEPRECATED - This will be removed in a future
616
+ # release and currently has no effect.
619
617
  #
620
618
  # @return [Nil]
621
619
  #
@@ -623,12 +621,12 @@ done
623
621
  # using `#clear_temp_hieradata` in the `after(:all)` hook. It may also be
624
622
  # retained for debugging purposes.
625
623
  #
626
- def write_hieradata_to(sut, hieradata, terminus = 'default')
624
+ def write_hieradata_to(sut, hieradata, terminus = 'deprecated')
627
625
  @temp_hieradata_dirs ||= []
628
626
  data_dir = Dir.mktmpdir('hieradata')
629
627
  @temp_hieradata_dirs << data_dir
630
628
 
631
- fh = File.open(File.join(data_dir, "#{terminus}.yaml"), 'w')
629
+ fh = File.open(File.join(data_dir, 'common.yaml'), 'w')
632
630
  if hieradata.is_a?(String)
633
631
  fh.puts(hieradata)
634
632
  else
@@ -636,10 +634,65 @@ done
636
634
  end
637
635
  fh.close
638
636
 
639
- apply_manifest_on sut, "file { '#{hiera_datadir(sut)}': ensure => 'directory', force => true }"
640
- copy_hiera_data_to sut, File.join(data_dir, "#{terminus}.yaml")
637
+ copy_hiera_data_to sut, File.join(data_dir, 'common.yaml')
638
+ end
639
+
640
+ # A shim to stand in for the now deprecated copy_hiera_data_to function
641
+ #
642
+ # @param sut [Host] One host to act upon
643
+ #
644
+ # @param [Path] File containing hiera data
645
+ def copy_hiera_data_to(sut, path)
646
+ copy_to(sut, path, hiera_datadir(sut))
641
647
  end
642
648
 
649
+ # A shim to stand in for the now deprecated hiera_datadir function
650
+ #
651
+ # Note: This may not work if you've shoved data somewhere that is not the
652
+ # default and/or are manipulating the default hiera.yaml.
653
+ #
654
+ # @param sut [Host] One host to act upon
655
+ #
656
+ # @returns [String] Path to the Hieradata directory on the target system
657
+ def hiera_datadir(sut)
658
+ # This output lets us know where Hiera is configured to look on the system
659
+ puppet_lookup_info = on(sut, 'puppet lookup --explain test__simp__test').output.strip.lines
660
+
661
+ if sut.puppet['manifest'].nil? || sut.puppet['manifest'].empty?
662
+ fail("No output returned from `puppet config print manifest` on #{sut}")
663
+ end
664
+
665
+ puppet_env_path = File.dirname(sut.puppet['manifest'])
666
+
667
+ # We'll just take the first match since Hiera will find things there
668
+ puppet_lookup_info = puppet_lookup_info.grep(/Path "/).grep(Regexp.new(puppet_env_path))
669
+
670
+ # Grep always returns an Array
671
+ if puppet_lookup_info.empty?
672
+ fail("Could not determine hiera data directory under #{puppet_env_path} on #{sut}")
673
+ end
674
+
675
+ # Snag the actual path without the extra bits
676
+ puppet_lookup_info = puppet_lookup_info.first.strip.split('"').last
677
+
678
+ # Make the parent directories exist
679
+ sut.mkdir_p(File.dirname(puppet_lookup_info))
680
+
681
+ # We just want the data directory name
682
+ datadir_name = puppet_lookup_info.split(puppet_env_path).last
683
+
684
+ # Grab the file separator to add back later
685
+ file_sep = datadir_name[0]
686
+
687
+ # Snag the first entry (this is the data directory)
688
+ datadir_name = datadir_name.split(file_sep)[1]
689
+
690
+ # Constitute the full path to the data directory
691
+ datadir_path = puppet_env_path + file_sep + datadir_name
692
+
693
+ # Return the path to the data directory
694
+ return datadir_path
695
+ end
643
696
 
644
697
  # Write the provided data structure to Hiera's :datadir and configure Hiera to
645
698
  # use that data exclusively.
@@ -652,14 +705,14 @@ done
652
705
  # @param heradata [Hash, String] The full hiera data structure to write to
653
706
  # the system.
654
707
  #
655
- # @param terminus [String] The basename of the YAML file minus the extension
656
- # to write to the system.
708
+ # @param terminus [String] DEPRECATED - Will be removed in a future release.
709
+ # All hieradata is written to the first discovered path via 'puppet
710
+ # lookup'
657
711
  #
658
712
  # @return [Nil]
659
713
  #
660
- def set_hieradata_on(sut, hieradata, terminus = 'default')
661
- write_hieradata_to sut, hieradata, terminus
662
- write_hiera_config_on sut, Array(terminus)
714
+ def set_hieradata_on(sut, hieradata, terminus = 'deprecated')
715
+ write_hieradata_to sut, hieradata
663
716
  end
664
717
 
665
718
 
@@ -56,7 +56,7 @@ module Simp::BeakerHelpers
56
56
  def run
57
57
  sut_inspec_results = '/tmp/inspec_results.json'
58
58
 
59
- inspec_cmd = "inspec exec --format json #{@test_dir} > #{sut_inspec_results}"
59
+ inspec_cmd = "inspec exec '#{@test_dir}' --reporter json > #{sut_inspec_results}"
60
60
  result = on(@sut, inspec_cmd, :accept_all_exit_codes => true)
61
61
 
62
62
  tmpdir = Dir.mktmpdir
@@ -5,7 +5,7 @@ module Simp::BeakerHelpers
5
5
  if ENV['BEAKER_ssg_repo']
6
6
  GIT_REPO = ENV['BEAKER_ssg_repo']
7
7
  else
8
- GIT_REPO = 'https://github.com/OpenSCAP/scap-security-guide.git'
8
+ GIT_REPO = 'https://github.com/ComplianceAsCode/content.git'
9
9
  end
10
10
 
11
11
  # If this is not set, the closest tag to the default branch will be used
@@ -143,15 +143,15 @@ module Simp::BeakerHelpers
143
143
  if ssg_release
144
144
  copy_to(@sut, ssg_release, @scap_working_dir)
145
145
 
146
- on(@sut, %(mkdir -p scap-security-guide && tar -xj -C scap-security-guide --strip-components 1 -f #{ssg_release} && cp scap-security-guide/*ds.xml #{@scap_working_dir}))
146
+ on(@sut, %(mkdir -p scap-content && tar -xj -C scap-content --strip-components 1 -f #{ssg_release} && cp scap-content/*ds.xml #{@scap_working_dir}))
147
147
  else
148
- on(@sut, %(git clone #{GIT_REPO}))
148
+ on(@sut, %(git clone #{GIT_REPO} scap-content))
149
149
  if GIT_BRANCH
150
- on(@sut, %(cd scap-security-guide; git checkout #{GIT_BRANCH}))
150
+ on(@sut, %(cd scap-content; git checkout #{GIT_BRANCH}))
151
151
  else
152
- on(@sut, %(cd scap-security-guide; git checkout $(git describe --abbrev=0 --tags)))
152
+ on(@sut, %(cd scap-content; git checkout $(git describe --abbrev=0 --tags)))
153
153
  end
154
- on(@sut, %(cd scap-security-guide/build; cmake ../; make -j4 #{OS_INFO[@os][@os_rel]['ssg']['build_target']}-content && cp *ds.xml #{@scap_working_dir}))
154
+ on(@sut, %(cd scap-content/build; cmake ../; make -j4 #{OS_INFO[@os][@os_rel]['ssg']['build_target']}-content && cp *ds.xml #{@scap_working_dir}))
155
155
  end
156
156
  end
157
157
  end
@@ -1,5 +1,5 @@
1
1
  module Simp; end
2
2
 
3
3
  module Simp::BeakerHelpers
4
- VERSION = '1.11.0'
4
+ VERSION = '1.11.1'
5
5
  end
@@ -4,54 +4,30 @@ hosts.each do |host|
4
4
  describe '#set_hieradata_on' do
5
5
  context 'when passed a YAML string' do
6
6
  before(:all) { set_hieradata_on(host, "---\n") }
7
- after(:all) { on(host, "rm -rf #{host.puppet['hiera_config']} #{hiera_datadir(host)}") }
7
+ after(:all) { on(host, "rm -rf #{hiera_datadir(host)}") }
8
8
 
9
9
  it 'creates the datadir' do
10
10
  on host, "test -d #{hiera_datadir(host)}"
11
11
  end
12
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
13
  it 'writes the correct contents to the correct file' do
19
- stdout = on(host, "cat #{hiera_datadir(host)}/default.yaml").stdout
14
+ stdout = on(host, "cat #{hiera_datadir(host)}/common.yaml").stdout
20
15
  expect(stdout).to eq("---\n")
21
16
  end
22
17
  end
23
18
 
24
19
  context 'when passed a hash' do
25
20
  before(:all) { set_hieradata_on(host, { 'foo' => 'bar' }) }
26
- after(:all) { on(host, "rm -rf #{host.puppet['hiera_config']} #{hiera_datadir(host)}") }
21
+ after(:all) { on(host, "rm -rf #{hiera_datadir(host)}") }
27
22
 
28
23
  it 'creates the datadir' do
29
24
  on host, "test -d #{hiera_datadir(host)}"
30
25
  end
31
26
 
32
27
  it 'writes the correct contents to the correct file' do
33
- stdout = on(host, "cat #{hiera_datadir(host)}/default.yaml").stdout
28
+ stdout = on(host, "cat #{hiera_datadir(host)}/common.yaml").stdout
34
29
  expect(stdout).to eq("---\nfoo: bar\n")
35
30
  end
36
31
  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
32
  end
57
33
  end
@@ -11,7 +11,7 @@ hosts.each do |host|
11
11
  end
12
12
 
13
13
  it 'writes the correct contents to the correct file' do
14
- stdout = on(host, "cat #{hiera_datadir(host)}/default.yaml").stdout
14
+ stdout = on(host, "cat #{hiera_datadir(host)}/common.yaml").stdout
15
15
  expect(stdout).to eq("---\n")
16
16
  end
17
17
  end
@@ -25,23 +25,9 @@ hosts.each do |host|
25
25
  end
26
26
 
27
27
  it 'writes the correct contents to the correct file' do
28
- stdout = on(host, "cat #{hiera_datadir(host)}/default.yaml").stdout
28
+ stdout = on(host, "cat #{hiera_datadir(host)}/common.yaml").stdout
29
29
  expect(stdout).to eq("---\nfoo: bar\n")
30
30
  end
31
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
32
  end
47
33
  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.11.0
4
+ version: 1.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Tessmer
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-09-25 00:00:00.000000000 Z
12
+ date: 2018-10-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: beaker