예제 #1
0
    def run(self,
            args,
            check_status=True,
            wait=True,
            stdout=None,
            stderr=None,
            cwd=None,
            stdin=None,
            logger=None,
            label=None,
            env=None):
        log.info("run args={0}".format(args))

        # We don't need no stinkin' sudo
        args = [a for a in args if a != "sudo"]

        # We have to use shell=True if any run.Raw was present, e.g. &&
        shell = any([a for a in args if isinstance(a, Raw)])

        if shell:
            filtered = []
            i = 0
            while i < len(args):
                if args[i] == 'adjust-ulimits':
                    i += 1
                elif args[i] == 'ceph-coverage':
                    i += 2
                elif args[i] == 'timeout':
                    i += 2
                else:
                    filtered.append(args[i])
                    i += 1

            args = quote(filtered)
            log.info("Running {0}".format(args))

            subproc = subprocess.Popen(args,
                                       stdout=subprocess.PIPE,
                                       stderr=subprocess.PIPE,
                                       stdin=subprocess.PIPE,
                                       cwd=cwd,
                                       shell=True)
        else:
            log.info("Running {0}".format(args))

            for arg in args:
                if not isinstance(arg, basestring):
                    raise RuntimeError(
                        "Oops, can't handle arg {0} type {1}".format(
                            arg, arg.__class__))

            subproc = subprocess.Popen(args,
                                       stdout=subprocess.PIPE,
                                       stderr=subprocess.PIPE,
                                       stdin=subprocess.PIPE,
                                       cwd=cwd,
                                       env=env)

        if stdin:
            if not isinstance(stdin, basestring):
                raise RuntimeError(
                    "Can't handle non-string stdins on a vstart cluster")

            # Hack: writing to stdin is not deadlock-safe, but it "always" works
            # as long as the input buffer is "small"
            subproc.stdin.write(stdin)

        proc = LocalRemoteProcess(args, subproc, check_status, stdout, stderr)

        if wait:
            proc.wait()

        return proc
예제 #2
0
    def run(self, args, check_status=True, wait=True,
            stdout=None, stderr=None, cwd=None, stdin=None,
            logger=None, label=None):
        log.info("run args={0}".format(args))

        # We don't need no stinkin' sudo
        args = [a for a in args if a != "sudo"]

        # We have to use shell=True if any run.Raw was present, e.g. &&
        shell = any([a for a in args if isinstance(a, Raw)])

        if shell:
            filtered = []
            i = 0
            while i < len(args):
                if args[i] == 'adjust-ulimits':
                    i += 1
                elif args[i] == 'ceph-coverage':
                    i += 2
                elif args[i] == 'timeout':
                    i += 2
                else:
                    filtered.append(args[i])
                    i += 1

            args = quote(filtered)
            log.info("Running {0}".format(args))

            subproc = subprocess.Popen(args,
                                       stdout=subprocess.PIPE,
                                       stderr=subprocess.PIPE,
                                       stdin=subprocess.PIPE,
                                       cwd=cwd,
                                       shell=True)
        else:
            log.info("Running {0}".format(args))

            for arg in args:
                if not isinstance(arg, basestring):
                    raise RuntimeError("Oops, can't handle arg {0} type {1}".format(
                        arg, arg.__class__
                    ))

            subproc = subprocess.Popen(args,
                                       stdout=subprocess.PIPE,
                                       stderr=subprocess.PIPE,
                                       stdin=subprocess.PIPE,
                                       cwd=cwd)

        if stdin:
            if not isinstance(stdin, basestring):
                raise RuntimeError("Can't handle non-string stdins on a vstart cluster")

            # Hack: writing to stdin is not deadlock-safe, but it "always" works
            # as long as the input buffer is "small"
            subproc.stdin.write(stdin)

        proc = LocalRemoteProcess(
            args, subproc, check_status,
            stdout, stderr
        )

        if wait:
            proc.wait()

        return proc
예제 #3
0
    def run(self, args, check_status=True, wait=True,
            stdout=None, stderr=None, cwd=None, stdin=None,
            logger=None, label=None, env=None, timeout=None):

        # We don't need no stinkin' sudo
        args = [a for a in args if a != "sudo"]

        # We have to use shell=True if any run.Raw was present, e.g. &&
        shell = any([a for a in args if isinstance(a, Raw)])

        # Filter out helper tools that don't exist in a vstart environment
        args = [a for a in args if a not in {
            'adjust-ulimits', 'ceph-coverage', 'timeout'}]

        # Adjust binary path prefix if given a bare program name
        if "/" not in args[0]:
            # If they asked for a bare binary name, and it exists
            # in our built tree, use the one there.
            local_bin = os.path.join(BIN_PREFIX, args[0])
            if os.path.exists(local_bin):
                args = [local_bin] + args[1:]
            else:
                log.debug("'{0}' is not a binary in the Ceph build dir".format(
                    args[0]
                ))

        log.info("Running {0}".format(args))

        if shell:
            subproc = subprocess.Popen(quote(args),
                                       stdout=subprocess.PIPE,
                                       stderr=subprocess.PIPE,
                                       stdin=subprocess.PIPE,
                                       cwd=cwd,
                                       shell=True)
        else:
            # Sanity check that we've got a list of strings
            for arg in args:
                if not isinstance(arg, basestring):
                    raise RuntimeError("Oops, can't handle arg {0} type {1}".format(
                        arg, arg.__class__
                    ))

            subproc = subprocess.Popen(args,
                                       stdout=subprocess.PIPE,
                                       stderr=subprocess.PIPE,
                                       stdin=subprocess.PIPE,
                                       cwd=cwd,
                                       env=env)

        if stdin:
            if not isinstance(stdin, basestring):
                raise RuntimeError("Can't handle non-string stdins on a vstart cluster")

            # Hack: writing to stdin is not deadlock-safe, but it "always" works
            # as long as the input buffer is "small"
            subproc.stdin.write(stdin)

        proc = LocalRemoteProcess(
            args, subproc, check_status,
            stdout, stderr
        )

        if wait:
            proc.wait()

        return proc
예제 #4
0
    def run(self,
            args,
            check_status=True,
            wait=True,
            stdout=None,
            stderr=None,
            cwd=None,
            stdin=None,
            logger=None,
            label=None,
            env=None,
            timeout=None,
            omit_sudo=True):
        args = self._perform_checks_and_return_list_of_args(args, omit_sudo)

        # We have to use shell=True if any run.Raw was present, e.g. &&
        shell = any([a for a in args if isinstance(a, Raw)])

        # Filter out helper tools that don't exist in a vstart environment
        args = [
            a for a in args
            if a not in {'adjust-ulimits', 'ceph-coverage', 'timeout'}
        ]

        # Adjust binary path prefix if given a bare program name
        if "/" not in args[0]:
            # If they asked for a bare binary name, and it exists
            # in our built tree, use the one there.
            local_bin = os.path.join(BIN_PREFIX, args[0])
            if os.path.exists(local_bin):
                args = [local_bin] + args[1:]
            else:
                log.debug("'{0}' is not a binary in the Ceph build dir".format(
                    args[0]))

        log.info("Running {0}".format(args))

        if shell:
            subproc = subprocess.Popen(quote(args),
                                       stdout=subprocess.PIPE,
                                       stderr=subprocess.PIPE,
                                       stdin=subprocess.PIPE,
                                       cwd=cwd,
                                       shell=True)
        else:
            # Sanity check that we've got a list of strings
            for arg in args:
                if not isinstance(arg, basestring):
                    raise RuntimeError(
                        "Oops, can't handle arg {0} type {1}".format(
                            arg, arg.__class__))

            subproc = subprocess.Popen(args,
                                       stdout=subprocess.PIPE,
                                       stderr=subprocess.PIPE,
                                       stdin=subprocess.PIPE,
                                       cwd=cwd,
                                       env=env)

        if stdin:
            if not isinstance(stdin, basestring):
                raise RuntimeError(
                    "Can't handle non-string stdins on a vstart cluster")

            # Hack: writing to stdin is not deadlock-safe, but it "always" works
            # as long as the input buffer is "small"
            subproc.stdin.write(stdin)

        proc = LocalRemoteProcess(args, subproc, check_status, stdout, stderr)

        if wait:
            proc.wait()

        return proc
예제 #5
0
 def test_quote_and_raw(self):
     got = run.quote(['true', run.Raw('&&'), 'echo', 'yay'])
     assert got == "true && echo yay"
예제 #6
0
 def test_quote_and_quote(self):
     got = run.quote(
         ['echo', 'this && is embedded', '&&', 'that was standalone'])
     assert got == "echo 'this && is embedded' '&&' 'that was standalone'"
예제 #7
0
 def test_quote_simple(self):
     got = run.quote(['a b', ' c', 'd e '])
     assert got == "'a b' ' c' 'd e '"
예제 #8
0
    def run(self, args, check_status=True, wait=True,
            stdout=None, stderr=None, cwd=None, stdin=None,
            logger=None, label=None, env=None, timeout=None, omit_sudo=True):
        try:
            if args[args.index('sudo') + 1] in ['-u', 'passwd', 'chown']:
                omit_sudo = False
        except ValueError:
            pass

        # We don't need no stinkin' sudo
        if omit_sudo:
            args = [a for a in args if a != "sudo"]

        # We have to use shell=True if any run.Raw was present, e.g. &&
        shell = any([a for a in args if isinstance(a, Raw)])

        # Filter out helper tools that don't exist in a vstart environment
        args = [a for a in args if a not in (
            'adjust-ulimits', 'ceph-coverage', 'timeout')]

        # Adjust binary path prefix if given a bare program name
        if "/" not in args[0]:
            # If they asked for a bare binary name, and it exists
            # in our built tree, use the one there.
            local_bin = os.path.join(BIN_PREFIX, args[0])
            if os.path.exists(local_bin):
                args = [local_bin] + args[1:]
            else:
                log.debug("'{0}' is not a binary in the Ceph build dir".format(
                    args[0]
                ))

        log.info("Running {0}".format(args))

        if shell:
            subproc = subprocess.Popen(quote(args),
                                       stdout=subprocess.PIPE,
                                       stderr=subprocess.PIPE,
                                       stdin=subprocess.PIPE,
                                       cwd=cwd,
                                       shell=True)
        else:
            # Sanity check that we've got a list of strings
            for arg in args:
                if not isinstance(arg, six.string_types):
                    raise RuntimeError("Oops, can't handle arg {0} type {1}".format(
                        arg, arg.__class__
                    ))

            subproc = subprocess.Popen(args,
                                       stdout=subprocess.PIPE,
                                       stderr=subprocess.PIPE,
                                       stdin=subprocess.PIPE,
                                       cwd=cwd,
                                       env=env)

        if stdin:
            # Hack: writing to stdin is not deadlock-safe, but it "always" works
            # as long as the input buffer is "small"
            if isinstance(stdin, str):
                subproc.stdin.write(stdin.encode())
            else:
                subproc.stdin.write(stdin)

        proc = LocalRemoteProcess(
            args, subproc, check_status,
            stdout, stderr
        )

        if wait:
            proc.wait()

        return proc
예제 #9
0
 def sh(args):
     args[0:2] = ["cat", ps_ef_output_path]
     debug(args)
     return subprocess.getoutput(quote(args))