summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2020-02-25 15:41:31 -0800
committerGitHub <noreply@github.com>2020-02-25 15:41:31 -0800
commit6655b02af9b63caed67fd839d0437bb8b828a56b (patch)
tree24945411b203706f0c21f8fe052c5e1ae2101972
parent372ce32577b49a499638a58d4f38ffbaab7640aa (diff)
parentc617c753a317db947ac505857da721a3f2feebde (diff)
downloadchef-6655b02af9b63caed67fd839d0437bb8b828a56b.tar.gz
Merge pull request #9393 from chef/lcg/unified-mode3
More unified mode conversion and resource cleanup
-rw-r--r--lib/chef/provider/mdadm.rb85
-rw-r--r--lib/chef/provider/user.rb14
-rw-r--r--lib/chef/provider/user/dscl.rb2
-rw-r--r--lib/chef/provider/user/mac.rb20
-rw-r--r--lib/chef/providers.rb3
-rw-r--r--lib/chef/resource/mdadm.rb60
-rw-r--r--lib/chef/resource/ohai_hint.rb2
-rw-r--r--lib/chef/resource/pacman_package.rb2
-rw-r--r--lib/chef/resource/paludis_package.rb4
-rw-r--r--lib/chef/resource/portage_package.rb4
-rw-r--r--lib/chef/resource/smartos_package.rb4
-rw-r--r--lib/chef/resource/snap_package.rb4
-rw-r--r--lib/chef/resource/solaris_package.rb4
-rw-r--r--lib/chef/resource/swap_file.rb6
-rw-r--r--lib/chef/resource/user/dscl_user.rb4
-rw-r--r--lib/chef/resource/user/linux_user.rb2
-rw-r--r--lib/chef/resource/user/mac_user.rb2
-rw-r--r--spec/unit/provider/mdadm_spec.rb6
-rw-r--r--spec/unit/provider_resolver_spec.rb4
19 files changed, 113 insertions, 119 deletions
diff --git a/lib/chef/provider/mdadm.rb b/lib/chef/provider/mdadm.rb
deleted file mode 100644
index c5df1d0724..0000000000
--- a/lib/chef/provider/mdadm.rb
+++ /dev/null
@@ -1,85 +0,0 @@
-#
-# Author:: Joe Williams (<joe@joetify.com>)
-# Copyright:: Copyright 2009-2016, Joe Williams
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require_relative "../log"
-require_relative "../provider"
-
-class Chef
- class Provider
- class Mdadm < Chef::Provider
-
- provides :mdadm
-
- def load_current_resource
- @current_resource = Chef::Resource::Mdadm.new(new_resource.name)
- current_resource.raid_device(new_resource.raid_device)
- logger.trace("#{new_resource} checking for software raid device #{current_resource.raid_device}")
-
- device_not_found = 4
- mdadm = shell_out!("mdadm", "--detail", "--test", new_resource.raid_device, returns: [0, device_not_found])
- exists = (mdadm.status == 0)
- current_resource.exists(exists)
- end
-
- def action_create
- unless current_resource.exists
- converge_by("create RAID device #{new_resource.raid_device}") do
- command = "yes | mdadm --create #{new_resource.raid_device} --level #{new_resource.level}"
- command << " --chunk=#{new_resource.chunk}" unless new_resource.level == 1
- command << " --metadata=#{new_resource.metadata}"
- command << " --bitmap=#{new_resource.bitmap}" if new_resource.bitmap
- command << " --layout=#{new_resource.layout}" if new_resource.layout
- command << " --raid-devices #{new_resource.devices.length} #{new_resource.devices.join(" ")}"
- logger.trace("#{new_resource} mdadm command: #{command}")
- shell_out!(command)
- logger.info("#{new_resource} created raid device (#{new_resource.raid_device})")
- end
- else
- logger.trace("#{new_resource} raid device already exists, skipping create (#{new_resource.raid_device})")
- end
- end
-
- def action_assemble
- unless current_resource.exists
- converge_by("assemble RAID device #{new_resource.raid_device}") do
- command = "yes | mdadm --assemble #{new_resource.raid_device} #{new_resource.devices.join(" ")}"
- logger.trace("#{new_resource} mdadm command: #{command}")
- shell_out!(command)
- logger.info("#{new_resource} assembled raid device (#{new_resource.raid_device})")
- end
- else
- logger.trace("#{new_resource} raid device already exists, skipping assemble (#{new_resource.raid_device})")
- end
- end
-
- def action_stop
- if current_resource.exists
- converge_by("stop RAID device #{new_resource.raid_device}") do
- command = "yes | mdadm --stop #{new_resource.raid_device}"
- logger.trace("#{new_resource} mdadm command: #{command}")
- shell_out!(command)
- logger.info("#{new_resource} stopped raid device (#{new_resource.raid_device})")
- end
- else
- logger.trace("#{new_resource} raid device doesn't exist (#{new_resource.raid_device}) - not stopping")
- end
- end
-
- end
- end
-end
diff --git a/lib/chef/provider/user.rb b/lib/chef/provider/user.rb
index 8c99e36dfc..481de6e4cb 100644
--- a/lib/chef/provider/user.rb
+++ b/lib/chef/provider/user.rb
@@ -1,6 +1,6 @@
#
# Author:: Adam Jacob (<adam@chef.io>)
-# Copyright:: Copyright 2008-2018, Chef Software Inc.
+# Copyright:: Copyright 2008-2020, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -116,7 +116,7 @@ class Chef
false
end
- def action_create
+ action :create do
if !@user_exists
converge_by("create user #{new_resource.username}") do
create_user
@@ -130,7 +130,7 @@ class Chef
end
end
- def action_remove
+ action :remove do
return unless @user_exists
converge_by("remove user #{new_resource.username}") do
@@ -139,7 +139,7 @@ class Chef
end
end
- def action_manage
+ action :manage do
return unless @user_exists && compare_user
converge_by("manage user #{new_resource.username}") do
@@ -148,7 +148,7 @@ class Chef
end
end
- def action_modify
+ action :modify do
return unless compare_user
converge_by("modify user #{new_resource.username}") do
@@ -157,7 +157,7 @@ class Chef
end
end
- def action_lock
+ action :lock do
if check_lock == false
converge_by("lock the user #{new_resource.username}") do
lock_user
@@ -168,7 +168,7 @@ class Chef
end
end
- def action_unlock
+ action :unlock do
if check_lock == true
converge_by("unlock user #{new_resource.username}") do
unlock_user
diff --git a/lib/chef/provider/user/dscl.rb b/lib/chef/provider/user/dscl.rb
index 027f9eba38..687fc021da 100644
--- a/lib/chef/provider/user/dscl.rb
+++ b/lib/chef/provider/user/dscl.rb
@@ -1,6 +1,6 @@
#
# Author:: Dreamcat4 (<dreamcat4@gmail.com>)
-# Copyright:: Copyright 2009-2019, Chef Software Inc.
+# Copyright:: Copyright 2009-2020, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/lib/chef/provider/user/mac.rb b/lib/chef/provider/user/mac.rb
index c570399ca3..fb220b2128 100644
--- a/lib/chef/provider/user/mac.rb
+++ b/lib/chef/provider/user/mac.rb
@@ -1,6 +1,6 @@
#
# Author:: Ryan Cragun (<ryan@chef.io>)
-# Copyright:: Copyright (c) 2019-2019, Chef Software Inc.
+# Copyright:: Copyright (c) 2019-2020, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -196,12 +196,12 @@ class Chef
# group magement should be done outside of the core resource.
group_name, group_id, group_action = user_group_info
- declare_resource(:group, group_name) do
+ group group_name do
members new_resource.username
gid group_id if group_id
- action :nothing
+ action group_action
append true
- end.run_action(group_action)
+ end
converge_by("create primary group ID") do
run_dscl("create", "/Users/#{new_resource.username}", "PrimaryGroupID", group_id)
@@ -246,16 +246,16 @@ class Chef
if diverged?(:admin)
converge_by("alter admin group membership") do
- declare_resource(:group, "admin") do
+ group "admin" do
if new_resource.admin
members new_resource.username
else
excluded_members new_resource.username
end
- action :nothing
+ action :create
append true
- end.run_action(:create)
+ end
admins = admin_group_plist[:group_members]
if new_resource.admin
@@ -271,12 +271,12 @@ class Chef
end
group_name, group_id, group_action = user_group_info
- declare_resource(:group, group_name) do
+ group group_name do
gid group_id if group_id
members new_resource.username
- action :nothing
+ action group_action
append true
- end.run_action(group_action)
+ end
if diverged?(:gid)
converge_by("alter group membership") do
diff --git a/lib/chef/providers.rb b/lib/chef/providers.rb
index 5022ef7327..aa482e9705 100644
--- a/lib/chef/providers.rb
+++ b/lib/chef/providers.rb
@@ -1,6 +1,6 @@
#
# Author:: Daniel DeLeo (<dan@chef.io>)
-# Copyright:: Copyright 2010-2019, Chef Software Inc.
+# Copyright:: Copyright 2010-2020, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -34,7 +34,6 @@ require_relative "provider/launchd"
require_relative "provider/link"
require_relative "provider/log"
require_relative "provider/ohai"
-require_relative "provider/mdadm"
require_relative "provider/mount"
require_relative "provider/noop"
require_relative "provider/package"
diff --git a/lib/chef/resource/mdadm.rb b/lib/chef/resource/mdadm.rb
index aff90059a7..e226644f5e 100644
--- a/lib/chef/resource/mdadm.rb
+++ b/lib/chef/resource/mdadm.rb
@@ -22,6 +22,8 @@ require_relative "../resource"
class Chef
class Resource
class Mdadm < Chef::Resource
+ unified_mode true
+
resource_name :mdadm
description "Use the mdadm resource to manage RAID devices in a Linux environment using the mdadm utility. The mdadm resource"\
@@ -62,6 +64,64 @@ class Chef
property :layout, String,
description: "The RAID5 parity algorithm. Possible values: left-asymmetric (or la), left-symmetric (or ls), right-asymmetric (or ra), or right-symmetric (or rs)."
+
+ action_class do
+ def load_current_resource
+ @current_resource = Chef::Resource::Mdadm.new(new_resource.name)
+ current_resource.raid_device(new_resource.raid_device)
+ logger.trace("#{new_resource} checking for software raid device #{current_resource.raid_device}")
+
+ device_not_found = 4
+ mdadm = shell_out!("mdadm", "--detail", "--test", new_resource.raid_device, returns: [0, device_not_found])
+ exists = (mdadm.status == 0)
+ current_resource.exists(exists)
+ end
+ end
+
+ action :create do
+ unless current_resource.exists
+ converge_by("create RAID device #{new_resource.raid_device}") do
+ command = "yes | mdadm --create #{new_resource.raid_device} --level #{new_resource.level}"
+ command << " --chunk=#{new_resource.chunk}" unless new_resource.level == 1
+ command << " --metadata=#{new_resource.metadata}"
+ command << " --bitmap=#{new_resource.bitmap}" if new_resource.bitmap
+ command << " --layout=#{new_resource.layout}" if new_resource.layout
+ command << " --raid-devices #{new_resource.devices.length} #{new_resource.devices.join(" ")}"
+ logger.trace("#{new_resource} mdadm command: #{command}")
+ shell_out!(command)
+ logger.info("#{new_resource} created raid device (#{new_resource.raid_device})")
+ end
+ else
+ logger.trace("#{new_resource} raid device already exists, skipping create (#{new_resource.raid_device})")
+ end
+ end
+
+ action :assemble do
+ unless current_resource.exists
+ converge_by("assemble RAID device #{new_resource.raid_device}") do
+ command = "yes | mdadm --assemble #{new_resource.raid_device} #{new_resource.devices.join(" ")}"
+ logger.trace("#{new_resource} mdadm command: #{command}")
+ shell_out!(command)
+ logger.info("#{new_resource} assembled raid device (#{new_resource.raid_device})")
+ end
+ else
+ logger.trace("#{new_resource} raid device already exists, skipping assemble (#{new_resource.raid_device})")
+ end
+ end
+
+ action :stop do
+ if current_resource.exists
+ converge_by("stop RAID device #{new_resource.raid_device}") do
+ command = "yes | mdadm --stop #{new_resource.raid_device}"
+ logger.trace("#{new_resource} mdadm command: #{command}")
+ shell_out!(command)
+ logger.info("#{new_resource} stopped raid device (#{new_resource.raid_device})")
+ end
+ else
+ logger.trace("#{new_resource} raid device doesn't exist (#{new_resource.raid_device}) - not stopping")
+ end
+ end
+
end
end
end
diff --git a/lib/chef/resource/ohai_hint.rb b/lib/chef/resource/ohai_hint.rb
index a2f06acaac..bf3c344cb0 100644
--- a/lib/chef/resource/ohai_hint.rb
+++ b/lib/chef/resource/ohai_hint.rb
@@ -20,6 +20,8 @@ require_relative "../resource"
class Chef
class Resource
class OhaiHint < Chef::Resource
+ unified_mode true
+
resource_name :ohai_hint
provides(:ohai_hint) { true }
diff --git a/lib/chef/resource/pacman_package.rb b/lib/chef/resource/pacman_package.rb
index 71177a42aa..79627cd3ae 100644
--- a/lib/chef/resource/pacman_package.rb
+++ b/lib/chef/resource/pacman_package.rb
@@ -21,6 +21,8 @@ require_relative "package"
class Chef
class Resource
class PacmanPackage < Chef::Resource::Package
+ unified_mode true
+
resource_name :pacman_package
provides :pacman_package
diff --git a/lib/chef/resource/paludis_package.rb b/lib/chef/resource/paludis_package.rb
index 94b73ab570..ee439b7e4e 100644
--- a/lib/chef/resource/paludis_package.rb
+++ b/lib/chef/resource/paludis_package.rb
@@ -1,6 +1,6 @@
#
# Author:: Vasiliy Tolstov (<v.tolstov@selfip.ru>)
-# Copyright:: Copyright 2014-2018, Chef Software Inc.
+# Copyright:: Copyright 2014-2020, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,6 +22,8 @@ require_relative "../provider/package/paludis"
class Chef
class Resource
class PaludisPackage < Chef::Resource::Package
+ unified_mode true
+
resource_name :paludis_package
provides :paludis_package
diff --git a/lib/chef/resource/portage_package.rb b/lib/chef/resource/portage_package.rb
index b7b434804b..ab79e9c789 100644
--- a/lib/chef/resource/portage_package.rb
+++ b/lib/chef/resource/portage_package.rb
@@ -1,6 +1,6 @@
#
# Author:: Adam Jacob (<adam@chef.io>)
-# Copyright:: Copyright 2008-2018, Chef Software Inc.
+# Copyright:: Copyright 2008-2020, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,6 +21,8 @@ require_relative "package"
class Chef
class Resource
class PortagePackage < Chef::Resource::Package
+ unified_mode true
+
resource_name :portage_package
provides :portage_package
diff --git a/lib/chef/resource/smartos_package.rb b/lib/chef/resource/smartos_package.rb
index 510e1ccc7b..10ef027ef9 100644
--- a/lib/chef/resource/smartos_package.rb
+++ b/lib/chef/resource/smartos_package.rb
@@ -1,6 +1,6 @@
#
# Author:: Toomas Pelberg (<toomasp@gmx.net>)
-# Copyright:: Copyright 2010-2016, Chef Software Inc.
+# Copyright:: Copyright 2010-2020, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,6 +21,8 @@ require_relative "package"
class Chef
class Resource
class SmartosPackage < Chef::Resource::Package
+ unified_mode true
+
resource_name :smartos_package
provides :smartos_package
provides :package, platform_family: "smartos"
diff --git a/lib/chef/resource/snap_package.rb b/lib/chef/resource/snap_package.rb
index 8fb6b61c2c..263ab0161b 100644
--- a/lib/chef/resource/snap_package.rb
+++ b/lib/chef/resource/snap_package.rb
@@ -1,6 +1,6 @@
#
# Author:: S.Cavallo (<smcavallo@hotmail.com>)
-# Copyright:: Copyright 2008-2018, Chef Software Inc.
+# Copyright:: Copyright 2008-2020, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,6 +21,8 @@ require_relative "package"
class Chef
class Resource
class SnapPackage < Chef::Resource::Package
+ unified_mode true
+
resource_name :snap_package
description "Use the snap_package resource to manage snap packages on Debian and Ubuntu platforms."
diff --git a/lib/chef/resource/solaris_package.rb b/lib/chef/resource/solaris_package.rb
index c6cda0ef36..8cade4abba 100644
--- a/lib/chef/resource/solaris_package.rb
+++ b/lib/chef/resource/solaris_package.rb
@@ -1,7 +1,7 @@
#
# Author:: Toomas Pelberg (<toomasp@gmx.net>)
# Author:: Prabhu Das (<prabhu.das@clogeny.com>)
-# Copyright:: Copyright 2013-2018, Chef Software Inc.
+# Copyright:: Copyright 2013-2020, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,6 +22,8 @@ require_relative "package"
class Chef
class Resource
class SolarisPackage < Chef::Resource::Package
+ unified_mode true
+
resource_name :solaris_package
provides :solaris_package
provides :package, os: "solaris2", platform_family: "nexentacore"
diff --git a/lib/chef/resource/swap_file.rb b/lib/chef/resource/swap_file.rb
index 2efe040c47..a2838c5be7 100644
--- a/lib/chef/resource/swap_file.rb
+++ b/lib/chef/resource/swap_file.rb
@@ -1,6 +1,6 @@
#
# Copyright 2012-2018, Seth Vargo
-# Copyright 2017-2018, Chef Software, Inc.
+# Copyright 2017-2020, Chef Software Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -20,6 +20,8 @@ require_relative "../resource"
class Chef
class Resource
class SwapFile < Chef::Resource
+ unified_mode true
+
resource_name :swap_file
provides(:swap_file) { true }
@@ -60,7 +62,7 @@ class Chef
end
end
if new_resource.swappiness
- declare_resource(:sysctl, "vm.swappiness") do
+ sysctl "vm.swappiness" do
value new_resource.swappiness
end
end
diff --git a/lib/chef/resource/user/dscl_user.rb b/lib/chef/resource/user/dscl_user.rb
index 5ba9d3d099..34d8a4180c 100644
--- a/lib/chef/resource/user/dscl_user.rb
+++ b/lib/chef/resource/user/dscl_user.rb
@@ -1,5 +1,5 @@
#
-# Copyright:: Copyright 2016-2017, Chef Software Inc.
+# Copyright:: Copyright 2016-2020, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,6 +21,8 @@ class Chef
class Resource
class User
class DsclUser < Chef::Resource::User
+ unified_mode true
+
resource_name :dscl_user
provides :dscl_user
diff --git a/lib/chef/resource/user/linux_user.rb b/lib/chef/resource/user/linux_user.rb
index 9ec6480035..4f3622213d 100644
--- a/lib/chef/resource/user/linux_user.rb
+++ b/lib/chef/resource/user/linux_user.rb
@@ -1,5 +1,5 @@
#
-# Copyright:: Copyright 2016-2017, Chef Software Inc.
+# Copyright:: Copyright 2016-2020, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/lib/chef/resource/user/mac_user.rb b/lib/chef/resource/user/mac_user.rb
index 6f40287951..62245f8df1 100644
--- a/lib/chef/resource/user/mac_user.rb
+++ b/lib/chef/resource/user/mac_user.rb
@@ -58,6 +58,8 @@ class Chef
# the 'password' property corresponds to a plaintext password and will
# attempt to use it in place of secure_token_password if it not set.
class MacUser < Chef::Resource::User
+ unified_mode true
+
resource_name :mac_user
provides :mac_user
diff --git a/spec/unit/provider/mdadm_spec.rb b/spec/unit/provider/mdadm_spec.rb
index d79c1b35db..7e3546dcce 100644
--- a/spec/unit/provider/mdadm_spec.rb
+++ b/spec/unit/provider/mdadm_spec.rb
@@ -19,15 +19,15 @@
require "spec_helper"
require "ostruct"
-describe Chef::Provider::Mdadm do
+describe Chef::Resource::Mdadm do
before(:each) do
@node = Chef::Node.new
@events = Chef::EventDispatch::Dispatcher.new
@run_context = Chef::RunContext.new(@node, {}, @events)
- @new_resource = Chef::Resource::Mdadm.new("/dev/md1")
+ @new_resource = Chef::Resource::Mdadm.new("/dev/md1", run_context)
@new_resource.devices ["/dev/sdz1", "/dev/sdz2", "/dev/sdz3"]
- @provider = Chef::Provider::Mdadm.new(@new_resource, @run_context)
+ @provider = @new_resource.provider_for_action(:create)
end
describe "when determining the current metadevice status" do
diff --git a/spec/unit/provider_resolver_spec.rb b/spec/unit/provider_resolver_spec.rb
index 2eadcd0d1c..79b43ccce2 100644
--- a/spec/unit/provider_resolver_spec.rb
+++ b/spec/unit/provider_resolver_spec.rb
@@ -1,6 +1,6 @@
#
# Author:: Lamont Granquist (<lamont@chef.io>)
-# Copyright:: Copyright 2014-2019, Chef Software Inc.
+# Copyright:: Copyright 2014-2020, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -562,7 +562,7 @@ describe Chef::ProviderResolver do
linux_user: [ Chef::Resource::User::LinuxUser, Chef::Provider::User::Linux ],
log: [ Chef::Resource::Log, Chef::Provider::Log::ChefLog ],
macports_package: [ Chef::Resource::MacportsPackage, Chef::Provider::Package::Macports ],
- mdadm: [ Chef::Resource::Mdadm, Chef::Provider::Mdadm ],
+ mdadm: [ Chef::Resource::Mdadm ],
mount: [ Chef::Resource::Mount, Chef::Provider::Mount::Mount ],
pacman_package: [ Chef::Resource::PacmanPackage, Chef::Provider::Package::Pacman ],
paludis_package: [ Chef::Resource::PaludisPackage, Chef::Provider::Package::Paludis ],