Skip to content

Commit 56f0d53

Browse files
Better assert_optional_dependency (#272)
* Fixed: * Allow `assert_optional_dependency` to handle extended version strings (Alpha, Beta, RC, 1.2.3.4, etc...) * Allow `module_metadata::os_supported` to handle metadata where the version is not specified (all versions supported) * Fix windows tests * Changed: * Support all versions of known OSs * Facter 4 test updates * Windows Beaker SUTs bumped from 2012r2 to 2022 Standard Closes #271 Needs simp/rubygem-simp-rspec-puppet-facts#43 Co-authored-by: op-ct <chris.tessmer@onyxpoint.com>
1 parent 71b9bd2 commit 56f0d53

24 files changed

Lines changed: 193 additions & 143 deletions

CHANGELOG

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
* Thu Dec 16 2021 Chris Tessmer <chris.tessmer@onyxpoint.com> - 4.10.3
1+
* Fri Jun 24 2022 Trevor Vaughan <tvaughan@sicura.us> - 4.10.3
2+
- Fixed
3+
- Allow `assert_optional_dependency` to handle extended version strings
4+
(Alpha, Beta, RC, 1.2.3.4, etc...)
5+
6+
* Fri Jun 24 2022 Chris Tessmer <chris.tessmer@onyxpoint.com> - 4.10.3
27
- Fixed
38
- Permit root user to run `puppet lookup --compile` without borking passgen
49

Gemfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ group :test do
2323
gem 'puppet-strings'
2424
gem 'puppet-lint-empty_string-check', :require => false
2525
gem 'puppet-lint-trailing_comma-check', :require => false
26-
gem 'simp-rspec-puppet-facts', ENV['SIMP_RSPEC_PUPPET_FACTS_VERSION'] || '~> 3.1'
27-
gem 'simp-rake-helpers', ENV['SIMP_RAKE_HELPERS_VERSION'] || ['>= 5.12.1', '< 6']
26+
gem 'simp-rspec-puppet-facts', ENV['SIMP_RSPEC_PUPPET_FACTS_VERSION'] || '~> 3.5'
27+
gem 'simp-rake-helpers', ENV['SIMP_RAKE_HELPERS_VERSION'] || ['>= 5.15.0', '< 6']
2828
gem( 'pdk', ENV['PDK_VERSION'] || '~> 2.0', :require => false) if major_puppet_version > 5
2929
gem 'pathspec', '~> 0.2' if Gem::Requirement.create('< 2.6').satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
3030
end
@@ -38,7 +38,7 @@ end
3838
group :system_tests do
3939
gem 'beaker'
4040
gem 'beaker-rspec'
41-
gem 'simp-beaker-helpers', ENV['SIMP_BEAKER_HELPERS_VERSION'] || ['>= 1.23.2', '< 2']
41+
gem 'simp-beaker-helpers', ENV['SIMP_BEAKER_HELPERS_VERSION'] || ['>= 1.25.0', '< 2']
4242
end
4343

4444
# Evaluate extra gemfiles if they exist

functions/module_metadata/os_supported.pp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,17 @@ function simplib::module_metadata::os_supported (
5050
if $os_info['operatingsystem'] == $facts['os']['name'] {
5151
$memo and case $_options['release_match'] {
5252
'full': {
53-
$facts['os']['release']['full'] in $os_info['operatingsystemrelease']
53+
!$os_info['operatingsystemrelease'] or ($facts['os']['release']['full'] in $os_info['operatingsystemrelease'])
5454
}
5555
'major': {
56-
$_os_major_releases = $os_info['operatingsystemrelease'].map |$os_release| {
57-
split($os_release, '\.')[0]
58-
}
56+
if $os_info['operatingsystemrelease'] {
57+
$_os_major_releases = $os_info['operatingsystemrelease'].map |$os_release| {
58+
split($os_release, '\.')[0]
59+
}
5960

60-
$facts['os']['release']['major'] in $_os_major_releases
61+
$facts['os']['release']['major'] in $_os_major_releases
62+
}
63+
else { true }
6164
}
6265
default: { true }
6366
}

lib/puppet/functions/simplib/assert_optional_dependency.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,15 @@ def get_module_dependencies(dependency_tree_levels, module_metadata)
7272
return metadata_level[current_level]
7373
end
7474

75+
# Concept lifted from 'node-semver'
76+
def coerce(version)
77+
version
78+
.split('-')
79+
.first
80+
.split('.')[0, 3]
81+
.join('.')
82+
end
83+
7584
def check_dependency(module_name, module_dependency)
7685
require 'semantic_puppet'
7786

@@ -103,7 +112,7 @@ def check_dependency(module_name, module_dependency)
103112
return %(invalid version range '#{module_dependency['version_requirement']}' for '#{_module_name}')
104113
end
105114

106-
module_version = module_metadata['version']
115+
module_version = coerce(module_metadata['version'])
107116

108117
begin
109118
module_version = SemanticPuppet::Version.parse(module_version)

metadata.json

Lines changed: 22 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -26,95 +26,28 @@
2626
}
2727
],
2828
"operatingsystem_support": [
29-
{
30-
"operatingsystem": "RedHat",
31-
"operatingsystemrelease": [
32-
"7",
33-
"8"
34-
]
35-
},
36-
{
37-
"operatingsystem": "CentOS",
38-
"operatingsystemrelease": [
39-
"7",
40-
"8"
41-
]
42-
},
43-
{
44-
"operatingsystem": "OracleLinux",
45-
"operatingsystemrelease": [
46-
"7",
47-
"8"
48-
]
49-
},
50-
{
51-
"operatingsystem": "Scientific",
52-
"operatingsystemrelease": [
53-
"7"
54-
]
55-
},
56-
{
57-
"operatingsystem": "SLES",
58-
"operatingsystemrelease": [
59-
"11 SP1",
60-
"12",
61-
"15"
62-
]
63-
},
64-
{
65-
"operatingsystem": "Debian",
66-
"operatingsystemrelease": [
67-
"8",
68-
"9",
69-
"10",
70-
"11"
71-
]
72-
},
73-
{
74-
"operatingsystem": "Ubuntu",
75-
"operatingsystemrelease": [
76-
"14.04",
77-
"16.04",
78-
"18.04",
79-
"19.04",
80-
"20.04"
81-
]
82-
},
83-
{
84-
"operatingsystem": "Solaris",
85-
"operatingsystemrelease": [
86-
"11",
87-
"12"
88-
]
89-
},
90-
{
91-
"operatingsystem": "Windows",
92-
"operatingsystemrelease": [
93-
"Server 2008",
94-
"Server 2008 R2",
95-
"Server 2012",
96-
"Server 2012 R2",
97-
"2016",
98-
"2019",
99-
"7",
100-
"8",
101-
"10"
102-
]
103-
},
104-
{
105-
"operatingsystem": "AIX",
106-
"operatingsystemrelease": [
107-
"6.1",
108-
"7.1",
109-
"7.2"
110-
]
111-
},
112-
{
113-
"operatingsystem": "Amazon",
114-
"operatingsystemrelease": [
115-
"2"
116-
]
117-
}
29+
{ "operatingsystem": "AlmaLinux" },
30+
{ "operatingsystem": "Amazon" },
31+
{ "operatingsystem": "Archlinux" },
32+
{ "operatingsystem": "CentOS" },
33+
{ "operatingsystem": "Darwin" },
34+
{ "operatingsystem": "Debian" },
35+
{ "operatingsystem": "Fedora" },
36+
{ "operatingsystem": "FreeBSD" },
37+
{ "operatingsystem": "Gentoo" },
38+
{ "operatingsystem": "LinuxMint" },
39+
{ "operatingsystem": "OpenBSD" },
40+
{ "operatingsystem": "OpenSUSE" },
41+
{ "operatingsystem": "OracleLinux" },
42+
{ "operatingsystem": "RedHat" },
43+
{ "operatingsystem": "Pop!_OS" },
44+
{ "operatingsystem": "Rocky" },
45+
{ "operatingsystem": "SLES" },
46+
{ "operatingsystem": "Scientific" },
47+
{ "operatingsystem": "Solaris" },
48+
{ "operatingsystem": "Ubuntu" },
49+
{ "operatingsystem": "VirtuozzoLinux" },
50+
{ "operatingsystem": "Windows" }
11851
],
11952
"requirements": [
12053
{

spec/acceptance/suites/windows/nodesets/default.yml

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,33 @@
66
end
77
-%>
88
HOSTS:
9-
el7:
10-
roles:
11-
- default
12-
platform: el-7-x86_64
13-
box: centos/7
14-
hypervisor: <%= hypervisor %>
15-
169
win:
1710
roles:
1811
- windows
1912
platform: windows-server-amd64
20-
box: devopsgroup-io/windows_server-2012r2-standard-amd64-nocm
13+
box: gusztavvargadr/windows-server
14+
box_version: 2102.0.2205
2115
hypervisor: <%= hypervisor %>
2216
vagrant_memsize: 2048
2317
vagrant_cpus: 2
2418
user: vagrant
2519
communicator: winrm
2620
is_cygwin: false
27-
ssh:
28-
host_key: '+ssh-dss'
2921

3022
CONFIG:
3123
log_level: verbose
3224
type: aio
3325
<% if ENV['BEAKER_PUPPET_ENVIRONMENT'] -%>
3426
puppet_environment: <%= ENV['BEAKER_PUPPET_ENVIRONMENT'] %>
3527
<% end -%>
28+
ssh:
29+
keepalive: true
30+
keepalive_interval: 10
31+
host_key:
32+
- <%= Net::SSH::Transport::Algorithms::ALGORITHMS[:host_key].join("\n#{' '*6}- ") %>
33+
kex:
34+
- <%= Net::SSH::Transport::Algorithms::ALGORITHMS[:kex].join("\n#{' '*6}- ") %>
35+
encryption:
36+
- <%= Net::SSH::Transport::Algorithms::ALGORITHMS[:encryption].join("\n#{' '*6}- ") %>
37+
hmac:
38+
- <%= Net::SSH::Transport::Algorithms::ALGORITHMS[:hmac].join("\n#{' '*6}- ") %>

spec/functions/assert_metadata_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
require 'spec_helper'
22

33
describe 'simplib::assert_metadata' do
4+
module_metadata = {
5+
'name' => 'simp-simplib',
6+
'version' => '1.2.3',
7+
'author' => 'Yep',
8+
'summary' => 'Stubby',
9+
'license' => 'Apache-2.0',
10+
'operatingsystem_support' => [
11+
{
12+
'operatingsystem' => 'Ubuntu',
13+
'operatingsystemrelease' => ['14.04']
14+
}
15+
]
16+
}.to_json
17+
418
valid_facts = {
519
:os => {
620
'name' => 'Ubuntu',
@@ -57,6 +71,14 @@
5771
}
5872
}
5973

74+
let(:pre_condition) do
75+
<<~PRE_CONDITION
76+
function load_module_metadata(String $any) {
77+
parsejson('#{module_metadata}')
78+
}
79+
PRE_CONDITION
80+
end
81+
6082
context 'with no version matching' do
6183
context 'on a supported OS' do
6284
let(:facts) { valid_facts }

spec/functions/module_metadata/assert_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
require 'spec_helper'
22

33
describe 'simplib::module_metadata::assert' do
4+
module_metadata = {
5+
'name' => 'simp-simplib',
6+
'version' => '1.2.3',
7+
'author' => 'Yep',
8+
'summary' => 'Stubby',
9+
'license' => 'Apache-2.0',
10+
'operatingsystem_support' => [
11+
{
12+
'operatingsystem' => 'Ubuntu',
13+
'operatingsystemrelease' => ['14.04']
14+
}
15+
]
16+
}.to_json
17+
418
valid_facts = {
519
:os => {
620
'name' => 'Ubuntu',
@@ -91,6 +105,14 @@
91105
}
92106
}
93107

108+
let(:pre_condition) do
109+
<<~PRE_CONDITION
110+
function load_module_metadata(String $any) {
111+
parsejson('#{module_metadata}')
112+
}
113+
PRE_CONDITION
114+
end
115+
94116
context 'with no version matching' do
95117
context 'on a supported OS' do
96118
let(:facts) { valid_facts }

spec/functions/simplib/assert_optional_dependency_spec.rb

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
},
1616
{
1717
'name' => 'dep/two'
18+
},
19+
{
20+
'name' => 'dep-three',
21+
'version_requirement' => '>= 1.2.3 < 2.0.0'
1822
}
1923
]
2024
}
@@ -35,6 +39,13 @@
3539
}
3640
}
3741

42+
let(:dep_three_metadata) {
43+
{
44+
'name' => 'dep-three',
45+
'version' => '1.2.3-alpha'
46+
}
47+
}
48+
3849
let(:dep_one_bad_author) {
3950
{
4051
'name' => 'narp/one',
@@ -57,6 +68,8 @@
5768
expect(func).to receive(:call_function).with('load_module_metadata', 'one').and_return(dep_one_metadata)
5869
expect(func).to receive(:call_function).with('simplib::module_exist', 'two').and_return(true)
5970
expect(func).to receive(:call_function).with('load_module_metadata', 'two').and_return(dep_two_metadata)
71+
expect(func).to receive(:call_function).with('simplib::module_exist', 'three').and_return(true)
72+
expect(func).to receive(:call_function).with('load_module_metadata', 'three').and_return(dep_three_metadata)
6073
is_expected.to run.with_params('my/module')
6174
end
6275

@@ -125,7 +138,7 @@
125138
it 'should fail' do
126139
expect(func).to_not receive(:call_function).with('simplib::module_exist', 'one')
127140

128-
expect{is_expected.to run.with_params('my/module', 'three')}.to raise_error(%r('three' not found in metadata.json))
141+
expect{is_expected.to run.with_params('my/module', 'badmod')}.to raise_error(%r('badmod' not found in metadata.json))
129142
end
130143
end
131144
end
@@ -137,6 +150,8 @@
137150
expect(func).to receive(:call_function).with('load_module_metadata', 'one').and_return(dep_one_bad_version)
138151
expect(func).to receive(:call_function).with('simplib::module_exist', 'two').and_return(true)
139152
expect(func).to receive(:call_function).with('load_module_metadata', 'two').and_return(dep_two_metadata)
153+
expect(func).to receive(:call_function).with('simplib::module_exist', 'three').and_return(true)
154+
expect(func).to receive(:call_function).with('load_module_metadata', 'three').and_return(dep_three_metadata)
140155

141156
expect{ is_expected.to run.with_params('my/module') }.to raise_error(%r('one-.+' does not satisfy)m)
142157
end

spec/functions/simplib/simp_version_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
context 'a valid version exists in simp.version' do
1818
before(:each) do
1919
allow(File).to receive(:read).with(any_args).and_call_original
20+
allow(File).to receive(:readable?).with(any_args).and_call_original
2021
end
2122

2223
it 'should return the version with whitespace retained' do

0 commit comments

Comments
 (0)