Skip to content

Commit

Permalink
Make rpm dist renderable
Browse files Browse the repository at this point in the history
  • Loading branch information
anish committed Jul 11, 2016
1 parent 00a48de commit eaa3d38
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 14 deletions.
31 changes: 23 additions & 8 deletions master/buildbot/steps/package/rpm/rpmbuild.py
Expand Up @@ -28,6 +28,7 @@ class RpmBuild(ShellCommand):
RpmBuild build step.
"""

renderables = ['dist']
name = "rpmbuilder"
haltOnFailure = 1
flunkOnFailure = 1
Expand All @@ -42,7 +43,7 @@ def __init__(self,
sourcedir='`pwd`',
specdir='`pwd`',
srcrpmdir='`pwd`',
dist='.el5',
dist='.el6',
autoRelease=False,
vcsRevision=False,
**kwargs):
Expand Down Expand Up @@ -71,12 +72,16 @@ def __init__(self,
@param vcsRevision: Use vcs version number as revision number.
"""
ShellCommand.__init__(self, **kwargs)
self.rpmbuild = (

self.dist = dist

self.base_rpmbuild = (
'rpmbuild --define "_topdir %s" --define "_builddir %s"'
' --define "_rpmdir %s" --define "_sourcedir %s"'
' --define "_specdir %s" --define "_srcrpmdir %s"'
' --define "dist %s"' % (topdir, builddir, rpmdir, sourcedir,
specdir, srcrpmdir, dist))
% (topdir, builddir, rpmdir, sourcedir, specdir,
srcrpmdir))

self.specfile = specfile
self.autoRelease = autoRelease
self.vcsRevision = vcsRevision
Expand All @@ -88,6 +93,10 @@ def __init__(self,
'stdio', logobserver.LineConsumerLogObserver(self.logConsumer))

def start(self):

rpm_extras_dict = {}
rpm_extras_dict['dist'] = self.dist

if self.autoRelease:
relfile = '%s.release' % (
os.path.basename(self.specfile).split('.')[0])
Expand All @@ -96,18 +105,24 @@ def start(self):
rel = int(rfile.readline().strip())
except (IOError, TypeError, ValueError):
rel = 0
self.rpmbuild = self.rpmbuild + ' --define "_release %s"' % rel
rpm_extras_dict['_release'] = rel
with open(relfile, 'w') as rfile:
rfile.write(str(rel + 1))

if self.vcsRevision:
revision = self.getProperty('got_revision')
# only do this in the case where there's a single codebase
if revision and not isinstance(revision, dict):
self.rpmbuild = (self.rpmbuild + ' --define "_revision %s"' %
revision)
rpm_extras_dict['_revision'] = revision

self.rpmbuild = self.base_rpmbuild

# The unit tests expect a certain order, so we sort the dict to keep
# format the same every time
for k, v in sorted(rpm_extras_dict.iteritems()):
self.rpmbuild = '{0} --define "{1} {2}"'.format(self.rpmbuild, k, v)

self.rpmbuild = self.rpmbuild + ' -ba %s' % self.specfile
self.rpmbuild = '{0} -ba {1}'.format(self.rpmbuild, self.specfile)

self.command = self.rpmbuild

Expand Down
29 changes: 23 additions & 6 deletions master/buildbot/test/unit/test_steps_package_rpm_rpmbuild.py
Expand Up @@ -12,9 +12,11 @@
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Copyright Buildbot Team Members
from twisted.internet import defer
from twisted.trial import unittest

from buildbot import config
from buildbot.process.properties import Interpolate
from buildbot.process.results import SUCCESS
from buildbot.steps.package.rpm import rpmbuild
from buildbot.test.fake.remotecommand import ExpectShell
Expand All @@ -34,12 +36,12 @@ def test_no_specfile(self):
rpmbuild.RpmBuild())

def test_success(self):
self.setupStep(rpmbuild.RpmBuild(specfile="foo.spec", dist=".el6"))
self.setupStep(rpmbuild.RpmBuild(specfile="foo.spec", dist=".el5"))
self.expectCommands(
ExpectShell(workdir='wkdir', command='rpmbuild --define "_topdir '
'`pwd`" --define "_builddir `pwd`" --define "_rpmdir '
'`pwd`" --define "_sourcedir `pwd`" --define "_specdir '
'`pwd`" --define "_srcrpmdir `pwd`" --define "dist .el6" '
'`pwd`" --define "_srcrpmdir `pwd`" --define "dist .el5" '
'-ba foo.spec')
+ ExpectShell.log('stdio',
stdout='lalala')
Expand All @@ -48,16 +50,31 @@ def test_success(self):
return self.runStep()

def test_autoRelease(self):
self.setupStep(rpmbuild.RpmBuild(specfile="foo.spec", dist=".el6",
autoRelease=True))
self.setupStep(rpmbuild.RpmBuild(specfile="foo.spec", autoRelease=True))
self.expectCommands(
ExpectShell(workdir='wkdir', command='rpmbuild --define "_topdir '
'`pwd`" --define "_builddir `pwd`" --define "_rpmdir `pwd`" '
'--define "_sourcedir `pwd`" --define "_specdir `pwd`" '
'--define "_srcrpmdir `pwd`" --define "dist .el6" '
'--define "_release 0" -ba foo.spec')
'--define "_srcrpmdir `pwd`" --define "_release 0" '
'--define "dist .el6" -ba foo.spec')
+ ExpectShell.log('stdio',
stdout='Your code has been rated at 10/10')
+ 0)
self.expectOutcome(result=SUCCESS, state_string='RPMBUILD')
return self.runStep()

@defer.inlineCallbacks
def test_renderable_dist(self):
self.setupStep(rpmbuild.RpmBuild(specfile="foo.spec", dist=Interpolate('%(prop:renderable_dist)s')))
self.properties.setProperty('renderable_dist', '.el7', 'test')
self.expectCommands(
ExpectShell(workdir='wkdir', command='rpmbuild --define "_topdir '
'`pwd`" --define "_builddir `pwd`" --define "_rpmdir '
'`pwd`" --define "_sourcedir `pwd`" --define "_specdir '
'`pwd`" --define "_srcrpmdir `pwd`" --define "dist .el7" '
'-ba foo.spec')
+ ExpectShell.log('stdio',
stdout='lalala')
+ 0)
self.expectOutcome(result=SUCCESS, state_string='RPMBUILD')
yield self.runStep()
2 changes: 2 additions & 0 deletions master/docs/relnotes/0.9.0rc1.rst
Expand Up @@ -21,6 +21,8 @@ Features

* :bb:worker:`OpenStackLatentWorker` now uses a single novaclient instance to not require re-authentication when starting or stopping instances.

* The ``dist`` parameter in :bb:step:`RpmBuild` is now renderable.

Fixes
~~~~~

Expand Down

0 comments on commit eaa3d38

Please sign in to comment.