def test_run_command(self):
        self._create_node()
        self._create_pm()

        self.mox.StubOutWithMock(self.pm, '_set_connection')
        self.mox.StubOutWithMock(processutils, 'ssh_execute')
        self.pm._set_connection().AndReturn(True)
        processutils.ssh_execute(None, '/usr/bin/VBoxManage test return',
                check_exit_code=True).AndReturn(("test\nreturn", ""))
        self.pm._matched_name = 'testNode'
        self.mox.ReplayAll()
        result = self.pm._run_command("test return")
        self.assertEqual(result, ['test', 'return'])
        self.mox.VerifyAll()
Exemplo n.º 2
0
    def test_run_command(self):
        self._create_node()
        self._create_pm()

        self.mox.StubOutWithMock(self.pm, '_set_connection')
        self.mox.StubOutWithMock(processutils, 'ssh_execute')
        self.pm._set_connection().AndReturn(True)
        processutils.ssh_execute(None, '/usr/bin/VBoxManage test return',
                check_exit_code=True).AndReturn(("test\nreturn", ""))
        self.pm._matched_name = 'testNode'
        self.mox.ReplayAll()
        result = self.pm._run_command("test return")
        self.assertEqual(result, ['test', 'return'])
        self.mox.VerifyAll()
    def test_run_command_raises_exception(self):
        self._create_node()
        self._create_pm()

        self.mox.StubOutWithMock(self.pm, '_set_connection')
        self.mox.StubOutWithMock(processutils, 'ssh_execute')

        self.pm._set_connection().AndReturn(True)
        processutils.ssh_execute(None, '/usr/bin/VBoxManage test return',
                check_exit_code=True).\
                AndRaise(processutils.ProcessExecutionError)
        self.mox.ReplayAll()

        result = self.pm._run_command("test return")
        self.assertEqual(result, [])
        self.mox.VerifyAll()
Exemplo n.º 4
0
    def _run_command(self, cmd, check_exit_code=True):
        """Run a remote command using an active ssh connection.

        :param command: String with the command to run.

        If {_NodeName_} is in the command it will get replaced by
        the _matched_name value.

        base_cmd will also get prepended to the command.
        """
        self._set_connection()

        cmd = cmd.replace('{_NodeName_}', self._matched_name)

        cmd = '%s %s' % (self._vp_cmd.base_cmd, cmd)

        try:
            stdout, stderr = processutils.ssh_execute(
                self._connection, cmd, check_exit_code=check_exit_code)
            result = stdout.strip().splitlines()
            LOG.debug('Result for run_command: %s' % result)
        except processutils.ProcessExecutionError:
            result = []
            LOG.exception("Error running command: %s" % cmd)
        return result
    def test_run_command_raises_exception(self):
        self._create_node()
        self._create_pm()

        self.mox.StubOutWithMock(self.pm, '_set_connection')
        self.mox.StubOutWithMock(processutils, 'ssh_execute')

        self.pm._set_connection().AndReturn(True)
        processutils.ssh_execute(None, '/usr/bin/VBoxManage test return',
                check_exit_code=True).\
                AndRaise(processutils.ProcessExecutionError)
        self.mox.ReplayAll()

        result = self.pm._run_command("test return")
        self.assertEqual(result, [])
        self.mox.VerifyAll()
Exemplo n.º 6
0
    def _run_command(self, cmd, check_exit_code=True):
        """Run a remote command using an active ssh connection.

        :param command: String with the command to run.

        If {_NodeName_} is in the command it will get replaced by
        the _matched_name value.

        base_cmd will also get prepended to the command.
        """
        self._set_connection()

        cmd = cmd.replace('{_NodeName_}', self._matched_name)

        cmd = '%s %s' % (self._vp_cmd.base_cmd, cmd)

        try:
            stdout, stderr = processutils.ssh_execute(
                self._connection, cmd, check_exit_code=check_exit_code)
            result = stdout.strip().splitlines()
            LOG.debug(_('Result for run_command: %s'), result)
        except processutils.ProcessExecutionError:
            result = []
            LOG.exception(_("Error running command: %s"), cmd)
        return result
    def test_activate_node_with_exception(self):
        self._create_node()
        self._create_pm()

        self.mox.StubOutWithMock(self.pm, '_check_for_node')
        self.mox.StubOutWithMock(processutils, 'ssh_execute')

        self.pm._check_for_node().AndReturn(['"testNode"'])
        self.pm._check_for_node().AndReturn(['"testNode"'])
        processutils.ssh_execute('test', '/usr/bin/VBoxManage startvm ',
                check_exit_code=True).\
                AndRaise(processutils.ProcessExecutionError)
        processutils.ssh_execute('test', '/usr/bin/VBoxManage list runningvms',
                check_exit_code=True).\
                AndRaise(processutils.ProcessExecutionError)

        self.mox.ReplayAll()
        self.pm._connection = 'test'
        state = self.pm.activate_node()
        self.assertEqual(state, 'error')
        self.mox.VerifyAll()
    def test_activate_node_with_exception(self):
        self._create_node()
        self._create_pm()

        self.mox.StubOutWithMock(self.pm, '_check_for_node')
        self.mox.StubOutWithMock(processutils, 'ssh_execute')

        self.pm._check_for_node().AndReturn(['"testNode"'])
        self.pm._check_for_node().AndReturn(['"testNode"'])
        processutils.ssh_execute('test', '/usr/bin/VBoxManage startvm ',
                check_exit_code=True).\
                AndRaise(processutils.ProcessExecutionError)
        processutils.ssh_execute('test', '/usr/bin/VBoxManage list runningvms',
                check_exit_code=True).\
                AndRaise(processutils.ProcessExecutionError)

        self.mox.ReplayAll()
        self.pm._connection = 'test'
        state = self.pm.activate_node()
        self.assertEqual(state, 'error')
        self.mox.VerifyAll()
Exemplo n.º 9
0
    def run_vios_command(self, cmd, check_exit_code=True):
        """Run a remote command using an active ssh connection.

        :param command: String with the command to run.
        """
        self._set_connection()
        stdout, stderr = processutils.ssh_execute(self._connection, cmd, check_exit_code=check_exit_code)

        error_text = stderr.strip()
        if error_text:
            LOG.warn(
                _('Found error stream for command "%(cmd)s": ' "%(error_text)s"), {"cmd": cmd, "error_text": error_text}
            )

        return stdout.strip().splitlines()
Exemplo n.º 10
0
    def run_vios_command(self, cmd, check_exit_code=True):
        """Run a remote command using an active ssh connection.

        :param command: String with the command to run.
        """
        self._set_connection()
        stdout, stderr = processutils.ssh_execute(
            self._connection, cmd, check_exit_code=check_exit_code)

        error_text = stderr.strip()
        if error_text:
            LOG.debug(
                _("Found error stream for command \"%(cmd)s\": %(error_text)s")
                % locals())

        return stdout.strip().splitlines()
Exemplo n.º 11
0
    def run_vios_command(self, cmd, check_exit_code=True):
        """Run a remote command using an active ssh connection.

        :param command: String with the command to run.
        """
        self._set_connection()
        stdout, stderr = processutils.ssh_execute(
            self._connection, cmd, check_exit_code=check_exit_code)

        error_text = stderr.strip()
        if error_text:
            LOG.debug(
                _("Found error stream for command \"%(cmd)s\": %(error_text)s")
                % locals())

        return stdout.strip().splitlines()
Exemplo n.º 12
0
 def run_command(conn_obj, cmd):
     stdout, stderr = processutils.ssh_execute(conn_obj, cmd)
     return stdout.strip().splitlines()
Exemplo n.º 13
0
 def run_command(conn_obj, cmd):
     stdout, stderr = processutils.ssh_execute(conn_obj, cmd)
     return stdout.strip().splitlines()