From 6a979bb2fabd187efc392de7b0852cd0361bc9b8 Mon Sep 17 00:00:00 2001 From: Ryan Harper Date: Tue, 17 Apr 2018 20:07:59 -0500 Subject: Implement bash completion script for cloud-init command line In bash shells with bash_completion enabled, now the cloud-init sub commands and parameters/flags will be shown. --- packages/redhat/cloud-init.spec.in | 1 + packages/suse/cloud-init.spec.in | 1 + 2 files changed, 2 insertions(+) (limited to 'packages') diff --git a/packages/redhat/cloud-init.spec.in b/packages/redhat/cloud-init.spec.in index 6ab0d20b..91faf3c6 100644 --- a/packages/redhat/cloud-init.spec.in +++ b/packages/redhat/cloud-init.spec.in @@ -197,6 +197,7 @@ fi %dir %{_sysconfdir}/cloud/templates %config(noreplace) %{_sysconfdir}/cloud/templates/* %config(noreplace) %{_sysconfdir}/rsyslog.d/21-cloudinit.conf +%{_sysconfdir}/bash_completion.d/cloud-init %{_libexecdir}/%{name} %dir %{_sharedstatedir}/cloud diff --git a/packages/suse/cloud-init.spec.in b/packages/suse/cloud-init.spec.in index 86e18b1b..bbb965a7 100644 --- a/packages/suse/cloud-init.spec.in +++ b/packages/suse/cloud-init.spec.in @@ -136,6 +136,7 @@ mkdir -p %{buildroot}/var/lib/cloud %config(noreplace) %{_sysconfdir}/cloud/cloud.cfg.d/README %dir %{_sysconfdir}/cloud/templates %config(noreplace) %{_sysconfdir}/cloud/templates/* +%{_sysconfdir}/bash_completion.d/cloud-init # Python code is here... %{python_sitelib}/* -- cgit v1.2.3 From 00d7b9c5f5380d01c76b648877943c4c0cfbcfff Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Tue, 24 Apr 2018 15:11:48 -0600 Subject: packages/debian/control.in: add missing dependency on iproute2. Ubuntu minimal images do not have iproute2, so correctly identify our dependency on it. LP: #1766711 --- packages/debian/control.in | 1 + 1 file changed, 1 insertion(+) (limited to 'packages') diff --git a/packages/debian/control.in b/packages/debian/control.in index 46da6dff..e9ed64f3 100644 --- a/packages/debian/control.in +++ b/packages/debian/control.in @@ -11,6 +11,7 @@ Package: cloud-init Architecture: all Depends: ${misc:Depends}, ${${python}:Depends}, + iproute2, isc-dhcp-client Recommends: eatmydata, sudo, software-properties-common, gdisk XB-Python-Version: ${python:Versions} -- cgit v1.2.3 From 26fbb1a0ce89451edad83a47054cacb6dd7b6dcc Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Tue, 1 May 2018 15:38:41 -0600 Subject: tools: Re-use the orig tarball in packages/bddeb if it is around. If you built packages with 'bddeb', each time it would create a new tarball with make-tarball. If you then tried to upload two different tarballs to launchpad (to a PPA), it would reject the second as the orig tarball already existed. This just supports looking in some places for a orig tarball and re-using if it is found. --- packages/bddeb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'packages') diff --git a/packages/bddeb b/packages/bddeb index 4f2e2ddf..0f124784 100755 --- a/packages/bddeb +++ b/packages/bddeb @@ -157,10 +157,18 @@ def main(): # This is really only a temporary archive # since we will extract it then add in the debian # folder, then re-archive it for debian happiness - print("Creating a temporary tarball using the 'make-tarball' helper") tarball = "cloud-init_%s.orig.tar.gz" % ver_data['version_long'] tarball_fp = util.abs_join(tdir, tarball) - run_helper('make-tarball', ['--long', '--output=' + tarball_fp]) + path = None + for pd in ("./", "../", "../dl/"): + if os.path.exists(pd + tarball): + path = pd + tarball + print("Using existing tarball %s" % path) + shutil.copy(path, tarball_fp) + break + if path is None: + print("Creating a temp tarball using the 'make-tarball' helper") + run_helper('make-tarball', ['--long', '--output=' + tarball_fp]) print("Extracting temporary tarball %r" % (tarball)) cmd = ['tar', '-xvzf', tarball_fp, '-C', tdir] -- cgit v1.2.3 From d24057adbc70e7b034b8aca36c5351938b5de74a Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Wed, 2 May 2018 20:03:23 -0600 Subject: tools: Support adding a release suffix through packages/bddeb. bddeb already supported passing in a '--release' and that would get into the changelog line. If you used bddeb to build packages for a PPA, and built multiple releases, then you would get the same version for each release, and launchpad would reject your upload. The change here means we get a ~16.04.1 (for xenial) suffix on the dpkg version. If the distro-info-data package is not installed, or the release is not known (such as the default "UNRELEASED"), then you get no suffix. --- packages/bddeb | 28 ++++++++++++++++++++++++++-- packages/debian/changelog.in | 2 +- 2 files changed, 27 insertions(+), 3 deletions(-) (limited to 'packages') diff --git a/packages/bddeb b/packages/bddeb index 0f124784..95602a02 100755 --- a/packages/bddeb +++ b/packages/bddeb @@ -1,11 +1,14 @@ #!/usr/bin/env python3 import argparse +import csv import json import os import shutil import sys +UNRELEASED = "UNRELEASED" + def find_root(): # expected path is in /packages/ @@ -28,6 +31,24 @@ if "avoid-pep8-E402-import-not-top-of-file": DEBUILD_ARGS = ["-S", "-d"] +def get_release_suffix(release): + """Given ubuntu release (xenial), return a suffix for package (~16.04.1)""" + csv_path = "/usr/share/distro-info/ubuntu.csv" + rels = {} + # fields are version, codename, series, created, release, eol, eol-server + if os.path.exists(csv_path): + with open(csv_path, "r") as fp: + # version has "16.04 LTS" or "16.10", so drop "LTS" portion. + rels = {row['series']: row['version'].replace(' LTS', '') + for row in csv.DictReader(fp)} + if release in rels: + return "~%s.1" % rels[release] + elif release != UNRELEASED: + print("missing distro-info-data package, unable to give " + "per-release suffix.\n") + return "" + + def run_helper(helper, args=None, strip=True): if args is None: args = [] @@ -117,7 +138,7 @@ def get_parser(): parser.add_argument("--release", dest="release", help=("build with changelog referencing RELEASE"), - default="UNRELEASED") + default=UNRELEASED) for ent in DEBUILD_ARGS: parser.add_argument(ent, dest="debuild_args", action='append_const', @@ -148,7 +169,10 @@ def main(): if args.verbose: capture = False - templ_data = {'debian_release': args.release} + templ_data = { + 'debian_release': args.release, + 'release_suffix': get_release_suffix(args.release)} + with temp_utils.tempdir() as tdir: # output like 0.7.6-1022-g36e92d3 diff --git a/packages/debian/changelog.in b/packages/debian/changelog.in index bdf8d56f..930322f5 100644 --- a/packages/debian/changelog.in +++ b/packages/debian/changelog.in @@ -1,5 +1,5 @@ ## template:basic -cloud-init (${version_long}-1~bddeb) ${debian_release}; urgency=low +cloud-init (${version_long}-1~bddeb${release_suffix}) ${debian_release}; urgency=low * build -- cgit v1.2.3 From 5446c788160412189200c6cc688b14c9f9071943 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Tue, 22 May 2018 16:06:41 -0400 Subject: Update version.version_string to contain packaged version. This modifies version.version_string to support having the package build write the *packaged* version in with a easy replace. Then, when cloud-init reports its version it will include the full packaged version. Also modified here are upstream package build files to get that done. Note part of the trickery in packages/debian/rules.in was to avoid the 'basic' templater consuming the '$variable' variable names. LP: #1770712 --- cloudinit/tests/test_version.py | 31 +++++++++++++++++++++++++++++++ cloudinit/version.py | 4 ++++ packages/debian/rules.in | 2 ++ tests/unittests/test_version.py | 14 -------------- 4 files changed, 37 insertions(+), 14 deletions(-) create mode 100644 cloudinit/tests/test_version.py delete mode 100644 tests/unittests/test_version.py (limited to 'packages') diff --git a/cloudinit/tests/test_version.py b/cloudinit/tests/test_version.py new file mode 100644 index 00000000..a96c2a47 --- /dev/null +++ b/cloudinit/tests/test_version.py @@ -0,0 +1,31 @@ +# This file is part of cloud-init. See LICENSE file for license information. + +from cloudinit.tests.helpers import CiTestCase +from cloudinit import version + +import mock + + +class TestExportsFeatures(CiTestCase): + def test_has_network_config_v1(self): + self.assertIn('NETWORK_CONFIG_V1', version.FEATURES) + + def test_has_network_config_v2(self): + self.assertIn('NETWORK_CONFIG_V2', version.FEATURES) + + +class TestVersionString(CiTestCase): + @mock.patch("cloudinit.version._PACKAGED_VERSION", + "17.2-3-gb05b9972-0ubuntu1") + def test_package_version_respected(self): + """If _PACKAGED_VERSION is filled in, then it should be returned.""" + self.assertEqual("17.2-3-gb05b9972-0ubuntu1", version.version_string()) + + @mock.patch("cloudinit.version._PACKAGED_VERSION", "@@PACKAGED_VERSION@@") + @mock.patch("cloudinit.version.__VERSION__", "17.2") + def test_package_version_skipped(self): + """If _PACKAGED_VERSION is not modified, then return __VERSION__.""" + self.assertEqual("17.2", version.version_string()) + + +# vi: ts=4 expandtab diff --git a/cloudinit/version.py b/cloudinit/version.py index ccd0f84e..ce3b8c1e 100644 --- a/cloudinit/version.py +++ b/cloudinit/version.py @@ -5,6 +5,7 @@ # This file is part of cloud-init. See LICENSE file for license information. __VERSION__ = "18.2" +_PACKAGED_VERSION = '@@PACKAGED_VERSION@@' FEATURES = [ # supports network config version 1 @@ -15,6 +16,9 @@ FEATURES = [ def version_string(): + """Extract a version string from cloud-init.""" + if not _PACKAGED_VERSION.startswith('@@'): + return _PACKAGED_VERSION return __VERSION__ # vi: ts=4 expandtab diff --git a/packages/debian/rules.in b/packages/debian/rules.in index 4aa907e3..e542c7f1 100755 --- a/packages/debian/rules.in +++ b/packages/debian/rules.in @@ -3,6 +3,7 @@ INIT_SYSTEM ?= systemd export PYBUILD_INSTALL_ARGS=--init-system=$(INIT_SYSTEM) PYVER ?= python${pyver} +DEB_VERSION := $(shell dpkg-parsechangelog --show-field=Version) %: dh $@ --with $(PYVER),systemd --buildsystem pybuild @@ -14,6 +15,7 @@ override_dh_install: cp tools/21-cloudinit.conf debian/cloud-init/etc/rsyslog.d/21-cloudinit.conf install -D ./tools/Z99-cloud-locale-test.sh debian/cloud-init/etc/profile.d/Z99-cloud-locale-test.sh install -D ./tools/Z99-cloudinit-warnings.sh debian/cloud-init/etc/profile.d/Z99-cloudinit-warnings.sh + flist=$$(find $(CURDIR)/debian/ -type f -name version.py) && sed -i 's,@@PACKAGED_VERSION@@,$(DEB_VERSION),' $${flist:-did-not-find-version-py-for-replacement} override_dh_auto_test: ifeq (,$(findstring nocheck,$(DEB_BUILD_OPTIONS))) diff --git a/tests/unittests/test_version.py b/tests/unittests/test_version.py deleted file mode 100644 index d012f69d..00000000 --- a/tests/unittests/test_version.py +++ /dev/null @@ -1,14 +0,0 @@ -# This file is part of cloud-init. See LICENSE file for license information. - -from cloudinit.tests.helpers import CiTestCase -from cloudinit import version - - -class TestExportsFeatures(CiTestCase): - def test_has_network_config_v1(self): - self.assertIn('NETWORK_CONFIG_V1', version.FEATURES) - - def test_has_network_config_v2(self): - self.assertIn('NETWORK_CONFIG_V2', version.FEATURES) - -# vi: ts=4 expandtab -- cgit v1.2.3 From 2ab8960402677ab66583d56dcb7704369a1256f5 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Wed, 23 May 2018 14:41:11 -0400 Subject: packages: Make rpm spec files patch in package version like in debs. This makes the necessary changes to patch the full packaged version into the trunk maintained redhat and suse spec files. --- packages/redhat/cloud-init.spec.in | 7 +++++++ packages/suse/cloud-init.spec.in | 7 +++++++ 2 files changed, 14 insertions(+) (limited to 'packages') diff --git a/packages/redhat/cloud-init.spec.in b/packages/redhat/cloud-init.spec.in index 91faf3c6..a3a6d1e0 100644 --- a/packages/redhat/cloud-init.spec.in +++ b/packages/redhat/cloud-init.spec.in @@ -115,6 +115,13 @@ rm -rf $RPM_BUILD_ROOT%{python_sitelib}/tests mkdir -p $RPM_BUILD_ROOT/%{_sharedstatedir}/cloud mkdir -p $RPM_BUILD_ROOT/%{_libexecdir}/%{name} +# patch in the full version to version.py +version_pys=$(cd "$RPM_BUILD_ROOT" && find . -name version.py -type f) +[ -n "$version_pys" ] || + { echo "failed to find 'version.py' to patch with version." 1>&2; exit 1; } +( cd "$RPM_BUILD_ROOT" && + sed -i "s,@@PACKAGED_VERSION@@,%{version}-%{release}," $version_pys ) + %clean rm -rf $RPM_BUILD_ROOT diff --git a/packages/suse/cloud-init.spec.in b/packages/suse/cloud-init.spec.in index bbb965a7..366a78c5 100644 --- a/packages/suse/cloud-init.spec.in +++ b/packages/suse/cloud-init.spec.in @@ -102,6 +102,13 @@ done mkdir -p %{buildroot}/var/lib/cloud +# patch in the full version to version.py +version_pys=$(cd "%{buildroot}" && find . -name version.py -type f) +[ -n "$version_pys" ] || + { echo "failed to find 'version.py' to patch with version." 1>&2; exit 1; } +( cd "%{buildroot}" && + sed -i "s,@@PACKAGED_VERSION@@,%{version}-%{release}," $version_pys ) + %postun %insserv_cleanup -- cgit v1.2.3 From 32c485bdc6e1eee0ad1d92dcd633a4e7ac9ac7a6 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Wed, 23 May 2018 15:29:09 -0400 Subject: packages/brpm: Get proper dependencies for cmdline distro. When invoked with '--distro=suse', the packages that would be attempted for installation would be from redhat. We just were not pasing the args.distro through. That is fixed here. --- packages/brpm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'packages') diff --git a/packages/brpm b/packages/brpm index 3439cf35..a154ef29 100755 --- a/packages/brpm +++ b/packages/brpm @@ -42,13 +42,13 @@ def run_helper(helper, args=None, strip=True): return stdout -def read_dependencies(requirements_file='requirements.txt'): +def read_dependencies(distro, requirements_file='requirements.txt'): """Returns the Python package depedencies from requirements.txt files. @returns a tuple of (requirements, test_requirements) """ pkg_deps = run_helper( - 'read-dependencies', args=['--distro', 'redhat']).splitlines() + 'read-dependencies', args=['--distro', distro]).splitlines() test_deps = run_helper( 'read-dependencies', args=[ '--requirements-file', 'test-requirements.txt', @@ -83,7 +83,7 @@ def generate_spec_contents(args, version_data, tmpl_fn, top_dir, arc_fn): rpm_upstream_version = version_data['version'] subs['rpm_upstream_version'] = rpm_upstream_version - deps, test_deps = read_dependencies() + deps, test_deps = read_dependencies(distro=args.distro) subs['buildrequires'] = deps + test_deps subs['requires'] = deps -- cgit v1.2.3 From ae02c367ea8a6ce8a9e6d97047edf31decd335b2 Mon Sep 17 00:00:00 2001 From: Robert Schweikert Date: Tue, 29 May 2018 10:13:35 -0400 Subject: - Do not use the systemd_prefix macro, not available in this environment --- packages/suse/cloud-init.spec.in | 63 ++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 42 deletions(-) (limited to 'packages') diff --git a/packages/suse/cloud-init.spec.in b/packages/suse/cloud-init.spec.in index 366a78c5..e781d743 100644 --- a/packages/suse/cloud-init.spec.in +++ b/packages/suse/cloud-init.spec.in @@ -5,7 +5,7 @@ # Or: http://www.rpm.org/max-rpm/ch-rpm-inside.html Name: cloud-init -Version: {{version}} +Version: {{rpm_upstream_version}} Release: 1{{subrelease}}%{?dist} Summary: Cloud instance init scripts @@ -16,22 +16,13 @@ URL: http://launchpad.net/cloud-init Source0: {{archive_name}} BuildRoot: %{_tmppath}/%{name}-%{version}-build -%if 0%{?suse_version} && 0%{?suse_version} <= 1110 -%{!?python_sitelib: %global python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")} -%else BuildArch: noarch -%endif + {% for r in buildrequires %} BuildRequires: {{r}} {% endfor %} -%if 0%{?suse_version} && 0%{?suse_version} <= 1210 - %define initsys sysvinit -%else - %define initsys systemd -%endif - # Install pypi 'dynamic' requirements {% for r in requires %} Requires: {{r}} @@ -39,7 +30,7 @@ Requires: {{r}} # Custom patches {% for p in patches %} -Patch{{loop.index0}: {{p}} +Patch{{loop.index0}}: {{p}} {% endfor %} %description @@ -63,35 +54,21 @@ end for %{__python} setup.py install \ --skip-build --root=%{buildroot} --prefix=%{_prefix} \ --record-rpm=INSTALLED_FILES --install-lib=%{python_sitelib} \ - --init-system=%{initsys} + --init-system=systemd + +# Move udev rules +mkdir -p %{buildroot}/usr/lib/udev/rules.d/ +mv %{buildroot}/lib/udev/rules.d/* %{buildroot}/usr/lib/udev/rules.d/ # Remove non-SUSE templates rm %{buildroot}/%{_sysconfdir}/cloud/templates/*.debian.* rm %{buildroot}/%{_sysconfdir}/cloud/templates/*.redhat.* rm %{buildroot}/%{_sysconfdir}/cloud/templates/*.ubuntu.* -# Remove cloud-init tests -rm -r %{buildroot}/%{python_sitelib}/tests - -# Move sysvinit scripts to the correct place and create symbolic links -%if %{initsys} == sysvinit - mkdir -p %{buildroot}/%{_initddir} - mv %{buildroot}%{_sysconfdir}/rc.d/init.d/* %{buildroot}%{_initddir}/ - rmdir %{buildroot}%{_sysconfdir}/rc.d/init.d - rmdir %{buildroot}%{_sysconfdir}/rc.d - - mkdir -p %{buildroot}/%{_sbindir} - pushd %{buildroot}/%{_initddir} - for file in * ; do - ln -s %{_initddir}/${file} %{buildroot}/%{_sbindir}/rc${file} - done - popd -%endif - # Move documentation mkdir -p %{buildroot}/%{_defaultdocdir} mv %{buildroot}/usr/share/doc/cloud-init %{buildroot}/%{_defaultdocdir} -for doc in TODO LICENSE ChangeLog requirements.txt; do +for doc in LICENSE ChangeLog requirements.txt; do cp ${doc} %{buildroot}/%{_defaultdocdir}/cloud-init done @@ -114,24 +91,23 @@ version_pys=$(cd "%{buildroot}" && find . -name version.py -type f) %files -# Sysvinit scripts -%if %{initsys} == sysvinit - %attr(0755, root, root) %{_initddir}/cloud-config - %attr(0755, root, root) %{_initddir}/cloud-final - %attr(0755, root, root) %{_initddir}/cloud-init-local - %attr(0755, root, root) %{_initddir}/cloud-init - - %{_sbindir}/rccloud-* -%endif - # Program binaries %{_bindir}/cloud-init* +# systemd files +/usr/lib/systemd/system-generators/* +/usr/lib/systemd/system/* + # There doesn't seem to be an agreed upon place for these # although it appears the standard says /usr/lib but rpmbuild # will try /usr/lib64 ?? /usr/lib/%{name}/uncloud-init /usr/lib/%{name}/write-ssh-key-fingerprints +/usr/lib/%{name}/ds-identify + +# udev rules +/usr/lib/udev/rules.d/66-azure-ephemeral.rules + # Docs %doc %{_defaultdocdir}/cloud-init/* @@ -145,6 +121,9 @@ version_pys=$(cd "%{buildroot}" && find . -name version.py -type f) %config(noreplace) %{_sysconfdir}/cloud/templates/* %{_sysconfdir}/bash_completion.d/cloud-init +%{_sysconfdir}/dhcp/dhclient-exit-hooks.d/hook-dhclient +%{_sysconfdir}/NetworkManager/dispatcher.d/hook-network-manager + # Python code is here... %{python_sitelib}/* -- cgit v1.2.3