'Execute dog command wrapper.'

def _run_dog(self, command, subcommand, *params):

    addr = self.get_addr()
    cmd = (('env', 'LC_ALL=C', 'LANG=C', 'dog', command, subcommand, '-a', addr, '-p', self.port) + params)
    try:
        (_stdout, _stderr) = utils.execute(*cmd)
        if _stderr.startswith(self.DOG_RESP_CONNECTION_ERROR):
            reason = (_('Failed    to    connect    to    sheep    daemon.    addr:    %(addr)s,    port:    %(port)s'), {'addr': addr, 'port': self.port})
            raise exception.SheepdogError(reason=reason)
        return (_stdout, _stderr)
    except OSError as e:
        with excutils.save_and_reraise_exception():
            if (e.errno == errno.ENOENT):
                msg = 'Sheepdog    is    not    installed.    OSError:    command    is    %s.'
            else:
                msg = 'OSError:    command    is    %s.'
            LOG.error(msg, cmd)
    except processutils.ProcessExecutionError as e:
        _stderr = e.stderr
        if _stderr.startswith(self.DOG_RESP_CONNECTION_ERROR):
            reason = (_('Failed    to    connect    to    sheep    daemon.    addr:    %(addr)s,    port:    %(port)s'), {'addr': addr, 'port': self.port})
            raise exception.SheepdogError(reason=reason)
        raise exception.SheepdogCmdError(cmd=e.cmd, exit_code=e.exit_code, stdout=e.stdout.replace('\n', '\\n'), stderr=e.stderr.replace('\n', '\\n'))
