Skip to content

Commit 210dfb8

Browse files
committed
Some cleanups before merge.
* removed the 'CLOUD-INIT-IGNORE' section, as we're just blindly writing the file now. removed the now-unnecessary import of 're' and 'os' * removed try/except block around write_apt_snippet. This will bubble up and cloud-init will let it through even to the console. Catching it and turning it into a debug would just hide it. * removed 'default' as a synonym for 'whatever cloud-init thinks is best' If people are going to change this, I'd rather they be specific. * supported value of "0" * fixed some complaints from ./tools/run-pylint cloudinit/CloudConfig/cc_apt_pipelining.py
1 parent 162762d commit 210dfb8

File tree

1 file changed

+12
-29
lines changed

1 file changed

+12
-29
lines changed

cloudinit/CloudConfig/cc_apt_pipelining.py

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,54 +17,37 @@
1717
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1818

1919
import cloudinit.util as util
20-
import re
21-
import os
2220
from cloudinit.CloudConfig import per_instance
2321

2422
frequency = per_instance
2523
default_file = "/etc/apt/apt.conf.d/90cloud-init-pipeling"
2624

27-
def handle(_name, cfg, cloud, log, _args):
25+
26+
def handle(_name, cfg, _cloud, log, _args):
2827

2928
apt_pipe_value = util.get_cfg_option_str(cfg, "apt_pipelining", False)
3029
apt_pipe_value = str(apt_pipe_value).lower()
3130

32-
if apt_pipe_value in ("false", "default", False):
33-
write_apt_snippet(0, log)
31+
if apt_pipe_value == "false":
32+
write_apt_snippet("0", log)
3433

3534
elif apt_pipe_value in ("none", "unchanged", "os"):
3635
return
3736

38-
elif apt_pipe_value in str(range(1, 5)):
37+
elif apt_pipe_value in str(range(0, 6)):
3938
write_apt_snippet(apt_pipe_value, log)
4039

4140
else:
42-
log.warn("Invalid option for apt_pipeling")
41+
log.warn("Invalid option for apt_pipeling: %s" % apt_pipe_value)
42+
4343

4444
def write_apt_snippet(setting, log, f_name=default_file):
45-
"""
46-
Reads f_name and determines if the setting matches or not. Sets to
47-
desired value
48-
"""
45+
""" Writes f_name with apt pipeline depth 'setting' """
4946

5047
acquire_pipeline_depth = 'Acquire::http::Pipeline-Depth "%s";\n'
51-
try:
52-
if os.path.exists(f_name):
53-
skip_re = re.compile('^//CLOUD-INIT-IGNORE.*')
54-
55-
for line in tweak.readlines():
56-
if skip_re.match(line):
57-
tweak.close()
58-
return
59-
60-
tweak.close()
61-
62-
file_contents = ("//Cloud-init Tweaks\n//Disables APT HTTP pipelining"\
63-
"\n" + (acquire_pipeline_depth % setting))
64-
65-
util.write_file(f_name, file_contents)
48+
file_contents = ("//Written by cloud-init per 'apt_pipelining'\n"
49+
+ (acquire_pipeline_depth % setting))
6650

67-
log.debug("Wrote %s with APT pipeline setting" % f_name )
51+
util.write_file(f_name, file_contents)
6852

69-
except IOError as e:
70-
log.debug("Unable to update pipeline settings in %s\n%s" % (f_name, e))
53+
log.debug("Wrote %s with APT pipeline setting" % f_name)

0 commit comments

Comments
 (0)