From e12d8a98ea0d277d5b0be7bed9f2d9cb234fd618 Mon Sep 17 00:00:00 2001 From: "Jeremiah D. Powell" Date: Fri, 6 May 2022 04:05:27 -0500 Subject: [PATCH 1/3] filter out configuration options that the underlying command does not support --- .../rhsm_config/subscription_manager.rb | 32 +++++- metadata.json | 2 +- .../rhsm_config/subscription_manager_spec.rb | 103 ++++++++++++++++++ 3 files changed, 135 insertions(+), 2 deletions(-) diff --git a/lib/puppet/provider/rhsm_config/subscription_manager.rb b/lib/puppet/provider/rhsm_config/subscription_manager.rb index 7a3df56..5f4d4fb 100755 --- a/lib/puppet/provider/rhsm_config/subscription_manager.rb +++ b/lib/puppet/provider/rhsm_config/subscription_manager.rb @@ -223,6 +223,33 @@ def self.ini_parse(input) output end + # Obtain the list of parameters from the config help subcommand + # @return Array(String) the options you can set though the cmd + def config_help_options() + data = subscription_manager(['config', '--help']) + opts = conf_help_parse(data) unless data.nil? + unless opts.nil? + Puppet.debug("Valid config parameters were #{opts}") + opts + end + end + + # Parse the output of a subscription_mnager config command + # @params data String the data from a command run + # @return Array(String) a list of section.option that can be set + def conf_help_parse(data) + opts = [] + unless data.nil? + data.split("\n").each do |line| + m = line.match(%r{^\s+--([a-z_0-9]+\.[a-z_0-9]+) [A-Z]+.*}) + unless m.nil? + opts.push m[1] + end + end + end + opts + end + # Build a config option string # @param removal Symbol :remove if to remove things # @return [Hash(Array(String))] the options for a config command @@ -231,16 +258,19 @@ def self.ini_parse(input) def build_config_parameters(removal) setparams = [] removeparams = [] + cmdparams = config_help_options() + # a map of parameter:section hence the 'reversed' nature of the bellow options = Puppet::Type.type(:rhsm_config).binary_options.merge( Puppet::Type.type(:rhsm_config).text_options, ) # filter out praramters from properties - arguments = @property_hash.select do |opt, _value| + arguments = @property_hash.select do |opt, value| options.keys.include?(opt) end Puppet.debug("Updates to subscription configuration are '#{arguments}'") arguments.each do |opt, value| section = options[opt] + next unless cmdparams.include? section param = resolve_value(removal, opt, value) if param.nil? removeparams.push("--remove=#{section}") diff --git a/metadata.json b/metadata.json index 5f8ecf5..60c395c 100644 --- a/metadata.json +++ b/metadata.json @@ -1,6 +1,6 @@ { "name": "waveclaw-subscription_manager", - "version": "5.6.5", + "version": "5.7.0", "author": "JD Powell ", "summary": "Manage Katello or Satellite registrations.", "license": "Apache-2.0", diff --git a/spec/unit/provider/rhsm_config/subscription_manager_spec.rb b/spec/unit/provider/rhsm_config/subscription_manager_spec.rb index cd0fd9a..f05cf72 100755 --- a/spec/unit/provider/rhsm_config/subscription_manager_spec.rb +++ b/spec/unit/provider/rhsm_config/subscription_manager_spec.rb @@ -142,6 +142,35 @@ rhsm_baseurl: 'https://katello01.example.com/pulp/repos', } + raw_help_data = <<-EOH + usage: subscription-manager config [OPTIONS] + +List, set, or remove the configuration parameters in use by this system + +optional arguments: + -h, --help show this help message and exit + --list list the configuration for this system + --remove REMOVE remove configuration entry by section.name + --server.proxy_scheme SERVER.PROXY_SCHEME + Section: server, Name: proxy_scheme + --server.server_timeout SERVER.SERVER_TIMEOUT + Section: server, Name: server_timeout + --server.proxy_hostname SERVER.PROXY_HOSTNAME + Section: server, Name: proxy_hostname + --server.no_proxy SERVER.NO_PROXY + Section: server, Name: no_proxy + --server.insecure SERVER.INSECURE + Section: server, Name: insecure + EOH + + help_values = [ + "server.proxy_scheme", + "server.server_timeout", + "server.proxy_hostname", + "server.no_proxy", + "server.insecure" + ] + let(:resource) do Puppet::Type.type(:rhsm_config).new(properties) end @@ -241,6 +270,9 @@ res.provider.set(server_port: 443) res[:server_port] = 8080 expect(res.provider).to receive(:exists?).and_call_original + expect(res.provider).to receive(:config_help_options).and_return([ + 'server.port','server.insecure' + ]) expect(res.provider).to receive(:build_config_parameters).with(:remove).and_call_original expect(res.provider).to receive(:subscription_manager).with( 'config', '--remove=server.insecure' @@ -452,11 +484,53 @@ end end + describe 'config_help_options' do + it 'returns nothing for an empty configuration' do + resource = Puppet::Type.type(:rhsm_config).new( + provider: provider, name: title, + ) + expect(provider.class).to receive(:subscription_manager).with(['config', '--help']).and_return('') + expect(resource.provider.config_help_options()).to eq([]) + end + it 'returns expected values for a given configuration' do + resource = Puppet::Type.type(:rhsm_config).new( + provider: provider, name: title, + ) + expect(provider.class).to receive(:subscription_manager).with(['config', '--help']).and_return(raw_help_data) + expect(resource.provider).to receive(:conf_help_parse).and_return(help_values) + expect(resource.provider.config_help_options()).to eq(help_values) + end + end + + describe 'conf_help_parse' do + it 'returns nothing for an empty configuration' do + resource = Puppet::Type.type(:rhsm_config).new( + provider: provider, name: title, + ) + expect(resource.provider.conf_help_parse('')).to eq([]) + end + it 'returns nothing for garbage' do + resource = Puppet::Type.type(:rhsm_config).new( + provider: provider, name: title, + ) + expect(resource.provider.conf_help_parse('asdlk;j12349567[[]]')).to eq([]) + end + help_values.each do |key| + it "parse the #{key} option" do + resource = Puppet::Type.type(:rhsm_config).new( + provider: provider, name: title, + ) + expect(resource.provider.conf_help_parse(raw_help_data)).to include(key) + end + end + end + describe 'build_config_parameters' do it 'returns nothing when provider or title are the only parameters' do resource = Puppet::Type.type(:rhsm_config).new( provider: provider, name: title, ) + expect(resource.provider).to receive(:config_help_options).and_return(nil) expect(resource.provider.build_config_parameters(:apply)).to eq( apply: nil, remove: nil, ) @@ -474,6 +548,9 @@ expect(resource.provider).to receive(:resolve_value).with(:remove, :server_insecure, '').and_return(nil) expect(resource.provider).to receive(:resolve_value).with(:remove, :server_port, '').and_return(nil) expect(resource.provider).to receive(:resolve_value).with(:remove, :rhsm_ca_cert_dir, '').and_return(nil) + expect(resource.provider).to receive(:config_help_options).and_return([ + 'server.insecure', 'server.port', 'rhsm.ca_cert_dir' + ]) result = resource.provider.build_config_parameters(:remove) expect(result).not_to eq(nil) expect(result.keys.sort).to eq([:apply, :remove]) @@ -497,17 +574,21 @@ binary_opt = Puppet::Type.type(:rhsm_config).binary_options[key] value = (properties[key] == true) ? 1 : 0 expect(resource.provider).to receive(:resolve_value).and_return(value) + expect(resource.provider).to receive(:config_help_options).and_return([binary_opt]) expect(resource.provider.build_config_parameters(:apply)[:apply]).to eq([ "--#{binary_opt}=#{value}", ]) expect(resource.provider).to receive(:resolve_value).and_return(nil) + expect(resource.provider).to receive(:config_help_options).and_return([binary_opt]) expect(resource.provider.build_config_parameters(:remove)[:remove]).to eq(["--remove=#{binary_opt}"]) else text_opt = resource.class.text_options[key] value = properties[key].to_s expect(resource.provider).to receive(:resolve_value).and_call_original + expect(resource.provider).to receive(:config_help_options).and_return([text_opt]) expect(resource.provider.build_config_parameters(:apply)[:apply]).to eq(["--#{text_opt}=#{value}"]) expect(resource.provider).to receive(:resolve_value).and_return(nil) + expect(resource.provider).to receive(:config_help_options).and_return([text_opt]) expect(resource.provider.build_config_parameters(:remove)[:remove]).to eq(["--remove=#{text_opt}"]) end end @@ -521,6 +602,9 @@ resource[:server_insecure] = 'true' resource.provider.set(server_port: nil) resource.provider.set(rhsm_ca_cert_dir: '/etc/rhsm/ca/') + expect(resource.provider).to receive(:config_help_options).and_return([ + 'rhsm.ca_cert_dir', 'server.insecure', 'server.port' + ]) combo = resource.provider.build_config_parameters(:apply) apply_expected = ['--rhsm.ca_cert_dir=/etc/rhsm/ca/', '--server.insecure=0'].sort @@ -535,11 +619,17 @@ resource.provider.set(server_insecure: false) resource.provider.set(server_port: 443) resource.provider.set(rhsm_ca_cert_dir: '/etc/rhsm/ca/') + expect(resource.provider).to receive(:config_help_options).and_return([ + 'server.port','rhsm.ca_cert_dir','server.insecure' + ]) apply = resource.provider.build_config_parameters(:apply) expect(apply[:apply].sort!).to eq([ '--server.port=443', '--rhsm.ca_cert_dir=/etc/rhsm/ca/', '--server.insecure=0' ].sort!) expect(apply[:remove]).to eq(nil) + expect(resource.provider).to receive(:config_help_options).and_return([ + 'server.port', 'rhsm.ca_cert_dir', 'server.insecure' + ]) remove = resource.provider.build_config_parameters(:remove) expect(remove[:apply]).to eq(nil) expect(remove[:remove].sort!).to eq([ @@ -554,8 +644,21 @@ resource.provider.set(server_port: 443) resource.provider.set(rhsm_ca_cert_dir: '/etc/rhsm/ca/') resource.provider.class.defaults_to = [:server_port] + expect(resource.provider).to receive(:config_help_options).and_return(['server.insecure']) apply = resource.provider.build_config_parameters(:apply)[:apply] expect(apply).to include('--server.insecure=0') end + it 'does skip unsupported options' do + resource = Puppet::Type.type(:rhsm_config).new( + provider: provider, name: title, + ) + resource.provider.set(server_insecure: false) + resource.provider.set(server_port: 443) + resource.provider.set(rhsm_ca_cert_dir: '/etc/rhsm/ca/') + resource.provider.class.defaults_to = [:server_port] + expect(resource.provider).to receive(:config_help_options).and_return([]) + apply = resource.provider.build_config_parameters(:apply)[:apply] + expect(apply).to eq(nil) + end end end From 1a905fec4c84e68ffb64e4a4f092f4d794330a65 Mon Sep 17 00:00:00 2001 From: "Jeremiah D. Powell" Date: Fri, 6 May 2022 04:05:48 -0500 Subject: [PATCH 2/3] discuss the replacement of goferd --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 6f9185c..c6e949b 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,10 @@ available in current version of satellite. To use this module beyond version 5.6 with a older Satellite installation, you may want to include the service in your own Puppet code. An example is provided for the `rhsmcertd` case bellow. +In Satellite 6.5.x and later, the remote command execution replaces this feature. +This uses the ssh service as the remove agent and does require configuration of +both the user and ssh configuration. This is a topic well discussed [elsewhere](https://www.ssh.org). + ### Terminology Due to various terminology differences between RHN Satellite, the upstream From 8f03efa533e52cddc56192b839b36a90fe2ca9e2 Mon Sep 17 00:00:00 2001 From: "Jeremiah D. Powell" Date: Fri, 6 May 2022 04:11:41 -0500 Subject: [PATCH 3/3] document the filtering of unsupported options --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c6e949b..8116e56 100644 --- a/README.md +++ b/README.md @@ -285,6 +285,10 @@ rhsm_register { 'subscription.rhn.example.com': Please see man(5) RHSM.CONF for your locally supported options. There are quite a few and they require specific inputs. +rhsm_config cannot set values that are not available from the `subscription-manager config` sub-command. + +For the rhsm.conf options that are not supported directly, it is recommended to use either the puppetlabs-stdlib `file_line` or one of the many forge.puppet.com modules for managing ini-format files. + ##### rhsm_config options See the documentation at [RedHat Support](https://access.redhat.com/documentation/en-US/Red_Hat_Subscription_Management/1/html/RHSM/rhsm-config.html#tab.rhsm.conf-parameters) for RedHat provided details on the `/etc/rhsm/rhsm.conf` file. @@ -301,9 +305,13 @@ The most important settings are as follows. Specific support is made for them. Other options can be rolled into a configuration hash and fed to the module as a whole. See init.pp and the following YAML example for details. +Do know the supported options to the specific version of `subscription-manager config --help` on your platform. + +***Options that are not supported will be ignored!*** + ##### rhsm_config Examples -As a resource. +As a resource, the format of `[section]` and `section.key` is transformed into the puppet language compatible `section_key`. ```puppet rhsm_config { 'katello.example.com':