From a15afba7698f9a2b3b9c1ecbbfee6299dc97b9ee Mon Sep 17 00:00:00 2001 From: veerendra-simha-garikipati <84907462+veerendra-simha-garikipati@users.noreply.github.com> Date: Thu, 13 Jan 2022 17:21:55 +0530 Subject: [PATCH] Bash script for creating py-utils test rpm. (#692) * Bash script for creating test rpm. Signed-off-by: Veerendra Garikipati * updating copyright year to 2022 Signed-off-by: Veerendra Garikipati Co-authored-by: Sachin Punadikar Signed-off-by: suryakumar.kumaravelan --- jenkins/build_test_rpm.sh | 77 +++++++++++++++++++++++++++++++ py-utils/test/README.md | 10 ++-- py-utils/test/VERSION | 0 py-utils/test/setup.py | 18 ++++---- py-utils/test/test-post-install | 4 +- py-utils/test/test-post-uninstall | 9 +++- 6 files changed, 103 insertions(+), 15 deletions(-) create mode 100755 jenkins/build_test_rpm.sh create mode 100755 py-utils/test/VERSION diff --git a/jenkins/build_test_rpm.sh b/jenkins/build_test_rpm.sh new file mode 100755 index 000000000..7a8f16065 --- /dev/null +++ b/jenkins/build_test_rpm.sh @@ -0,0 +1,77 @@ +#!/bin/bash +# +# Copyright (c) 2022 Seagate Technology LLC and/or its Affiliates +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# For any questions about this software or licensing, +# please email opensource@seagate.com or cortx-questions@seagate.com. + +set -e +PROG_NAME=$(basename "$0") +BASE_DIR=$(realpath $(dirname "$0")/../py-utils/test) +BUILD_NUMBER= +GIT_VER= + +#Following Install_path should be in sync with cortx.conf.sample config file. +INSTALL_PATH=/opt/seagate + +usage() { + echo """usage: $PROG_NAME [-v version] [-g git_version] [-b build_number]""" 1>&2; + exit 1; +} + +# Check for passed in arguments +while getopts ":g:v:b:" o; do + case "${o}" in + v) + VER=${OPTARG} + ;; + g) + GIT_VER=${OPTARG} + ;; + b) + BUILD_NUMBER=${OPTARG} + ;; + *) + usage + ;; + esac +done + +[ -z $"$GIT_VER" ] && GIT_VER="$(git rev-parse --short HEAD)" \ + || GIT_VER="${GIT_VER}_$(git rev-parse --short HEAD)" +[ -z "$VER" ] && VER="1.0.0" +[ -z "$BUILD_NUMBER" ] && BUILD_NUMBER=1 +REL="${BUILD_NUMBER}_${GIT_VER}" + +# Change cwd to py-utils/test +cd "$BASE_DIR" + +# Create version file +echo $VER > VERSION +/bin/chmod +rx VERSION + +# Update install_path in test-post-install +sed -i -e "s||${INSTALL_PATH}|g" test-post-install + +# Update install_path in test-post-uninstall +sed -i -e "s||${INSTALL_PATH}|g" test-post-uninstall + +echo "Creating cortx-py-utils-test RPM with version $VER, release $REL" + +# Create the rpm +/bin/python3.6 setup.py bdist_rpm --requires cortx-py-utils \ +--release="$REL" --post-install test-post-install \ +--post-uninstall test-post-uninstall +if [ $? -ne 0 ]; then + echo "build failed" + exit 1 +fi diff --git a/py-utils/test/README.md b/py-utils/test/README.md index 5f4e2c216..533db90a2 100644 --- a/py-utils/test/README.md +++ b/py-utils/test/README.md @@ -43,10 +43,14 @@ git clone https://github.com/Seagate/cortx-utils.git - Create RPM package +**Note:** Do not use rpm if cortx-py-utils is installed using wheel & pip + +It will create `cortx-py-utils-test-1.0.0-1_.noarch.rpm` by default. One can change the version by passing extra `-v ` parameter. +Below command passes version string as 2.0.0 and build number 2, which creates `cortx-py-utils-test-2.0.0-2_.noarch.rpm`. + +Run below command from repo root (cortx-utils). ```bash -# NOTE: Do not use rpm if cortx-py-utils is installed using wheel & pip -cd cortx-utils/py-utils/test -sudo python3 setup.py bdist_rpm --requires cortx-py-utils --version=1.0.0 --post-install test-post-install --post-uninstall test-post-uninstall +$ ./jenkins/build_test_rpm.sh -v 2.0.0 -b 2 ``` - Create pip Package diff --git a/py-utils/test/VERSION b/py-utils/test/VERSION new file mode 100755 index 000000000..e69de29bb diff --git a/py-utils/test/setup.py b/py-utils/test/setup.py index b2d9fd44e..3e350bdc3 100644 --- a/py-utils/test/setup.py +++ b/py-utils/test/setup.py @@ -13,22 +13,23 @@ # For any questions about this software or licensing, # please email opensource@seagate.com or cortx-questions@seagate.com. -from setuptools import setup +import os import sys +from setuptools import setup +if not os.path.isfile("./VERSION"): + print("error: VERSION file not found!", file=sys.stderr) + sys.exit(1) -# Get the version string from command line -version = "1.0.0" -for arg in sys.argv: - if arg.startswith("--version") or arg.startswith("-v"): - version = arg.split("=")[1] - sys.argv.remove(arg) +# Fetch version +with open("VERSION") as v_file: + utils_version = v_file.read().strip() setup( name="cortx-py-utils-test", - version=version, + version=utils_version, url="https://github.com/Seagate/cortx-utils/py-utils/test", license="Seagate", author="Seagate Foundation Team", @@ -61,6 +62,7 @@ ], package_data={ "": [ + "VERSION", "plans/*.pln", "ha_dm/*.json", "ha_dm/test_schema/*.json", diff --git a/py-utils/test/test-post-install b/py-utils/test/test-post-install index 4d29d3d3f..7816c2fb2 100644 --- a/py-utils/test/test-post-install +++ b/py-utils/test/test-post-install @@ -14,8 +14,8 @@ # For any questions about this software or licensing, # please email opensource@seagate.com or cortx-questions@seagate.com. -# Replace /opt/seagate with cortx installation path example: /opt/seagate -install_path=/opt/seagate +## Replace INSTALL_PATH with cortx installation path. example: /opt/seagate +install_path= cortx_path=$install_path/cortx/ utils_path=$cortx_path/utils diff --git a/py-utils/test/test-post-uninstall b/py-utils/test/test-post-uninstall index fa9fa7666..17cb9fe82 100644 --- a/py-utils/test/test-post-uninstall +++ b/py-utils/test/test-post-uninstall @@ -14,9 +14,14 @@ # For any questions about this software or licensing, # please email opensource@seagate.com or cortx-questions@seagate.com. +## Replace INSTALL_PATH with cortx installation path. example: /opt/seagate +install_path= +cortx_path=$install_path/cortx/ +utils_path=$cortx_path/utils + # Take action only in case of un-install if [ $1 == 0 ] then - # Remove the files we have created - /bin/rm -f /opt/seagate/cortx/utils/bin/run_test + # Removes the files created by test rpm + /bin/rm -f $utils_path/bin/run_test fi