Skip to content

Commit 0334e55

Browse files
author
Mike Milner
committed
Switch to using util.subp.
1 parent 9f719a8 commit 0334e55

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

cloudinit/CloudConfig/cc_ca_certs.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import os
1717
from subprocess import check_call
1818
from cloudinit.util import (write_file, get_cfg_option_list_or_str,
19-
delete_dir_contents)
19+
delete_dir_contents, subp)
2020

2121
CA_CERT_PATH = "/usr/share/ca-certificates/"
2222
CA_CERT_FILENAME = "cloud-init-ca-certs.crt"
@@ -54,9 +54,8 @@ def remove_default_ca_certs():
5454
delete_dir_contents(CA_CERT_PATH)
5555
delete_dir_contents(CA_CERT_SYSTEM_PATH)
5656
write_file(CA_CERT_CONFIG, "", mode=0644)
57-
check_call([
58-
"echo 'ca-certificates ca-certificates/trust_new_crts select no' | "
59-
"debconf-set-selections"], shell=True)
57+
debconf_sel = "ca-certificates ca-certificates/trust_new_crts select no"
58+
subp(('debconf-set-selections', '-'), debconf_sel)
6059

6160

6261
def handle(_name, cfg, _cloud, log, _args):

tests/unittests/test_handler_ca_certs.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,14 @@ def test_commands(self):
169169
mock_delete_dir_contents = self.mocker.replace(delete_dir_contents,
170170
passthrough=False)
171171
mock_write = self.mocker.replace(write_file, passthrough=False)
172-
mock_check_call = self.mocker.replace("subprocess.check_call",
173-
passthrough=False)
172+
mock_subp = self.mocker.replace("cloudinit.util.subp",
173+
passthrough=False)
174174

175175
mock_delete_dir_contents("/usr/share/ca-certificates/")
176176
mock_delete_dir_contents("/etc/ssl/certs/")
177177
mock_write("/etc/ca-certificates.conf", "", mode=0644)
178-
mock_check_call([
179-
"echo 'ca-certificates ca-certificates/trust_new_crts select no'"
180-
" | debconf-set-selections"], shell=True)
178+
mock_subp(('debconf-set-selections', '-'),
179+
"ca-certificates ca-certificates/trust_new_crts select no")
181180
self.mocker.replay()
182181

183182
remove_default_ca_certs()

0 commit comments

Comments
 (0)