Example #1
0
    def test_RemoteShellCommand_usePTY(self):
        with assertNotProducesWarnings(DeprecatedWorkerAPIWarning):
            cmd = remotecommand.RemoteShellCommand(
                'workdir', 'command')

        self.assertTrue(cmd.args['usePTY'] is None)

        with assertNotProducesWarnings(DeprecatedWorkerAPIWarning):
            cmd = remotecommand.RemoteShellCommand(
                'workdir', 'command', usePTY=True)

        self.assertTrue(cmd.args['usePTY'])

        with assertNotProducesWarnings(DeprecatedWorkerAPIWarning):
            cmd = remotecommand.RemoteShellCommand(
                'workdir', 'command', usePTY=False)

        self.assertFalse(cmd.args['usePTY'])

        with assertProducesWarning(
                DeprecatedWorkerNameWarning,
                message_pattern="'slave-config' value of 'usePTY' "
                                "attribute is deprecated"):
            cmd = remotecommand.RemoteShellCommand(
                'workdir', 'command', usePTY='slave-config')

        self.assertTrue(cmd.args['usePTY'] is None)
    def test_obfuscated_arguments(self):
        command = [
            "echo",
            ("obfuscated", "real", "fake"),
            "test",
            ("obfuscated", "real2", "fake2"),
            ("not obfuscated", "a", "b"),
            ("obfuscated"),  # not obfuscated
            ("obfuscated", "test"),  # not obfuscated
            ("obfuscated", "1", "2", "3"),  # not obfuscated)
        ]
        cmd = remotecommand.RemoteShellCommand("build", command)
        self.assertEqual(cmd.command, command)
        self.assertEqual(
            cmd.fake_command,
            [
                "echo",
                "fake",
                "test",
                "fake2",
                ("not obfuscated", "a", "b"),
                ("obfuscated"),  # not obfuscated
                # not obfuscated
                ("obfuscated", "test"),
                # not obfuscated)
                ("obfuscated", "1", "2", "3"),
            ])

        command = "echo test"
        cmd = remotecommand.RemoteShellCommand("build", command)
        self.assertEqual(cmd.command, command)
        self.assertEqual(cmd.fake_command, command)
Example #3
0
    def checkBasetgz(self):
        cmd = remotecommand.RemoteCommand('stat', {'file': self.basetgz})
        yield self.runCommand(cmd)

        if cmd.rc != 0:
            log.msg("basetgz not found, initializing it.")

            command = ['sudo', self.pbuilder, '--create', self.baseOption,
                       self.basetgz, '--distribution', self.distribution,
                       '--mirror', self.mirror]
            if self.othermirror:
                command += ['--othermirror', self.othermirror]
            if self.architecture:
                command += ['--architecture', self.architecture]
            if self.extrapackages:
                command += ['--extrapackages', " ".join(self.extrapackages)]
            if self.keyring:
                command += ['--debootstrapopts', "--keyring={}".format(self.keyring)]
            if self.components:
                command += ['--components', self.components]

            cmd = remotecommand.RemoteShellCommand(self.workdir, command)

            stdio_log = yield self.addLog("pbuilder")
            cmd.useLog(stdio_log, True, "stdio")

            self.description = ["PBuilder", "create."]
            yield self.updateSummary()

            yield self.runCommand(cmd)
            if cmd.rc != 0:
                log.msg("Failure when running {}.".format(cmd))
                return results.FAILURE
            return results.SUCCESS

        s = cmd.updates["stat"][-1]
        # basetgz will be a file when running in pbuilder
        # and a directory in case of cowbuilder
        if stat.S_ISREG(s[stat.ST_MODE]) or stat.S_ISDIR(s[stat.ST_MODE]):
            log.msg("{} found.".format(self.basetgz))
            age = time.time() - s[stat.ST_MTIME]
            if age >= self.maxAge:
                log.msg("basetgz outdated, updating")
                command = ['sudo', self.pbuilder, '--update',
                           self.baseOption, self.basetgz]

                cmd = remotecommand.RemoteShellCommand(self.workdir, command)
                stdio_log = yield self.addLog("pbuilder")
                cmd.useLog(stdio_log, True, "stdio")

                yield self.runCommand(cmd)
                if cmd.rc != 0:
                    log.msg("Failure when running {}.".format(cmd))
                    return results.FAILURE
            return results.SUCCESS

        log.msg("{} is not a file or a directory.".format(self.basetgz))
        return results.FAILURE
Example #4
0
    def checkBasetgz(self, cmd):
        if cmd.rc != 0:
            log.msg("basetgz not found, initializing it.")

            command = [
                'sudo', self.pbuilder, '--create', self.baseOption,
                self.basetgz, '--distribution', self.distribution, '--mirror',
                self.mirror
            ]
            if self.architecture:
                command += ['--architecture', self.architecture]
            if self.extrapackages:
                command += ['--extrapackages', " ".join(self.extrapackages)]
            if self.keyring:
                command += [
                    '--debootstrapopts', "--keyring={}".format(self.keyring)
                ]
            if self.components:
                command += ['--components', self.components]

            cmd = remotecommand.RemoteShellCommand(self.workdir, command)

            stdio_log = stdio_log = self.addLog("pbuilder")
            cmd.useLog(stdio_log, True, "stdio")
            d = self.runCommand(cmd)
            self.step_status.setText(["PBuilder create."])
            d.addCallback(lambda res: self.startBuild(cmd))
            return d
        s = cmd.updates["stat"][-1]
        # basetgz will be a file when running in pbuilder
        # and a directory in case of cowbuilder
        if stat.S_ISREG(s[stat.ST_MODE]) or stat.S_ISDIR(s[stat.ST_MODE]):
            log.msg("{} found.".format(self.basetgz))
            age = time.time() - s[stat.ST_MTIME]
            if age >= self.maxAge:
                log.msg("basetgz outdated, updating")
                command = [
                    'sudo', self.pbuilder, '--update', self.baseOption,
                    self.basetgz
                ]

                cmd = remotecommand.RemoteShellCommand(self.workdir, command)
                stdio_log = stdio_log = self.addLog("pbuilder")
                cmd.useLog(stdio_log, True, "stdio")
                d = self.runCommand(cmd)
                d.addCallback(lambda res: self.startBuild(cmd))
                return d
            return self.startBuild(cmd)
        else:
            log.msg("{} is not a file or a directory.".format(self.basetgz))
            self.finished(FAILURE)
        return None
Example #5
0
    def makeRemoteShellCommand(self, collectStdout=False, collectStderr=False,
                               stdioLogName='stdio',
                               **overrides):
        kwargs = dict([(arg, getattr(self, arg))
                       for arg in self._shellMixinArgs])
        kwargs.update(overrides)
        stdio = None
        if stdioLogName is not None:
            stdio = yield self.addLog(stdioLogName)
        kwargs['command'] = flatten(kwargs['command'], (list, tuple))

        # check for the usePTY flag
        if kwargs['usePTY'] != 'slave-config':
            if self.slaveVersionIsOlderThan("shell", "2.7"):
                if stdio is not None:
                    yield stdio.addHeader(
                        "NOTE: slave does not allow master to override usePTY\n")
                del kwargs['usePTY']

        # check for the interruptSignal flag
        if kwargs["interruptSignal"] and self.slaveVersionIsOlderThan("shell", "2.15"):
            if stdio is not None:
                yield stdio.addHeader(
                    "NOTE: slave does not allow master to specify interruptSignal\n")
            del kwargs['interruptSignal']

        # lazylogfiles are handled below
        del kwargs['lazylogfiles']

        # merge the builder's environment with that supplied here
        builderEnv = self.build.builder.config.env
        kwargs['env'] = yield self.build.render(builderEnv)
        kwargs['env'].update(self.env)
        kwargs['stdioLogName'] = stdioLogName
        # default the workdir appropriately
        if not self.workdir:
            if callable(self.build.workdir):
                kwargs['workdir'] = self.build.workdir(self.build.sources)
            else:
                kwargs['workdir'] = self.build.workdir

        # the rest of the args go to RemoteShellCommand
        cmd = remotecommand.RemoteShellCommand(**kwargs)

        # set up logging
        if stdio is not None:
            cmd.useLog(stdio, False)
        for logname, remotefilename in self.logfiles.items():
            if self.lazylogfiles:
                # it's OK if this does, or does not, return a Deferred
                callback = lambda cmd_arg, logname=logname: self.addLog(
                    logname)
                cmd.useLogDelayed(logname, callback, True)
            else:
                # tell the BuildStepStatus to add a LogFile
                newlog = yield self.addLog(logname)
                # and tell the RemoteCommand to feed it
                cmd.useLog(newlog, False)

        defer.returnValue(cmd)
Example #6
0
    def _Cmd(self, command, abandonOnFailure=True, workdir=None, **kwargs):
        if workdir is None:
            workdir = self.workdir
        cmd = remotecommand.RemoteShellCommand(workdir,
                                               command,
                                               env=self.env,
                                               logEnviron=self.logEnviron,
                                               timeout=self.timeout,
                                               **kwargs)
        self.lastCommand = cmd
        # does not make sense to logEnviron for each command (just for first)
        self.logEnviron = False
        cmd.useLog(self.stdio_log, False)
        yield self.stdio_log.addHeader("Starting command: {}\n".format(
            " ".join(command)))
        self.description = ' '.join(command[:2])
        # FIXME: enable when new style step is switched on yield self.updateSummary()
        yield self.runCommand(cmd)

        if abandonOnFailure and cmd.didFail():
            self.descriptionDone = "repo failed at: {}".format(" ".join(
                command[:2]))
            msg = "Source step failed while running command {}\n".format(cmd)
            yield self.stdio_log.addStderr(msg)
            raise buildstep.BuildStepFailed()
        return cmd.rc
Example #7
0
    def _dovccmd(self, command, collectStdout=False, initialStdin=None):
        command = self._buildVCCommand(command)

        if self.debug:
            log.msg("P4:_dovccmd():workdir->{}".format(self.workdir))

        cmd = remotecommand.RemoteShellCommand(
            self.workdir,
            command,
            env=self.env,
            logEnviron=self.logEnviron,
            timeout=self.timeout,
            collectStdout=collectStdout,
            initialStdin=initialStdin,
        )
        cmd.useLog(self.stdio_log, False)
        if self.debug:
            log.msg("Starting p4 command : p4 {}".format(" ".join(command)))

        yield self.runCommand(cmd)

        if cmd.rc != 0:
            if self.debug:
                log.msg(
                    "P4:_dovccmd():Source step failed while running command {}"
                    .format(cmd))
            raise buildstep.BuildStepFailed()
        if collectStdout:
            return cmd.stdout
        return cmd.rc
Example #8
0
    def _dovccmd(self,
                 command,
                 collectStdout=False,
                 initialStdin=None,
                 decodeRC=None,
                 abandonOnFailure=True,
                 wkdir=None):
        if not command:
            raise ValueError("No command specified")

        if decodeRC is None:
            decodeRC = {0: SUCCESS}
        workdir = wkdir or self.workdir
        cmd = remotecommand.RemoteShellCommand(workdir,
                                               command,
                                               env=self.env,
                                               logEnviron=self.logEnviron,
                                               timeout=self.timeout,
                                               collectStdout=collectStdout,
                                               initialStdin=initialStdin,
                                               decodeRC=decodeRC)
        cmd.useLog(self.stdio_log, False)
        yield self.runCommand(cmd)

        if abandonOnFailure and cmd.didFail():
            log.msg("Source step failed while running command {}".format(cmd))
            raise buildstep.BuildStepFailed()
        if collectStdout:
            return cmd.stdout
        return cmd.rc
Example #9
0
    def parseGotRevision(self):
        command = self._buildVCCommand(['changes', '-m1', '#have'])

        cmd = remotecommand.RemoteShellCommand(self.workdir,
                                               command,
                                               env=self.env,
                                               timeout=self.timeout,
                                               logEnviron=self.logEnviron,
                                               collectStdout=True)
        cmd.useLog(self.stdio_log, False)
        yield self.runCommand(cmd)

        stdout = cmd.stdout.strip()
        # Example output from p4 changes -m1 #have
        # Change 212798 on 2012/04/13 by user@user-unix-bldng2 'change to
        # pickup build'
        revision = stdout.split()[1]
        try:
            int(revision)
        except ValueError as e:
            msg = (("p4.parseGotRevision unable to parse output "
                    "of 'p4 changes -m1 \"#have\"': '{}'").format(stdout))
            log.msg(msg)
            raise buildstep.BuildStepFailed() from e

        if self.debug:
            log.msg("Got p4 revision {}".format(revision))
        self.updateSourceProperty('got_revision', revision)
Example #10
0
    def _dovccmd(self,
                 command,
                 abandonOnFailure=True,
                 collectStdout=False,
                 initialStdin=None):
        full_command = ['git']
        full_env = self.env.copy() if self.env else {}

        if self.config is not None:
            for name, value in self.config.items():
                full_command.append('-c')
                full_command.append('{}={}'.format(name, value))

        if self._isSshPrivateKeyNeededForGitCommand(command):
            self._adjustCommandParamsForSshPrivateKey(full_command, full_env)

        full_command.extend(command)

        # check for the interruptSignal flag
        sigtermTime = None
        interruptSignal = None

        # If possible prefer to send a SIGTERM to git before we send a SIGKILL.
        # If we send a SIGKILL, git is prone to leaving around stale lockfiles.
        # By priming it with a SIGTERM first we can ensure that it has a chance to shut-down
        # gracefully before getting terminated
        if not self.workerVersionIsOlderThan("shell", "2.16"):
            # git should shut-down quickly on SIGTERM.  If it doesn't don't let it
            # stick around for too long because this is on top of any timeout
            # we have hit.
            sigtermTime = 1
        else:
            # Since sigtermTime is unavailable try to just use SIGTERM by itself instead of
            # killing.  This should be safe.
            if self.workerVersionIsOlderThan("shell", "2.15"):
                log.msg(
                    "NOTE: worker does not allow master to specify "
                    "interruptSignal. This may leave a stale lockfile around "
                    "if the command is interrupted/times out\n")
            else:
                interruptSignal = 'TERM'

        cmd = remotecommand.RemoteShellCommand(self.workdir,
                                               full_command,
                                               env=full_env,
                                               logEnviron=self.logEnviron,
                                               timeout=self.timeout,
                                               sigtermTime=sigtermTime,
                                               interruptSignal=interruptSignal,
                                               collectStdout=collectStdout,
                                               initialStdin=initialStdin)
        cmd.useLog(self.stdio_log, False)
        yield self.runCommand(cmd)

        if abandonOnFailure and cmd.didFail():
            log.msg("Source step failed while running command {}".format(cmd))
            raise buildstep.BuildStepFailed()
        if collectStdout:
            return cmd.stdout
        return cmd.rc
Example #11
0
 def checkP4(self):
     cmd = remotecommand.RemoteShellCommand(self.workdir, [self.p4bin, '-V'],
                                            env=self.env,
                                            logEnviron=self.logEnviron)
     cmd.useLog(self.stdio_log, False)
     yield self.runCommand(cmd)
     return cmd.rc == 0
Example #12
0
    def _dovccmd(self,
                 command,
                 abandonOnFailure=True,
                 collectStdout=False,
                 initialStdin=None):
        full_command = ['git']
        if self.config is not None:
            for name, value in iteritems(self.config):
                full_command.append('-c')
                full_command.append('%s=%s' % (name, value))
        full_command.extend(command)
        cmd = remotecommand.RemoteShellCommand(self.workdir,
                                               full_command,
                                               env=self.env,
                                               logEnviron=self.logEnviron,
                                               timeout=self.timeout,
                                               collectStdout=collectStdout,
                                               initialStdin=initialStdin)
        cmd.useLog(self.stdio_log, False)
        d = self.runCommand(cmd)

        @d.addCallback
        def evaluateCommand(_):
            if abandonOnFailure and cmd.didFail():
                log.msg("Source step failed while running command %s" % cmd)
                raise buildstep.BuildStepFailed()
            if collectStdout:
                return cmd.stdout
            else:
                return cmd.rc

        return d
Example #13
0
    def _dovccmd(self,
                 command,
                 workdir=None,
                 abandonOnFailure=True,
                 initialStdin=None):
        if workdir is None:
            workdir = self.workdir
        if not command:
            raise ValueError("No command specified")
        cmd = remotecommand.RemoteShellCommand(workdir, ['cvs'] + command,
                                               env=self.env,
                                               timeout=self.timeout,
                                               logEnviron=self.logEnviron,
                                               initialStdin=initialStdin)
        cmd.useLog(self.stdio_log, False)
        d = self.runCommand(cmd)

        @d.addCallback
        def evaluateCommand(_):
            if cmd.rc != 0 and abandonOnFailure:
                log.msg(
                    "Source step failed while running command {}".format(cmd))
                raise buildstep.BuildStepFailed()
            return cmd.rc

        return d
Example #14
0
    def _dovccmd(self,
                 command,
                 collectStdout=False,
                 initialStdin=None,
                 decodeRC=None,
                 abandonOnFailure=True):
        if not command:
            raise ValueError("No command specified")

        if decodeRC is None:
            decodeRC = {0: SUCCESS}
        cmd = remotecommand.RemoteShellCommand(self.workdir,
                                               ['hg', '--verbose'] + command,
                                               env=self.env,
                                               logEnviron=self.logEnviron,
                                               timeout=self.timeout,
                                               collectStdout=collectStdout,
                                               initialStdin=initialStdin,
                                               decodeRC=decodeRC)
        cmd.useLog(self.stdio_log, False)
        d = self.runCommand(cmd)

        @d.addCallback
        def evaluateCommand(_):
            if abandonOnFailure and cmd.didFail():
                log.msg("Source step failed while running command %s" % cmd)
                raise buildstep.BuildStepFailed()
            if collectStdout:
                return cmd.stdout
            else:
                return cmd.rc

        return d
Example #15
0
    def _dovccmd(self, command, collectStdout=False, abandonOnFailure=True):
        assert command, "No command specified"
        command.extend(['--non-interactive', '--no-auth-cache'])
        if self.username:
            command.extend(['--username', self.username])
        if self.password is not None:
            command.extend(['--password', self.password])
        if self.depth:
            command.extend(['--depth', self.depth])
        if self.extra_args:
            command.extend(self.extra_args)

        cmd = remotecommand.RemoteShellCommand(self.workdir, ['svn'] + command,
                                               env=self.env,
                                               logEnviron=self.logEnviron,
                                               timeout=self.timeout,
                                               collectStdout=collectStdout)
        cmd.useLog(self.stdio_log, False)
        d = self.runCommand(cmd)

        def evaluateCommand(cmd):
            if cmd.didFail() and abandonOnFailure:
                log.msg("Source step failed while running command %s" % cmd)
                raise buildstep.BuildStepFailed()
            if collectStdout:
                return cmd.stdout
            else:
                return cmd.rc
        d.addCallback(lambda _: evaluateCommand(cmd))
        return d
Example #16
0
    def _dovccmd(self, command, collectStdout=False, collectStderr=False, abandonOnFailure=True):
        assert command, "No command specified"
        command.extend(['--non-interactive', '--no-auth-cache'])
        if self.username:
            command.extend(['--username', self.username])
        if self.password is not None:
            command.extend(['--password', self.password])
        if self.depth:
            command.extend(['--depth', self.depth])
        if self.extra_args:
            command.extend(self.extra_args)

        cmd = remotecommand.RemoteShellCommand(self.workdir, ['svn'] + command,
                                               env=self.env,
                                               logEnviron=self.logEnviron,
                                               timeout=self.timeout,
                                               collectStdout=collectStdout,
                                               collectStderr=collectStderr)
        cmd.useLog(self.stdio_log, False)
        yield self.runCommand(cmd)

        if cmd.didFail() and abandonOnFailure:
            log.msg("Source step failed while running command {}".format(cmd))
            raise buildstep.BuildStepFailed()
        if collectStdout and collectStderr:
            return (cmd.stdout, cmd.stderr)
        elif collectStdout:
            return cmd.stdout
        elif collectStderr:
            return cmd.stderr
        return cmd.rc
Example #17
0
 def checkSvn(self):
     cmd = remotecommand.RemoteShellCommand(self.workdir, ['svn', '--version'],
                                            env=self.env,
                                            logEnviron=self.logEnviron,
                                            timeout=self.timeout)
     cmd.useLog(self.stdio_log, False)
     yield self.runCommand(cmd)
     return cmd.rc == 0
    def test_RemoteShellCommand_usePTY(self):
        with assertNotProducesWarnings(DeprecatedWorkerAPIWarning):
            cmd = remotecommand.RemoteShellCommand(
                'workdir', 'command')

        self.assertTrue(cmd.args['usePTY'] is None)

        with assertNotProducesWarnings(DeprecatedWorkerAPIWarning):
            cmd = remotecommand.RemoteShellCommand(
                'workdir', 'command', usePTY=True)

        self.assertTrue(cmd.args['usePTY'])

        with assertNotProducesWarnings(DeprecatedWorkerAPIWarning):
            cmd = remotecommand.RemoteShellCommand(
                'workdir', 'command', usePTY=False)

        self.assertFalse(cmd.args['usePTY'])
Example #19
0
 def checkMonotone(self):
     cmd = remotecommand.RemoteShellCommand(self.workdir,
                                            ['mtn', '--version'],
                                            env=self.env,
                                            logEnviron=self.logEnviron,
                                            timeout=self.timeout)
     cmd.useLog(self.stdio_log, False)
     yield self.runCommand(cmd)
     defer.returnValue(cmd.rc == 0)
Example #20
0
File: svn.py Project: nvg24/lit
    def checkSvn(self):
        cmd = remotecommand.RemoteShellCommand(self.workdir, ['svn', '--version'],
                                               env=self.env,
                                               logEnviron=self.logEnviron,
                                               timeout=self.timeout)
        cmd.useLog(self.stdio_log, False)
        d = self.runCommand(cmd)

        @d.addCallback
        def evaluate(_):
            return cmd.rc == 0
        return d
Example #21
0
def isRedhat(step):
    """Return true if the worker's OS is RedHat.

    Used as a step parameter (per example 'doStepIf') to identify wheiter
    the worker is using Redhat as a OS or another.

    """

    command = "rpm -qa | grep -qE '^redhat-release.+'"
    cmd = remotecommand.RemoteShellCommand('/', command)
    yield step.runCommand(cmd)
    defer.returnValue(not cmd.didFail())
Example #22
0
    def start(self):
        # this block is specific to ShellCommands. subclasses that don't need
        # to set up an argv array, an environment, or extra logfiles= (like
        # the Source subclasses) can just skip straight to startCommand()

        warnings = []

        # create the actual RemoteShellCommand instance now
        kwargs = self.buildCommandKwargs(warnings)
        cmd = remotecommand.RemoteShellCommand(**kwargs)
        self.setupEnvironment(cmd)

        self.startCommand(cmd, warnings)
Example #23
0
    def applyPatch(self, patch):
        patch_command = ['patch', '-p{}'.format(patch[0]), '--remove-empty-files',
                         '--force', '--forward', '-i', '.buildbot-diff']
        cmd = remotecommand.RemoteShellCommand(self.workdir,
                                               patch_command,
                                               env=self.env,
                                               logEnviron=self.logEnviron)

        cmd.useLog(self.stdio_log, False)
        yield self.runCommand(cmd)
        if cmd.didFail():
            raise buildstep.BuildStepFailed()
        return cmd.rc
Example #24
0
    def checkMonotone(self):
        cmd = remotecommand.RemoteShellCommand(self.workdir, ['mtn', '--version'],
                                               env=self.env,
                                               logEnviron=self.logEnviron,
                                               timeout=self.timeout)
        cmd.useLog(self.stdio_log, False)
        d = self.runCommand(cmd)

        @d.addCallback
        def evaluate(_):
            if cmd.rc != 0:
                return False
            return True
        return d
Example #25
0
    def parseGotRevision(self, _):
        # if this was a full/export, then we need to check svnversion in the
        # *source* directory, not the build directory
        svnversion_dir = self.workdir
        if self.mode == 'full' and self.method == 'export':
            svnversion_dir = 'source'
        cmd = remotecommand.RemoteShellCommand(svnversion_dir,
                                               ['svn', 'info', '--xml'],
                                               env=self.env,
                                               logEnviron=self.logEnviron,
                                               timeout=self.timeout,
                                               collectStdout=True)
        cmd.useLog(self.stdio_log, False)
        yield self.runCommand(cmd)

        stdout = cmd.stdout
        try:
            stdout_xml = xml.dom.minidom.parseString(stdout)
        except xml.parsers.expat.ExpatError:
            msg = "Corrupted xml, aborting step"
            self.stdio_log.addHeader(msg)
            raise buildstep.BuildStepFailed()

        revision = None
        if self.preferLastChangedRev:
            try:
                revision = stdout_xml.getElementsByTagName(
                    'commit')[0].attributes['revision'].value
            except (KeyError, IndexError):
                msg = (
                    "SVN.parseGotRevision unable to detect Last Changed Rev in"
                    " output of svn info")
                log.msg(msg)
                # fall through and try to get 'Revision' instead

        if revision is None:
            try:
                revision = stdout_xml.getElementsByTagName(
                    'entry')[0].attributes['revision'].value
            except (KeyError, IndexError):
                msg = ("SVN.parseGotRevision unable to detect revision in"
                       " output of svn info")
                log.msg(msg)
                raise buildstep.BuildStepFailed()

        msg = "Got SVN revision %s" % (revision, )
        self.stdio_log.addHeader(msg)
        self.updateSourceProperty('got_revision', revision)

        defer.returnValue(cmd.rc)
Example #26
0
    def purge(self, ignore_ignores):
        command = ['cvsdiscard']
        if ignore_ignores:
            command += ['--ignore']
        cmd = remotecommand.RemoteShellCommand(self.workdir,
                                               command,
                                               env=self.env,
                                               logEnviron=self.logEnviron,
                                               timeout=self.timeout)
        cmd.useLog(self.stdio_log, False)
        yield self.runCommand(cmd)

        if cmd.didFail():
            raise buildstep.BuildStepFailed()
Example #27
0
    def checkSvn(self):
        cmd = remotecommand.RemoteShellCommand(self.workdir, ['svn', '--version'],
                                               env=self.env,
                                               logEnviron=self.logEnviron,
                                               timeout=self.timeout)
        cmd.useLog(self.stdio_log, False)
        d = self.runCommand(cmd)

        def evaluate(cmd):
            if cmd.rc != 0:
                return False
            return True
        d.addCallback(lambda _: evaluate(cmd))
        return d
Example #28
0
    def test_runCommand(self):
        bs = buildstep.BuildStep()
        bs.worker = worker.FakeWorker(master=None)  # master is not used here
        bs.remote = 'dummy'
        bs.build = fakebuild.FakeBuild()
        bs.build.builder.name = 'fake'
        cmd = remotecommand.RemoteShellCommand("build", ["echo", "hello"])

        def run(*args, **kwargs):
            # check that runCommand sets step.cmd
            self.assertIdentical(bs.cmd, cmd)
            return SUCCESS
        cmd.run = run
        yield bs.runCommand(cmd)
        # check that step.cmd is cleared after the command runs
        self.assertEqual(bs.cmd, None)
Example #29
0
    def copy(self):
        yield self.runRmdir(self.workdir, timeout=self.timeout)

        checkout_dir = 'source'
        if self.codebase:
            checkout_dir = self.build.path_module.join(checkout_dir,
                                                       self.codebase)
        # temporarily set workdir = checkout_dir and do an incremental checkout
        try:
            old_workdir = self.workdir
            self.workdir = checkout_dir
            yield self.mode_incremental(None)
        finally:
            self.workdir = old_workdir
        self.workdir = old_workdir

        # if we're copying, copy; otherwise, export from source to build
        if self.method == 'copy':
            cmd = remotecommand.RemoteCommand(
                'cpdir', {
                    'fromdir': checkout_dir,
                    'todir': self.workdir,
                    'logEnviron': self.logEnviron
                })
        else:
            export_cmd = ['svn', 'export']
            if self.revision:
                export_cmd.extend(["--revision", str(self.revision)])
            if self.username:
                export_cmd.extend(['--username', self.username])
            if self.password is not None:
                export_cmd.extend(['--password', self.password])
            if self.extra_args:
                export_cmd.extend(self.extra_args)
            export_cmd.extend([checkout_dir, self.workdir])

            cmd = remotecommand.RemoteShellCommand('',
                                                   export_cmd,
                                                   env=self.env,
                                                   logEnviron=self.logEnviron,
                                                   timeout=self.timeout)
        cmd.useLog(self.stdio_log, False)

        yield self.runCommand(cmd)

        if cmd.didFail():
            raise buildstep.BuildStepFailed()
Example #30
0
    def applyPatch(self, patch):
        patch_command = ['patch', '-p%s' % patch[0], '--remove-empty-files',
                         '--force', '--forward', '-i', '.buildbot-diff']
        cmd = remotecommand.RemoteShellCommand(self.workdir,
                                               patch_command,
                                               env=self.env,
                                               logEnviron=self.logEnviron)

        cmd.useLog(self.stdio_log, False)
        d = self.runCommand(cmd)

        @d.addCallback
        def evaluateCommand(_):
            if cmd.didFail():
                raise buildstep.BuildStepFailed()
            return cmd.rc
        return d