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.")
Ejemplo n.º 2
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)