def _cleanup_container(self,
                        container: docker.models.containers.Container):
     """Stop the container and remove it's associated storage."""
     try:
         container.stop(timeout=0)
     except (docker.errors.APIError, docker.errors.NotFound):
         raise PipCheckerError(
             error_msg="Error occurs when cleaning up docker container."
             "Container does not exist.")
 def _cleanup_container(self,
                        container: docker.models.containers.Container):
     """Remove the container."""
     try:
         container.stop()
         container.remove()
     except (docker.errors.APIError, docker.errors.NotFound):
         raise PipCheckerError(
             error_msg="Error occurs when cleaning up docker container."
                       "Container does not exist.")
Beispiel #3
0
 def _cleanup_container(self,
                        container: docker.models.containers.Container):
     """Stop the container and remove it's associated storage."""
     try:
         container.stop(timeout=0)
     except (docker.errors.APIError, docker.errors.NotFound):
         raise PipCheckerError(
             error_msg="Error occurs when cleaning up docker container."
             "Container does not exist.")
     except IOError as e:
         # TODO: Log the exception and monitor it after trying to decode
         # this into a requests.exception.* e.g. ReadTimeout. See:
         # http://docs.python-requests.org/en/master/_modules/requests/exceptions/
         raise PipCheckerError(
             error_msg="An error occurred while stopping a docker"
             "container. Error message: {}".format(e))
Beispiel #4
0
    def destroy(container: docker.models.containers.Container) -> None:
        """
        Destroy a container containing a block device that is used with
        loopback devices. Also removes the loopback device.

        Args:
            container: The container to destroy.
        """
        exit_code, output = container.exec_run(
            cmd=['cat', 'loopback_device_path'], )
        assert exit_code == 0, output.decode()

        path = output.decode().rstrip()

        exit_code, output = container.exec_run(cmd=['losetup', '-d', path])
        assert exit_code == 0, output.decode()

        container.stop()
        container.remove(v=True)