From 1f01aabad6963b6f61434e81c2d4234cd3095372 Mon Sep 17 00:00:00 2001 From: Alok Anand Date: Wed, 31 Jan 2018 17:35:35 +0530 Subject: [PATCH] Fix issues in deb pipeline. 1.Use lib.py:cache_sysd() to cache .service file as well. 2.Correct path for resulting .deb file. 3.Provide correct name of distro tarball to debian/rules 4.Provide correct path to copy .service file. 5.Fixed pep8 errors in lib.py and deb/lib.py Change-Id: I6c45cf7f86d4327cfd2a328ddeb0c66fd20d9381 Signed-off-by: Alok Anand --- packages/deb/lib.py | 16 ++++++++------ packages/deb/templates/rules_template | 5 +++-- packages/lib.py | 31 +++++++++++++++------------ 3 files changed, 29 insertions(+), 23 deletions(-) diff --git a/packages/deb/lib.py b/packages/deb/lib.py index 766f21e..c9c12da 100755 --- a/packages/deb/lib.py +++ b/packages/deb/lib.py @@ -23,8 +23,8 @@ templates_dir = os.path.join(deb_root, "templates") # cast to strings for concatenation. If they could, we would do elegant # refactoring like concatenating paths to templates here and only calling # Template.substitute in the build_rpm function. -deb_template = Template("opendaylight/opendaylight_$version_major.$version_minor." - "$version_patch-${pkg_version}_all.deb") +deb_template = Template("opendaylight/opendaylight_$version_major." + "$version_minor.$version_patch-${pkg_version}_all.deb") src_in_dir_template = Template("opendaylight/opendaylight-$version_major." "$version_minor.$version_patch-$pkg_version/") cfg_in_dir_template = Template("opendaylight/opendaylight-$version_major." @@ -47,23 +47,25 @@ def build_deb(build): deb_root, src_in_dir_template.substitute(build), "debian/control") - deb = deb_template.substitute(build) + deb = os.path.join(deb_root, deb_template.substitute(build)) src_in_dir_path = os.path.join( deb_root, src_in_dir_template.substitute(build)) - # Call helper script to build the required Debian files - build_debfiles.build_debfiles(build) - # Cache ODL distro and systemd unit file to package distro_tar_path = pkg_lib.cache_distro(build) + distro_tar_name = os.path.basename(distro_tar_path) + build['tarball_name'] = distro_tar_name unitfile_path = pkg_lib.cache_sysd(build)["unitfile_path"] + # Call helper script to build the required Debian files + build_debfiles.build_debfiles(build) + # Copy ODL tarball into src input directory shutil.copy(distro_tar_path, src_in_dir_path) # Copy ODL systemd unit file to src input directory - shutil.copy(unitfile_path, cfg_in_dir_path) + shutil.copy(unitfile_path, cfg_in_dir) # Build Debian package os.chdir(src_in_dir_path) diff --git a/packages/deb/templates/rules_template b/packages/deb/templates/rules_template index 5e46503..fddc5cf 100644 --- a/packages/deb/templates/rules_template +++ b/packages/deb/templates/rules_template @@ -7,7 +7,8 @@ PKG_VERSION = {{ pkg_version }} CODENAME = "{{ codename }}" VERSION = 0.$(VERSION_MAJOR).$(VERSION_MINOR)$(CODENAME) PACKAGEVERSION = $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH)-$(PKG_VERSION) -TARBALL = $(notdir {{ download_url }}) +TARBALL = {{ tarball_name }} +DISTRIBUTION_PREFIX = {{ distro_name_prefix }} %: dh $@ --with systemd @@ -19,7 +20,7 @@ override_dh_usrlocal: override_dh_auto_install: tar -xf $(TARBALL) mkdir -p ./debian/opendaylight/opt/opendaylight/ - cp -r ./distribution-karaf-$(VERSION)/* ./debian/opendaylight/opt/opendaylight/ + cp -r ./$(DISTRIBUTION_PREFIX)-$(VERSION)/* ./debian/opendaylight/opt/opendaylight/ override_dh_gencontrol: dh_gencontrol -- -v$(PACKAGEVERSION) diff --git a/packages/lib.py b/packages/lib.py index ca3dd67..96d5923 100644 --- a/packages/lib.py +++ b/packages/lib.py @@ -198,8 +198,9 @@ def get_snap_url(version_major): parent_dir_html = urlopen(parent_dir_url).read().decode('utf-8') # Get most recent minor version of the given major version - version_minor = max(re.findall(r'>\d\.{}\.(\d)-SNAPSHOT\/'.format(version_major), - parent_dir_html)) + version_minor = max(re.findall( + r'>\d\.{}\.(\d)-SNAPSHOT\/'.format(version_major), + parent_dir_html)) # Dir that contains snapshot builds for the given major version snapshot_dir_url = parent_dir_url + "0.{}.{}-SNAPSHOT/".format( @@ -325,13 +326,13 @@ def cache_distro(build): # Get the most recent file in cache dir, hopefully unzipped archive unzipped_distro_path = max(cache_dir_ls, key=os.path.getctime) print("Extracted: {}".format(unzipped_distro_path)) - # Remove path from unzipped distro filename, as will cd to dir below + # Remove path from 'unzipped_distro_path', as will cd to dir below unzipped_distro = os.path.basename(unzipped_distro_path) - # Using the full paths here creates those paths in the tarball, which - # breaks the build. There's a way to change the working dir during a - # single tar command using the system tar binary, but I don't see a - # way to do that with Python. - # TODO: Is there a good way to do this without changing directories? + # Using the full paths here creates those paths in the tarball, + # which breaks the build. There's a way to change the working dir + # during a single tar command using the system tar binary, but I + # don't see a way to do that with Python. + # TODO: Can this be done without changing directories? # TODO: Try https://goo.gl/XMx5gb cwd = os.getcwd() os.chdir(cache_dir) @@ -365,11 +366,15 @@ def cache_sysd(build): unitfile_path = os.path.join(cache_dir, unitfile) unitfile_tar_path = os.path.join(cache_dir, unitfile_tar) - # Cache appropriate version of ODL's systemd unit file as a tarball - if not os.path.isfile(unitfile_tar_path): - # Download ODL's systemd unit file + # Download ODL's systemd unit file + if not os.path.isfile(unitfile_path): urllib.urlretrieve(unitfile_url, unitfile_path) + print("Cached: {}".format(unitfile)) + else: + print("Already cached: {}".format(unitfile_path)) + # Cache ODL's systemd unit file as a tarball + if not os.path.isfile(unitfile_tar_path): # Using the full paths here creates those paths in the tarball, which # breaks the build. There's a way to change the working dir during a # single tar command using the system tar binary, but I don't see a @@ -383,11 +388,9 @@ def cache_sysd(build): tb.add(unitfile) os.chdir(cwd) - # Remove the now-archived unitfile - os.remove(unitfile_path) print("Cached: {}".format(unitfile_tar)) else: - print("Already cached: {}".format(unitfile_tar)) + print("Already cached: {}".format(unitfile_tar_path)) return {"unitfile_tar_path": unitfile_tar_path, "unitfile_path": unitfile_path} -- 2.36.6