summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMal Graty <mal.graty@googlemail.com>2018-05-16 19:06:30 +0100
committerMal Graty <mal.graty@googlemail.com>2018-05-19 00:35:58 +0100
commitd436e257b5666163e02608c4afeada60e231fa88 (patch)
treef4b3b3bd1ccc6e59dcc3d6e7579ff94b01db72c3
parentf8d9aea002009d49c529cc87a691c8a19de3f664 (diff)
downloadchef-d436e257b5666163e02608c4afeada60e231fa88.tar.gz
Fix systemd_unit user property usage
Use Etc.getpwnam rather than Etc.getpwuid, since getpwuid expects a UID and the resource provides a string. Signed-off-by: Mal Graty <mal.graty@googlemail.com>
-rw-r--r--lib/chef/provider/service/systemd.rb2
-rw-r--r--lib/chef/provider/systemd_unit.rb2
-rw-r--r--spec/unit/provider/service/systemd_service_spec.rb2
-rw-r--r--spec/unit/provider/systemd_unit_spec.rb2
4 files changed, 4 insertions, 4 deletions
diff --git a/lib/chef/provider/service/systemd.rb b/lib/chef/provider/service/systemd.rb
index 1bcc2f3a00..704f94a7ff 100644
--- a/lib/chef/provider/service/systemd.rb
+++ b/lib/chef/provider/service/systemd.rb
@@ -77,7 +77,7 @@ class Chef::Provider::Service::Systemd < Chef::Provider::Service::Simple
def get_systemctl_options_args
if new_resource.user
- uid = Etc.getpwuid(new_resource.user).uid
+ uid = Etc.getpwnam(new_resource.user).uid
options = {
:environment => {
"DBUS_SESSION_BUS_ADDRESS" => "unix:path=/run/user/#{uid}/bus",
diff --git a/lib/chef/provider/systemd_unit.rb b/lib/chef/provider/systemd_unit.rb
index d8c83d2b4b..124f255c3a 100644
--- a/lib/chef/provider/systemd_unit.rb
+++ b/lib/chef/provider/systemd_unit.rb
@@ -245,7 +245,7 @@ class Chef
def systemctl_opts
@systemctl_opts ||=
if new_resource.user
- uid = Etc.getpwuid(new_resource.user).uid
+ uid = Etc.getpwnam(new_resource.user).uid
{
:user => new_resource.user,
:environment => {
diff --git a/spec/unit/provider/service/systemd_service_spec.rb b/spec/unit/provider/service/systemd_service_spec.rb
index a9c11b7c18..8286176fed 100644
--- a/spec/unit/provider/service/systemd_service_spec.rb
+++ b/spec/unit/provider/service/systemd_service_spec.rb
@@ -47,7 +47,7 @@ describe Chef::Provider::Service::Systemd do
before(:each) do
allow(Chef::Resource::Service).to receive(:new).with(service_name).and_return(current_resource)
- allow(Etc).to receive(:getpwuid).and_return(OpenStruct.new(uid: 10000))
+ allow(Etc).to receive(:getpwnam).and_return(OpenStruct.new(uid: 10000))
end
describe "load_current_resource" do
diff --git a/spec/unit/provider/systemd_unit_spec.rb b/spec/unit/provider/systemd_unit_spec.rb
index 15d5944992..ce04b6c84c 100644
--- a/spec/unit/provider/systemd_unit_spec.rb
+++ b/spec/unit/provider/systemd_unit_spec.rb
@@ -74,7 +74,7 @@ describe Chef::Provider::SystemdUnit do
end
before(:each) do
- allow(Etc).to receive(:getpwuid).and_return(OpenStruct.new(uid: 1000))
+ allow(Etc).to receive(:getpwnam).and_return(OpenStruct.new(uid: 1000))
allow(Chef::Resource::SystemdUnit).to receive(:new)
.with(unit_name)
.and_return(current_resource)