Skip to content

Commit 77628f6

Browse files
(SIMP-8382) Confine tmp_mounts on directories (#231)
* Fix confines for tmp_mounts fact * Fix simplib__mountpoints fact (again) * The main facter 'mountpoints' fact does not correctly pick up all options, so we now use our collected options in all cases. * Added a windows test to ensure that we don't break windows (again) moving forward SIMP-8382 #close
1 parent 5864783 commit 77628f6

File tree

7 files changed

+135
-10
lines changed

7 files changed

+135
-10
lines changed

.gitlab-ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,3 +408,9 @@ pup6.16.0-oel-fips:
408408
<<: *with_SIMP_ACCEPTANCE_MATRIX_LEVEL_3
409409
script:
410410
- 'BEAKER_fips=yes bundle exec rake beaker:suites[default,oel]'
411+
412+
pup6.16.0-win:
413+
<<: *acceptance_base
414+
<<: *pup_6_16_0
415+
script:
416+
- 'bundle exec rake beaker:suites[windows,default]'

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ end
3434
group :system_tests do
3535
gem 'beaker'
3636
gem 'beaker-rspec'
37+
gem 'beaker-windows'
3738
gem 'simp-beaker-helpers', ENV['SIMP_BEAKER_HELPERS_VERSION'] || ['>= 1.18.7', '< 2']
3839
end
3940

lib/facter/simplib__mountpoints.rb

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@
3939
require 'facter'
4040

4141
Facter.add('simplib__mountpoints') do
42-
setcode do
43-
confine :kernel => :Linux
44-
confine { File.exist?('/proc/mounts') }
42+
confine :kernel => :Linux
43+
confine { File.exist?('/proc/mounts') }
4544

45+
setcode do
4646
target_dirs = ['/tmp', '/var/tmp', '/dev/shm', '/proc']
4747

4848
# Holder of the multi-call content
@@ -60,12 +60,23 @@
6060

6161
next unless target_dirs.include?(path)
6262

63-
mount_list[path] = (facter_mountpoints[path] || {
63+
path_settings = {
6464
'device' => dev,
6565
'filesystem' => fs,
6666
# Split on commas that are not in quotes
6767
'options' => opts.gsub(%r{'|"}, '').split(%r{,(?=(?:(?:[^'"]*(?:'|")){2})*[^'"]*$)}).map(&:strip)
68-
})
68+
}
69+
70+
if facter_mountpoints[path]
71+
mount_list[path] = facter_mountpoints[path]
72+
73+
# The mountpoins fact does not capture all options correctly
74+
mount_list[path]['options'] = path_settings['options']
75+
else
76+
mount_list[path] = path_settings
77+
end
78+
79+
6980
end
7081

7182
# Lookup table so we don't constantly lookup found UIDs and GIDs, etc...

lib/facter/tmp_mounts.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,32 @@
2121

2222
simplib__tmp_mount_target_dirs.each do |dir|
2323
Facter.add("tmp_mount#{dir.gsub('/','_')}") do
24+
confine :kernel => :Linux
25+
confine { File.directory?(dir) }
2426
setcode do
27+
2528
simplib__tmp_mount_list ||= Facter.value(:simplib__mountpoints)
2629
next unless simplib__tmp_mount_list[dir]
2730
simplib__tmp_mount_list[dir]['options'].join(',')
2831
end
2932
end
3033

3134
Facter.add("tmp_mount_path#{dir.gsub('/','_')}") do
35+
confine :kernel => :Linux
36+
confine { File.directory?(dir) }
3237
setcode do
38+
3339
simplib__tmp_mount_list ||= Facter.value(:simplib__mountpoints)
3440
next unless simplib__tmp_mount_list[dir]
3541
simplib__tmp_mount_list[dir]['device']
3642
end
3743
end
3844

3945
Facter.add("tmp_mount_fstype#{dir.gsub('/','_')}") do
46+
confine :kernel => :Linux
47+
confine { File.directory?(dir) }
4048
setcode do
49+
4150
simplib__tmp_mount_list ||= Facter.value(:simplib__mountpoints)
4251
next unless simplib__tmp_mount_list[dir]
4352
simplib__tmp_mount_list[dir]['filesystem']
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
require 'spec_helper_acceptance'
2+
3+
test_name 'overall fact sanity'
4+
5+
describe 'running facts' do
6+
hosts.each do |host|
7+
context "on #{host}" do
8+
it do
9+
result = on(host, 'puppet facts').output.strip.lines
10+
11+
expect(result.grep(/Error/).grep(/Facter/)).to be_empty
12+
end
13+
end
14+
end
15+
end
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<%
2+
if ENV['BEAKER_HYPERVISOR']
3+
hypervisor = ENV['BEAKER_HYPERVISOR']
4+
else
5+
hypervisor = 'vagrant'
6+
end
7+
-%>
8+
HOSTS:
9+
el7:
10+
roles:
11+
- default
12+
platform: el-7-x86_64
13+
box: centos/7
14+
hypervisor: <%= hypervisor %>
15+
16+
win:
17+
roles:
18+
- windows
19+
platform: windows-server-amd64
20+
box: gusztavvargadr/windows-server
21+
box_version: 1809.0.2006.standard
22+
hypervisor: <%= hypervisor %>
23+
vagrant_memsize: 2048
24+
vagrant_cpus: 2
25+
user: vagrant
26+
communicator: winrm
27+
is_cygwin: false
28+
ssh:
29+
host_key: '+ssh-dss'
30+
31+
CONFIG:
32+
log_level: verbose
33+
type: aio
34+
vagrant_memsize: 256
35+
<% if ENV['BEAKER_PUPPET_ENVIRONMENT'] -%>
36+
puppet_environment: <%= ENV['BEAKER_PUPPET_ENVIRONMENT'] %>
37+
<% end -%>

spec/spec_helper_acceptance.rb

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
require 'simp/beaker_helpers'
55
include Simp::BeakerHelpers
66

7+
require 'beaker/puppet_install_helper'
8+
require 'beaker-windows'
9+
include BeakerWindows::Path
10+
include BeakerWindows::Powershell
11+
include BeakerWindows::Registry
12+
include BeakerWindows::WindowsFeature
13+
714
unless ENV['BEAKER_provision'] == 'no'
815
hosts.each do |host|
916
# Install Puppet
@@ -15,25 +22,64 @@
1522
end
1623
end
1724

25+
hosts.each do |host|
26+
# https://petersouter.co.uk/testing-windows-puppet-with-beaker/
27+
case host['platform']
28+
when /windows/
29+
GEOTRUST_GLOBAL_CA = <<-EOM.freeze
30+
-----BEGIN CERTIFICATE-----
31+
MIIDVDCCAjygAwIBAgIDAjRWMA0GCSqGSIb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3aBd7YdStysVAq45pmp06drE57xNNB6pXE0zX5IJL4hmXXeXxx12E6nV
48+
5fEWCRE11azbJHFwLJhWC9kXtNHjUStedejV0NxPNO3CBWaAocvmMw==
49+
-----END CERTIFICATE-----
50+
EOM
51+
install_cert_on_windows(host, 'geotrustglobal', GEOTRUST_GLOBAL_CA)
52+
end
53+
end
54+
1855

1956
RSpec.configure do |c|
2057
# ensure that environment OS is ready on each host
21-
fix_errata_on hosts
58+
fix_errata_on(hosts)
2259

2360
# Readable test descriptions
2461
c.formatter = :documentation
2562

2663
# Configure all nodes in nodeset
2764
c.before :suite do
2865
begin
66+
nonwin = hosts.dup
67+
nonwin.delete_if {|h| h[:platform] =~ /windows/ }
2968
# Install modules and dependencies from spec/fixtures/modules
30-
copy_fixture_modules_to( hosts )
31-
69+
copy_fixture_modules_to( nonwin )
70+
begin
71+
server = only_host_with_role(nonwin, 'server')
72+
rescue ArgumentError => e
73+
server = only_host_with_role(nonwin, 'default')
74+
end
3275
# Generate and install PKI certificates on each SUT
3376
Dir.mktmpdir do |cert_dir|
34-
run_fake_pki_ca_on( default, hosts, cert_dir )
35-
hosts.each{ |sut| copy_pki_to( sut, cert_dir, '/etc/pki/simp-testing' )}
77+
run_fake_pki_ca_on(server, nonwin, cert_dir )
78+
nonwin.each{ |sut| copy_pki_to( sut, cert_dir, '/etc/pki/simp-testing' )}
3679
end
80+
81+
# add PKI keys
82+
copy_keydist_to(server)
3783
rescue StandardError, ScriptError => e
3884
if ENV['PRY']
3985
require 'pry'; binding.pry

0 commit comments

Comments
 (0)