Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cloudinit/analyze/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class SystemctlReader(object):

def __init__(self, property, parameter=None):
self.epoch = None
self.args = ["/bin/systemctl", "show"]
self.args = [subp.which("systemctl"), "show"]
if parameter:
self.args.append(parameter)
self.args.extend(["-p", property])
Expand Down
6 changes: 2 additions & 4 deletions cloudinit/config/cc_puppet.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,8 @@ def _autostart_puppet(log):
],
capture=False,
)
elif os.path.exists("/bin/systemctl"):
subp.subp(
["/bin/systemctl", "enable", "puppet.service"], capture=False
)
elif subp.which("systemctl"):
subp.subp(["systemctl", "enable", "puppet.service"], capture=False)
elif os.path.exists("/sbin/chkconfig"):
subp.subp(["/sbin/chkconfig", "puppet", "on"], capture=False)
else:
Expand Down
4 changes: 2 additions & 2 deletions cloudinit/sources/helpers/azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def get_boot_telemetry():

try:
out, _ = subp.subp(
["/bin/systemctl", "show", "-p", "UserspaceTimestampMonotonic"],
["systemctl", "show", "-p", "UserspaceTimestampMonotonic"],
capture=True,
)
tsm = None
Expand All @@ -140,7 +140,7 @@ def get_boot_telemetry():
try:
out, _ = subp.subp(
[
"/bin/systemctl",
"systemctl",
"show",
"cloud-init-local",
"-p",
Expand Down
24 changes: 14 additions & 10 deletions tests/unittests/config/test_cc_puppet.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
LOG = logging.getLogger(__name__)


@mock.patch("cloudinit.config.cc_puppet.subp.which")
@mock.patch("cloudinit.config.cc_puppet.subp.subp")
@mock.patch("cloudinit.config.cc_puppet.os")
class TestAutostartPuppet(CiTestCase):
def test_wb_autostart_puppet_updates_puppet_default(self, m_os, m_subp):
def test_wb_autostart_puppet_updates_puppet_default(
self, m_os, m_subp, m_subpw
):
"""Update /etc/default/puppet to autostart if it exists."""

def _fake_exists(path):
Expand All @@ -37,27 +40,28 @@ def _fake_exists(path):
m_subp.call_args_list,
)

def test_wb_autostart_pupppet_enables_puppet_systemctl(self, m_os, m_subp):
def test_wb_autostart_pupppet_enables_puppet_systemctl(
self, m_os, m_subp, m_subpw
):
"""If systemctl is present, enable puppet via systemctl."""

def _fake_exists(path):
return path == "/bin/systemctl"

m_os.path.exists.side_effect = _fake_exists
m_os.path.exists.return_value = False
m_subpw.return_value = "/usr/bin/systemctl"
cc_puppet._autostart_puppet(LOG)
expected_calls = [
mock.call(
["/bin/systemctl", "enable", "puppet.service"], capture=False
)
mock.call(["systemctl", "enable", "puppet.service"], capture=False)
]
self.assertEqual(expected_calls, m_subp.call_args_list)

def test_wb_autostart_pupppet_enables_puppet_chkconfig(self, m_os, m_subp):
def test_wb_autostart_pupppet_enables_puppet_chkconfig(
self, m_os, m_subp, m_subpw
):
"""If chkconfig is present, enable puppet via checkcfg."""

def _fake_exists(path):
return path == "/sbin/chkconfig"

m_subpw.return_value = None
m_os.path.exists.side_effect = _fake_exists
cc_puppet._autostart_puppet(LOG)
expected_calls = [
Expand Down