1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134 | commit 912c4a6f44aa820b71d508f84409d4323b1e07f7 (HEAD)
Author: Scott Moser <smoser@brickies.net>
Date: Wed Jul 19 15:38:10 2017 -0400
fixup: combine the render_tmpl and render_cloud_cfg.
diff --git a/packages/redhat/cloud-init.spec.in b/packages/redhat/cloud-init.spec.in
index 72e8ac87..6ab0d20b 100644
--- a/packages/redhat/cloud-init.spec.in
+++ b/packages/redhat/cloud-init.spec.in
@@ -99,30 +99,24 @@ ssh keys and to let the user run various scripts.
%install
%{__python} setup.py install -O1 \
- --skip-build --root \$RPM_BUILD_ROOT \
+ --skip-build --root $RPM_BUILD_ROOT \
--init-system=%{init_system}
# Note that /etc/rsyslog.d didn't exist by default until F15.
# el6 request: https://bugzilla.redhat.com/show_bug.cgi?id=740420
-mkdir -p \$RPM_BUILD_ROOT/%{_sysconfdir}/rsyslog.d
+mkdir -p $RPM_BUILD_ROOT/%{_sysconfdir}/rsyslog.d
cp -p tools/21-cloudinit.conf \
- \$RPM_BUILD_ROOT/%{_sysconfdir}/rsyslog.d/21-cloudinit.conf
+ $RPM_BUILD_ROOT/%{_sysconfdir}/rsyslog.d/21-cloudinit.conf
# Remove the tests
-rm -rf \$RPM_BUILD_ROOT%{python_sitelib}/tests
+rm -rf $RPM_BUILD_ROOT%{python_sitelib}/tests
# Required dirs...
-mkdir -p \$RPM_BUILD_ROOT/%{_sharedstatedir}/cloud
-mkdir -p \$RPM_BUILD_ROOT/%{_libexecdir}/%{name}
-
-%if "%{init_system}" == "systemd"
-mkdir -p \$RPM_BUILD_ROOT/%{_unitdir}
-# only copy targets, .service files are installed by setup.py
-cp -p systemd/*.target \$RPM_BUILD_ROOT/%{_unitdir}
-%endif
+mkdir -p $RPM_BUILD_ROOT/%{_sharedstatedir}/cloud
+mkdir -p $RPM_BUILD_ROOT/%{_libexecdir}/%{name}
%clean
-rm -rf \$RPM_BUILD_ROOT
+rm -rf $RPM_BUILD_ROOT
%post
diff --git a/setup.py b/setup.py
index fbcad6fd..1197eceb 100755
--- a/setup.py
+++ b/setup.py
@@ -87,8 +87,8 @@ def read_requires():
return str(deps).splitlines()
-def render_cloud_cfg():
- """render cloud.cfg into a tmpdir under same dir as setup.py
+def render_tmpl(template):
+ """render template into a tmpdir under same dir as setup.py
This is rendered to a temporary directory under the top level
directory with the name 'cloud.cfg'. The reason for not just rendering
@@ -99,45 +99,21 @@ def render_cloud_cfg():
# older versions of tox use bdist (xenial), and then install from there.
# newer versions just use install.
if not (sys.argv[1] == 'install' or sys.argv[1].startswith('bdist*')):
- return 'config/cloud.cfg.tmpl'
- topdir = os.path.dirname(sys.argv[0])
- tmpd = tempfile.mkdtemp(dir=topdir)
- atexit.register(shutil.rmtree, tmpd)
- fpath = os.path.join(tmpd, 'cloud.cfg')
- tiny_p([sys.executable, './tools/render-cloudcfg',
- 'config/cloud.cfg.tmpl', fpath])
- # relpath is relative to setup.py
- relpath = os.path.join(os.path.basename(tmpd), 'cloud.cfg')
- return relpath
-
-def render_systemd_unit(template):
- """render systemd unit into a tmpdir under same dir as setup.py
-
- This is rendered to a temporary directory under the top level
- directory with the name 'systemd.cfg'. The reason for not just
- rendering to systemd/{unit}.service is for a.) don't want to write
- over contents in that file if user had something there. b.) debuild
- will complain that files are different outside of the debian directory."""
-
- # older versions of tox use bdist (xenial), and then install from there.
- # newer versions just use install.
- if not (sys.argv[1] == 'install' or sys.argv[1].startswith('bdist*')):
return template
+ tmpl_ext = ".tmpl"
# we may get passed a non-template file, just pass it back
- if not template.endswith('.tmpl'):
+ if not template.endswith(tmpl_ext):
return template
topdir = os.path.dirname(sys.argv[0])
tmpd = tempfile.mkdtemp(dir=topdir)
atexit.register(shutil.rmtree, tmpd)
- unit_fname = os.path.basename(template.rstrip('.tmpl'))
- fpath = os.path.join(tmpd, unit_fname)
- tiny_p([sys.executable, './tools/render-cloudcfg',
- template, fpath])
- # relpath is relative to setup.py
- relpath = os.path.join(os.path.basename(tmpd), unit_fname)
- return relpath
+ bname = os.path.basename(template).rstrip(tmpl_ext)
+ fpath = os.path.join(tmpd, bname)
+ tiny_p([sys.executable, './tools/render-cloudcfg', template, fpath])
+ # return path relative to setup.py
+ return os.path.join(os.path.basename(tmpd), bname)
INITSYS_FILES = {
@@ -145,7 +121,7 @@ INITSYS_FILES = {
'sysvinit_freebsd': [f for f in glob('sysvinit/freebsd/*') if is_f(f)],
'sysvinit_deb': [f for f in glob('sysvinit/debian/*') if is_f(f)],
'sysvinit_openrc': [f for f in glob('sysvinit/gentoo/*') if is_f(f)],
- 'systemd': [render_systemd_unit(f)
+ 'systemd': [render_tmpl(f)
for f in (glob('systemd/*.tmpl') +
glob('systemd/*.service') +
glob('systemd/*.target')) if is_f(f)],
@@ -226,7 +202,7 @@ if not in_virtualenv():
INITSYS_ROOTS[k] = "/" + INITSYS_ROOTS[k]
data_files = [
- (ETC + '/cloud', [render_cloud_cfg()]),
+ (ETC + '/cloud', [render_tmpl("config/cloud.cfg.tmpl")]),
(ETC + '/cloud/cloud.cfg.d', glob('config/cloud.cfg.d/*')),
(ETC + '/cloud/templates', glob('templates/*')),
(USR_LIB_EXEC + '/cloud-init', ['tools/ds-identify',
|