Пример #1
0
    def test_mounts(self):
        with self._create_test_job() as job:
            client = local_client()
            info = client.inspect_container(job.container_id)

            work_mount = None
            resources_mount = None
            output_mount = None
            for mount in info["Mounts"]:
                if mount["Destination"] == DockerJob.WORK_DIR:
                    work_mount = mount
                elif mount["Destination"] == DockerJob.RESOURCES_DIR:
                    resources_mount = mount
                elif mount["Destination"] == DockerJob.OUTPUT_DIR:
                    output_mount = mount

            work_dir = self.work_dir if not is_windows() \
                else nt_path_to_posix_path(self.work_dir)
            resource_dir = self.resources_dir if not is_windows() \
                else nt_path_to_posix_path(self.resources_dir)
            output_dir = self.output_dir if not is_windows()\
                else nt_path_to_posix_path(self.output_dir)

            self.assertIsNotNone(work_mount)
            self.assertEqual(work_mount["Source"], work_dir)
            self.assertTrue(work_mount["RW"])
            self.assertIsNotNone(resources_mount)
            self.assertEqual(resources_mount["Source"], resource_dir)
            self.assertTrue(resources_mount["RW"])
            self.assertIsNotNone(output_mount)
            self.assertEqual(output_mount["Source"], output_dir)
            self.assertTrue(output_mount["RW"])
Пример #2
0
 def test_start(self):
     with self._create_test_job() as job:
         job.start()
         client = local_client()
         info = client.inspect_container(job.container_id)
         self.assertIn("Path", info)
         self.assertEqual(info["Path"], "/usr/local/bin/entrypoint.sh")
         self.assertIn("Args", info)
         self.assertEqual(info["Args"], [job._get_container_script_path()])
Пример #3
0
    def test_cleanup(self):
        with self._create_test_job() as job:
            container_id = job.container_id
            self.assertIsNotNone(container_id)

        self.assertIsNone(job.container_id)
        with self.assertRaises(docker.errors.NotFound):
            client = local_client()
            client.inspect_container(container_id)
Пример #4
0
 def tearDown(self):
     if self.test_job and self.test_job.container:
         client = local_client()
         try:
             client.remove_container(self.test_job.container_id, force=True)
         except docker.errors.APIError:
             pass  # Already removed?
     self.test_job = None
     if self.test_dir:
         shutil.rmtree(self.test_dir)
Пример #5
0
    def test_container_created(self):
        with self._create_test_job() as job:
            self.assertIsNotNone(job.container_id)
            client = local_client()
            info = client.inspect_container(job.container_id)
            self.assertEqual(info["Id"], job.container_id)
            self.assertEqual(info["State"]["Status"], "created")
            self.assertFalse(info["State"]["Running"])

            image_id = client.inspect_image(self.image.name)["Id"]
            self.assertEqual(info["Image"], image_id)
Пример #6
0
 def setUpClass(cls):
     """Disable all tests if Docker or the test image is not available."""
     try:
         client = local_client()
         images = client.images()
         repo_tags = sum([img["RepoTags"]
                          for img in images
                          if img["RepoTags"]], [])
         if cls.TEST_IMAGE not in repo_tags:
             raise unittest.SkipTest(
                 "Skipping tests: Image {} not available".format(
                     cls.TEST_IMAGE))
         cls.TEST_ENV_ID = client.inspect_image(cls.TEST_IMAGE)["Id"]
     except (requests.exceptions.ConnectionError, errors.DockerException):
         raise unittest.SkipTest(
             "Skipping tests: Cannot connect with Docker daemon")
Пример #7
0
    def _create_volume(self, hostname: str, shared_dir: Path) -> str:
        assert self._work_dir is not None
        try:
            relpath = shared_dir.relative_to(self._work_dir)
        except ValueError:
            raise ValueError(
                f'Cannot create docker volume: "{shared_dir}" is not a '
                f'subdirectory of docker work dir ("{self._work_dir}")')

        share_name = smbshare.get_share_name(self._work_dir)
        volume_name = f'{hostname}/{share_name}/{relpath.as_posix()}'

        # Client must be created here, do it in __init__() will not work since
        # environment variables are not set yet when __init__() is called
        client = local_client()
        client.create_volume(name=volume_name,
                             driver=self.VOLUME_DRIVER,
                             driver_opts={
                                 'username': self.DOCKER_USER,
                                 'password': self.DOCKER_PASSWORD
                             })

        return volume_name
Пример #8
0
 def tearDown(self):
     client = local_client()
     for c in client.containers(all=True):
         if c["Image"] == self.TEST_IMAGE:
             client.remove_container(c["Id"], force=True)