Merge ~raharper/cloud-init:fix/fedora-build into cloud-init:master

Proposed by Ryan Harper
Status: Work in progress
Proposed branch: ~raharper/cloud-init:fix/fedora-build
Merge into: cloud-init:master
Diff against target: 476 lines (+156/-43)
5 files modified
packages/brpm (+15/-7)
packages/pkg-deps.json (+23/-10)
packages/redhat/cloud-init.spec.in (+59/-12)
tools/read-dependencies (+34/-1)
tools/run-container (+25/-13)
Reviewer Review Type Date Requested Status
Chad Smith Needs Fixing
Server Team CI bot continuous-integration Needs Fixing
Dan Watkins Needs Information
Review via email: mp+368845@code.launchpad.net

Commit message

update redhat specfile and tools to support python2 and python3

Note, this needs to rebase after the cloud-init-template.generator fix has landed in master.

To post a comment you must log in.
Revision history for this message
Ryan Harper (raharper) wrote :

We should take an srpm out of this and test-build Fedora on COPR repo before landing.

Revision history for this message
Server Team CI bot (server-team-bot) wrote :

FAILED: Continuous integration, rev:4cbd01cfd7e075ccf4279b931baef60028e42463
https://jenkins.ubuntu.com/server/job/cloud-init-ci/734/
Executed test runs:
    SUCCESS: Checkout
    FAILED: Unit & Style Tests

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/734/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Ryan Harper (raharper) wrote :
bd9d4b4... by Ryan Harper

drop fedora specific spec file

Revision history for this message
Server Team CI bot (server-team-bot) wrote :

PASSED: Continuous integration, rev:8aa87376f1338970d21933f862f94f89f9d73566
https://jenkins.ubuntu.com/server/job/cloud-init-ci/738/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/738/rebuild

review: Approve (continuous-integration)
Revision history for this message
Dan Watkins (oddbloke) wrote :

Overall this looks good, thanks! Just a few inline comments/questions.

review: Needs Information
Revision history for this message
Ryan Harper (raharper) wrote :

Thanks for the review; this needs some testing and I can see if we can keep the install section the same save the interpreter we run.

Revision history for this message
Dan Watkins (oddbloke) wrote :

Thanks for the responses, Ryan. The two outstanding issues I believe we have are: ensuring we haven't broken RH builds, and working out if we can/should run setup.py for Python 3 RPM builds.

Revision history for this message
Dan Watkins (oddbloke) wrote :

Oh, yep, just saw your summary comment; we are in agreement. :)

cab1663... by Ryan Harper

Consolidate %install section by defining python_cmd value and always passing variant

2b5163b... by Ryan Harper

setup.py takes --distro for variant

12efb6d... by Ryan Harper

setup.py is awkward on arg parsing for --distro

Revision history for this message
Server Team CI bot (server-team-bot) wrote :

FAILED: Continuous integration, rev:12efb6d3e6d07664db030e295d18fd872b867461
https://jenkins.ubuntu.com/server/job/cloud-init-ci/746/
Executed test runs:
    FAILED: Checkout

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/746/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Chad Smith (chad.smith) wrote :

I think we may have to solve the buildrequires_py* om the specfile and possibly how to copy with httpretty on centos8 for the package name changes?

review: Needs Fixing
Revision history for this message
Ryan Harper (raharper) wrote :

Thanks. I've a few questions for clarification.

Unmerged commits

12efb6d... by Ryan Harper

setup.py is awkward on arg parsing for --distro

2b5163b... by Ryan Harper

setup.py takes --distro for variant

cab1663... by Ryan Harper

Consolidate %install section by defining python_cmd value and always passing variant

bd9d4b4... by Ryan Harper

drop fedora specific spec file

5336b5f... by Ryan Harper

drop devel deps, fetch os_variant and pass to render-cloudcfg

8b97cb8... by Ryan Harper

have build env pick whether it uses python3 or not

1045123... by Ryan Harper

add --python2 param to brpm call if target build env is using py2

d952e8d... by Ryan Harper

fix py3 macros and sitelib paths

25c3eeb... by Ryan Harper

add pyver to template

88d85a1... by Ryan Harper

work out how to pass variant and skip build for py3

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/packages/brpm b/packages/brpm
2index a154ef2..502cfb4 100755
3--- a/packages/brpm
4+++ b/packages/brpm
5@@ -42,13 +42,14 @@ def run_helper(helper, args=None, strip=True):
6 return stdout
7
8
9-def read_dependencies(distro, requirements_file='requirements.txt'):
10+def read_dependencies(distro, pyver, requirements_file='requirements.txt'):
11 """Returns the Python package depedencies from requirements.txt files.
12
13 @returns a tuple of (requirements, test_requirements)
14 """
15 pkg_deps = run_helper(
16- 'read-dependencies', args=['--distro', distro]).splitlines()
17+ 'read-dependencies', args=['--distro', distro,
18+ '--python-version', pyver]).splitlines()
19 test_deps = run_helper(
20 'read-dependencies', args=[
21 '--requirements-file', 'test-requirements.txt',
22@@ -83,9 +84,10 @@ def generate_spec_contents(args, version_data, tmpl_fn, top_dir, arc_fn):
23 rpm_upstream_version = version_data['version']
24 subs['rpm_upstream_version'] = rpm_upstream_version
25
26- deps, test_deps = read_dependencies(distro=args.distro)
27- subs['buildrequires'] = deps + test_deps
28- subs['requires'] = deps
29+ for pyver in ['2', '3']:
30+ deps, test_deps = read_dependencies(distro=args.distro, pyver=pyver)
31+ subs['buildrequires_py%s' % pyver] = deps + test_deps
32+ subs['requires_py%s' % pyver] = deps
33
34 if args.boot == 'sysvinit':
35 subs['sysvinit'] = True
36@@ -108,7 +110,7 @@ def main():
37 parser.add_argument("-d", "--distro", dest="distro",
38 help="select distro (default: %(default)s)",
39 metavar="DISTRO", default='redhat',
40- choices=('redhat', 'suse'))
41+ choices=('fedora', 'redhat', 'suse'))
42 parser.add_argument('--srpm',
43 help='Produce a source rpm',
44 action='store_true')
45@@ -155,6 +157,12 @@ def main():
46 'make-tarball', ['--long', '--output=' + real_archive_fn])
47 print("Archived the code in %r" % (real_archive_fn))
48
49+ if args.distro == "fedora":
50+ args.distro = "redhat"
51+ args.variant = "fedora"
52+ else:
53+ args.variant = args.distro
54+
55 # Form the spec file to be used
56 tmpl_fn = util.abs_join(find_root(), 'packages',
57 args.distro, 'cloud-init.spec.in')
58@@ -189,7 +197,7 @@ def main():
59 for rpm_fn in globs:
60 tgt_fn = util.abs_join(os.getcwd(), os.path.basename(rpm_fn))
61 shutil.move(rpm_fn, tgt_fn)
62- print("Wrote out %s package %r" % (args.distro, tgt_fn))
63+ print("Wrote out %s package %r" % (args.variant, tgt_fn))
64 finally:
65 if workdir is not None:
66 shutil.rmtree(workdir)
67diff --git a/packages/pkg-deps.json b/packages/pkg-deps.json
68index 72409dd..0470187 100644
69--- a/packages/pkg-deps.json
70+++ b/packages/pkg-deps.json
71@@ -24,32 +24,43 @@
72 },
73 "redhat" : {
74 "build-requires" : [
75- "python-devel",
76- "python-setuptools"
77+ "xfsprogs",
78+ "rpm-build"
79 ],
80 "renames" : {
81+ "httpretty" : {
82+ "3" : "python3-httpretty"
83+ },
84 "jinja2" : {
85- "3" : "python34-jinja2"
86+ "3" : "python3-jinja2"
87 },
88 "jsonschema" : {
89- "3" : "python34-jsonschema"
90+ "3" : "python3-jsonschema"
91+ },
92+ "prettytable" : {
93+ "3": "python3-prettytable"
94 },
95 "pyflakes" : {
96 "2" : "pyflakes",
97- "3" : "python34-pyflakes"
98+ "3" : "python3-pyflakes"
99 },
100 "pyyaml" : {
101 "2" : "PyYAML",
102- "3" : "python34-PyYAML"
103+ "3" : "python3-PyYAML"
104 },
105 "pyserial" : {
106- "2" : "pyserial"
107+ "2" : "pyserial",
108+ "3" : "python3-pyserial"
109 },
110 "requests" : {
111- "3" : "python34-requests"
112+ "3" : "python3-requests"
113 },
114+ "setuptools" : {
115+ "2" : "python-setuptools",
116+ "3" : "python3-setuptools"
117+ },
118 "six" : {
119- "3" : "python34-six"
120+ "3" : "python3-six"
121 }
122 },
123 "requires" : [
124@@ -59,7 +70,9 @@
125 "procps",
126 "rsyslog",
127 "shadow-utils",
128- "sudo"
129+ "sudo",
130+ "util-linux",
131+ "xfsprogs"
132 ]
133 },
134 "suse" : {
135diff --git a/packages/redhat/cloud-init.spec.in b/packages/redhat/cloud-init.spec.in
136index 057a578..0746bcd 100644
137--- a/packages/redhat/cloud-init.spec.in
138+++ b/packages/redhat/cloud-init.spec.in
139@@ -2,6 +2,8 @@
140 %{!?python_sitelib: %global python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")}
141
142 %define use_systemd (0%{?fedora} && 0%{?fedora} >= 18) || (0%{?rhel} && 0%{?rhel} >= 7)
143+%define use_python3 (0%{?fedora} && 0%{?fedora} >= 29) || (0%{?rhel} && 0%{?rhel} >= 8)
144+%define os_variant %(source /etc/os-release; echo $ID ;)
145
146 %if %{use_systemd}
147 %define init_system systemd
148@@ -9,6 +11,14 @@
149 %define init_system sysvinit
150 %endif
151
152+%if %{use_python3}
153+%define python_major 3
154+%define python_cmd python3
155+%define python_minor %(%{python_cmd} -c "import sys; %sys.stdout.write(str(sys.version_info.minor))")
156+%else
157+%define python_cmd python
158+%endif
159+
160 # See: http://www.zarb.org/~jasonc/macros.php
161 # Or: http://fedoraproject.org/wiki/Packaging:ScriptletSnippets
162 # Or: http://www.rpm.org/max-rpm/ch-rpm-inside.html
163@@ -41,12 +51,29 @@ Requires(post): chkconfig
164 Requires(preun): chkconfig
165 %endif
166
167+%if "%{python_major}" == "3"
168+BuildRequires: python3-devel
169+BuildRequires: python3-setuptools
170+%if "%{python_minor}" >= "8"
171+BuildRequires: python3-distro
172+%endif
173+%else
174+BuildRequires: python-devel
175+BuildRequires: python-setuptools
176+%endif
177+
178 # These are runtime dependencies, but declared as BuildRequires so that
179 # - tests can be run here.
180 # - parts of cloud-init such (setup.py) use these dependencies.
181-{% for r in requires %}
182+%if %{use_python3}
183+{% for r in requires_py3 %}
184 BuildRequires: {{r}}
185 {% endfor %}
186+%else
187+{% for r in requires_py2 %}
188+BuildRequires: {{r}}
189+{% endfor %}
190+%endif
191
192 # System util packages needed
193 %ifarch %{?ix86} x86_64 ia64
194@@ -58,11 +85,16 @@ Requires: dmidecode
195 Requires: python-argparse
196 %endif
197
198-
199 # Install 'dynamic' runtime reqs from *requirements.txt and pkg-deps.json
200-{% for r in requires %}
201+%if %{use_python3}
202+{% for r in requires_py3 %}
203+Requires: {{r}}
204+{% endfor %}
205+%else
206+{% for r in requires_py2 %}
207 Requires: {{r}}
208 {% endfor %}
209+%endif
210
211 # Custom patches
212 {% for p in patches %}
213@@ -93,14 +125,21 @@ ssh keys and to let the user run various scripts.
214 %patch{{loop.index0}} -p1
215 {% endfor %}
216
217+%if "%{python_major}" == "3"
218+# Change shebangs
219+sed -i -e 's|#!/usr/bin/env python|#!/usr/bin/env python3|' \
220+ -e 's|#!/usr/bin/python|#!/usr/bin/python3|' tools/* cloudinit/ssh_util.py
221+%endif
222+
223+
224 %build
225-%{__python} setup.py build
226+%{python_cmd} setup.py build
227
228-%install
229
230-%{__python} setup.py install -O1 \
231+%install
232+%{python_cmd} setup.py install -O1 \
233 --skip-build --root $RPM_BUILD_ROOT \
234- --init-system=%{init_system}
235+ --init-system=%{init_system} --distro %{os_variant}
236
237 # Note that /etc/rsyslog.d didn't exist by default until F15.
238 # el6 request: https://bugzilla.redhat.com/show_bug.cgi?id=740420
239@@ -109,7 +148,11 @@ cp -p tools/21-cloudinit.conf \
240 $RPM_BUILD_ROOT/%{_sysconfdir}/rsyslog.d/21-cloudinit.conf
241
242 # Remove the tests
243+%if "%{python_major}" == "3"
244+rm -rf $RPM_BUILD_ROOT%{python3_sitelib}/tests
245+%else
246 rm -rf $RPM_BUILD_ROOT%{python_sitelib}/tests
247+%endif
248
249 # Required dirs...
250 mkdir -p $RPM_BUILD_ROOT/%{_sharedstatedir}/cloud
251@@ -122,11 +165,12 @@ version_pys=$(cd "$RPM_BUILD_ROOT" && find . -name version.py -type f)
252 ( cd "$RPM_BUILD_ROOT" &&
253 sed -i "s,@@PACKAGED_VERSION@@,%{version}-%{release}," $version_pys )
254
255+
256 %clean
257 rm -rf $RPM_BUILD_ROOT
258
259-%post
260
261+%post
262 %if "%{init_system}" == "systemd"
263 if [ $1 -eq 1 ]
264 then
265@@ -142,8 +186,8 @@ fi
266 /sbin/chkconfig --add %{_initrddir}/cloud-final
267 %endif
268
269-%preun
270
271+%preun
272 %if "%{init_system}" == "systemd"
273 if [ $1 -eq 0 ]
274 then
275@@ -166,14 +210,14 @@ then
276 fi
277 %endif
278
279-%postun
280
281+%postun
282 %if "%{init_system}" == "systemd"
283 /bin/systemctl daemon-reload >/dev/null 2>&1 || :
284 %endif
285
286-%files
287
288+%files
289 /lib/udev/rules.d/66-azure-ephemeral.rules
290
291 %if "%{init_system}" == "systemd"
292@@ -188,7 +232,6 @@ fi
293
294 %{_sysconfdir}/NetworkManager/dispatcher.d/hook-network-manager
295 %{_sysconfdir}/dhcp/dhclient-exit-hooks.d/hook-dhclient
296-
297 # Program binaries
298 %{_bindir}/cloud-init*
299 %{_bindir}/cloud-id*
300@@ -213,4 +256,8 @@ fi
301 %dir %{_sharedstatedir}/cloud
302
303 # Python code is here...
304+%if "%{python_major}" == "3"
305+%{python3_sitelib}/*
306+%else
307 %{python_sitelib}/*
308+%endif
309diff --git a/tools/read-dependencies b/tools/read-dependencies
310index b4656e6..77c2ec5 100755
311--- a/tools/read-dependencies
312+++ b/tools/read-dependencies
313@@ -23,6 +23,7 @@ DEFAULT_REQUIREMENTS = 'requirements.txt'
314 # Map the appropriate package dir needed for each distro choice
315 DISTRO_PKG_TYPE_MAP = {
316 'centos': 'redhat',
317+ 'fedora': 'fedora',
318 'redhat': 'redhat',
319 'debian': 'debian',
320 'ubuntu': 'debian',
321@@ -51,17 +52,41 @@ MAYBE_RELIABLE_YUM_INSTALL = [
322 """,
323 'reliable-yum-install']
324
325+MAYBE_RELIABLE_DNF_INSTALL = [
326+ 'sh', '-c',
327+ """
328+ error() { echo "$@" 1>&2; }
329+ n=0; max=10;
330+ bcmd="dnf install --downloadonly --assumeyes --setopt=keepcache=1"
331+ while n=$(($n+1)); do
332+ error ":: running $bcmd $* [$n/$max]"
333+ $bcmd "$@"
334+ r=$?
335+ [ $r -eq 0 ] && break
336+ [ $n -ge $max ] && { error "gave up on $bcmd"; exit $r; }
337+ nap=$(($n*5))
338+ error ":: failed [$r] ($n/$max). sleeping $nap."
339+ sleep $nap
340+ done
341+ error ":: running dnf install --cacheonly --assumeyes $*"
342+ dnf install --cacheonly --assumeyes "$@"
343+ """,
344+ 'reliable-dnf-install']
345+
346+
347 ZYPPER_INSTALL = [
348 'zypper', '--non-interactive', '--gpg-auto-import-keys', 'install',
349 '--auto-agree-with-licenses']
350
351 DRY_DISTRO_INSTALL_PKG_CMD = {
352 'centos': ['yum', 'install', '--assumeyes'],
353+ 'fedora': ['dnf', 'install', '--assumeyes'],
354 'redhat': ['yum', 'install', '--assumeyes'],
355 }
356
357 DISTRO_INSTALL_PKG_CMD = {
358 'centos': MAYBE_RELIABLE_YUM_INSTALL,
359+ 'fedora': MAYBE_RELIABLE_DNF_INSTALL,
360 'redhat': MAYBE_RELIABLE_YUM_INSTALL,
361 'debian': ['apt', 'install', '-y'],
362 'ubuntu': ['apt', 'install', '-y'],
363@@ -73,6 +98,7 @@ DISTRO_INSTALL_PKG_CMD = {
364 # List of base system packages required to enable ci automation
365 CI_SYSTEM_BASE_PKGS = {
366 'common': ['make', 'sudo', 'tar'],
367+ 'fedora': ['python3-tox'],
368 'redhat': ['python-tox'],
369 'centos': ['python-tox'],
370 'ubuntu': ['devscripts', 'python3-dev', 'libssl-dev', 'tox', 'sbuild'],
371@@ -192,6 +218,13 @@ def main(distro):
372 else:
373 topd = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
374
375+ # allow fedora to use redhat, mark it as variant
376+ if args.distro in ['fedora']:
377+ args.variant = args.distro
378+ args.distro = 'redhat'
379+ else:
380+ args.variant = args.distro
381+
382 if args.test_distro:
383 # Give us all the system deps we need for continuous integration
384 if args.req_files:
385@@ -234,7 +267,7 @@ def main(distro):
386 else:
387 all_deps = pip_pkg_names
388 if args.install:
389- pkg_install(all_deps, args.distro, args.test_distro, args.dry_run)
390+ pkg_install(all_deps, args.variant, args.test_distro, args.dry_run)
391 else:
392 print('\n'.join(all_deps))
393
394diff --git a/tools/run-container b/tools/run-container
395index 1d24e15..114803c 100755
396--- a/tools/run-container
397+++ b/tools/run-container
398@@ -218,9 +218,10 @@ get_os_info() {
399 { error "Unable to determine OS_NAME/OS_VERSION"; return 1; }
400 }
401
402-yum_install() {
403+_rpm_install() {
404+ install_cmd="$1"; shift;
405 local n=0 max=10 ret
406- bcmd="yum install --downloadonly --assumeyes --setopt=keepcache=1"
407+ bcmd="$install_cmd install --downloadonly --assumeyes --setopt=keepcache=1"
408 while n=$((n+1)); do
409 error ":: running $bcmd $* [$n/$max]"
410 $bcmd "$@"
411@@ -231,8 +232,16 @@ yum_install() {
412 error ":: failed [$ret] ($n/$max). sleeping $nap."
413 sleep $nap
414 done
415- error ":: running yum install --cacheonly --assumeyes $*"
416- yum install --cacheonly --assumeyes "$@"
417+ error ":: running $install_cmd install --cacheonly --assumeyes $*"
418+ $install_cmd install --cacheonly --assumeyes "$@"
419+}
420+
421+yum_install() {
422+ _rpm_install "yum" "$@"
423+}
424+
425+dnf_install() {
426+ _rpm_install "dnf" "$@"
427 }
428
429 zypper_install() {
430@@ -250,6 +259,7 @@ apt_install() {
431 install_packages() {
432 get_os_info || return
433 case "$OS_NAME" in
434+ fedora) dnf_install "$@";;
435 centos) yum_install "$@";;
436 opensuse) zypper_install "$@";;
437 debian|ubuntu) apt_install "$@";;
438@@ -492,8 +502,15 @@ main() {
439 return
440 }
441
442+ local distflag=""
443+ case "$OS_NAME" in
444+ centos) distflag="--distro=redhat";;
445+ fedora) distflag="--distro=fedora";;
446+ opensuse) distflag="--distro=suse";;
447+ esac
448+
449 inside_as_cd "$name" root "$cdir" \
450- $pyexe ./tools/read-dependencies "--distro=${OS_NAME}" \
451+ $pyexe ./tools/read-dependencies "$distflag" \
452 --test-distro || {
453 errorrc "FAIL: failed to install dependencies with read-dependencies"
454 return
455@@ -514,18 +531,13 @@ main() {
456 }
457 fi
458
459- local build_pkg="" build_srcpkg="" pkg_ext="" distflag=""
460- case "$OS_NAME" in
461- centos) distflag="--distro=redhat";;
462- opensuse) distflag="--distro=suse";;
463- esac
464-
465+ local build_pkg="" build_srcpkg="" pkg_ext="" pyver=""
466 case "$OS_NAME" in
467 debian|ubuntu)
468- build_pkg="./packages/bddeb -d"
469+ build_pkg="./packages/bddeb -d"
470 build_srcpkg="./packages/bddeb -S -d"
471 pkg_ext=".deb";;
472- centos|opensuse)
473+ centos|fedora|opensuse|redhat)
474 build_pkg="./packages/brpm $distflag"
475 build_srcpkg="./packages/brpm $distflag --srpm"
476 pkg_ext=".rpm";;

Subscribers

People subscribed via source and target branches