Skip to content

Commit

Permalink
rename checkSlaveVersion to checkSlaveHasCommand
Browse files Browse the repository at this point in the history
update doc and tests

Signed-off-by: Pierre Tardy <pierre.tardy@intel.com>
  • Loading branch information
Pierre Tardy committed Dec 29, 2014
1 parent 4bae1f4 commit 5f14b1f
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 46 deletions.
4 changes: 1 addition & 3 deletions master/buildbot/process/buildstep.py
Expand Up @@ -652,9 +652,7 @@ def slaveVersionIsOlderThan(self, command, minversion):
return True
return False

# Check that buildslave version used have implementation for
# a remote command. Raise exception if buildslave is to old.
def checkSlaveVersion(self, command):
def checkSlaveHasCommand(self, command):
if not self.slaveVersion(command):
message = "slave is too old, does not know about %s" % command
raise BuildSlaveTooOldError(message)
Expand Down
2 changes: 1 addition & 1 deletion master/buildbot/steps/slave.py
Expand Up @@ -321,7 +321,7 @@ def commandComplete(cmd):
evaluateCommand=commandComplete)

def getFileContentFromSlave(self, filename, abandonOnFailure=False):
self.checkSlaveVersion("uploadFile")
self.checkSlaveHasCommand("uploadFile")
fileWriter = StringFileWriter()
# default arguments
args = {
Expand Down
14 changes: 7 additions & 7 deletions master/buildbot/steps/transfer.py
Expand Up @@ -267,7 +267,7 @@ def __init__(self, slavesrc, masterdest,
self.url = url

def start(self):
self.checkSlaveVersion("uploadFile")
self.checkSlaveHasCommand("uploadFile")

source = self.slavesrc
masterdest = self.masterdest
Expand Down Expand Up @@ -328,7 +328,7 @@ def __init__(self, slavesrc, masterdest,
self.url = url

def start(self):
self.checkSlaveVersion("uploadDirectory")
self.checkSlaveHasCommand("uploadDirectory")

source = self.slavesrc
masterdest = self.masterdest
Expand Down Expand Up @@ -454,9 +454,9 @@ def allUploadsDone(self, result, sources, masterdest):
self.addURL(os.path.basename(masterdest), self.url)

def start(self):
self.checkSlaveVersion("uploadDirectory")
self.checkSlaveVersion("uploadFile")
self.checkSlaveVersion("stat")
self.checkSlaveHasCommand("uploadDirectory")
self.checkSlaveHasCommand("uploadFile")
self.checkSlaveHasCommand("stat")

masterdest = os.path.expanduser(self.masterdest)
sources = self.slavesrcs
Expand Down Expand Up @@ -554,7 +554,7 @@ def __init__(self, mastersrc, slavedest,
self.mode = mode

def start(self):
self.checkSlaveVersion("downloadFile")
self.checkSlaveHasCommand("downloadFile")

# we are currently in the buildmaster's basedir, so any non-absolute
# paths will be interpreted relative to that
Expand Down Expand Up @@ -616,7 +616,7 @@ def __init__(self, s, slavedest,

def start(self):
# we use 'downloadFile' remote command on the slave
self.checkSlaveVersion("downloadFile")
self.checkSlaveHasCommand("downloadFile")

# we are currently in the buildmaster's basedir, so any non-absolute
# paths will be interpreted relative to that
Expand Down
28 changes: 28 additions & 0 deletions master/buildbot/test/unit/test_process_buildstep.py
Expand Up @@ -15,6 +15,7 @@

import mock

from buildbot.interfaces import BuildSlaveTooOldError
from buildbot.process import buildstep
from buildbot.process import properties
from buildbot.process import remotecommand
Expand Down Expand Up @@ -463,6 +464,33 @@ def test_getResultSummary_descriptionSuffix_failure(self):
st.description = 'fooing'
self.checkSummary(st.getResultSummary(), u'fooing (failure)')

# Test calling checkSlaveHasCommand() when buildslave have support for
# requested remote command.
def testcheckSlaveHasCommandGood(self):
# patch BuildStep.slaveVersion() to return success
mockedSlaveVersion = mock.Mock()
self.patch(buildstep.BuildStep, "slaveVersion", mockedSlaveVersion)

# check that no exceptions are raised
buildstep.BuildStep().checkSlaveHasCommand("foo")

# make sure slaveVersion() was called with correct arguments
mockedSlaveVersion.assert_called_once_with("foo")

# Test calling checkSlaveHasCommand() when buildslave is to old to support
# requested remote command.
def testcheckSlaveHasCommandTooOld(self):
# patch BuildStep.slaveVersion() to return error
self.patch(buildstep.BuildStep,
"slaveVersion",
mock.Mock(return_value=None))

# make sure appropriate exception is raised
step = buildstep.BuildStep()
self.assertRaisesRegexp(BuildSlaveTooOldError,
"slave is too old, does not know about foo",
step.checkSlaveHasCommand, "foo")


class TestLoggingBuildStep(unittest.TestCase):

Expand Down
35 changes: 0 additions & 35 deletions master/buildbot/test/unit/test_steps_transfer.py
Expand Up @@ -26,8 +26,6 @@
from mock import Mock

from buildbot import config
from buildbot import interfaces
from buildbot.process import buildstep
from buildbot.process.properties import Properties
from buildbot.status.results import EXCEPTION
from buildbot.status.results import FAILURE
Expand Down Expand Up @@ -119,39 +117,6 @@ def testInit(self):
mockedMkstemp.assert_called_once_with(dir=absdir)
mockedFdopen.assert_called_once_with(7, 'wb')

# Test buildbot.steps.transfer._TransferBuildStep class.


class TestTransferBuildStep(unittest.TestCase):

# Test calling checkSlaveVersion() when buildslave have support for
# requested remote command.

def testCheckSlaveVersionGood(self):
# patch BuildStep.slaveVersion() to return success
mockedSlaveVersion = Mock()
self.patch(buildstep.BuildStep, "slaveVersion", mockedSlaveVersion)

# check that no exceptions are raised
transfer._TransferBuildStep().checkSlaveVersion("foo")

# make sure slaveVersion() was called with correct arguments
mockedSlaveVersion.assert_called_once_with("foo")

# Test calling checkSlaveVersion() when buildslave is to old to support
# requested remote command.
def testCheckSlaveVersionTooOld(self):
# patch BuildStep.slaveVersion() to return error
self.patch(buildstep.BuildStep,
"slaveVersion",
Mock(return_value=None))

# make sure appropriate exception is raised
step = transfer._TransferBuildStep()
self.assertRaisesRegexp(interfaces.BuildSlaveTooOldError,
"slave is too old, does not know about foo",
step.checkSlaveVersion, "foo")


class TestFileUpload(steps.BuildStepMixin, unittest.TestCase):

Expand Down
7 changes: 7 additions & 0 deletions master/docs/developer/cls-buildsteps.rst
Expand Up @@ -342,6 +342,13 @@ BuildStep

This method returns true if ``command`` is not implemented on the slave, or if it is older than ``minversion``.

.. py:method:: slaveVersionHasCommand(command)
:param command: command to examine
:type command: string

This method raise BuildSlaveTooOldError if ``command`` is not implemented on the slave

.. py:method:: getSlaveName()
:returns: string
Expand Down

0 comments on commit 5f14b1f

Please sign in to comment.