Skip to content

Commit

Permalink
Merge branch 'master' into attach
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov committed May 20, 2020
2 parents bd336db + 186b424 commit c999308
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 81 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.D/1505.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed parsing image URIs with the single slash after scheme, like `image:/otheruser/imagename`.
5 changes: 2 additions & 3 deletions neuromation/api/parsing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,13 @@ def _parse_as_neuro_image(

registry = self._registry
name, tag = self._split_image_name(url.path.lstrip("/"), default_tag)
if url.host:
cluster_name = url.host
cluster_name = url.host or self._default_cluster
if url.path.startswith("/"):
owner, _, name = name.partition("/")
if not name:
raise ValueError("no image name specified")
else:
owner = self._default_user
cluster_name = self._default_cluster
return RemoteImage(
name=name,
tag=tag,
Expand Down
4 changes: 2 additions & 2 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ async_generator==1.10; python_version<"3.7"
python-jose==3.1.0
python-dateutil==2.8.1
yarl==1.4.2
aiodocker==0.18.7
aiodocker==0.18.8
click==7.1.2
colorama==0.4.3; platform_system=="Windows"
humanize==2.3.0
Expand All @@ -14,6 +14,6 @@ certifi==2020.4.5.1
psutil==5.7.0
typing_extensions==3.7.4.2
wcwidth==0.1.9
toml==0.10.0
toml==0.10.1
requests==2.23.0
-e .
2 changes: 1 addition & 1 deletion requirements/ci.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pytest-timeout==1.3.4
flake8==3.7.9
isort==4.3.21
black==19.10b0
setuptools==46.1.3
setuptools==46.4.0
wheel==0.34.2
cmarkgfm==0.4.2
twine==3.1.1
Expand Down
158 changes: 83 additions & 75 deletions tests/api/test_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,188 +372,196 @@ def test_parse_as_neuro_image_with_scheme_no_slash_no_user_with_tag_2(self) -> N
registry="reg.neu.ro",
)

def test_parse_as_neuro_image_with_scheme_1_slash_no_user_no_tag(self) -> None:
def test_parse_as_neuro_image_with_scheme_1_slash_no_cluster_no_name_no_tag(
self,
) -> None:
image = "image:/ubuntu"
with pytest.raises(ValueError, match="no image name specified"):
self.parser.parse_as_neuro_image(image)

def test_parse_as_neuro_image_with_scheme_1_slash_no_cluster_no_tag(self) -> None:
image = "image:/bob/ubuntu"
parsed = self.parser.parse_as_neuro_image(image)
assert parsed == RemoteImage(
name="ubuntu",
tag="latest",
owner="alice",
owner="bob",
cluster_name="test-cluster",
registry="reg.neu.ro",
)

def test_parse_as_neuro_image_with_scheme_1_slash_no_user_no_tag_2(self) -> None:
image = "image:/library/ubuntu"
def test_parse_as_neuro_image_with_scheme_1_slash_no_cluster_no_tag_2(self) -> None:
image = "image:/bob/library/ubuntu"
parsed = self.parser.parse_as_neuro_image(image)
assert parsed == RemoteImage(
name="library/ubuntu",
tag="latest",
owner="alice",
owner="bob",
cluster_name="test-cluster",
registry="reg.neu.ro",
)

def test_parse_as_neuro_image_with_scheme_1_slash_no_user_with_tag(self) -> None:
def test_parse_as_neuro_image_with_scheme_1_slash_no_cluster_no_name_with_tag(
self,
) -> None:
image = "image:/ubuntu:v10.04"
with pytest.raises(ValueError, match="no image name specified"):
self.parser.parse_as_neuro_image(image)

def test_parse_as_neuro_image_with_scheme_1_slash_no_cluster_with_tag(self) -> None:
image = "image:/bob/ubuntu:v10.04"
parsed = self.parser.parse_as_neuro_image(image)
assert parsed == RemoteImage(
name="ubuntu",
tag="v10.04",
owner="alice",
owner="bob",
cluster_name="test-cluster",
registry="reg.neu.ro",
)

def test_parse_as_neuro_image_with_scheme_1_slash_no_user_with_tag_2(self) -> None:
image = "image:/library/ubuntu:v10.04"
def test_parse_as_neuro_image_with_scheme_1_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(
name="library/ubuntu",
tag="v10.04",
owner="alice",
owner="bob",
cluster_name="test-cluster",
registry="reg.neu.ro",
)

def test_parse_as_neuro_image_with_scheme_2_slash_user_no_tag_fail(self) -> None:
def test_parse_as_neuro_image_with_scheme_2_slash_cluster_user_no_name_no_tag_fail(
self,
) -> None:
image = "image://other-cluster/ubuntu"
with pytest.raises(ValueError, match="no image name specified"):
self.parser.parse_as_neuro_image(image)

def test_parse_as_neuro_image_with_scheme_2_slash_user_with_tag_fail(self) -> None:
def test_parse_as_neuro_image_with_scheme_2_slash_cluster_no_user_with_tag_fail(
self,
) -> None:
image = "image://ubuntu:v10.04"
with pytest.raises(ValueError, match="port can't be converted to integer"):
self.parser.parse_as_neuro_image(image)

def test_parse_as_neuro_image_with_scheme_3_slash_no_user_no_tag(self) -> None:
def test_parse_as_neuro_image_with_scheme_3_slash_no_cluster_no_name_no_tag(
self,
) -> None:
image = "image:///ubuntu"
with pytest.raises(ValueError, match="no image name specified"):
self.parser.parse_as_neuro_image(image)

def test_parse_as_neuro_image_with_scheme_3_slash_no_cluster_no_tag(self) -> None:
image = "image:///bob/ubuntu"
parsed = self.parser.parse_as_neuro_image(image)
assert parsed == RemoteImage(
name="ubuntu",
tag="latest",
owner="alice",
owner="bob",
cluster_name="test-cluster",
registry="reg.neu.ro",
)

def test_parse_as_neuro_image_with_scheme_3_slash_no_user_no_tag_2(self) -> None:
image = "image:///library/ubuntu"
def test_parse_as_neuro_image_with_scheme_3_slash_no_cluster_no_tag_2(self) -> None:
image = "image:///bob/library/ubuntu"
parsed = self.parser.parse_as_neuro_image(image)
assert parsed == RemoteImage(
name="library/ubuntu",
tag="latest",
owner="alice",
owner="bob",
cluster_name="test-cluster",
registry="reg.neu.ro",
)

def test_parse_as_neuro_image_with_scheme_3_slash_no_user_with_tag(self) -> None:
def test_parse_as_neuro_image_with_scheme_3_slash_no_cluster_no_name_with_tag(
self,
) -> None:
image = "image:///ubuntu:v10.04"
with pytest.raises(ValueError, match="no image name specified"):
self.parser.parse_as_neuro_image(image)

def test_parse_as_neuro_image_with_scheme_3_slash_no_cluster_with_tag(self) -> None:
image = "image:///bob/ubuntu:v10.04"
parsed = self.parser.parse_as_neuro_image(image)
assert parsed == RemoteImage(
name="ubuntu",
tag="v10.04",
owner="alice",
owner="bob",
cluster_name="test-cluster",
registry="reg.neu.ro",
)

def test_parse_as_neuro_image_with_scheme_3_slash_no_user_with_tag_2(self) -> None:
image = "image:///library/ubuntu:v10.04"
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(
name="library/ubuntu",
tag="v10.04",
owner="alice",
owner="bob",
cluster_name="test-cluster",
registry="reg.neu.ro",
)

def test_parse_as_neuro_image_with_scheme_4_slash_no_user_with_tag(self) -> None:
def test_parse_as_neuro_image_with_scheme_4_slash_no_cluster_no_name_with_tag(
self,
) -> None:
image = "image:////ubuntu:v10.04"
with pytest.raises(ValueError, match="no image name specified"):
self.parser.parse_as_neuro_image(image)

def test_parse_as_neuro_image_with_scheme_4_slash_no_cluster_with_tag(self) -> None:
image = "image:////bob/ubuntu:v10.04"
parsed = self.parser.parse_as_neuro_image(image)
assert parsed == RemoteImage(
name="ubuntu",
tag="v10.04",
owner="alice",
owner="bob",
cluster_name="test-cluster",
registry="reg.neu.ro",
)

def test_parse_as_neuro_image_with_scheme_4_slash_no_user_with_tag_2(self) -> None:
image = "image:////library/ubuntu:v10.04"
def test_parse_as_neuro_image_with_scheme_4_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(
name="library/ubuntu",
tag="v10.04",
owner="alice",
owner="bob",
cluster_name="test-cluster",
registry="reg.neu.ro",
)

def test_parse_as_neuro_image_with_scheme_4_slash_no_user_no_tag(self) -> None:
def test_parse_as_neuro_image_with_scheme_4_slash_no_cluster_no_name_no_tag(
self,
) -> None:
image = "image:////ubuntu"
parsed = self.parser.parse_as_neuro_image(image)
assert parsed == RemoteImage(
name="ubuntu",
tag="latest",
owner="alice",
cluster_name="test-cluster",
registry="reg.neu.ro",
)

def test_parse_as_neuro_image_with_scheme_4_slash_no_user_no_tag_2(self) -> None:
image = "image:////library/ubuntu"
parsed = self.parser.parse_as_neuro_image(image)
assert parsed == RemoteImage(
name="library/ubuntu",
tag="latest",
owner="alice",
cluster_name="test-cluster",
registry="reg.neu.ro",
)
with pytest.raises(ValueError, match="no image name specified"):
self.parser.parse_as_neuro_image(image)

def test_parse_as_neuro_image_with_scheme_tilde_user_no_tag(self) -> None:
image = "image:ubuntu"
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(
name="ubuntu",
tag="latest",
owner="alice",
owner="bob",
cluster_name="test-cluster",
registry="reg.neu.ro",
)

def test_parse_as_neuro_image_with_scheme_tilde_user_no_tag_2(self) -> None:
image = "image:library/ubuntu"
def test_parse_as_neuro_image_with_scheme_4_slash_no_cluster_no_tag_2(self) -> None:
image = "image:////bob/library/ubuntu"
parsed = self.parser.parse_as_neuro_image(image)
assert parsed == RemoteImage(
name="library/ubuntu",
tag="latest",
owner="alice",
cluster_name="test-cluster",
registry="reg.neu.ro",
)

def test_parse_as_neuro_image_with_scheme_tilde_user_with_tag(self) -> None:
image = "image:ubuntu:v10.04"
parsed = self.parser.parse_as_neuro_image(image)
assert parsed == RemoteImage(
name="ubuntu",
tag="v10.04",
owner="alice",
cluster_name="test-cluster",
registry="reg.neu.ro",
)

def test_parse_as_neuro_image_with_scheme_tilde_user_with_tag_2(self) -> None:
image = "image:library/ubuntu:v10.04"
parsed = self.parser.parse_as_neuro_image(image)
assert parsed == RemoteImage(
name="library/ubuntu",
tag="v10.04",
owner="alice",
owner="bob",
cluster_name="test-cluster",
registry="reg.neu.ro",
)
Expand Down

0 comments on commit c999308

Please sign in to comment.