Esempio n. 1
0
    async def test_ls_repositories(self, aiohttp_server: _TestServerFactory,
                                   make_client: _MakeClient) -> None:
        JSON = {"repositories": ["bob/alpine", "jill/bananas"]}

        async def handler(request: web.Request) -> web.Response:
            return web.json_response(JSON)

        app = web.Application()
        app.router.add_get("/v2/_catalog", handler)

        srv = await aiohttp_server(app)
        url = "http://platform"
        registry_url = srv.make_url("/v2/")

        async with make_client(url, registry_url=registry_url) as client:
            ret = await client.images.ls()

        registry = _get_url_authority(registry_url)
        assert registry is not None
        assert set(ret) == {
            RemoteImage.new_neuro_image(
                "alpine",
                tag=None,
                owner="bob",
                cluster_name="default",
                registry=registry,
            ),
            RemoteImage.new_neuro_image(
                "bananas",
                tag=None,
                owner="jill",
                cluster_name="default",
                registry=registry,
            ),
        }
Esempio n. 2
0
 def test_parse_as_neuro_image_with_scheme_with_user_no_tag_2(self) -> None:
     image = "image://other-cluster/bob/library/ubuntu"
     parsed = self.parser.parse_as_neuro_image(image)
     assert parsed == RemoteImage.new_neuro_image(
         name="library/ubuntu",
         tag="latest",
         owner="bob",
         cluster_name="other-cluster",
         registry="reg.neu.ro",
     )
Esempio n. 3
0
 def test_convert_to_local_image(self) -> None:
     neuro_image = RemoteImage.new_neuro_image(
         name="ubuntu",
         tag="latest",
         owner="artem",
         cluster_name="test-cluster",
         registry="reg.com",
     )
     local_image = self.parser.convert_to_local_image(neuro_image)
     assert local_image == LocalImage(name="ubuntu", tag="latest")
Esempio n. 4
0
async def test_parse_remote(make_client: _MakeClient) -> None:
    async with make_client("https://api.localhost.localdomain") as client:
        result = client.parse.remote_image("image://test-cluster/bob/bananas:latest")
    assert result == RemoteImage.new_neuro_image(
        name="bananas",
        tag="latest",
        owner="bob",
        registry="registry-dev.neu.ro",
        cluster_name="test-cluster",
    )
Esempio n. 5
0
 def test_as_str_in_neuro_registry_tag_yes(self) -> None:
     image = RemoteImage.new_neuro_image(
         name="ubuntu",
         tag="v10.04",
         owner="me",
         cluster_name="test-cluster",
         registry="registry.io",
     )
     assert str(image) == "image://test-cluster/me/ubuntu:v10.04"
     assert _as_repo_str(image) == "registry.io/me/ubuntu:v10.04"
Esempio n. 6
0
 def test_convert_to_neuro_image(self) -> None:
     local_image = LocalImage(name="ubuntu", tag="latest")
     neuro_image = self.parser.convert_to_neuro_image(local_image)
     assert neuro_image == RemoteImage.new_neuro_image(
         name="ubuntu",
         tag="latest",
         owner="alice",
         cluster_name="test-cluster",
         registry="reg.neu.ro",
     )
Esempio n. 7
0
 def test_parse_as_neuro_image_with_scheme_4_slash_no_cluster_no_tag(
         self) -> None:
     image = "image:////bob/ubuntu"
     parsed = self.parser.parse_as_neuro_image(image)
     assert parsed == RemoteImage.new_neuro_image(
         name="ubuntu",
         tag="latest",
         owner="bob",
         cluster_name="test-cluster",
         registry="reg.neu.ro",
     )
Esempio n. 8
0
 def test_parse_as_neuro_image_with_scheme_3_slash_no_cluster_with_tag_2(
     self, ) -> None:
     image = "image:///bob/library/ubuntu:v10.04"
     parsed = self.parser.parse_as_neuro_image(image)
     assert parsed == RemoteImage.new_neuro_image(
         name="library/ubuntu",
         tag="v10.04",
         owner="bob",
         cluster_name="test-cluster",
         registry="reg.neu.ro",
     )
Esempio n. 9
0
 def test_parse_as_neuro_image_with_scheme_no_slash_no_user_with_tag(
         self) -> None:
     image = "image:ubuntu:v10.04"
     parsed = self.parser.parse_as_neuro_image(image)
     assert parsed == RemoteImage.new_neuro_image(
         name="ubuntu",
         tag="v10.04",
         owner="alice",
         cluster_name="test-cluster",
         registry="reg.neu.ro",
     )
async def test_parse_remote_registry_image(make_client: _MakeClient) -> None:
    async with make_client("https://api.localhost.localdomain",
                           registry_url="http://localhost:5000") as client:
        result = client.parse.remote_image(
            "localhost:5000/bob/library/bananas:latest")
    assert result == RemoteImage.new_neuro_image(
        name="library/bananas",
        tag="latest",
        owner="bob",
        registry="localhost:5000",
        cluster_name="default",
    )
Esempio n. 11
0
 def test_parse_as_neuro_image_allow_tag_false_with_scheme_no_tag(
         self) -> None:
     image = "image:ubuntu"
     parsed = self.parser.parse_as_neuro_image(image,
                                               tag_option=TagOption.DENY)
     assert parsed == RemoteImage.new_neuro_image(
         name="ubuntu",
         tag=None,
         owner="alice",
         cluster_name="test-cluster",
         registry="reg.neu.ro",
     )
Esempio n. 12
0
 async def test_tags_bad_image_without_name(
         self, make_client: _MakeClient) -> None:
     url = URL("http://whatever")
     registry_url = URL("http://whatever-registry")
     async with make_client(url, registry_url=registry_url) as client:
         image = RemoteImage.new_neuro_image(
             name="",
             tag=None,
             owner="me",
             cluster_name="test-cluster",
             registry="reg",
         )
         with pytest.raises(ValueError, match="missing image name"):
             await client.images.tags(image)
Esempio n. 13
0
 def test_parse_remote__registry_has_port__image_in_good_repo(self) -> None:
     my_parser = _ImageNameParser(
         default_user="******",
         default_cluster="test-cluster",
         registry_url=URL("http://localhost:5000"),
     )
     image = "localhost:5000/bob/library/ubuntu:v10.04"
     parsed = my_parser.parse_remote(image)
     assert parsed == RemoteImage.new_neuro_image(
         name="library/ubuntu",
         tag="v10.04",
         owner="bob",
         cluster_name="test-cluster",
         registry="localhost:5000",
     )
Esempio n. 14
0
 def test_no_tty_commit_started(self, capfd: Any) -> None:
     formatter = DockerImageProgress.create(tty=False, quiet=False)
     formatter.commit_started(
         ImageCommitStarted(
             job_id="job-id",
             target_image=RemoteImage.new_neuro_image(
                 name="output",
                 tag="stream",
                 owner="bob",
                 registry="https://registry-dev.neu.ro",
                 cluster_name="test-cluster",
             ),
         ))
     formatter.close()
     out, err = capfd.readouterr()
     assert "Using remote image 'image://test-cluster/bob/output:stream'" in out
     assert f"Creating image from the job container..." in out
     assert err == ""
Esempio n. 15
0
 def test_tty_save(self, capfd: Any, click_tty_emulation: Any) -> None:
     formatter = DockerImageProgress.create(tty=True, quiet=False)
     formatter.save(
         ImageProgressSave(
             "job-id",
             RemoteImage.new_neuro_image(
                 name="output",
                 tag="stream",
                 owner="bob",
                 registry="https://registry-dev.neu.ro",
                 cluster_name="test-cluster",
             ),
         ))
     formatter.close()
     out, err = capfd.readouterr()
     assert err == ""
     assert "job-id" in out
     assert "image://test-cluster/bob/output:stream" in out
     assert CSI in out
Esempio n. 16
0
 def test_no_tty_save(self, capfd: Any) -> None:
     formatter = DockerImageProgress.create(tty=False, quiet=False)
     formatter.save(
         ImageProgressSave(
             "job-id",
             RemoteImage.new_neuro_image(
                 name="output",
                 tag="stream",
                 owner="bob",
                 registry="https://registry-dev.neu.ro",
                 cluster_name="test-cluster",
             ),
         ))
     formatter.close()
     out, err = capfd.readouterr()
     assert (
         "Saving job 'job-id' to image 'image://test-cluster/bob/output:stream'"
         in out)
     assert err == ""
Esempio n. 17
0
 def test_tty_push(self, capfd: Any, click_tty_emulation: Any) -> None:
     formatter = DockerImageProgress.create(tty=True, quiet=False)
     formatter.push(
         ImageProgressPush(
             LocalImage("input", "latest"),
             RemoteImage.new_neuro_image(
                 name="output",
                 tag="stream",
                 owner="bob",
                 registry="https://registry-dev.neu.ro",
                 cluster_name="test-cluster",
             ),
         ))
     formatter.step(ImageProgressStep("message1", "layer1"))
     formatter.step(ImageProgressStep("message2", "layer1"))
     formatter.close()
     out, err = capfd.readouterr()
     assert err == ""
     assert "input:latest" in out
     assert "image://test-cluster/bob/output:stream" in out
     assert "message1" in out
     assert "message2" in out
     assert CSI in out