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 <lpabon@redhat.com>
Reviewed-on: http://review.gluster.org/5669
Reviewed-by: Peter Portante <pportant@redhat.com>
Reviewed-by: Kaleb KEITHLEY <kkeithle@redhat.com>
Tested-by: Peter Portante <pportant@redhat.com>
Reviewed-on: http://review.gluster.org/5679
This commit is contained in:
Luis Pabon 2013-08-19 14:59:30 -04:00
parent 4023c7277f
commit 54bb5bec7a
5 changed files with 60 additions and 27 deletions

View File

@ -17,8 +17,9 @@
class PkgInfo(object): class PkgInfo(object):
def __init__(self, canonical_version, name, final): def __init__(self, canonical_version, release, name, final):
self.canonical_version = canonical_version self.canonical_version = canonical_version
self.release = release
self.name = name self.name = name
self.final = final self.final = final
@ -28,8 +29,9 @@ class PkgInfo(object):
a bash script. a bash script.
""" """
with open(filename, 'w') as fd: with open(filename, 'w') as fd:
fd.write("PKG_NAME=%s\n" % self.name) fd.write("NAME=%s\n" % self.name)
fd.write("PKG_VERSION=%s\n" % self.canonical_version) fd.write("VERSION=%s\n" % self.canonical_version)
fd.write("RELEASE=%s\n" % self.release)
@property @property
def pretty_version(self): def pretty_version(self):
@ -42,6 +44,6 @@ class PkgInfo(object):
### ###
### Change the Package version here ### 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 __version__ = _pkginfo.pretty_version
__canonical_version__ = _pkginfo.canonical_version __canonical_version__ = _pkginfo.canonical_version

View File

@ -20,20 +20,22 @@
# to rpmbuild. For example: # to rpmbuild. For example:
# --define "_version 1.0" --define "_release 1" --define "_name g4s" # --define "_version 1.0" --define "_release 1" --define "_name g4s"
# #
%{!?_version:%define _version XXX} %{!?_version:%define _version __PKG_VERSION__}
%{!?_release:%define _release XXX} %{!?_name:%define _name __PKG_NAME__}
%{!?_name:%define _name XXX} %{!?_release:%define _release __PKG_RELEASE__}
Summary : GlusterFS Integration with OpenStack Object Storage (Swift). Summary : GlusterFS Integration with OpenStack Object Storage (Swift).
Name : %{_name} Name : %{_name}
Version : %{_version} Version : %{_version}
Release : %{_release} Release : %{_release}%{?dist}
Group : Application/File Group : Application/File
Vendor : Red Hat, Inc. Vendor : Red Hat, Inc.
Source0 : %{name}-%{version}-%{release}.tar.gz Source0 : %{_name}-%{_version}-%{_release}.tar.gz
Packager : gluster-users@gluster.org Packager : gluster-users@gluster.org
License : Apache License : Apache
BuildArch: noarch BuildArch: noarch
BuildRequires: python
BuildRequires: python-setuptools
Requires : memcached Requires : memcached
Requires : openssl Requires : openssl
Requires : python Requires : python
@ -94,3 +96,7 @@ rm -rf %{buildroot}
%config %{_confdir}/swift.conf-gluster %config %{_confdir}/swift.conf-gluster
%config %{_confdir}/proxy-server.conf-gluster %config %{_confdir}/proxy-server.conf-gluster
%config %{_confdir}/fs.conf-gluster %config %{_confdir}/fs.conf-gluster
%changelog
* Wed Aug 21 2013 Luis Pabon <lpabon@redhat.com> - 1.8.0-7
- Update RPM spec file to support SRPMS

View File

@ -28,7 +28,22 @@ create_dir()
gittotar() gittotar()
{ {
# Only archives committed changes # 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 if [ $? -ne 0 -o \! -s ${SRCTAR} ] ; then
fail "Unable to create git archive" $? fail "Unable to create git archive" $?
fi fi
@ -52,9 +67,6 @@ create_rpm()
# _release Allows Jenkins to setup the version using the # _release Allows Jenkins to setup the version using the
# build number # build number
rpmbuild --define "_topdir ${RPMBUILDDIR}" \ rpmbuild --define "_topdir ${RPMBUILDDIR}" \
--define "_release ${PKG_RELEASE}" \
--define "_version ${PKG_VERSION}" \
--define "_name ${PKG_NAME}" \
-ta ${SRCTAR} -ta ${SRCTAR}
if [ $? -ne 0 ] ; then if [ $? -ne 0 ] ; then
fail "Unable to create rpm" $? fail "Unable to create rpm" $?
@ -62,6 +74,7 @@ create_rpm()
# Move the rpms to the root directory # Move the rpms to the root directory
mv ${RPMBUILDDIR_RPMS}/noarch/*rpm ${BUILDDIR} mv ${RPMBUILDDIR_RPMS}/noarch/*rpm ${BUILDDIR}
mv ${RPMBUILDDIR_SRPMS}/*rpm ${BUILDDIR}
if [ $? -ne 0 ] ; then if [ $? -ne 0 ] ; then
fail "Unable to move rpm to ${BUILDDIR}" $? fail "Unable to move rpm to ${BUILDDIR}" $?
fi fi
@ -78,14 +91,20 @@ if [ ! -f "${PKGCONFIG}" ] ; then
fail "Unable to create package information file ${PKGCONFIG}" 1 fail "Unable to create package information file ${PKGCONFIG}" 1
fi fi
# Get PKG_NAME and PKG_VERSION # Get package version information
. ${PKGCONFIG} . ${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 fail "Unable to read the package name from the file created by pkgconfig.py" 1
fi 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 fail "Unable to read the package version from the file created by pkgconfig.py" 1
fi 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 # This can be set by JENKINS builds
@ -94,13 +113,15 @@ fi
# a default value # a default value
# #
if [ -z "$PKG_RELEASE" ] ; then if [ -z "$PKG_RELEASE" ] ; then
PKG_RELEASE=0 PKG_RELEASE="${RELEASE}"
else
PKG_RELEASE="${RELEASE}.${PKG_RELEASE}"
fi fi
BUILDDIR=$PWD/build BUILDDIR=$PWD/build
RPMBUILDDIR=${BUILDDIR}/rpmbuild RPMBUILDDIR=${BUILDDIR}/rpmbuild
RPMBUILDDIR_RPMS=${RPMBUILDDIR}/RPMS RPMBUILDDIR_RPMS=${RPMBUILDDIR}/RPMS
RPMBUILDDIR_SRPMS=${RPMBUILDDIR}/SRPMS
SRCNAME=${PKG_NAME}-${PKG_VERSION}-${PKG_RELEASE} SRCNAME=${PKG_NAME}-${PKG_VERSION}-${PKG_RELEASE}
SRCTAR_DIR=${PKG_NAME}-${PKG_VERSION} SRCTAR_DIR=${PKG_NAME}-${PKG_VERSION}
SRCTAR=${RPMBUILDDIR}/${SRCNAME}.tar.gz SRCTAR=${RPMBUILDDIR}/${SRCNAME}.tar.gz

View File

@ -29,24 +29,25 @@ class TestPkgInfo(unittest.TestCase):
""" """
def test_constructor(self): def test_constructor(self):
pi = gs.PkgInfo('a', 'b', 'c') pi = gs.PkgInfo('a', 'b', 'c', 'd')
assert pi.canonical_version == 'a' assert pi.canonical_version == 'a'
assert pi.name == 'b' assert pi.name == 'c'
assert pi.final == 'c' self.assertEqual(pi.release, 'b')
assert pi.final == 'd'
def test_pretty_version(self): def test_pretty_version(self):
pi = gs.PkgInfo('a', 'b', False) pi = gs.PkgInfo('a', 'b', 'c', False)
assert pi.pretty_version == 'a-dev' assert pi.pretty_version == 'a-dev'
pi = gs.PkgInfo('a', 'b', True) pi = gs.PkgInfo('a', 'b', 'c', True)
assert pi.pretty_version == 'a' assert pi.pretty_version == 'a'
def test_save_config(self): def test_save_config(self):
pi = gs.PkgInfo('a', 'b', 'c') pi = gs.PkgInfo('a', 'b', 'c', 'd')
td = tempfile.mkdtemp() td = tempfile.mkdtemp()
try: try:
sc = os.path.join(td, 'saved_config.txt') sc = os.path.join(td, 'saved_config.txt')
pi.save_config(sc) 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() contents = file(sc, 'r').read()
assert contents == exp assert contents == exp
finally: finally:

View File

@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# Globals
FUNCTAG=functest.$$
cleanup() cleanup()
{ {
@ -22,6 +24,7 @@ cleanup()
sudo swift-init main stop sudo swift-init main stop
sudo yum -y remove glusterfs-openstack-swift sudo yum -y remove glusterfs-openstack-swift
sudo rm -rf /etc/swift > /dev/null 2>&1 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 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 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 export SWIFT_TEST_CONFIG_FILE=/etc/swift/test.conf
# Create and install the rpm # Create and install the rpm
PKG_RELEASE=functest bash makerpm.sh PKG_RELEASE=${FUNCTAG} bash makerpm.sh
sudo yum -y install build/glusterfs-openstack-swift-1.8.0-functest.noarch.rpm || fail "Unable to install rpm" sudo yum -y install build/glusterfs-openstack-swift-*${FUNCTAG}*.noarch.rpm || fail "Unable to install rpm"
# Install the configuration files # Install the configuration files
mkdir /etc/swift > /dev/null 2>&1 mkdir /etc/swift > /dev/null 2>&1