Skip to content

Commit

Permalink
Support ignores in RPM dependency overrides (#196)
Browse files Browse the repository at this point in the history
The RPM dependency file can now use `ignores` to remove items instead of
needing to redefine the entire dependency stack to remove deps

Closes: #195
Refs: simp/simp-core#853
  • Loading branch information
trevor-vaughan authored Oct 31, 2022
1 parent 92456b5 commit 67a4751
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 14 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
### 5.17.0 /2022-10-30
- Added
- The RPM dependency file can now use `ignores` to remove items instead of
needing to redefine the entire dependency stack to remove deps

### 5.16.0 / 2022-06-24
- Added
- The `puppet-lint-optional_default-check` was added to prevent setting
Expand Down
48 changes: 38 additions & 10 deletions lib/simp/rake/build/rpmdeps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ def self.generate_custom_rpm_obsoletes(obsoletes_hash, module_metadata)
# * Requires rpm-name <= 2.0.0
# +module_metadata+:: Hash containing the contents of the
# module's 'metadata.json' file
def self.generate_custom_rpm_requires(requires_list, module_metadata)
# +ignores+:: Array of package names to ignore during processing
def self.generate_custom_rpm_requires(requires_list, module_metadata, ignores=[])
rpm_metadata_content = []

requires_list.each do |pkg_to_modify|
Expand All @@ -114,6 +115,8 @@ def self.generate_custom_rpm_requires(requires_list, module_metadata)

pkg, min_version, max_version = pkg if pkg.is_a?(Array)

next if ignores.include?(pkg)

rpm_version_chars = ['<','>','=']

if min_version && rpm_version_chars.none? { |x| min_version.include?(x) }
Expand All @@ -140,7 +143,7 @@ def self.generate_custom_rpm_requires(requires_list, module_metadata)
end

if dep_info.empty?
err_msg = "Could not find #{short_names.first} dependency"
err_msg = "Could not find '#{short_names.first}' dependency"
raise SIMPRpmDepException.new(err_msg)
else
dep_version = dep_info.first['version_requirement']
Expand All @@ -154,7 +157,7 @@ def self.generate_custom_rpm_requires(requires_list, module_metadata)
begin
rpm_metadata_content << get_version_requires(pkg, dep_version)
rescue SIMPRpmDepVersionException
err_msg = "Unable to parse #{short_names.first} dependency" +
err_msg = "Unable to parse '#{short_names.first}' dependency" +
" version '#{dep_version}'"
raise SIMPRpmDepException.new(err_msg)
end
Expand All @@ -174,15 +177,19 @@ def self.generate_custom_rpm_requires(requires_list, module_metadata)
# is a Hash containing the version info. For example,
# [ 'package1' => { :min => '1.0.0' },
# 'package2' => { :min => '3.1-1', :max => '4.0' } ]
def self.generate_external_rpm_requires(ext_deps_list)
# +ignores+:: Array of package names to ignore during processing
def self.generate_external_rpm_requires(ext_deps_list, ignores=[])
requires = []

ext_deps_list.each do |pkg_name, options|
next if ignores.include?(pkg_name)

requires << "Requires: #{pkg_name} >= #{options[:min]}"
if options[:max]
requires << "Requires: #{pkg_name} < #{options[:max]}"
end
end

requires
end

Expand All @@ -197,7 +204,8 @@ def self.generate_external_rpm_requires(ext_deps_list)
#
# +module_metadata+:: Hash containing the contents of the
# module's 'metadata.json' file
def self.generate_module_rpm_requires(module_metadata)
# +ignores+:: Array of package names to ignore during processing
def self.generate_module_rpm_requires(module_metadata, ignores=[])
rpm_metadata_content = []

deps = []
Expand All @@ -214,12 +222,15 @@ def self.generate_module_rpm_requires(module_metadata)
deps.sort! { |x,y| x['name'] <=> y['name'] }
deps.each do |dep|
pkg = "pupmod-#{dep['name'].gsub('/', '-')}"

next if ignores.include?(pkg)

dep_version = dep['version_requirement']

begin
rpm_metadata_content << get_version_requires(pkg, dep_version)
rescue SIMPRpmDepVersionException
err_msg = "Unable to parse #{dep['name']} dependency" +
err_msg = "Unable to parse '#{dep['name']}' dependency" +
" version '#{dep_version}'"
raise SIMPRpmDepException.new(err_msg)
end
Expand Down Expand Up @@ -252,6 +263,10 @@ def self.rpm_requires_up_to_date?(new_requires, rpm_requires_file)
# dependencies are pulled from module_metadata.
# * 'Requires' line(s) for any external dependencies specified
# in the module_rpm_meta hash.
# * Any items matching the name in an 'ignores' array will be removed from the
# dependency list.
# * This will be an *exact* match, globbing and regexes are not supported
# * Does not affect Obsoletes statements
#
# Otherwise, the generated 'requires' file will contain "Requires"
# lines for each dependency and each SIMP optional dependency
Expand All @@ -269,18 +284,31 @@ def self.rpm_requires_up_to_date?(new_requires, rpm_requires_file)
# 'dependencies.yaml' file or nil, if no entry exists
def self.generate_rpm_requires_file(dir, module_metadata, module_rpm_meta)
rpm_metadata_content = []

ignores = module_rpm_meta ? Array(module_rpm_meta[:ignores]) : []

if module_rpm_meta and module_rpm_meta[:obsoletes]
rpm_metadata_content = generate_custom_rpm_obsoletes(module_rpm_meta[:obsoletes], module_metadata)
rpm_metadata_content = generate_custom_rpm_obsoletes(
module_rpm_meta[:obsoletes],
module_metadata
)
end

if module_rpm_meta and module_rpm_meta[:requires]
rpm_metadata_content += generate_custom_rpm_requires(module_rpm_meta[:requires], module_metadata)
rpm_metadata_content += generate_custom_rpm_requires(
module_rpm_meta[:requires],
module_metadata,
ignores
)
else
rpm_metadata_content += generate_module_rpm_requires(module_metadata)
rpm_metadata_content += generate_module_rpm_requires(module_metadata, ignores)
end

if module_rpm_meta and module_rpm_meta[:external_dependencies]
rpm_metadata_content += generate_external_rpm_requires(module_rpm_meta[:external_dependencies])
rpm_metadata_content += generate_external_rpm_requires(
module_rpm_meta[:external_dependencies],
ignores
)
end

rpm_metadata_file = File.join(dir, 'build', 'rpm_metadata', 'requires')
Expand Down
2 changes: 1 addition & 1 deletion lib/simp/rake/helpers/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ module Simp; end
module Simp::Rake; end

class Simp::Rake::Helpers
VERSION = '5.16.0'
VERSION = '5.17.0'
end
3 changes: 3 additions & 0 deletions spec/lib/simp/rake/build/files/dependencies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
# does NOT include puppetlabs/apt
- 'pupmod-puppetlabs-stdlib'
- 'pupmod-ceritsc-yum'
- 'i-should-not-exist'
- ['pupmod-richardc-datacat', '1.2.3', '<=3.4.5']
:ignores:
- 'i-should-not-exist'
:release: '2017.0'
:external_dependencies:
'rubygem-puppetserver-toml':
Expand Down
6 changes: 3 additions & 3 deletions spec/lib/simp/rake/build/rpmdeps_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@
context 'dependency from dependencies.yaml not found in metadata.json' do
it 'should fail when dep in depedencies.yaml is not found in metadata.json' do
mod_dir = File.join(@tmp_dir, 'files', 'unknown_dep_mod')
err_msg = "Could not find oops/unknown dependency in #{mod_dir}/metadata.json"
err_msg = "Could not find 'oops/unknown' dependency in #{mod_dir}/metadata.json"
expect {
Simp::Rake::Build::RpmDeps::generate_rpm_meta_files(mod_dir, rpm_metadata)
}.to raise_error(err_msg)
Expand All @@ -204,7 +204,7 @@
context 'malformed dependency version' do
it 'should fail for managed component with invalid dep version in metadata.json' do
mod_dir = File.join(@tmp_dir, 'files', 'malformed_dep_meta_mod')
err_msg = "Unable to parse foo1/bar1 dependency version '1.0.0.1' in #{mod_dir}/metadata.json"
err_msg = "Unable to parse 'foo1/bar1' dependency version '1.0.0.1' in #{mod_dir}/metadata.json"
expect {
Simp::Rake::Build::RpmDeps::generate_rpm_meta_files(mod_dir, rpm_metadata)
}.to raise_error(err_msg)
Expand All @@ -214,7 +214,7 @@
rpm_meta = rpm_metadata.dup
rpm_meta ['malformed_dep_meta_mod'] = nil
mod_dir = File.join(@tmp_dir, 'files', 'malformed_dep_meta_mod')
err_msg = "Unable to parse foo1/bar1 dependency version '1.0.0.1' in #{mod_dir}/metadata.json"
err_msg = "Unable to parse 'foo1/bar1' dependency version '1.0.0.1' in #{mod_dir}/metadata.json"
expect {
Simp::Rake::Build::RpmDeps::generate_rpm_meta_files(mod_dir, rpm_meta)
}.to raise_error(err_msg)
Expand Down

0 comments on commit 67a4751

Please sign in to comment.