Exemple #1
0
def test_wait_for_process_termination(loop):

    process = MagicMock()
    process.returncode = 0
    exec = wait_for_process_termination(process)
    loop.run_until_complete(asyncio. async (exec))

    process = MagicMock()
    process.returncode = None
    exec = wait_for_process_termination(process, timeout=0.5)
    with pytest.raises(asyncio.TimeoutError):
        loop.run_until_complete(asyncio. async (exec))
Exemple #2
0
def test_wait_for_process_termination(loop):

    process = MagicMock()
    process.returncode = 0
    exec = wait_for_process_termination(process)
    loop.run_until_complete(asyncio.async(exec))

    process = MagicMock()
    process.returncode = None
    exec = wait_for_process_termination(process, timeout=0.5)
    with pytest.raises(asyncio.TimeoutError):
        loop.run_until_complete(asyncio.async(exec))
Exemple #3
0
def test_wait_for_process_termination(loop):

    if sys.version_info >= (3, 5):
        # No need for test we use native version
        return
    process = MagicMock()
    process.returncode = 0
    exec = wait_for_process_termination(process)
    loop.run_until_complete(asyncio.async(exec))

    process = MagicMock()
    process.returncode = None
    exec = wait_for_process_termination(process, timeout=0.5)
    with pytest.raises(asyncio.TimeoutError):
        loop.run_until_complete(asyncio.async(exec))
Exemple #4
0
def test_wait_for_process_termination(loop):

    if sys.version_info >= (3, 5):
        # No need for test we use native version
        return
    process = MagicMock()
    process.returncode = 0
    exec = wait_for_process_termination(process)
    loop.run_until_complete(asyncio. async (exec))

    process = MagicMock()
    process.returncode = None
    exec = wait_for_process_termination(process, timeout=0.5)
    with pytest.raises(asyncio.TimeoutError):
        loop.run_until_complete(asyncio. async (exec))
Exemple #5
0
    def stop(self):
        """
        Stops the uBridge hypervisor process.
        """

        if self.is_running():
            log.info("Stopping uBridge process PID={}".format(
                self._process.pid))
            yield from UBridgeHypervisor.stop(self)
            try:
                yield from wait_for_process_termination(self._process,
                                                        timeout=3)
            except asyncio.TimeoutError:
                if self._process.returncode is None:
                    log.warn(
                        "uBridge process {} is still running... killing it".
                        format(self._process.pid))
                    self._process.kill()

        if self._stdout_file and os.access(self._stdout_file, os.W_OK):
            try:
                os.remove(self._stdout_file)
            except OSError as e:
                log.warning(
                    "could not delete temporary uBridge log file: {}".format(
                        e))
        self._started = False
    def stop(self):
        """
        Stops the Dynamips hypervisor process.
        """

        if self.is_running():
            log.info("Stopping Dynamips process PID={}".format(self._process.pid))
            yield from DynamipsHypervisor.stop(self)
            # give some time for the hypervisor to properly stop.
            # time to delete UNIX NIOs for instance.
            yield from asyncio.sleep(0.01)
            try:
                yield from wait_for_process_termination(self._process, timeout=3)
            except asyncio.TimeoutError:
                if self._process.returncode is None:
                    log.warn("Dynamips process {} is still running... killing it".format(self._process.pid))
                    try:
                        self._process.kill()
                    except OSError as e:
                        log.error("Cannot stop the Dynamips process: {}".format(e))
                    if self._process.returncode is None:
                        log.warn('Dynamips hypervisor with PID={} is still running'.format(self._process.pid))

        if self._stdout_file and os.access(self._stdout_file, os.W_OK):
            try:
                os.remove(self._stdout_file)
            except OSError as e:
                log.warning("could not delete temporary Dynamips log file: {}".format(e))
        self._started = False
Exemple #7
0
    def stop(self):
        """
        Stops the Dynamips hypervisor process.
        """

        if self.is_running():
            log.info("Stopping Dynamips process PID={}".format(self._process.pid))
            yield from DynamipsHypervisor.stop(self)
            # give some time for the hypervisor to properly stop.
            # time to delete UNIX NIOs for instance.
            yield from asyncio.sleep(0.01)
            try:
                yield from wait_for_process_termination(self._process, timeout=3)
            except asyncio.TimeoutError:
                if self._process.returncode is None:
                    log.warn("Dynamips process {} is still running... killing it".format(self._process.pid))
                    try:
                        self._process.kill()
                    except OSError as e:
                        log.error("Cannot stop the Dynamips process: {}".format(e))
                    if self._process.returncode is None:
                        log.warn('Dynamips hypervisor with PID={} is still running'.format(self._process.pid))

        if self._stdout_file and os.access(self._stdout_file, os.W_OK):
            try:
                os.remove(self._stdout_file)
            except OSError as e:
                log.warning("could not delete temporary Dynamips log file: {}".format(e))
        self._started = False
Exemple #8
0
    def stop(self):
        """
        Stops the uBridge hypervisor process.
        """

        if self.is_running():
            log.info("Stopping uBridge process PID={}".format(self._process.pid))
            yield from UBridgeHypervisor.stop(self)
            try:
                yield from wait_for_process_termination(self._process, timeout=3)
            except asyncio.TimeoutError:
                if self._process and self._process.returncode is None:
                    log.warn("uBridge process {} is still running... killing it".format(self._process.pid))
                    try:
                        self._process.kill()
                    except ProcessLookupError:
                        pass

        if self._stdout_file and os.access(self._stdout_file, os.W_OK):
            try:
                os.remove(self._stdout_file)
            except OSError as e:
                log.warning("could not delete temporary uBridge log file: {}".format(e))
        self._process = None
        self._started = False
Exemple #9
0
    def stop(self):
        """
        Stops the VPCS process.
        """

        yield from self._stop_ubridge()
        if self.is_running():
            self._terminate_process()
            if self._process.returncode is None:
                try:
                    yield from wait_for_process_termination(self._process,
                                                            timeout=3)
                except asyncio.TimeoutError:
                    if self._process.returncode is None:
                        try:
                            self._process.kill()
                        except OSError as e:
                            log.error(
                                "Cannot stop the VPCS process: {}".format(e))
                        if self._process.returncode is None:
                            log.warn(
                                'VPCS VM "{}" with PID={} is still running'.
                                format(self._name, self._process.pid))

        self._process = None
        self._started = False
        yield from super().stop()
Exemple #10
0
    def stop(self):
        """
        Stops the VPCS process.
        """

        if self.is_running():
            self._terminate_process()
            if self._process.returncode is None:
                try:
                    yield from wait_for_process_termination(self._process, timeout=3)
                except asyncio.TimeoutError:
                    if self._process.returncode is None:
                        log.warn("VPCS process {} is still running... killing it".format(self._process.pid))
                        try:
                            self._process.kill()
                        except OSError as e:
                            raise VPCSError("Can not stop the VPCS process: {}".format(e))

        self._process = None
        self._started = False
        self.status = "stopped"
Exemple #11
0
    def stop(self):
        """
        Stops the VPCS process.
        """

        yield from self._stop_ubridge()
        if self.is_running():
            self._terminate_process()
            if self._process.returncode is None:
                try:
                    yield from wait_for_process_termination(self._process, timeout=3)
                except asyncio.TimeoutError:
                    if self._process.returncode is None:
                        try:
                            self._process.kill()
                        except OSError as e:
                            log.error("Cannot stop the VPCS process: {}".format(e))
                        if self._process.returncode is None:
                            log.warn('VPCS VM "{}" with PID={} is still running'.format(self._name, self._process.pid))

        self._process = None
        self._started = False
        yield from super().stop()