Ejemplo n.º 1
0
    def test_handleLine_errorDetail(self, text: str) -> None:
        json = {"errorDetail": text}
        jsonText = jsonTextFromObject(json)

        handler = DockerPushResponseHandler(repository="repo", tag="latest")

        e = self.assertRaises(DockerServiceError, handler._handleLine,
                              jsonText)
        self.assertEqual(str(e), text)
Ejemplo n.º 2
0
    def test_handleLine_status_image(self, imageID: str) -> None:
        json = {"status": "Preparing", "id": imageID, "progressDetail": {}}
        jsonText = jsonTextFromObject(json)

        handler = DockerPushResponseHandler(repository="repo", tag="latest")

        handler._handleLine(jsonText)

        self.assertEqual(
            handler._statusForImage(imageID).state, ImagePushState.preparing)
Ejemplo n.º 3
0
    def test_handleLine_status_general(self, status: str) -> None:
        tag = "latest"

        # Exclude non-error cases so that we get an error, which has a visible
        # result we can test for.
        assume(
            not status.startswith(DockerPushResponseHandler._repoStatusPrefix))
        assume(not status.startswith(f"{tag}: digest: "))

        json = {"status": status}
        jsonText = jsonTextFromObject(json)

        handler = DockerPushResponseHandler(repository="repo", tag=tag)

        handler._handleLine(jsonText)

        self.assertEqual(handler.errors,
                         [f"Unknown push status message: {status!r}"])
Ejemplo n.º 4
0
    def test_handleLine_aux(self, tag: str, blob: str) -> None:
        digest = f"sha256:{sha256Hash(blob)}"
        size = len(blob)

        json = {
            "aux": {
                "Tag": tag,
                "Digest": digest,
                "Size": size
            },
            "progressDetail": {},
        }
        jsonText = jsonTextFromObject(json)

        handler = DockerPushResponseHandler(repository="repo", tag=tag)

        handler._handleLine(jsonText)

        self.assertEqual(
            handler.result,
            [ImagePushResult(tag=tag, digest=digest, size=size)],
        )
Ejemplo n.º 5
0
    def push(
        self,
        repository: str,
        tag: Optional[str] = None,
        stream: bool = False,
        decode: bool = False,
        auth_config: Optional[Dict[str, str]] = None,
    ) -> Union[bytes, Iterator[bytes]]:
        assert ":" not in repository
        assert tag is not None
        assert stream is True

        assert not decode, "decode not implemented"

        name = f"{repository}:{tag}"

        image = self.get(name)
        ecrImage = MockImage(id=image.id, tags=[name])

        # Untag any existing images with the same name
        existing = self._fromECR(name)
        # No tests currently exercise replace a tag
        assert existing is None, "Replace with below when we hit this"
        # if existing is not None:
        #     existing.tags.remove(name)

        self._parent._cloudImages.append(ecrImage)

        size = len(image.id)
        digest = f"sha256:{sha256Hash(image.id)}"

        # Fake some activity
        json = [
            {
                "status": f"The push refers to a repository [{repository}]"
            },
            {
                "status": "Preparing",
                "id": image.id,
                "progressDetail": {}
            },
            {
                "status": "Waiting",
                "id": image.id,
                "progressDetail": {}
            },
            {
                "status": "Pushing",
                "id": image.id,
                "progressDetail": {
                    "current": 0,
                    "total": size
                },
            },
            {
                "status": "Pushing",
                "id": image.id,
                "progressDetail": {
                    "current": int(size / 2),
                    "total": size
                },
            },
            {
                "status": "Pushing",
                "id": image.id,
                "progressDetail": {
                    "current": size,
                    "total": size
                },
            },
            {
                "status": "Pushed",
                "id": image.id,
                "progressDetail": {}
            },
            {
                "status": f"{tag}: digest: {digest} size: {size}"
            },
            {
                "aux": {
                    "Tag": tag,
                    "Digest": digest,
                    "Size": size
                },
                "progressDetail": {},
            },
        ]

        if self._parent._generateErrors:
            json += [{"errorDetail": self._fakeNewsError}]

        return (jsonTextFromObject(j).encode("utf-8") for j in json)