From 54bb5bec7a025eecb51f85274ec37dbd0c478758 Mon Sep 17 00:00:00 2001 From: Luis Pabon Date: Mon, 19 Aug 2013 14:59:30 -0400 Subject: Fix spec file to support source rpms Our initial implementation only required Jenkins to export binary RPMs, but as we move foward, we really need to also export SRPMs. To support SRPMs, the spec file in the RPM has to have the correct NAME, VERSION, and RELEASE information. Change-Id: Icd7132b4aafdbe7a1f02a35d0be7ad63b2e7c056 Signed-off-by: Luis Pabon Reviewed-on: http://review.gluster.org/5669 Reviewed-by: Peter Portante Reviewed-by: Kaleb KEITHLEY Tested-by: Peter Portante Reviewed-on: http://review.gluster.org/5679 --- gluster/swift/__init__.py | 10 ++++++---- glusterfs-openstack-swift.spec | 16 +++++++++++----- makerpm.sh | 39 ++++++++++++++++++++++++++++++--------- test/unit/test_swift.py | 15 ++++++++------- tools/functional_tests.sh | 7 +++++-- 5 files changed, 60 insertions(+), 27 deletions(-) diff --git a/gluster/swift/__init__.py b/gluster/swift/__init__.py index 66397a6..4af47a2 100644 --- a/gluster/swift/__init__.py +++ b/gluster/swift/__init__.py @@ -17,8 +17,9 @@ class PkgInfo(object): - def __init__(self, canonical_version, name, final): + def __init__(self, canonical_version, release, name, final): self.canonical_version = canonical_version + self.release = release self.name = name self.final = final @@ -28,8 +29,9 @@ class PkgInfo(object): a bash script. """ with open(filename, 'w') as fd: - fd.write("PKG_NAME=%s\n" % self.name) - fd.write("PKG_VERSION=%s\n" % self.canonical_version) + fd.write("NAME=%s\n" % self.name) + fd.write("VERSION=%s\n" % self.canonical_version) + fd.write("RELEASE=%s\n" % self.release) @property def pretty_version(self): @@ -42,6 +44,6 @@ class PkgInfo(object): ### ### Change the Package version here ### -_pkginfo = PkgInfo('1.8.0', 'glusterfs-openstack-swift', False) +_pkginfo = PkgInfo('1.8.0', '7', 'glusterfs-openstack-swift', False) __version__ = _pkginfo.pretty_version __canonical_version__ = _pkginfo.canonical_version diff --git a/glusterfs-openstack-swift.spec b/glusterfs-openstack-swift.spec index 7ecf92e..71439f0 100644 --- a/glusterfs-openstack-swift.spec +++ b/glusterfs-openstack-swift.spec @@ -20,20 +20,22 @@ # to rpmbuild. For example: # --define "_version 1.0" --define "_release 1" --define "_name g4s" # -%{!?_version:%define _version XXX} -%{!?_release:%define _release XXX} -%{!?_name:%define _name XXX} +%{!?_version:%define _version __PKG_VERSION__} +%{!?_name:%define _name __PKG_NAME__} +%{!?_release:%define _release __PKG_RELEASE__} Summary : GlusterFS Integration with OpenStack Object Storage (Swift). Name : %{_name} Version : %{_version} -Release : %{_release} +Release : %{_release}%{?dist} Group : Application/File Vendor : Red Hat, Inc. -Source0 : %{name}-%{version}-%{release}.tar.gz +Source0 : %{_name}-%{_version}-%{_release}.tar.gz Packager : gluster-users@gluster.org License : Apache BuildArch: noarch +BuildRequires: python +BuildRequires: python-setuptools Requires : memcached Requires : openssl Requires : python @@ -94,3 +96,7 @@ rm -rf %{buildroot} %config %{_confdir}/swift.conf-gluster %config %{_confdir}/proxy-server.conf-gluster %config %{_confdir}/fs.conf-gluster + +%changelog +* Wed Aug 21 2013 Luis Pabon - 1.8.0-7 +- Update RPM spec file to support SRPMS diff --git a/makerpm.sh b/makerpm.sh index 74d7c00..b00d5d7 100644 --- a/makerpm.sh +++ b/makerpm.sh @@ -28,7 +28,22 @@ create_dir() gittotar() { # Only archives committed changes - git archive --format=tar --prefix=${SRCTAR_DIR}/ HEAD | gzip -c > ${SRCTAR} + gitarchive_dir="${RPMBUILDDIR}/gitarchive" + specfile="${gitarchive_dir}/${SRCTAR_DIR}/${PKG_NAME}.spec" + create_dir "${gitarchive_dir}" + + # Export the current commited git changes to a directory + git archive --format=tar --prefix=${SRCTAR_DIR}/ HEAD | (cd ${gitarchive_dir} && tar xf -) + + # Create a new spec file with the current package version information + sed -e "s#__PKG_RELEASE__#${PKG_RELEASE}#" \ + -e "s#__PKG_NAME__#${PKG_NAME}#" \ + -e "s#__PKG_VERSION__#${PKG_VERSION}#" \ + ${specfile} > ${specfile}.new + mv ${specfile}.new ${specfile} + + # Now create a tar file + ( cd ${gitarchive_dir} && tar cf - ${SRCTAR_DIR} | gzip -c > ${SRCTAR} ) if [ $? -ne 0 -o \! -s ${SRCTAR} ] ; then fail "Unable to create git archive" $? fi @@ -52,9 +67,6 @@ create_rpm() # _release Allows Jenkins to setup the version using the # build number rpmbuild --define "_topdir ${RPMBUILDDIR}" \ - --define "_release ${PKG_RELEASE}" \ - --define "_version ${PKG_VERSION}" \ - --define "_name ${PKG_NAME}" \ -ta ${SRCTAR} if [ $? -ne 0 ] ; then fail "Unable to create rpm" $? @@ -62,6 +74,7 @@ create_rpm() # Move the rpms to the root directory mv ${RPMBUILDDIR_RPMS}/noarch/*rpm ${BUILDDIR} + mv ${RPMBUILDDIR_SRPMS}/*rpm ${BUILDDIR} if [ $? -ne 0 ] ; then fail "Unable to move rpm to ${BUILDDIR}" $? fi @@ -78,15 +91,21 @@ if [ ! -f "${PKGCONFIG}" ] ; then fail "Unable to create package information file ${PKGCONFIG}" 1 fi -# Get PKG_NAME and PKG_VERSION +# Get package version information . ${PKGCONFIG} -if [ -z "${PKG_NAME}" ] ; then +if [ -z "${NAME}" ] ; then fail "Unable to read the package name from the file created by pkgconfig.py" 1 fi -if [ -z "${PKG_VERSION}" ] ; then +if [ -z "${VERSION}" ] ; then + fail "Unable to read the package version from the file created by pkgconfig.py" 1 +fi +if [ -z "${RELEASE}" ] ; then fail "Unable to read the package version from the file created by pkgconfig.py" 1 fi +PKG_NAME=$NAME +PKG_VERSION=$VERSION + # # This can be set by JENKINS builds # If the environment variable PKG_RELEASE @@ -94,13 +113,15 @@ fi # a default value # if [ -z "$PKG_RELEASE" ] ; then - PKG_RELEASE=0 + PKG_RELEASE="${RELEASE}" +else + PKG_RELEASE="${RELEASE}.${PKG_RELEASE}" fi - BUILDDIR=$PWD/build RPMBUILDDIR=${BUILDDIR}/rpmbuild RPMBUILDDIR_RPMS=${RPMBUILDDIR}/RPMS +RPMBUILDDIR_SRPMS=${RPMBUILDDIR}/SRPMS SRCNAME=${PKG_NAME}-${PKG_VERSION}-${PKG_RELEASE} SRCTAR_DIR=${PKG_NAME}-${PKG_VERSION} SRCTAR=${RPMBUILDDIR}/${SRCNAME}.tar.gz diff --git a/test/unit/test_swift.py b/test/unit/test_swift.py index 5c78a8b..78c126c 100644 --- a/test/unit/test_swift.py +++ b/test/unit/test_swift.py @@ -29,24 +29,25 @@ class TestPkgInfo(unittest.TestCase): """ def test_constructor(self): - pi = gs.PkgInfo('a', 'b', 'c') + pi = gs.PkgInfo('a', 'b', 'c', 'd') assert pi.canonical_version == 'a' - assert pi.name == 'b' - assert pi.final == 'c' + assert pi.name == 'c' + self.assertEqual(pi.release, 'b') + assert pi.final == 'd' def test_pretty_version(self): - pi = gs.PkgInfo('a', 'b', False) + pi = gs.PkgInfo('a', 'b', 'c', False) assert pi.pretty_version == 'a-dev' - pi = gs.PkgInfo('a', 'b', True) + pi = gs.PkgInfo('a', 'b', 'c', True) assert pi.pretty_version == 'a' def test_save_config(self): - pi = gs.PkgInfo('a', 'b', 'c') + pi = gs.PkgInfo('a', 'b', 'c', 'd') td = tempfile.mkdtemp() try: sc = os.path.join(td, 'saved_config.txt') pi.save_config(sc) - exp = 'PKG_NAME=b\nPKG_VERSION=a\n' + exp = 'NAME=c\nVERSION=a\nRELEASE=b\n' contents = file(sc, 'r').read() assert contents == exp finally: diff --git a/tools/functional_tests.sh b/tools/functional_tests.sh index f758145..e1be404 100755 --- a/tools/functional_tests.sh +++ b/tools/functional_tests.sh @@ -15,6 +15,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +# Globals +FUNCTAG=functest.$$ cleanup() { @@ -22,6 +24,7 @@ cleanup() sudo swift-init main stop sudo yum -y remove glusterfs-openstack-swift sudo rm -rf /etc/swift > /dev/null 2>&1 + rm -f build/glusterfs-openstack-swift-*${FUNCTAG}*rpm > /dev/null 2>&1 sudo rm -rf /mnt/gluster-object/test{,2}/* > /dev/null 2>&1 sudo setfattr -x user.swift.metadata /mnt/gluster-object/test{,2} > /dev/null 2>&1 } @@ -57,8 +60,8 @@ done export SWIFT_TEST_CONFIG_FILE=/etc/swift/test.conf # Create and install the rpm -PKG_RELEASE=functest bash makerpm.sh -sudo yum -y install build/glusterfs-openstack-swift-1.8.0-functest.noarch.rpm || fail "Unable to install rpm" +PKG_RELEASE=${FUNCTAG} bash makerpm.sh +sudo yum -y install build/glusterfs-openstack-swift-*${FUNCTAG}*.noarch.rpm || fail "Unable to install rpm" # Install the configuration files mkdir /etc/swift > /dev/null 2>&1 -- cgit