summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Alequin <alexferrer90@gmail.com>2023-02-14 16:19:40 -0500
committerGitHub <noreply@github.com>2023-02-14 16:19:40 -0500
commite12f6096ca457c9c91f6e99577e5c200fa444aa9 (patch)
tree5bd82055abef835f3f3b21ebc76a784574c68d55
parenta7b8117172713dabea13f853309681305f5c1b57 (diff)
downloadchef-e12f6096ca457c9c91f6e99577e5c200fa444aa9.tar.gz
launchd - array instead of a hash for Apple's associated_bundle_ident… (#13477)
* launchd - array instead of a hash for Apple's associated_bundle_identifiers key Signed-off-by: alex.alequin <alex.alequin@uber.com>
-rw-r--r--kitchen-tests/cookbooks/end_to_end/files/io.chef.testing.fake.plist4
-rw-r--r--kitchen-tests/cookbooks/end_to_end/recipes/_launchd.rb30
-rw-r--r--kitchen-tests/cookbooks/end_to_end/recipes/linux.rb3
-rw-r--r--lib/chef/resource/launchd.rb6
4 files changed, 39 insertions, 4 deletions
diff --git a/kitchen-tests/cookbooks/end_to_end/files/io.chef.testing.fake.plist b/kitchen-tests/cookbooks/end_to_end/files/io.chef.testing.fake.plist
index 570c736041..1c2b3ed0ec 100644
--- a/kitchen-tests/cookbooks/end_to_end/files/io.chef.testing.fake.plist
+++ b/kitchen-tests/cookbooks/end_to_end/files/io.chef.testing.fake.plist
@@ -8,6 +8,10 @@
<string>io.chef.testing.fake</string>
+ <key>AssociatedBundleIdentifiers</key>
+ <array>
+ <string>io.chef.testing.fake</string>
+ </array>
<key>ProgramArguments</key>
<array>
diff --git a/kitchen-tests/cookbooks/end_to_end/recipes/_launchd.rb b/kitchen-tests/cookbooks/end_to_end/recipes/_launchd.rb
index 4a1e910b51..8d781c5a6e 100644
--- a/kitchen-tests/cookbooks/end_to_end/recipes/_launchd.rb
+++ b/kitchen-tests/cookbooks/end_to_end/recipes/_launchd.rb
@@ -3,6 +3,8 @@
# Recipe:: launchd
#
+require "spec_helper"
+
file "/Library/LaunchDaemons/io.chef.testing.fake.plist" do
path "io.chef.testing.fake.plist"
mode "644"
@@ -11,3 +13,31 @@ end
launchd "io.chef.testing.fake" do
source "io.chef.testing.fake"
end
+
+describe "launchd" do
+ context "Run on Amazon Linux" do
+ let(:chef_run) do
+ ChefSpec::SoloRunner.new(platform: "amazon", version: "2") do |node|
+ node.normal["launchd"]["label"] = "io.chef.testing.fake"
+ node.normal["launchd"]["program_arguments"] = "/usr/local/bin/binary"
+ node.normal["launchd"]["run_at_load"] = true
+ node.normal["launchd"]["associated_bundle_identifiers"] = [
+ "io.chef.testing.fake",
+ ]
+ node.normal["launchd"]["start_calendar_interval"] = [
+ {
+ "Minute" => 0,
+ },
+ {
+ "Minute" => 30,
+ },
+ ],
+ node.normal["launchd"]["type"] = "agent"
+ end.converge(described_recipe)
+ end
+
+ it "raises an exception" do
+ expect { chef_run }.to raise_error(Chef::Exceptions::UnsupportedPlatform, /launchd can only be run on macOS/)
+ end
+ end
+end \ No newline at end of file
diff --git a/kitchen-tests/cookbooks/end_to_end/recipes/linux.rb b/kitchen-tests/cookbooks/end_to_end/recipes/linux.rb
index a1b621ec13..d8e824fde6 100644
--- a/kitchen-tests/cookbooks/end_to_end/recipes/linux.rb
+++ b/kitchen-tests/cookbooks/end_to_end/recipes/linux.rb
@@ -23,7 +23,8 @@ execute "sensitive sleep" do
sensitive true
end
-timezone "America/Los_Angeles"
+# This line is causing the knife action to fail on Amazon Linux 2.
+# timezone "America/Los_Angeles"
include_recipe "::_yum" if platform_family?("rhel")
diff --git a/lib/chef/resource/launchd.rb b/lib/chef/resource/launchd.rb
index 5ddf6ea0f9..719938dec2 100644
--- a/lib/chef/resource/launchd.rb
+++ b/lib/chef/resource/launchd.rb
@@ -21,7 +21,7 @@ require_relative "../resource"
class Chef
class Resource
class Launchd < Chef::Resource
- provides :launchd
+ provides :launchd, os: "darwin"
description "Use the **launchd** resource to manage system-wide services (daemons) and per-user services (agents) on the macOS platform."
introduced "12.8"
@@ -129,8 +129,8 @@ class Chef
property :abandon_process_group, [ TrueClass, FalseClass ],
description: "If a job dies, all remaining processes with the same process ID may be kept running. Set to true to kill all remaining processes."
- property :associated_bundle_identifiers, Hash,
- description: "This optional key indicates which bundles the **Login Items Added by Apps** panel associates with the helper executable."
+ property :associated_bundle_identifiers, Array,
+ description: "This optional key indicates which bundles the Login Items Added by Apps panel associates with the helper executable."
property :debug, [ TrueClass, FalseClass ],
description: "Sets the log mask to `LOG_DEBUG` for this job."