chef 16.4.38-universal-mingw32 → 16.4.41-universal-mingw32

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f5a1ff6498a5f9581a873db77ee290d2c4c2ab90979c8f690e37db745fe33265
4
- data.tar.gz: 18f800622adc96e1a0aecf9156feb31688ab369e583f9e1e793db2864b476282
3
+ metadata.gz: 11fe48a3054797d5ccd6622aab868f9924c24994a0eca31713ebadae82069477
4
+ data.tar.gz: 6251429cdd24a722d1e621e18a5fe5a09c75be795ce2b4f706790e5baa991db3
5
5
  SHA512:
6
- metadata.gz: 4e873923869649205017ceeff860c071862d6ae4dcd209a551228dc98ddd53553397a09f618728fd146ebe5b4c7bd6a17f6388d255e9d995f66bc46f78d95964
7
- data.tar.gz: 2e29fc4612a2ccfa5b131c80b318c26575543dbbace18f867081bcdc77e40df02ca4bde4125656f4efd04aa462d81f206a78df63cbe1c75a78a7d7c8c059377e
6
+ metadata.gz: 47a3e7c115c20ecfbc42173b551f812490e546ed4c1d417b5d180bc16942f35147551dae7f41c2c3d3801417c72f754ed26d9ef7d47ecdb316e5b486b29ca418
7
+ data.tar.gz: ab248bee2c350f4822800be24e26ba0899be504f0aa4643295412bf2971e687c6074d9dd3c2d2e765d9227aa661ac46b28279d94892826e1d286a00eec0b1e27
@@ -27,6 +27,8 @@ class Chef
27
27
 
28
28
  deps do
29
29
  require_relative "../util/path_helper"
30
+ require_relative "client_create"
31
+ require_relative "user_create"
30
32
  require "ohai" unless defined?(Ohai::System)
31
33
  Chef::Knife::ClientCreate.load_deps
32
34
  Chef::Knife::UserCreate.load_deps
@@ -26,7 +26,7 @@ class Chef
26
26
 
27
27
  provides :timezone
28
28
 
29
- description "Use the **timezone** resource to change the system timezone on Windows, Linux, and macOS hosts. Timezones are specified in tz database format, with a complete list of available TZ values for Linux and macOS here: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones and for Windows here: https://ss64.com/nt/timezones.html."
29
+ description "Use the **timezone** resource to change the system timezone on Windows, Linux, and macOS hosts. Timezones are specified in tz database format, with a complete list of available TZ values for Linux and macOS here: <https://en.wikipedia.org/wiki/List_of_tz_database_time_zones>. On Windows systems run `tzutil /l` for a complete list of valid timezones."
30
30
  introduced "14.6"
31
31
  examples <<~DOC
32
32
  **Set the timezone to UTC**
@@ -35,11 +35,19 @@ class Chef
35
35
  timezone 'UTC'
36
36
  ```
37
37
 
38
- **Set the timezone to UTC with a friendly resource name**
38
+ **Set the timezone to America/Los_Angeles with a friendly resource name on Linux/macOS**
39
39
 
40
40
  ```ruby
41
- timezone 'Set the host's timezone to UTC' do
42
- timezone 'UTC'
41
+ timezone 'Set the host's timezone to America/Los_Angeles' do
42
+ timezone 'America/Los_Angeles'
43
+ end
44
+ ```
45
+
46
+ **Set the timezone to PST with a friendly resource name on Windows**
47
+
48
+ ```ruby
49
+ timezone 'Set the host's timezone to PST' do
50
+ timezone 'Pacific Standard time'
43
51
  end
44
52
  ```
45
53
  DOC
@@ -48,90 +56,121 @@ class Chef
48
56
  description: "An optional property to set the timezone value if it differs from the resource block's name.",
49
57
  name_property: true
50
58
 
51
- action :set do
52
- description "Set the timezone."
53
-
54
- # some linux systems may be missing the timezone data
55
- if linux?
56
- package "tzdata" do
57
- package_name suse? ? "timezone" : "tzdata"
58
- end
59
+ # detect the current TZ on darwin hosts
60
+ #
61
+ # @since 14.7
62
+ # @return [String] TZ database value
63
+ def current_macos_tz
64
+ tz_shellout = shell_out!(["systemsetup", "-gettimezone"])
65
+ if /You need administrator access/.match?(tz_shellout.stdout)
66
+ raise "The timezone resource requires administrative privileges to run on macOS hosts!"
67
+ else
68
+ /Time Zone: (.*)/.match(tz_shellout.stdout)[1]
59
69
  end
70
+ end
60
71
 
61
- # Modern SUSE, Amazon, Fedora, RHEL, Ubuntu & Debian
62
- if systemd?
63
- cmd_set_tz = "/usr/bin/timedatectl --no-ask-password set-timezone #{new_resource.timezone}"
72
+ # detect the current timezone on windows hosts
73
+ #
74
+ # @since 14.7
75
+ # @return [String] timezone id
76
+ def current_windows_tz
77
+ tz_shellout = shell_out("tzutil /g")
78
+ raise "There was an error running the tzutil command" if tz_shellout.error?
64
79
 
65
- cmd_check_if_set = "/usr/bin/timedatectl status"
66
- cmd_check_if_set += " | /usr/bin/awk '/Time.*zone/{print}'"
67
- cmd_check_if_set += " | grep -q #{new_resource.timezone}"
80
+ tz_shellout.stdout.strip
81
+ end
68
82
 
69
- execute cmd_set_tz do
70
- action :run
71
- not_if cmd_check_if_set
72
- end
83
+ # detect the current timezone on systemd hosts
84
+ #
85
+ # @since 16.5
86
+ # @return [String] timezone id
87
+ def current_systemd_tz
88
+ tz_shellout = shell_out(["/usr/bin/timedatectl", "status"])
89
+ raise "There was an error running the timedatectl command" if tz_shellout.error?
90
+
91
+ # https://rubular.com/r/eV68MX9XXbyG4k
92
+ /Time zone: (.*) \(.*/.match(tz_shellout.stdout)[1]
93
+ end
94
+
95
+ # detect the current timezone on non-systemd RHEL-ish hosts
96
+ #
97
+ # @since 16.5
98
+ # @return [String] timezone id
99
+ def current_rhel_tz
100
+ return nil unless ::File.exist?("/etc/sysconfig/clock")
101
+
102
+ # https://rubular.com/r/aoj01L3bKBM7wh
103
+ /ZONE="(.*)"/.match(::File.read("/etc/sysconfig/clock"))[1]
104
+ end
105
+
106
+ load_current_value do
107
+ if systemd?
108
+ timezone current_systemd_tz
73
109
  else
74
110
  case node["platform_family"]
75
111
  # Old version of RHEL < 7 and Amazon 201X
76
112
  when "rhel", "amazon"
77
- file "/etc/sysconfig/clock" do
78
- owner "root"
79
- group "root"
80
- mode "0644"
81
- action :create
82
- content %{ZONE="#{new_resource.timezone}"\nUTC="true"\n}
83
- end
84
-
85
- execute "tzdata-update" do
86
- command "/usr/sbin/tzdata-update"
87
- action :nothing
88
- only_if { ::File.executable?("/usr/sbin/tzdata-update") }
89
- subscribes :run, "file[/etc/sysconfig/clock]", :immediately
90
- end
91
-
92
- link "/etc/localtime" do
93
- to "/usr/share/zoneinfo/#{new_resource.timezone}"
94
- not_if { ::File.executable?("/usr/sbin/tzdata-update") }
95
- end
113
+ timezone current_rhel_tz
96
114
  when "mac_os_x"
97
- unless current_darwin_tz == new_resource.timezone
98
- converge_by("set timezone to #{new_resource.timezone}") do
99
- shell_out!("sudo systemsetup -settimezone #{new_resource.timezone}")
100
- end
101
- end
115
+ timezone current_macos_tz
102
116
  when "windows"
103
- unless current_windows_tz.casecmp?(new_resource.timezone)
104
- converge_by("setting timezone to \"#{new_resource.timezone}\"") do
105
- shell_out!("tzutil /s \"#{new_resource.timezone}\"")
106
- end
107
- end
117
+ timezone current_windows_tz
108
118
  end
109
119
  end
110
120
  end
111
121
 
112
- action_class do
113
- # detect the current TZ on darwin hosts
114
- #
115
- # @since 14.7
116
- # @return [String] TZ database value
117
- def current_darwin_tz
118
- tz_shellout = shell_out!("systemsetup -gettimezone")
119
- if /You need administrator access/.match?(tz_shellout.stdout)
120
- raise "The timezone resource requires administrative privileges to run on macOS hosts!"
121
- else
122
- /Time Zone: (.*)/.match(tz_shellout.stdout)[1]
123
- end
124
- end
125
-
126
- # detect the current timezone on windows hosts
127
- #
128
- # @since 14.7
129
- # @return [String] timezone id
130
- def current_windows_tz
131
- tz_shellout = shell_out("tzutil /g")
132
- raise "There was an error running the tzutil command" if tz_shellout.exitstatus == 1
122
+ action :set do
123
+ description "Set the timezone."
133
124
 
134
- tz_shellout.stdout.strip
125
+ # we have to check windows first since the value isn't case sensitive here
126
+ if windows?
127
+ unless current_windows_tz.casecmp?(new_resource.timezone)
128
+ converge_by("setting timezone to '#{new_resource.timezone}'") do
129
+ shell_out!(["tzutil", "/s", new_resource.timezone])
130
+ end
131
+ end
132
+ else # linux / macos
133
+ converge_if_changed(:timezone) do
134
+ # Modern SUSE, Amazon, Fedora, RHEL, Ubuntu & Debian
135
+ if systemd?
136
+ # make sure we have the tzdata files
137
+ package suse? ? "timezone" : "tzdata"
138
+
139
+ shell_out!(["/usr/bin/timedatectl", "--no-ask-password", "set-timezone", new_resource.timezone])
140
+ else
141
+ case node["platform_family"]
142
+ # Old version of RHEL < 7 and Amazon 201X
143
+ when "rhel", "amazon"
144
+ # make sure we have the tzdata files
145
+ package "tzdata"
146
+
147
+ file "/etc/sysconfig/clock" do
148
+ owner "root"
149
+ group "root"
150
+ mode "0644"
151
+ action :create
152
+ content <<~CONTENT
153
+ ZONE="#{new_resource.timezone}"
154
+ UTC="true"
155
+ CONTENT
156
+ end
157
+
158
+ execute "tzdata-update" do
159
+ command "/usr/sbin/tzdata-update"
160
+ action :nothing
161
+ only_if { ::File.executable?("/usr/sbin/tzdata-update") }
162
+ subscribes :run, "file[/etc/sysconfig/clock]", :immediately
163
+ end
164
+
165
+ link "/etc/localtime" do
166
+ to "/usr/share/zoneinfo/#{new_resource.timezone}"
167
+ not_if { ::File.executable?("/usr/sbin/tzdata-update") }
168
+ end
169
+ when "mac_os_x"
170
+ shell_out!(["sudo", "systemsetup", "-settimezone", new_resource.timezone])
171
+ end
172
+ end
173
+ end
135
174
  end
136
175
  end
137
176
  end
@@ -23,7 +23,7 @@ require_relative "version_string"
23
23
 
24
24
  class Chef
25
25
  CHEF_ROOT = File.expand_path("..", __dir__)
26
- VERSION = Chef::VersionString.new("16.4.38")
26
+ VERSION = Chef::VersionString.new("16.4.41")
27
27
  end
28
28
 
29
29
  #
@@ -20,6 +20,31 @@ require "spec_helper"
20
20
  describe Chef::Resource::Timezone do
21
21
  let(:resource) { Chef::Resource::Timezone.new("fakey_fakerton") }
22
22
 
23
+ let(:shellout_tzutil) do
24
+ double("shell_out", stdout: "UTC\n", exitstatus: 0, error?: false)
25
+ end
26
+
27
+ # note: This weird indention is correct
28
+ let(:shellout_timedatectl) do
29
+ double("shell_out", exitstatus: 0, error?: false, stdout: <<-OUTPUT)
30
+ Local time: Tue 2020-08-18 20:55:05 UTC
31
+ Universal time: Tue 2020-08-18 20:55:05 UTC
32
+ RTC time: Tue 2020-08-18 20:55:05
33
+ Time zone: Etc/UTC (UTC, +0000)
34
+ System clock synchronized: yes
35
+ systemd-timesyncd.service active: yes
36
+ RTC in local TZ: no
37
+ OUTPUT
38
+ end
39
+
40
+ let(:shellout_systemsetup_fail) do
41
+ double("shell_out!", stdout: "You need administrator access to run this tool... exiting!", exitstatus: 0, error?: false) # yes it's a non-error exit
42
+ end
43
+
44
+ let(:shellout_systemsetup) do
45
+ double("shell_out!", stdout: "Time Zone: UTC", exitstatus: 0, error?: false)
46
+ end
47
+
23
48
  it "sets resource name as :timezone" do
24
49
  expect(resource.resource_name).to eql(:timezone)
25
50
  end
@@ -36,4 +61,42 @@ describe Chef::Resource::Timezone do
36
61
  expect { resource.action :set }.not_to raise_error
37
62
  expect { resource.action :unset }.to raise_error(Chef::Exceptions::ValidationFailed)
38
63
  end
64
+
65
+ describe "#current_macos_tz" do
66
+ context "with admin privs" do
67
+ it "returns the TZ" do
68
+ expect(resource).to receive(:shell_out!).and_return(shellout_systemsetup)
69
+ expect(resource.current_macos_tz).to eql("UTC")
70
+ end
71
+ end
72
+
73
+ context "without admin privs" do
74
+ it "returns the TZ" do
75
+ expect(resource).to receive(:shell_out!).and_return(shellout_systemsetup_fail)
76
+ expect { resource.current_macos_tz }.to raise_error(RuntimeError, "The timezone resource requires administrative privileges to run on macOS hosts!")
77
+ end
78
+ end
79
+ end
80
+
81
+ describe "#current_systemd_tz" do
82
+ it "returns the TZ" do
83
+ expect(resource).to receive(:shell_out).and_return(shellout_timedatectl)
84
+ expect(resource.current_systemd_tz).to eql("Etc/UTC")
85
+ end
86
+ end
87
+
88
+ describe "#current_windows_tz" do
89
+ it "returns the TZ" do
90
+ expect(resource).to receive(:shell_out).and_return(shellout_tzutil)
91
+ expect(resource.current_windows_tz).to eql("UTC")
92
+ end
93
+ end
94
+
95
+ describe "#current_rhel_tz" do
96
+ it "returns the TZ" do
97
+ allow(File).to receive(:exist?).with("/etc/sysconfig/clock").and_return true
98
+ expect(File).to receive(:read).with("/etc/sysconfig/clock").and_return 'ZONE="UTC"'
99
+ expect(resource.current_rhel_tz).to eql("UTC")
100
+ end
101
+ end
39
102
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef
3
3
  version: !ruby/object:Gem::Version
4
- version: 16.4.38
4
+ version: 16.4.41
5
5
  platform: universal-mingw32
6
6
  authors:
7
7
  - Adam Jacob
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-18 00:00:00.000000000 Z
11
+ date: 2020-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef-config
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 16.4.38
19
+ version: 16.4.41
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 16.4.38
26
+ version: 16.4.41
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: chef-utils
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 16.4.38
33
+ version: 16.4.41
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 16.4.38
40
+ version: 16.4.41
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: train-core
43
43
  requirement: !ruby/object:Gem::Requirement