Skip to content

Commit

Permalink
Bash script for creating py-utils test rpm. (Seagate#692)
Browse files Browse the repository at this point in the history
* Bash script for creating test rpm.

Signed-off-by: Veerendra Garikipati <[email protected]>

* updating copyright year to 2022

Signed-off-by: Veerendra Garikipati <[email protected]>

Co-authored-by: Sachin Punadikar <[email protected]>
Signed-off-by: suryakumar.kumaravelan <[email protected]>
  • Loading branch information
2 people authored and suryakumar1024 committed Mar 21, 2022
1 parent 171df19 commit a15afba
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 15 deletions.
77 changes: 77 additions & 0 deletions jenkins/build_test_rpm.sh
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
# For any questions about this software or licensing,
# please email [email protected] or [email protected].

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>|${INSTALL_PATH}|g" test-post-install

# Update install_path in test-post-uninstall
sed -i -e "s|<INSTALL_PATH>|${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
10 changes: 7 additions & 3 deletions py-utils/test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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_<git-version>.noarch.rpm` by default. One can change the version by passing extra `-v <version_string>` parameter.
Below command passes version string as 2.0.0 and build number 2, which creates `cortx-py-utils-test-2.0.0-2_<git-version>.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
Expand Down
Empty file added py-utils/test/VERSION
Empty file.
18 changes: 10 additions & 8 deletions py-utils/test/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,23 @@
# For any questions about this software or licensing,
# please email [email protected] or [email protected].

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",
Expand Down Expand Up @@ -61,6 +62,7 @@
],
package_data={
"": [
"VERSION",
"plans/*.pln",
"ha_dm/*.json",
"ha_dm/test_schema/*.json",
Expand Down
4 changes: 2 additions & 2 deletions py-utils/test/test-post-install
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
# For any questions about this software or licensing,
# please email [email protected] or [email protected].

# 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=<INSTALL_PATH>
cortx_path=$install_path/cortx/
utils_path=$cortx_path/utils

Expand Down
9 changes: 7 additions & 2 deletions py-utils/test/test-post-uninstall
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@
# For any questions about this software or licensing,
# please email [email protected] or [email protected].

## Replace INSTALL_PATH with cortx installation path. example: /opt/seagate
install_path=<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

0 comments on commit a15afba

Please sign in to comment.