From 00ef4a99f1c0dbc91472934271cd3921aaca3bc9 Mon Sep 17 00:00:00 2001
From: Takashi Kajinami <tkajinam@redhat.com>
Date: Sun, 13 Feb 2022 00:14:04 +0900
Subject: [PATCH] Add support for MultiStrOpt

This replaces the provider implementation of watcher_config type so
that MultiStrOpt, which is used by several options like
 - oslo_messaging_notifications/driver
 - oslo_policy/policy_dirs
are handled correctly.

Change-Id: I3e92b0123cf18803cc8abfebcbe48b51812a8c27
---
 .../{ini_setting.rb => openstackconfig.rb}           |  4 ++--
 lib/puppet/type/watcher_config.rb                    | 12 ++++++++++--
 .../{ini_setting_spec.rb => openstackconfig_spec.rb} |  2 +-
 spec/unit/type/watcher_config_spec.rb                |  4 ++--
 4 files changed, 15 insertions(+), 7 deletions(-)
 rename lib/puppet/provider/watcher_config/{ini_setting.rb => openstackconfig.rb} (56%)
 rename spec/unit/provider/watcher_config/{ini_setting_spec.rb => openstackconfig_spec.rb} (94%)

diff --git a/lib/puppet/provider/watcher_config/ini_setting.rb b/lib/puppet/provider/watcher_config/openstackconfig.rb
similarity index 56%
rename from lib/puppet/provider/watcher_config/ini_setting.rb
rename to lib/puppet/provider/watcher_config/openstackconfig.rb
index b2188d4..be6f796 100644
--- a/lib/puppet/provider/watcher_config/ini_setting.rb
+++ b/lib/puppet/provider/watcher_config/openstackconfig.rb
@@ -1,6 +1,6 @@
 Puppet::Type.type(:watcher_config).provide(
-  :ini_setting,
-  :parent => Puppet::Type.type(:openstack_config).provider(:ini_setting)
+  :openstackconfig,
+  :parent => Puppet::Type.type(:openstack_config).provider(:ruby)
 ) do
 
   def self.file_path
diff --git a/lib/puppet/type/watcher_config.rb b/lib/puppet/type/watcher_config.rb
index 2e833a2..d19f643 100644
--- a/lib/puppet/type/watcher_config.rb
+++ b/lib/puppet/type/watcher_config.rb
@@ -7,14 +7,22 @@ Puppet::Type.newtype(:watcher_config) do
     newvalues(/\S+\/\S+/)
   end
 
-  newproperty(:value) do
+  newproperty(:value, :array_matching => :all) do
     desc 'The value of the setting to be defined.'
+    def insync?(is)
+      return true if @should.empty?
+      return false unless is.is_a? Array
+      return false unless is.length == @should.length
+      return (
+        is & @should == is or
+        is & @should.map(&:to_s) == is
+      )
+    end
     munge do |value|
       value = value.to_s.strip
       value.capitalize! if value =~ /^(true|false)$/i
       value
     end
-    newvalues(/^[\S ]*$/)
 
     def is_to_s( currentvalue )
       if resource.secret?
diff --git a/spec/unit/provider/watcher_config/ini_setting_spec.rb b/spec/unit/provider/watcher_config/openstackconfig_spec.rb
similarity index 94%
rename from spec/unit/provider/watcher_config/ini_setting_spec.rb
rename to spec/unit/provider/watcher_config/openstackconfig_spec.rb
index 4e39988..03f9124 100644
--- a/spec/unit/provider/watcher_config/ini_setting_spec.rb
+++ b/spec/unit/provider/watcher_config/openstackconfig_spec.rb
@@ -1,5 +1,5 @@
 require 'spec_helper'
-provider_class = Puppet::Type.type(:watcher_config).provider(:ini_setting)
+provider_class = Puppet::Type.type(:watcher_config).provider(:openstackconfig)
 describe provider_class do
 
   it 'should default to the default setting when no other one is specified' do
diff --git a/spec/unit/type/watcher_config_spec.rb b/spec/unit/type/watcher_config_spec.rb
index 18205cb..7d43027 100644
--- a/spec/unit/type/watcher_config_spec.rb
+++ b/spec/unit/type/watcher_config_spec.rb
@@ -30,12 +30,12 @@ describe 'Puppet::Type.type(:watcher_config)' do
 
   it 'should accept a valid value' do
     @watcher_config[:value] = 'bar'
-    expect(@watcher_config[:value]).to eq('bar')
+    expect(@watcher_config[:value]).to eq(['bar'])
   end
 
   it 'should not accept a value with whitespace' do
     @watcher_config[:value] = 'b ar'
-    expect(@watcher_config[:value]).to eq('b ar')
+    expect(@watcher_config[:value]).to eq(['b ar'])
   end
 
   it 'should accept valid ensure values' do