From b38ca705c6cddbf4c8e992aefc8662dc3d5a4907 Mon Sep 17 00:00:00 2001 From: Yevhenii Semendiak Date: Sun, 23 Apr 2023 19:11:12 +0300 Subject: [PATCH 1/5] add support for project names in disks --- CLI.md | 2 + neuro-cli/docs/disk.md | 2 + neuro-cli/src/neuro_cli/disks.py | 42 +++++++++++++++---- neuro-cli/src/neuro_cli/formatters/disks.py | 2 + neuro-cli/src/neuro_cli/formatters/utils.py | 11 ++++- neuro-cli/src/neuro_cli/utils.py | 2 +- .../ascii/test_disk_formatter_0.ref | 20 +++++---- .../ascii/test_disks_formatter_long_0.ref | 6 +-- .../ascii/test_disks_formatter_short_0.ref | 12 +++--- neuro-cli/tests/unit/formatters/test_disks.py | 5 +++ neuro-cli/tests/unit/test_shell_completion.py | 3 ++ neuro-sdk/src/neuro_sdk/_config.py | 11 +++++ neuro-sdk/src/neuro_sdk/_disks.py | 23 ++++++++-- neuro-sdk/src/neuro_sdk/_jobs.py | 5 ++- neuro-sdk/src/neuro_sdk/_url_utils.py | 4 +- neuro-sdk/tests/test_disks.py | 13 ++++++ neuro-sdk/tests/test_jobs.py | 4 +- 17 files changed, 131 insertions(+), 36 deletions(-) diff --git a/CLI.md b/CLI.md index f4343d067..279c2222d 100644 --- a/CLI.md +++ b/CLI.md @@ -2103,6 +2103,7 @@ Name | Description| |_--cluster CLUSTER_|Perform in a specified cluster \(the current cluster by default).| |_--name NAME_|Optional disk name| |_--org ORG_|Perform in a specified org \(the current org by default).| +|_--project PROJECT_|Create disk in a specified project \(the current project by default).| |_\--timeout-unused TIMEDELTA_|Optional disk lifetime limit after last usage in the format '1d2h3m4s' \(some parts may be missing). Set '0' to disable. Default value '1d' can be changed in the user config.| @@ -2147,6 +2148,7 @@ Name | Description| |_--cluster CLUSTER_|Look on a specified cluster \(the current cluster by default).| |_\--full-uri_|Output full disk URI.| |_\--long-format_|Output all info about disk.| +|_--project PROJECT_|Look on a specified project \(all projects in current cluster by default).| diff --git a/neuro-cli/docs/disk.md b/neuro-cli/docs/disk.md index 37f020e78..3afaabbd1 100644 --- a/neuro-cli/docs/disk.md +++ b/neuro-cli/docs/disk.md @@ -64,6 +64,7 @@ $ neuro disk create 500M | _--cluster CLUSTER_ | Perform in a specified cluster \(the current cluster by default\). | | _--name NAME_ | Optional disk name | | _--org ORG_ | Perform in a specified org \(the current org by default\). | +| _--project PROJECT_ | Create disk in a specified project \(the current project by default\). | | _--timeout-unused TIMEDELTA_ | Optional disk lifetime limit after last usage in the format '1d2h3m4s' \(some parts may be missing\). Set '0' to disable. Default value '1d' can be changed in the user config. | @@ -112,6 +113,7 @@ List disks. | _--cluster CLUSTER_ | Look on a specified cluster \(the current cluster by default\). | | _--full-uri_ | Output full disk URI. | | _--long-format_ | Output all info about disk. | +| _--project PROJECT_ | Look on a specified project \(all projects in current cluster by default\). | diff --git a/neuro-cli/src/neuro_cli/disks.py b/neuro-cli/src/neuro_cli/disks.py index e2c3815f6..775d9f9f4 100644 --- a/neuro-cli/src/neuro_cli/disks.py +++ b/neuro-cli/src/neuro_cli/disks.py @@ -1,11 +1,14 @@ from datetime import timedelta -from typing import Optional, Sequence +from typing import Optional, Sequence, Union + +from yarl import URL from neuro_cli.click_types import ( CLUSTER, DISK, DISK_NAME, ORG, + PROJECT, PlatformURIType, UnionType, ) @@ -39,10 +42,19 @@ def disk() -> None: type=CLUSTER, help="Look on a specified cluster (the current cluster by default).", ) +@option( + "--project", + type=PROJECT, + help="Look on a specified project (all projects in current cluster by default).", +) @option("--full-uri", is_flag=True, help="Output full disk URI.") @option("--long-format", is_flag=True, help="Output all info about disk.") async def ls( - root: Root, full_uri: bool, long_format: bool, cluster: Optional[str] + root: Root, + full_uri: bool, + long_format: bool, + cluster: Optional[str], + project: Optional[str], ) -> None: """ List disks. @@ -57,6 +69,7 @@ async def ls( username=root.client.username, cluster_name=cluster or root.client.cluster_name, org_name=root.client.config.org_name, + project_name=project or root.client.config.project_name, ) disks_fmtr = DisksFormatter( uri_fmtr, @@ -66,7 +79,9 @@ async def ls( disks = [] with root.status("Fetching disks") as status: - async with root.client.disks.list(cluster_name=cluster) as it: + async with root.client.disks.list( + cluster_name=cluster, project_name=project + ) as it: async for disk in it: disks.append(disk) status.update(f"Fetching disks ({len(disks)} loaded)") @@ -105,6 +120,11 @@ async def ls( help="Optional disk name", default=None, ) +@option( + "--project", + type=PROJECT, + help="Create disk in a specified project (the current project by default).", +) async def create( root: Root, storage: str, @@ -112,6 +132,7 @@ async def create( name: Optional[str] = None, cluster: Optional[str] = None, org: Optional[str] = None, + project: Optional[str] = None, ) -> None: """ Create a disk @@ -146,6 +167,7 @@ async def create( timeout_unused=disk_timeout_unused, name=name, cluster_name=cluster, + project_name=project, org_name=org_name, ) disk_fmtr = DiskFormatter( @@ -165,17 +187,23 @@ async def create( "disk", type=UnionType("disk", PlatformURIType(allowed_schemes=("disk",)), DISK) ) @option("--full-uri", is_flag=True, help="Output full disk URI.") -async def get(root: Root, cluster: Optional[str], disk: str, full_uri: bool) -> None: +async def get( + root: Root, cluster: Optional[str], disk: Union[str, URL], full_uri: bool +) -> None: """ Get disk DISK_ID. """ - disk_id = await resolve_disk(disk, client=root.client, cluster_name=cluster) - disk_obj = await root.client.disks.get(disk_id, cluster_name=cluster) + if isinstance(disk, URL): + disk_str = disk.parts[-1] + else: + disk_str = disk + disk_obj = await root.client.disks.get(disk_str, cluster_name=cluster) + if full_uri: uri_fmtr: URIFormatter = str else: uri_fmtr = uri_formatter( - username=root.client.username, + project_name=root.client.config.project_name, cluster_name=cluster or root.client.cluster_name, org_name=root.client.config.org_name, ) diff --git a/neuro-cli/src/neuro_cli/formatters/disks.py b/neuro-cli/src/neuro_cli/formatters/disks.py index 53a9747f5..9f77c915d 100644 --- a/neuro-cli/src/neuro_cli/formatters/disks.py +++ b/neuro-cli/src/neuro_cli/formatters/disks.py @@ -103,6 +103,8 @@ def __call__(self, disk: Disk) -> RenderableType: if disk.name: table.add_row("Name", disk.name) table.add_row("Org name", disk.org_name or ORG.NO_ORG_STR) + table.add_row("Project name", disk.project_name) + table.add_row("Owner", disk.owner) table.add_row("Status", disk.status.value) table.add_row("Created at", self._datetime_formatter(disk.created_at)) table.add_row("Last used", self._datetime_formatter(disk.last_usage)) diff --git a/neuro-cli/src/neuro_cli/formatters/utils.py b/neuro-cli/src/neuro_cli/formatters/utils.py index 6a368233c..c1cc5f961 100644 --- a/neuro-cli/src/neuro_cli/formatters/utils.py +++ b/neuro-cli/src/neuro_cli/formatters/utils.py @@ -12,7 +12,10 @@ def uri_formatter( - username: str, cluster_name: str, org_name: Optional[str] + cluster_name: str, + org_name: Optional[str], + username: Optional[str] = None, + project_name: Optional[str] = None, ) -> URIFormatter: def formatter(uri: URL) -> str: if uri.scheme in SCHEMES: @@ -27,7 +30,11 @@ def formatter(uri: URL) -> str: owner, _, rest = path.partition("/") else: owner = owner_or_org - if owner == username: + # TODO (Y.S.): remove this check and use project_name parameter + # when the last patch for projects is done + project = project_name or username + assert project, "Ensure you've set project_name" + if owner == project: path = rest.lstrip("/") else: path = "/" + path diff --git a/neuro-cli/src/neuro_cli/utils.py b/neuro-cli/src/neuro_cli/utils.py index d79686a2c..128baeb62 100644 --- a/neuro-cli/src/neuro_cli/utils.py +++ b/neuro-cli/src/neuro_cli/utils.py @@ -521,7 +521,7 @@ async def resolve_disk( return disk.id except ResourceNotFound: pass - raise ValueError(f"Failed to resolve job {id_or_name_or_uri}") + raise ValueError(f"Failed to resolve disk {id_or_name_or_uri}") else: disk = await client.disks.get(id_or_name, cluster_name) return disk.id diff --git a/neuro-cli/tests/unit/formatters/ascii/test_disk_formatter_0.ref b/neuro-cli/tests/unit/formatters/ascii/test_disk_formatter_0.ref index 509a5aeaf..8b25a5769 100644 --- a/neuro-cli/tests/unit/formatters/ascii/test_disk_formatter_0.ref +++ b/neuro-cli/tests/unit/formatters/ascii/test_disk_formatter_0.ref @@ -1,10 +1,12 @@ -Id disk - Storage 12.8 GB - Used - Uri disk://cluster/user/disk - Name test-disk - Org name NO_ORG - Status Ready - Created at Mar 04 2017 - Last used Apr 04 2017 +Id disk + Storage 12.8 GB + Used + Uri disk://cluster/test-project/disk + Name test-disk + Org name NO_ORG + Project name test-project + Owner user + Status Ready + Created at Mar 04 2017 + Last used Apr 04 2017 Timeout unused 1d2h3m4s diff --git a/neuro-cli/tests/unit/formatters/ascii/test_disks_formatter_long_0.ref b/neuro-cli/tests/unit/formatters/ascii/test_disks_formatter_long_0.ref index 67fd0216d..b809490af 100644 --- a/neuro-cli/tests/unit/formatters/ascii/test_disks_formatter_long_0.ref +++ b/neuro-cli/tests/unit/formatters/ascii/test_disks_formatter_long_0.ref @@ -1,6 +1,6 @@ Id Name Storage Used Uri Status Org name Created at Last used Timeout unused ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - disk-1 53.7 GB disk://cluster/user/… Pending NO_ORG Mar 04 2017 Mar 08 2017 no limit - disk-2 52.4 MB disk://cluster/user/… Ready NO_ORG Apr 04 2017 2d3h4m5s + disk-1 53.7 GB disk://cluster/test-… Pending NO_ORG Mar 04 2017 Mar 08 2017 no limit + disk-2 52.4 MB disk://cluster/anoth… Ready NO_ORG Apr 04 2017 2d3h4m5s disk-3 51.2 kB disk://cluster/test-… Ready test-org May 04 2017 no limit - disk-4 50 Bytes disk://cluster/user/… Broken NO_ORG Jun 04 2017 no limit + disk-4 50 Bytes disk://cluster/test-… Broken NO_ORG Jun 04 2017 no limit diff --git a/neuro-cli/tests/unit/formatters/ascii/test_disks_formatter_short_0.ref b/neuro-cli/tests/unit/formatters/ascii/test_disks_formatter_short_0.ref index 0efd48e07..f4f601dad 100644 --- a/neuro-cli/tests/unit/formatters/ascii/test_disks_formatter_short_0.ref +++ b/neuro-cli/tests/unit/formatters/ascii/test_disks_formatter_short_0.ref @@ -1,6 +1,6 @@ -Id Name Storage Used Uri Status - ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - disk-1 53.7 GB disk://cluster/user/disk-1 Pending - disk-2 52.4 MB disk://cluster/user/disk-2 Ready - disk-3 51.2 kB disk://cluster/test-org/user/disk-3 Ready - disk-4 50 Bytes disk://cluster/user/disk-4 Broken +Id Name Storage Used Uri Status + ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + disk-1 53.7 GB disk://cluster/test-project/disk-1 Pending + disk-2 52.4 MB disk://cluster/another-project/disk-2 Ready + disk-3 51.2 kB disk://cluster/test-org/another-project/disk-3 Ready + disk-4 50 Bytes disk://cluster/test-project/disk-4 Broken diff --git a/neuro-cli/tests/unit/formatters/test_disks.py b/neuro-cli/tests/unit/formatters/test_disks.py index c1c462898..89a2b78d8 100644 --- a/neuro-cli/tests/unit/formatters/test_disks.py +++ b/neuro-cli/tests/unit/formatters/test_disks.py @@ -20,6 +20,7 @@ def test_disk_formatter(rich_cmp: Any) -> None: name="test-disk", storage=int(11.93 * (1024**3)), owner="user", + project_name="test-project", status=Disk.Status.READY, cluster_name="cluster", org_name=None, @@ -38,6 +39,7 @@ def disks_list() -> List[Disk]: id="disk-1", storage=50 * (1024**3), owner="user", + project_name="test-project", status=Disk.Status.PENDING, cluster_name="cluster", org_name=None, @@ -48,6 +50,7 @@ def disks_list() -> List[Disk]: id="disk-2", storage=50 * (1024**2), owner="user", + project_name="another-project", status=Disk.Status.READY, cluster_name="cluster", org_name=None, @@ -58,6 +61,7 @@ def disks_list() -> List[Disk]: id="disk-3", storage=50 * (1024**1), owner="user", + project_name="another-project", status=Disk.Status.READY, cluster_name="cluster", org_name="test-org", @@ -67,6 +71,7 @@ def disks_list() -> List[Disk]: id="disk-4", storage=50, owner="user", + project_name="test-project", status=Disk.Status.BROKEN, cluster_name="cluster", org_name=None, diff --git a/neuro-cli/tests/unit/test_shell_completion.py b/neuro-cli/tests/unit/test_shell_completion.py index 8d8583f6b..8000336df 100644 --- a/neuro-cli/tests/unit/test_shell_completion.py +++ b/neuro-cli/tests/unit/test_shell_completion.py @@ -1041,6 +1041,7 @@ def test_disk_autocomplete(run_autocomplete: _RunAC) -> None: id="disk-123", storage=500, owner="user", + project_name="test-project", status=Disk.Status.READY, cluster_name="default", org_name=None, @@ -1055,6 +1056,7 @@ def test_disk_autocomplete(run_autocomplete: _RunAC) -> None: status=Disk.Status.PENDING, cluster_name="default", org_name="test-org", + project_name="another-project", created_at=created_at, last_usage=last_usage, timeout_unused=timedelta(hours=1), @@ -1068,6 +1070,7 @@ def test_disk_autocomplete(run_autocomplete: _RunAC) -> None: owner="user", status=Disk.Status.PENDING, cluster_name="other", + project_name="test-project", org_name="test-org", created_at=created_at, last_usage=last_usage, diff --git a/neuro-sdk/src/neuro_sdk/_config.py b/neuro-sdk/src/neuro_sdk/_config.py index 7f353b137..76dd655cc 100644 --- a/neuro-sdk/src/neuro_sdk/_config.py +++ b/neuro-sdk/src/neuro_sdk/_config.py @@ -158,6 +158,17 @@ def project_name(self) -> Optional[str]: name = self._config_data.project_name return name + @property + def project_name_or_raise(self) -> str: + name = self.project_name + if not name: + raise RuntimeError( + "The current project is not selected. " + "Please create one with 'neuro admin add-project', or " + "switch to existing with 'neuro config switch-project'." + ) + return name + def _get_user_project_name(self) -> Optional[str]: config = self._get_user_config() section = config.get("job") diff --git a/neuro-sdk/src/neuro_sdk/_disks.py b/neuro-sdk/src/neuro_sdk/_disks.py index 4a519f7c8..8326c56ba 100644 --- a/neuro-sdk/src/neuro_sdk/_disks.py +++ b/neuro-sdk/src/neuro_sdk/_disks.py @@ -28,6 +28,7 @@ class Disk: owner: str status: "Disk.Status" cluster_name: str + project_name: str org_name: Optional[str] created_at: datetime last_usage: Optional[datetime] = None @@ -40,7 +41,7 @@ def uri(self) -> URL: base = f"disk://{self.cluster_name}" if self.org_name: base += f"/{self.org_name}" - return URL(f"{base}/{self.owner}/{self.id}") + return URL(f"{base}/{self.project_name}/{self.id}") class Status(Enum): PENDING = "Pending" @@ -70,6 +71,7 @@ def _parse_disk_payload(self, payload: Mapping[str, Any]) -> Disk: storage=payload["storage"], used_bytes=payload.get("used_bytes"), owner=payload["owner"], + project_name=payload["project_name"], name=payload.get("name"), status=Disk.Status(payload["status"]), cluster_name=self._config.cluster_name, @@ -85,12 +87,25 @@ def _get_disks_url(self, cluster_name: Optional[str]) -> URL: return self._config.get_cluster(cluster_name).disks_url @asyncgeneratorcontextmanager - async def list(self, cluster_name: Optional[str] = None) -> AsyncIterator[Disk]: + async def list( + self, + cluster_name: Optional[str] = None, + org_name: Optional[str] = None, + project_name: Optional[str] = None, + ) -> AsyncIterator[Disk]: url = self._get_disks_url(cluster_name) + params = {} + org = org_name or self._config.org_name + if org: + params["org_name"] = org + if project_name: + params["project_name"] = project_name + auth = await self._config._api_auth() - async with self._core.request("GET", url, auth=auth) as resp: + async with self._core.request("GET", url, auth=auth, params=params) as resp: ret = await resp.json() for disk_payload in ret: + print(disk_payload) yield self._parse_disk_payload(disk_payload) async def create( @@ -99,6 +114,7 @@ async def create( timeout_unused: Optional[timedelta] = None, name: Optional[str] = None, cluster_name: Optional[str] = None, + project_name: Optional[str] = None, org_name: Union[Optional[str], OrgNameSentinel] = ORG_NAME_SENTINEL, ) -> Disk: url = self._get_disks_url(cluster_name) @@ -107,6 +123,7 @@ async def create( "storage": storage, "life_span": timeout_unused.total_seconds() if timeout_unused else None, "name": name, + "project_name": project_name or self._config.project_name_or_raise, "org_name": org_name if not isinstance(org_name, OrgNameSentinel) else self._config.org_name, diff --git a/neuro-sdk/src/neuro_sdk/_jobs.py b/neuro-sdk/src/neuro_sdk/_jobs.py index d31ccea06..a4f69fb69 100644 --- a/neuro-sdk/src/neuro_sdk/_jobs.py +++ b/neuro-sdk/src/neuro_sdk/_jobs.py @@ -1156,7 +1156,10 @@ def _secret_file_to_api(secret_file: SecretFile, config: Config) -> Dict[str, An def _disk_volume_to_api(volume: DiskVolume, config: Config) -> Dict[str, Any]: uri = normalize_disk_uri( - volume.disk_uri, config.username, config.cluster_name, config.org_name + volume.disk_uri, + config.project_name_or_raise, + config.cluster_name, + config.org_name, ) resp: Dict[str, Any] = { "src_disk_uri": str(uri), diff --git a/neuro-sdk/src/neuro_sdk/_url_utils.py b/neuro-sdk/src/neuro_sdk/_url_utils.py index e7054d13e..12e36823c 100644 --- a/neuro-sdk/src/neuro_sdk/_url_utils.py +++ b/neuro-sdk/src/neuro_sdk/_url_utils.py @@ -97,14 +97,14 @@ def normalize_secret_uri( def normalize_disk_uri( - uri: URL, username: str, cluster_name: str, org_name: Optional[str] + uri: URL, project_name: str, cluster_name: str, org_name: Optional[str] ) -> URL: """Normalize disk url.""" if uri.scheme != "disk": raise ValueError( f"Invalid disk scheme '{uri.scheme}:' (only 'disk:' is allowed)" ) - return _normalize_uri(uri, username, cluster_name, org_name) + return _normalize_uri(uri, project_name, cluster_name, org_name) def _normalize_uri( diff --git a/neuro-sdk/tests/test_disks.py b/neuro-sdk/tests/test_disks.py index 47b16f618..85bb03136 100644 --- a/neuro-sdk/tests/test_disks.py +++ b/neuro-sdk/tests/test_disks.py @@ -25,6 +25,7 @@ async def handler(request: web.Request) -> web.Response: "id": "disk-1", "storage": 500, "owner": "user", + "project_name": "test-project", "status": "Ready", "created_at": created_at.isoformat(), "name": None, @@ -33,6 +34,7 @@ async def handler(request: web.Request) -> web.Response: "id": "disk-2", "storage": 600, "owner": "user", + "project_name": "test-project", "status": "Pending", "org_name": "test-org", "created_at": created_at.isoformat(), @@ -51,6 +53,7 @@ async def handler(request: web.Request) -> web.Response: ret = [] async with make_client(srv.make_url("/")) as client: + project_name = client.config.project_name_or_raise async with client.disks.list() as it: async for s in it: ret.append(s) @@ -62,6 +65,7 @@ async def handler(request: web.Request) -> web.Response: owner="user", status=Disk.Status.READY, cluster_name=cluster_config.name, + project_name=project_name, org_name=None, created_at=created_at, timeout_unused=None, @@ -73,6 +77,7 @@ async def handler(request: web.Request) -> web.Response: owner="user", status=Disk.Status.PENDING, cluster_name=cluster_config.name, + project_name=project_name, org_name="test-org", created_at=created_at, last_usage=last_usage, @@ -96,6 +101,7 @@ async def handler(request: web.Request) -> web.Response: "life_span": 3600, "name": "test-disk", "org_name": None, + "project_name": "test-project", } return web.json_response( { @@ -106,6 +112,7 @@ async def handler(request: web.Request) -> web.Response: "created_at": created_at.isoformat(), "life_span": 3600, "name": "test-disk", + "project_name": "test-project", }, ) @@ -122,6 +129,7 @@ async def handler(request: web.Request) -> web.Response: owner="user", status=Disk.Status.READY, cluster_name=cluster_config.name, + project_name=client.config.project_name_or_raise, org_name=None, created_at=created_at, timeout_unused=timedelta(hours=1), @@ -143,6 +151,7 @@ async def handler(request: web.Request) -> web.Response: "life_span": 3600, "name": "test-disk", "org_name": "test-org", + "project_name": "test-project", } return web.json_response( { @@ -154,6 +163,7 @@ async def handler(request: web.Request) -> web.Response: "life_span": 3600, "name": "test-disk", "org_name": "test-org", + "project_name": "test-project", }, ) @@ -173,6 +183,7 @@ async def handler(request: web.Request) -> web.Response: status=Disk.Status.READY, cluster_name=cluster_config.name, org_name="test-org", + project_name="test-project", created_at=created_at, timeout_unused=timedelta(hours=1), name="test-disk", @@ -194,6 +205,7 @@ async def handler(request: web.Request) -> web.Response: "storage": 500, "used_bytes": 150, "owner": "user", + "project_name": "some-project", "status": "Ready", "created_at": created_at.isoformat(), }, @@ -214,6 +226,7 @@ async def handler(request: web.Request) -> web.Response: status=Disk.Status.READY, cluster_name=cluster_config.name, org_name=None, + project_name="some-project", created_at=created_at, ) diff --git a/neuro-sdk/tests/test_jobs.py b/neuro-sdk/tests/test_jobs.py index ea63fa2f6..8cf4530df 100644 --- a/neuro-sdk/tests/test_jobs.py +++ b/neuro-sdk/tests/test_jobs.py @@ -1747,7 +1747,7 @@ async def test_job_run_with_disk_volume_uris( }, "disk_volumes": [ { - "src_disk_uri": "disk://default/user/disk-1", + "src_disk_uri": "disk://default/test-project/disk-1", "dst_path": "/container/my_path", "read_only": False, } @@ -1774,7 +1774,7 @@ async def handler(request: web.Request) -> web.Response: }, "disk_volumes": [ { - "src_disk_uri": "disk://default/user/disk-1", + "src_disk_uri": "disk://default/test-project/disk-1", "dst_path": "/container/my_path", "read_only": False, } From 530205d512d5e4c670c3b5e33bab564c44af60ff Mon Sep 17 00:00:00 2001 From: Yevhenii Semendiak Date: Sun, 23 Apr 2023 20:23:12 +0300 Subject: [PATCH 2/5] add custom project create disk test --- neuro-sdk/src/neuro_sdk/_disks.py | 1 - neuro-sdk/tests/test_disks.py | 83 +++++++++++++++++++++++++++++-- 2 files changed, 79 insertions(+), 5 deletions(-) diff --git a/neuro-sdk/src/neuro_sdk/_disks.py b/neuro-sdk/src/neuro_sdk/_disks.py index 8326c56ba..61872116b 100644 --- a/neuro-sdk/src/neuro_sdk/_disks.py +++ b/neuro-sdk/src/neuro_sdk/_disks.py @@ -105,7 +105,6 @@ async def list( async with self._core.request("GET", url, auth=auth, params=params) as resp: ret = await resp.json() for disk_payload in ret: - print(disk_payload) yield self._parse_disk_payload(disk_payload) async def create( diff --git a/neuro-sdk/tests/test_disks.py b/neuro-sdk/tests/test_disks.py index 85bb03136..e207aee1a 100644 --- a/neuro-sdk/tests/test_disks.py +++ b/neuro-sdk/tests/test_disks.py @@ -34,7 +34,7 @@ async def handler(request: web.Request) -> web.Response: "id": "disk-2", "storage": 600, "owner": "user", - "project_name": "test-project", + "project_name": "other-project", "status": "Pending", "org_name": "test-org", "created_at": created_at.isoformat(), @@ -53,7 +53,6 @@ async def handler(request: web.Request) -> web.Response: ret = [] async with make_client(srv.make_url("/")) as client: - project_name = client.config.project_name_or_raise async with client.disks.list() as it: async for s in it: ret.append(s) @@ -65,7 +64,7 @@ async def handler(request: web.Request) -> web.Response: owner="user", status=Disk.Status.READY, cluster_name=cluster_config.name, - project_name=project_name, + project_name="test-project", org_name=None, created_at=created_at, timeout_unused=None, @@ -77,7 +76,7 @@ async def handler(request: web.Request) -> web.Response: owner="user", status=Disk.Status.PENDING, cluster_name=cluster_config.name, - project_name=project_name, + project_name="other-project", org_name="test-org", created_at=created_at, last_usage=last_usage, @@ -190,6 +189,82 @@ async def handler(request: web.Request) -> web.Response: ) +async def test_add_with_custom_project_name( + aiohttp_server: _TestServerFactory, + make_client: _MakeClient, + cluster_config: Cluster, +) -> None: + created_at = datetime.now() + resp_pl = { + "id": "disk-1", + "storage": 500, + "owner": "user", + "status": "Ready", + "created_at": created_at.isoformat(), + "life_span": 3600, + "name": "test-disk", + "project_name": "other-project", + } + + async def handle_post(request: web.Request) -> web.Response: + data = await request.json() + assert data == { + "storage": 500, + "life_span": 3600, + "name": "test-disk", + "org_name": None, + "project_name": "other-project", + } + return web.json_response(resp_pl) + + async def handle_list(request: web.Request) -> web.Response: + return web.json_response([resp_pl]) + + async def handle_get(request: web.Request) -> web.Response: + return web.json_response(resp_pl) + + app = web.Application() + app.router.add_post("/disk", handle_post) + app.router.add_get("/disk/{key}", handle_get) + app.router.add_get("/disk", handle_list) + + srv = await aiohttp_server(app) + + expected = Disk( + id="disk-1", + storage=500, + owner="user", + org_name=None, + status=Disk.Status.READY, + cluster_name=cluster_config.name, + project_name="other-project", + created_at=created_at, + timeout_unused=timedelta(hours=1), + name="test-disk", + ) + + async with make_client(srv.make_url("/")) as client: + disk_created = await client.disks.create( + 500, timedelta(hours=1), "test-disk", project_name="other-project" + ) + assert disk_created == expected + + disk_get = await client.disks.get("test-disk") + assert disk_get == expected + + l1 = [] + async with client.disks.list() as it: + async for s in it: + l1.append(s) + assert l1 == [expected] + + l2 = [] + async with client.disks.list(project_name="other-project") as it: + async for disk in it: + l2.append(disk) + assert l2 == [expected] + + async def test_get( aiohttp_server: _TestServerFactory, make_client: _MakeClient, From c558ad7b45ad675e739ea289644df7428f282833 Mon Sep 17 00:00:00 2001 From: Yevhenii Semendiak Date: Sun, 23 Apr 2023 20:25:15 +0300 Subject: [PATCH 3/5] changelog --- CHANGELOG.D/2960.feature | 1 + 1 file changed, 1 insertion(+) create mode 100644 CHANGELOG.D/2960.feature diff --git a/CHANGELOG.D/2960.feature b/CHANGELOG.D/2960.feature new file mode 100644 index 000000000..3e27a90ad --- /dev/null +++ b/CHANGELOG.D/2960.feature @@ -0,0 +1 @@ +Support projects in disk CLI commands and SDK methods. From c381a1ecf85a8bc5423310dac2449a8259a72415 Mon Sep 17 00:00:00 2001 From: Yevhenii Semendiak Date: Mon, 24 Apr 2023 15:00:05 +0300 Subject: [PATCH 4/5] revert usage of resolve_disk --- neuro-cli/src/neuro_cli/disks.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/neuro-cli/src/neuro_cli/disks.py b/neuro-cli/src/neuro_cli/disks.py index 775d9f9f4..6f4519500 100644 --- a/neuro-cli/src/neuro_cli/disks.py +++ b/neuro-cli/src/neuro_cli/disks.py @@ -193,11 +193,8 @@ async def get( """ Get disk DISK_ID. """ - if isinstance(disk, URL): - disk_str = disk.parts[-1] - else: - disk_str = disk - disk_obj = await root.client.disks.get(disk_str, cluster_name=cluster) + disk_id = await resolve_disk(disk, client=root.client, cluster_name=cluster) + disk_obj = await root.client.disks.get(disk_id, cluster_name=cluster) if full_uri: uri_fmtr: URIFormatter = str From 866ebfef4280d30e72a779aca4687b5483ce0a7b Mon Sep 17 00:00:00 2001 From: Yevhenii Semendiak Date: Mon, 24 Apr 2023 15:04:44 +0300 Subject: [PATCH 5/5] assume there is no owner in URIs --- neuro-cli/src/neuro_cli/blob_storage.py | 8 +- neuro-cli/src/neuro_cli/disks.py | 5 +- neuro-cli/src/neuro_cli/formatters/utils.py | 19 +-- neuro-cli/src/neuro_cli/image.py | 2 +- neuro-cli/src/neuro_cli/job.py | 6 +- neuro-cli/src/neuro_cli/secrets.py | 2 +- neuro-cli/src/neuro_cli/share.py | 2 +- ...t_job_with_disk_volumes_short[human]_0.ref | 4 +- ...est_job_with_disk_volumes_short[iso]_0.ref | 4 +- ...ter.test_job_with_environment[human]_0.ref | 46 +++---- ...atter.test_job_with_environment[iso]_0.ref | 46 +++---- ...matter.test_job_with_org_urls[human]_0.ref | 46 +++---- ...ormatter.test_job_with_org_urls[iso]_0.ref | 46 +++---- ...r.test_job_with_secrets_short[human]_0.ref | 8 +- ...ter.test_job_with_secrets_short[iso]_0.ref | 8 +- ...r.test_job_with_volumes_short[human]_0.ref | 4 +- ...ter.test_job_with_volumes_short[iso]_0.ref | 4 +- ...ter.test_job_with_working_dir[human]_0.ref | 44 +++---- ...atter.test_job_with_working_dir[iso]_0.ref | 44 +++---- .../unit/formatters/test_jobs_formatters.py | 56 ++++----- neuro-cli/tests/unit/formatters/test_utils.py | 114 ++++++++++-------- 21 files changed, 265 insertions(+), 253 deletions(-) diff --git a/neuro-cli/src/neuro_cli/blob_storage.py b/neuro-cli/src/neuro_cli/blob_storage.py index a020c5429..30be85915 100644 --- a/neuro-cli/src/neuro_cli/blob_storage.py +++ b/neuro-cli/src/neuro_cli/blob_storage.py @@ -96,7 +96,7 @@ async def lsbucket( uri_fmtr: URIFormatter = str else: uri_fmtr = uri_formatter( - username=root.client.username, + project_name=root.client.config.project_name_or_raise, cluster_name=cluster or root.client.cluster_name, org_name=root.client.config.org_name, ) @@ -365,7 +365,7 @@ async def statbucket( uri_fmtr: URIFormatter = str else: uri_fmtr = uri_formatter( - username=root.client.username, + project_name=root.client.config.project_name_or_raise, cluster_name=cluster or root.client.cluster_name, org_name=root.client.config.org_name, ) @@ -550,7 +550,7 @@ async def ls( uri_fmtr: URIFormatter = str else: uri_fmtr = uri_formatter( - username=root.client.username, + project_name=root.client.config.project_name_or_raise, cluster_name=root.client.cluster_name, org_name=root.client.config.org_name, ) @@ -606,7 +606,7 @@ async def glob(root: Root, full_uri: bool, patterns: Sequence[URL]) -> None: uri_fmtr: URIFormatter = str else: uri_fmtr = uri_formatter( - username=root.client.username, + project_name=root.client.config.project_name_or_raise, cluster_name=root.client.cluster_name, org_name=root.client.config.org_name, ) diff --git a/neuro-cli/src/neuro_cli/disks.py b/neuro-cli/src/neuro_cli/disks.py index 6f4519500..0d34fa123 100644 --- a/neuro-cli/src/neuro_cli/disks.py +++ b/neuro-cli/src/neuro_cli/disks.py @@ -66,10 +66,9 @@ async def ls( uri_fmtr: URIFormatter = str else: uri_fmtr = uri_formatter( - username=root.client.username, + project_name=root.client.config.project_name_or_raise, cluster_name=cluster or root.client.cluster_name, org_name=root.client.config.org_name, - project_name=project or root.client.config.project_name, ) disks_fmtr = DisksFormatter( uri_fmtr, @@ -200,7 +199,7 @@ async def get( uri_fmtr: URIFormatter = str else: uri_fmtr = uri_formatter( - project_name=root.client.config.project_name, + project_name=root.client.config.project_name_or_raise, cluster_name=cluster or root.client.cluster_name, org_name=root.client.config.org_name, ) diff --git a/neuro-cli/src/neuro_cli/formatters/utils.py b/neuro-cli/src/neuro_cli/formatters/utils.py index c1cc5f961..45d8251a0 100644 --- a/neuro-cli/src/neuro_cli/formatters/utils.py +++ b/neuro-cli/src/neuro_cli/formatters/utils.py @@ -12,29 +12,22 @@ def uri_formatter( - cluster_name: str, - org_name: Optional[str], - username: Optional[str] = None, - project_name: Optional[str] = None, + project_name: str, cluster_name: str, org_name: Optional[str] ) -> URIFormatter: def formatter(uri: URL) -> str: if uri.scheme in SCHEMES: if uri.host == cluster_name: assert uri.path[0] == "/" path = uri.path.lstrip("/") - owner_or_org, _, rest = path.partition("/") + project_or_org, _, rest = path.partition("/") if org_name: - if owner_or_org != org_name: + if project_or_org != org_name: return str(uri) path = rest - owner, _, rest = path.partition("/") + project, _, rest = path.partition("/") else: - owner = owner_or_org - # TODO (Y.S.): remove this check and use project_name parameter - # when the last patch for projects is done - project = project_name or username - assert project, "Ensure you've set project_name" - if owner == project: + project = project_or_org + if project == project_name: path = rest.lstrip("/") else: path = "/" + path diff --git a/neuro-cli/src/neuro_cli/image.py b/neuro-cli/src/neuro_cli/image.py index d3d4a8fa8..ff770205a 100644 --- a/neuro-cli/src/neuro_cli/image.py +++ b/neuro-cli/src/neuro_cli/image.py @@ -154,7 +154,7 @@ async def ls( image_fmtr = str else: uri_fmtr = uri_formatter( - username=root.client.username, + project_name=root.client.config.project_name_or_raise, cluster_name=root.client.cluster_name, org_name=root.client.config.org_name, ) diff --git a/neuro-cli/src/neuro_cli/job.py b/neuro-cli/src/neuro_cli/job.py index c976ca291..079d32932 100644 --- a/neuro-cli/src/neuro_cli/job.py +++ b/neuro-cli/src/neuro_cli/job.py @@ -411,7 +411,7 @@ async def ls( uri_fmtr = str else: uri_fmtr = uri_formatter( - username=root.client.username, + project_name=root.client.config.project_name_or_raise, cluster_name=root.client.cluster_name, org_name=root.client.config.org_name, ) @@ -483,7 +483,7 @@ async def status(root: Root, job: str, full_uri: bool) -> None: uri_fmtr = str else: uri_fmtr = uri_formatter( - username=root.client.username, + project_name=root.client.config.project_name_or_raise, cluster_name=root.client.cluster_name, org_name=root.client.config.org_name, ) @@ -745,7 +745,7 @@ async def renderer() -> None: uri_fmtr = str else: uri_fmtr = uri_formatter( - username=root.client.username, + project_name=root.client.config.project_name_or_raise, cluster_name=root.client.cluster_name, org_name=root.client.config.org_name, ) diff --git a/neuro-cli/src/neuro_cli/secrets.py b/neuro-cli/src/neuro_cli/secrets.py index c762e956f..da2d2dd02 100644 --- a/neuro-cli/src/neuro_cli/secrets.py +++ b/neuro-cli/src/neuro_cli/secrets.py @@ -38,7 +38,7 @@ async def ls(root: Root, full_uri: bool, cluster: Optional[str]) -> None: uri_fmtr: URIFormatter = str else: uri_fmtr = uri_formatter( - username=root.client.username, + project_name=root.client.config.project_name_or_raise, cluster_name=cluster or root.client.cluster_name, org_name=root.client.config.org_name, ) diff --git a/neuro-cli/src/neuro_cli/share.py b/neuro-cli/src/neuro_cli/share.py index 2313dabc6..8aaa26cd0 100644 --- a/neuro-cli/src/neuro_cli/share.py +++ b/neuro-cli/src/neuro_cli/share.py @@ -138,7 +138,7 @@ async def ls( uri_fmtr = str else: uri_fmtr = uri_formatter( - username=root.client.username, + project_name=root.client.config.project_name_or_raise, cluster_name=root.client.cluster_name, org_name=root.client.config.org_name, ) diff --git a/neuro-cli/tests/unit/formatters/ascii/TestJobOutputFormatter.test_job_with_disk_volumes_short[human]_0.ref b/neuro-cli/tests/unit/formatters/ascii/TestJobOutputFormatter.test_job_with_disk_volumes_short[human]_0.ref index 2657d1b92..54f10a7c3 100644 --- a/neuro-cli/tests/unit/formatters/ascii/TestJobOutputFormatter.test_job_with_disk_volumes_short[human]_0.ref +++ b/neuro-cli/tests/unit/formatters/ascii/TestJobOutputFormatter.test_job_with_disk_volumes_short[human]_0.ref @@ -4,7 +4,7 @@ Job test-job Cluster default Description test job description Status failed (ErrorReason) - Image image:test-image:sometag + Image image:/test-user/test-image:sometag Command test-command Priority Normal Price (credits / hour) 15.0000 @@ -12,7 +12,7 @@ Job test-job Resources Memory 16.8 MB CPU 0.1 TTY False - Disk volumes /mnt/disk1 disk:disk1 READONLY + Disk volumes /mnt/disk1 disk:/test-user/disk1 READONLY /mnt/disk2 disk:/otheruser/disk2 /mnt/disk3 disk://othercluster/otheruser/disk3 Http URL http://local.host.test/ diff --git a/neuro-cli/tests/unit/formatters/ascii/TestJobOutputFormatter.test_job_with_disk_volumes_short[iso]_0.ref b/neuro-cli/tests/unit/formatters/ascii/TestJobOutputFormatter.test_job_with_disk_volumes_short[iso]_0.ref index 01d0f7089..c26b0d25d 100644 --- a/neuro-cli/tests/unit/formatters/ascii/TestJobOutputFormatter.test_job_with_disk_volumes_short[iso]_0.ref +++ b/neuro-cli/tests/unit/formatters/ascii/TestJobOutputFormatter.test_job_with_disk_volumes_short[iso]_0.ref @@ -4,7 +4,7 @@ Job test-job Cluster default Description test job description Status failed (ErrorReason) - Image image:test-image:sometag + Image image:/test-user/test-image:sometag Command test-command Priority Normal Price (credits / hour) 15.0000 @@ -12,7 +12,7 @@ Job test-job Resources Memory 16.8 MB CPU 0.1 TTY False - Disk volumes /mnt/disk1 disk:disk1 READONLY + Disk volumes /mnt/disk1 disk:/test-user/disk1 READONLY /mnt/disk2 disk:/otheruser/disk2 /mnt/disk3 disk://othercluster/otheruser/disk3 Http URL http://local.host.test/ diff --git a/neuro-cli/tests/unit/formatters/ascii/TestJobOutputFormatter.test_job_with_environment[human]_0.ref b/neuro-cli/tests/unit/formatters/ascii/TestJobOutputFormatter.test_job_with_environment[human]_0.ref index bacbd854d..c9612bcd8 100644 --- a/neuro-cli/tests/unit/formatters/ascii/TestJobOutputFormatter.test_job_with_environment[human]_0.ref +++ b/neuro-cli/tests/unit/formatters/ascii/TestJobOutputFormatter.test_job_with_environment[human]_0.ref @@ -1,24 +1,24 @@ -Job test-job - Name test-job-name - Owner test-user - Cluster default - Description test job description - Status failed (ErrorReason) - Image image:test-image:sometag - Command test-command - Priority Normal - Price (credits / hour) 15.0000 - Current cost 150.0000 - Resources Memory 16.8 MB - CPU 0.1 - TTY False - Http URL http://local.host.test/ - Http port 80 - Http authentication True - Environment ENV_NAME_1 __value1__ - ENV_NAME_2 **value2** - Created Sep 25 2018 at 12:28 - Started Sep 25 2018 at 12:28 - Finished Sep 25 2018 at 12:28 - Exit code 123 +Job test-job + Name test-job-name + Owner test-user + Cluster default + Description test job description + Status failed (ErrorReason) + Image image:/test-user/test-image:sometag + Command test-command + Priority Normal + Price (credits / hour) 15.0000 + Current cost 150.0000 + Resources Memory 16.8 MB + CPU 0.1 + TTY False + Http URL http://local.host.test/ + Http port 80 + Http authentication True + Environment ENV_NAME_1 __value1__ + ENV_NAME_2 **value2** + Created Sep 25 2018 at 12:28 + Started Sep 25 2018 at 12:28 + Finished Sep 25 2018 at 12:28 + Exit code 123 Description ErrorDesc diff --git a/neuro-cli/tests/unit/formatters/ascii/TestJobOutputFormatter.test_job_with_environment[iso]_0.ref b/neuro-cli/tests/unit/formatters/ascii/TestJobOutputFormatter.test_job_with_environment[iso]_0.ref index 0b2cf8c2f..06259b2ba 100644 --- a/neuro-cli/tests/unit/formatters/ascii/TestJobOutputFormatter.test_job_with_environment[iso]_0.ref +++ b/neuro-cli/tests/unit/formatters/ascii/TestJobOutputFormatter.test_job_with_environment[iso]_0.ref @@ -1,24 +1,24 @@ -Job test-job - Name test-job-name - Owner test-user - Cluster default - Description test job description - Status failed (ErrorReason) - Image image:test-image:sometag - Command test-command - Priority Normal - Price (credits / hour) 15.0000 - Current cost 150.0000 - Resources Memory 16.8 MB - CPU 0.1 - TTY False - Http URL http://local.host.test/ - Http port 80 - Http authentication True - Environment ENV_NAME_1 __value1__ - ENV_NAME_2 **value2** - Created 2018-09-25T12:28:21.298672+00:00 - Started 2018-09-25T12:28:59.759433+00:00 - Finished 2018-09-25T12:28:59.759433+00:00 - Exit code 123 +Job test-job + Name test-job-name + Owner test-user + Cluster default + Description test job description + Status failed (ErrorReason) + Image image:/test-user/test-image:sometag + Command test-command + Priority Normal + Price (credits / hour) 15.0000 + Current cost 150.0000 + Resources Memory 16.8 MB + CPU 0.1 + TTY False + Http URL http://local.host.test/ + Http port 80 + Http authentication True + Environment ENV_NAME_1 __value1__ + ENV_NAME_2 **value2** + Created 2018-09-25T12:28:21.298672+00:00 + Started 2018-09-25T12:28:59.759433+00:00 + Finished 2018-09-25T12:28:59.759433+00:00 + Exit code 123 Description ErrorDesc diff --git a/neuro-cli/tests/unit/formatters/ascii/TestJobOutputFormatter.test_job_with_org_urls[human]_0.ref b/neuro-cli/tests/unit/formatters/ascii/TestJobOutputFormatter.test_job_with_org_urls[human]_0.ref index ecc40f6ba..5f479df1e 100644 --- a/neuro-cli/tests/unit/formatters/ascii/TestJobOutputFormatter.test_job_with_org_urls[human]_0.ref +++ b/neuro-cli/tests/unit/formatters/ascii/TestJobOutputFormatter.test_job_with_org_urls[human]_0.ref @@ -1,24 +1,24 @@ -Job test-job - Name test-job-name - Owner test-user - Cluster default - Organization test-org - Description test job description - Status failed (ErrorReason) - Image test-image - Command test-command - Priority Normal - Price (credits / hour) 15.0000 - Current cost 150.0000 - Resources Memory 16.8 MB - CPU 0.1 - TTY False - Volumes /mnt/storage storage:folder - Http URL http://local.host.test/ - Http port 80 - Http authentication True - Created Sep 25 2018 at 12:28 - Started Sep 25 2018 at 12:28 - Finished Sep 25 2018 at 12:28 - Exit code 123 +Job test-job + Name test-job-name + Owner test-user + Cluster default + Organization test-org + Description test job description + Status failed (ErrorReason) + Image test-image + Command test-command + Priority Normal + Price (credits / hour) 15.0000 + Current cost 150.0000 + Resources Memory 16.8 MB + CPU 0.1 + TTY False + Volumes /mnt/storage storage:/test-user/folder + Http URL http://local.host.test/ + Http port 80 + Http authentication True + Created Sep 25 2018 at 12:28 + Started Sep 25 2018 at 12:28 + Finished Sep 25 2018 at 12:28 + Exit code 123 Description ErrorDesc diff --git a/neuro-cli/tests/unit/formatters/ascii/TestJobOutputFormatter.test_job_with_org_urls[iso]_0.ref b/neuro-cli/tests/unit/formatters/ascii/TestJobOutputFormatter.test_job_with_org_urls[iso]_0.ref index b7b3106e3..b60eab8f5 100644 --- a/neuro-cli/tests/unit/formatters/ascii/TestJobOutputFormatter.test_job_with_org_urls[iso]_0.ref +++ b/neuro-cli/tests/unit/formatters/ascii/TestJobOutputFormatter.test_job_with_org_urls[iso]_0.ref @@ -1,24 +1,24 @@ -Job test-job - Name test-job-name - Owner test-user - Cluster default - Organization test-org - Description test job description - Status failed (ErrorReason) - Image test-image - Command test-command - Priority Normal - Price (credits / hour) 15.0000 - Current cost 150.0000 - Resources Memory 16.8 MB - CPU 0.1 - TTY False - Volumes /mnt/storage storage:folder - Http URL http://local.host.test/ - Http port 80 - Http authentication True - Created 2018-09-25T12:28:21.298672+00:00 - Started 2018-09-25T12:28:59.759433+00:00 - Finished 2018-09-25T12:28:59.759433+00:00 - Exit code 123 +Job test-job + Name test-job-name + Owner test-user + Cluster default + Organization test-org + Description test job description + Status failed (ErrorReason) + Image test-image + Command test-command + Priority Normal + Price (credits / hour) 15.0000 + Current cost 150.0000 + Resources Memory 16.8 MB + CPU 0.1 + TTY False + Volumes /mnt/storage storage:/test-user/folder + Http URL http://local.host.test/ + Http port 80 + Http authentication True + Created 2018-09-25T12:28:21.298672+00:00 + Started 2018-09-25T12:28:59.759433+00:00 + Finished 2018-09-25T12:28:59.759433+00:00 + Exit code 123 Description ErrorDesc diff --git a/neuro-cli/tests/unit/formatters/ascii/TestJobOutputFormatter.test_job_with_secrets_short[human]_0.ref b/neuro-cli/tests/unit/formatters/ascii/TestJobOutputFormatter.test_job_with_secrets_short[human]_0.ref index f72789849..fafdf66a0 100644 --- a/neuro-cli/tests/unit/formatters/ascii/TestJobOutputFormatter.test_job_with_secrets_short[human]_0.ref +++ b/neuro-cli/tests/unit/formatters/ascii/TestJobOutputFormatter.test_job_with_secrets_short[human]_0.ref @@ -4,7 +4,7 @@ Job test-job Cluster default Description test job description Status failed (ErrorReason) - Image image:test-image:sometag + Image image:/test-user/test-image:sometag Command test-command Priority Normal Price (credits / hour) 15.0000 @@ -12,15 +12,15 @@ Job test-job Resources Memory 16.8 MB CPU 0.1 TTY False - Volumes /mnt/rw storage:rw - Secret files /var/run/secret1 secret:secret1 + Volumes /mnt/rw storage:/test-user/rw + Secret files /var/run/secret1 secret:/test-user/secret1 /var/run/secret2 secret:/otheruser/secret2 /var/run/secret3 secret://othercluster/otheruser/secret3 Http URL http://local.host.test/ Http port 80 Http authentication True Environment ENV_NAME_0 somevalue - Secret environment ENV_NAME_1 secret:secret4 + Secret environment ENV_NAME_1 secret:/test-user/secret4 ENV_NAME_2 secret:/otheruser/secret5 ENV_NAME_3 secret://othercluster/otheruser/secret6 Created Sep 25 2018 at 12:28 diff --git a/neuro-cli/tests/unit/formatters/ascii/TestJobOutputFormatter.test_job_with_secrets_short[iso]_0.ref b/neuro-cli/tests/unit/formatters/ascii/TestJobOutputFormatter.test_job_with_secrets_short[iso]_0.ref index d4376724e..ece499fee 100644 --- a/neuro-cli/tests/unit/formatters/ascii/TestJobOutputFormatter.test_job_with_secrets_short[iso]_0.ref +++ b/neuro-cli/tests/unit/formatters/ascii/TestJobOutputFormatter.test_job_with_secrets_short[iso]_0.ref @@ -4,7 +4,7 @@ Job test-job Cluster default Description test job description Status failed (ErrorReason) - Image image:test-image:sometag + Image image:/test-user/test-image:sometag Command test-command Priority Normal Price (credits / hour) 15.0000 @@ -12,15 +12,15 @@ Job test-job Resources Memory 16.8 MB CPU 0.1 TTY False - Volumes /mnt/rw storage:rw - Secret files /var/run/secret1 secret:secret1 + Volumes /mnt/rw storage:/test-user/rw + Secret files /var/run/secret1 secret:/test-user/secret1 /var/run/secret2 secret:/otheruser/secret2 /var/run/secret3 secret://othercluster/otheruser/secret3 Http URL http://local.host.test/ Http port 80 Http authentication True Environment ENV_NAME_0 somevalue - Secret environment ENV_NAME_1 secret:secret4 + Secret environment ENV_NAME_1 secret:/test-user/secret4 ENV_NAME_2 secret:/otheruser/secret5 ENV_NAME_3 secret://othercluster/otheruser/secret6 Created 2018-09-25T12:28:21.298672+00:00 diff --git a/neuro-cli/tests/unit/formatters/ascii/TestJobOutputFormatter.test_job_with_volumes_short[human]_0.ref b/neuro-cli/tests/unit/formatters/ascii/TestJobOutputFormatter.test_job_with_volumes_short[human]_0.ref index 2a9d06f3c..3c5b42d99 100644 --- a/neuro-cli/tests/unit/formatters/ascii/TestJobOutputFormatter.test_job_with_volumes_short[human]_0.ref +++ b/neuro-cli/tests/unit/formatters/ascii/TestJobOutputFormatter.test_job_with_volumes_short[human]_0.ref @@ -4,7 +4,7 @@ Job test-job Cluster default Description test job description Status failed (ErrorReason) - Image image:test-image:sometag + Image image:/test-user/test-image:sometag Command test-command Priority Normal Price (credits / hour) 15.0000 @@ -13,7 +13,7 @@ Job test-job CPU 0.1 TTY False Volumes /mnt/_ro_ storage:/otheruser/_ro_ READONLY - /mnt/rw storage:rw + /mnt/rw storage:/test-user/rw /mnt/ro storage://othercluster/otheruser/ro READONLY Http URL http://local.host.test/ Http port 80 diff --git a/neuro-cli/tests/unit/formatters/ascii/TestJobOutputFormatter.test_job_with_volumes_short[iso]_0.ref b/neuro-cli/tests/unit/formatters/ascii/TestJobOutputFormatter.test_job_with_volumes_short[iso]_0.ref index 57e20a81a..3c6a410f7 100644 --- a/neuro-cli/tests/unit/formatters/ascii/TestJobOutputFormatter.test_job_with_volumes_short[iso]_0.ref +++ b/neuro-cli/tests/unit/formatters/ascii/TestJobOutputFormatter.test_job_with_volumes_short[iso]_0.ref @@ -4,7 +4,7 @@ Job test-job Cluster default Description test job description Status failed (ErrorReason) - Image image:test-image:sometag + Image image:/test-user/test-image:sometag Command test-command Priority Normal Price (credits / hour) 15.0000 @@ -13,7 +13,7 @@ Job test-job CPU 0.1 TTY False Volumes /mnt/_ro_ storage:/otheruser/_ro_ READONLY - /mnt/rw storage:rw + /mnt/rw storage:/test-user/rw /mnt/ro storage://othercluster/otheruser/ro READONLY Http URL http://local.host.test/ Http port 80 diff --git a/neuro-cli/tests/unit/formatters/ascii/TestJobOutputFormatter.test_job_with_working_dir[human]_0.ref b/neuro-cli/tests/unit/formatters/ascii/TestJobOutputFormatter.test_job_with_working_dir[human]_0.ref index 0303e9dc6..155dc9868 100644 --- a/neuro-cli/tests/unit/formatters/ascii/TestJobOutputFormatter.test_job_with_working_dir[human]_0.ref +++ b/neuro-cli/tests/unit/formatters/ascii/TestJobOutputFormatter.test_job_with_working_dir[human]_0.ref @@ -1,23 +1,23 @@ -Job test-job - Name test-job-name - Owner test-user - Cluster default - Description test job description - Status failed (ErrorReason) - Image image:test-image:sometag - Command test-command - Working dir /working/dir - Priority Normal - Price (credits / hour) 15.0000 - Current cost 150.0000 - Resources Memory 16.8 MB - CPU 0.1 - TTY False - Http URL http://local.host.test/ - Http port 80 - Http authentication True - Created Sep 25 2018 at 12:28 - Started Sep 25 2018 at 12:28 - Finished Sep 25 2018 at 12:28 - Exit code 123 +Job test-job + Name test-job-name + Owner test-user + Cluster default + Description test job description + Status failed (ErrorReason) + Image image:/test-user/test-image:sometag + Command test-command + Working dir /working/dir + Priority Normal + Price (credits / hour) 15.0000 + Current cost 150.0000 + Resources Memory 16.8 MB + CPU 0.1 + TTY False + Http URL http://local.host.test/ + Http port 80 + Http authentication True + Created Sep 25 2018 at 12:28 + Started Sep 25 2018 at 12:28 + Finished Sep 25 2018 at 12:28 + Exit code 123 Description ErrorDesc diff --git a/neuro-cli/tests/unit/formatters/ascii/TestJobOutputFormatter.test_job_with_working_dir[iso]_0.ref b/neuro-cli/tests/unit/formatters/ascii/TestJobOutputFormatter.test_job_with_working_dir[iso]_0.ref index 1307fa84d..0689ec8e1 100644 --- a/neuro-cli/tests/unit/formatters/ascii/TestJobOutputFormatter.test_job_with_working_dir[iso]_0.ref +++ b/neuro-cli/tests/unit/formatters/ascii/TestJobOutputFormatter.test_job_with_working_dir[iso]_0.ref @@ -1,23 +1,23 @@ -Job test-job - Name test-job-name - Owner test-user - Cluster default - Description test job description - Status failed (ErrorReason) - Image image:test-image:sometag - Command test-command - Working dir /working/dir - Priority Normal - Price (credits / hour) 15.0000 - Current cost 150.0000 - Resources Memory 16.8 MB - CPU 0.1 - TTY False - Http URL http://local.host.test/ - Http port 80 - Http authentication True - Created 2018-09-25T12:28:21.298672+00:00 - Started 2018-09-25T12:28:59.759433+00:00 - Finished 2018-09-25T12:28:59.759433+00:00 - Exit code 123 +Job test-job + Name test-job-name + Owner test-user + Cluster default + Description test job description + Status failed (ErrorReason) + Image image:/test-user/test-image:sometag + Command test-command + Working dir /working/dir + Priority Normal + Price (credits / hour) 15.0000 + Current cost 150.0000 + Resources Memory 16.8 MB + CPU 0.1 + TTY False + Http URL http://local.host.test/ + Http port 80 + Http authentication True + Created 2018-09-25T12:28:21.298672+00:00 + Started 2018-09-25T12:28:59.759433+00:00 + Finished 2018-09-25T12:28:59.759433+00:00 + Exit code 123 Description ErrorDesc diff --git a/neuro-cli/tests/unit/formatters/test_jobs_formatters.py b/neuro-cli/tests/unit/formatters/test_jobs_formatters.py index e03887d40..377cdf4ae 100644 --- a/neuro-cli/tests/unit/formatters/test_jobs_formatters.py +++ b/neuro-cli/tests/unit/formatters/test_jobs_formatters.py @@ -434,7 +434,7 @@ def test_job_with_name( ) uri_fmtr = uri_formatter( - username="test-user", cluster_name="test-cluster", org_name=None + project_name="test-project", cluster_name="test-cluster", org_name=None ) rich_cmp( JobStatusFormatter( @@ -483,7 +483,7 @@ def test_job_with_org_urls( ) uri_fmtr = uri_formatter( - username="test-user", cluster_name="default", org_name="test-org" + project_name="test-project", cluster_name="default", org_name="test-org" ) rich_cmp( JobStatusFormatter( @@ -525,7 +525,7 @@ def test_job_with_tags( ) uri_fmtr = uri_formatter( - username="test-user", cluster_name="test-cluster", org_name=None + project_name="test-project", cluster_name="test-cluster", org_name=None ) rich_cmp( JobStatusFormatter( @@ -567,7 +567,7 @@ def test_job_with_tags_wrap_tags( ) uri_fmtr = uri_formatter( - username="test-user", cluster_name="test-cluster", org_name=None + project_name="test-project", cluster_name="test-cluster", org_name=None ) rich_cmp( JobStatusFormatter( @@ -609,7 +609,7 @@ def test_job_with_life_span_with_value( ) uri_fmtr = uri_formatter( - username="test-user", cluster_name="test-cluster", org_name=None + project_name="test-project", cluster_name="test-cluster", org_name=None ) rich_cmp( JobStatusFormatter( @@ -651,7 +651,7 @@ def test_job_with_life_span_without_value( ) uri_fmtr = uri_formatter( - username="test-user", cluster_name="test-cluster", org_name=None + project_name="test-project", cluster_name="test-cluster", org_name=None ) rich_cmp( JobStatusFormatter( @@ -694,7 +694,7 @@ def test_job_with_restart_policy( ) uri_fmtr = uri_formatter( - username="test-user", cluster_name="test-cluster", org_name=None + project_name="test-project", cluster_name="test-cluster", org_name=None ) rich_cmp( JobStatusFormatter( @@ -735,7 +735,7 @@ def test_pending_job( ) uri_fmtr = uri_formatter( - username="test-user", cluster_name="test-cluster", org_name=None + project_name="test-project", cluster_name="test-cluster", org_name=None ) rich_cmp( JobStatusFormatter( @@ -773,7 +773,7 @@ def test_pending_job_no_reason( ) uri_fmtr = uri_formatter( - username="test-user", cluster_name="test-cluster", org_name=None + project_name="test-project", cluster_name="test-cluster", org_name=None ) rich_cmp( JobStatusFormatter( @@ -812,7 +812,7 @@ def test_pending_job_with_reason( ) uri_fmtr = uri_formatter( - username="test-user", cluster_name="test-cluster", org_name=None + project_name="test-project", cluster_name="test-cluster", org_name=None ) rich_cmp( JobStatusFormatter( @@ -850,7 +850,7 @@ def test_pending_job_no_description( ) uri_fmtr = uri_formatter( - username="test-user", cluster_name="test-cluster", org_name=None + project_name="test-project", cluster_name="test-cluster", org_name=None ) rich_cmp( JobStatusFormatter( @@ -890,7 +890,7 @@ def test_running_job( ) uri_fmtr = uri_formatter( - username="test-user", cluster_name="test-cluster", org_name=None + project_name="test-project", cluster_name="test-cluster", org_name=None ) rich_cmp( JobStatusFormatter( @@ -951,7 +951,7 @@ def test_running_job_with_status_items( ) uri_fmtr = uri_formatter( - username="test-user", cluster_name="test-cluster", org_name=None + project_name="test-project", cluster_name="test-cluster", org_name=None ) rich_cmp( JobStatusFormatter( @@ -993,7 +993,7 @@ def test_running_named_job( ) uri_fmtr = uri_formatter( - username="test-user", cluster_name="test-cluster", org_name=None + project_name="test-project", cluster_name="test-cluster", org_name=None ) rich_cmp( JobStatusFormatter( @@ -1034,7 +1034,7 @@ def test_job_with_entrypoint( ) uri_fmtr = uri_formatter( - username="test-user", cluster_name="test-cluster", org_name=None + project_name="test-project", cluster_name="test-cluster", org_name=None ) rich_cmp( JobStatusFormatter( @@ -1084,7 +1084,7 @@ def test_job_with_environment( ) uri_fmtr = uri_formatter( - username="test-user", cluster_name="test-cluster", org_name=None + project_name="test-project", cluster_name="test-cluster", org_name=None ) rich_cmp( JobStatusFormatter( @@ -1150,7 +1150,7 @@ def test_job_with_volumes_short( ) uri_fmtr = uri_formatter( - username="test-user", cluster_name="test-cluster", org_name=None + project_name="test-project", cluster_name="test-cluster", org_name=None ) rich_cmp( JobStatusFormatter( @@ -1284,7 +1284,7 @@ def test_job_with_secrets_short( ) uri_fmtr = uri_formatter( - username="test-user", cluster_name="test-cluster", org_name=None + project_name="test-project", cluster_name="test-cluster", org_name=None ) rich_cmp( JobStatusFormatter( @@ -1350,7 +1350,7 @@ def test_job_with_disk_volumes_short( ) uri_fmtr = uri_formatter( - username="test-user", cluster_name="test-cluster", org_name=None + project_name="test-project", cluster_name="test-cluster", org_name=None ) rich_cmp( JobStatusFormatter( @@ -1400,7 +1400,7 @@ def test_job_with_working_dir( ) uri_fmtr = uri_formatter( - username="test-user", cluster_name="test-cluster", org_name=None + project_name="test-project", cluster_name="test-cluster", org_name=None ) rich_cmp( JobStatusFormatter( @@ -1439,7 +1439,7 @@ def test_job_with_preset_name( ) uri_fmtr = uri_formatter( - username="test-user", cluster_name="test-cluster", org_name=None + project_name="test-project", cluster_name="test-cluster", org_name=None ) rich_cmp( JobStatusFormatter( @@ -1478,7 +1478,7 @@ def test_job_on_preemptible_node( ) uri_fmtr = uri_formatter( - username="test-user", cluster_name="test-cluster", org_name=None + project_name="test-project", cluster_name="test-cluster", org_name=None ) rich_cmp( JobStatusFormatter( @@ -1518,7 +1518,7 @@ def test_job_with_org_name( ) uri_fmtr = uri_formatter( - username="test-user", cluster_name="test-cluster", org_name=None + project_name="test-project", cluster_name="test-cluster", org_name=None ) rich_cmp( JobStatusFormatter( @@ -1558,7 +1558,7 @@ def test_job_with_partial_credits( ) uri_fmtr = uri_formatter( - username="test-user", cluster_name="test-cluster", org_name=None + project_name="test-project", cluster_name="test-cluster", org_name=None ) rich_cmp( JobStatusFormatter( @@ -1598,7 +1598,7 @@ def test_job_with_energy_schedule( ) uri_fmtr = uri_formatter( - username="test-user", cluster_name="test-cluster", org_name=None + project_name="test-project", cluster_name="test-cluster", org_name=None ) rich_cmp( JobStatusFormatter( @@ -1977,13 +1977,15 @@ def test_status_date_relation( def test_image_from_registry_parsing_short( self, root: Root, datetime_formatter: DatetimeFormatter ) -> None: - uri_fmtr = uri_formatter(username="bob", cluster_name="default", org_name=None) + uri_fmtr = uri_formatter( + project_name="test-project", cluster_name="default", org_name=None + ) image_fmtr = image_formatter(uri_formatter=uri_fmtr) row = TabularJobRow.from_job( self._job_descr_with_status( root, JobStatus.PENDING, - "registry-dev.neu.ro/bob/swiss-box:red", + "registry-dev.neu.ro/test-project/swiss-box:red", ), "bob", image_formatter=image_fmtr, diff --git a/neuro-cli/tests/unit/formatters/test_utils.py b/neuro-cli/tests/unit/formatters/test_utils.py index 786886fd8..8ce879924 100644 --- a/neuro-cli/tests/unit/formatters/test_utils.py +++ b/neuro-cli/tests/unit/formatters/test_utils.py @@ -8,125 +8,143 @@ @pytest.mark.parametrize("scheme", ("storage", "image")) def test_uri_formatter_without_org(scheme: str) -> None: - fmtr = uri_formatter(username="user", cluster_name="cluster", org_name=None) + fmtr = uri_formatter( + project_name="test-project", cluster_name="cluster", org_name=None + ) assert ( - fmtr(URL(f"{scheme}://cluster/user/path/to/file")) == f"{scheme}:path/to/file" + fmtr(URL(f"{scheme}://cluster/test-project/path/to/file")) + == f"{scheme}:path/to/file" ) - assert fmtr(URL(f"{scheme}://cluster/user/")) == f"{scheme}:" - assert fmtr(URL(f"{scheme}://cluster/user")) == f"{scheme}:" + assert fmtr(URL(f"{scheme}://cluster/test-project/")) == f"{scheme}:" + assert fmtr(URL(f"{scheme}://cluster/test-project")) == f"{scheme}:" assert fmtr(URL(f"{scheme}://cluster/")) == f"{scheme}:/" assert fmtr(URL(f"{scheme}://cluster")) == f"{scheme}:/" assert ( - fmtr(URL(f"{scheme}://cluster/otheruser/path/to/file")) - == f"{scheme}:/otheruser/path/to/file" + fmtr(URL(f"{scheme}://cluster/other-project/path/to/file")) + == f"{scheme}:/other-project/path/to/file" ) assert ( - fmtr(URL(f"{scheme}://cluster/org/user/path/to/file")) - == f"{scheme}:/org/user/path/to/file" + fmtr(URL(f"{scheme}://cluster/org/test-project/path/to/file")) + == f"{scheme}:/org/test-project/path/to/file" ) assert ( - fmtr(URL(f"{scheme}://othercluster/user/path/to/file")) - == f"{scheme}://othercluster/user/path/to/file" + fmtr(URL(f"{scheme}://othercluster/test-project/path/to/file")) + == f"{scheme}://othercluster/test-project/path/to/file" ) assert fmtr(URL("user://cluster/user/rest")) == "user://cluster/user/rest" @pytest.mark.parametrize("scheme", ("storage", "image")) def test_uri_formatter_with_org(scheme: str) -> None: - fmtr = uri_formatter(username="user", cluster_name="cluster", org_name="org") + fmtr = uri_formatter( + project_name="test-project", cluster_name="cluster", org_name="org" + ) assert ( - fmtr(URL(f"{scheme}://cluster/org/user/path/to/file")) + fmtr(URL(f"{scheme}://cluster/org/test-project/path/to/file")) == f"{scheme}:path/to/file" ) - assert fmtr(URL(f"{scheme}://cluster/org/user/")) == f"{scheme}:" - assert fmtr(URL(f"{scheme}://cluster/org/user")) == f"{scheme}:" + assert fmtr(URL(f"{scheme}://cluster/org/test-project/")) == f"{scheme}:" + assert fmtr(URL(f"{scheme}://cluster/org/test-project")) == f"{scheme}:" assert fmtr(URL(f"{scheme}://cluster/org/")) == f"{scheme}:/" assert fmtr(URL(f"{scheme}://cluster/org")) == f"{scheme}:/" assert fmtr(URL(f"{scheme}://cluster/")) == f"{scheme}://cluster/" assert fmtr(URL(f"{scheme}://cluster")) == f"{scheme}://cluster" assert ( - fmtr(URL(f"{scheme}://cluster/user/path/to/file")) - == f"{scheme}://cluster/user/path/to/file" + fmtr(URL(f"{scheme}://cluster/test-project/path/to/file")) + == f"{scheme}://cluster/test-project/path/to/file" ) assert ( - fmtr(URL(f"{scheme}://cluster/org/otheruser/path/to/file")) - == f"{scheme}:/otheruser/path/to/file" + fmtr(URL(f"{scheme}://cluster/org/other-project/path/to/file")) + == f"{scheme}:/other-project/path/to/file" ) assert ( - fmtr(URL(f"{scheme}://cluster/otherorg/user/path/to/file")) - == f"{scheme}://cluster/otherorg/user/path/to/file" + fmtr(URL(f"{scheme}://cluster/otherorg/test-project/path/to/file")) + == f"{scheme}://cluster/otherorg/test-project/path/to/file" ) assert ( - fmtr(URL(f"{scheme}://othercluster/org/user/path/to/file")) - == f"{scheme}://othercluster/org/user/path/to/file" + fmtr(URL(f"{scheme}://othercluster/org/test-project/path/to/file")) + == f"{scheme}://othercluster/org/test-project/path/to/file" ) assert ( - fmtr(URL(f"{scheme}://cluster/user/path/to/file")) - == f"{scheme}://cluster/user/path/to/file" + fmtr(URL(f"{scheme}://cluster/test-project/path/to/file")) + == f"{scheme}://cluster/test-project/path/to/file" + ) + assert ( + fmtr(URL("user://cluster/org/test-project/rest")) + == "user://cluster/org/test-project/rest" ) - assert fmtr(URL("user://cluster/org/user/rest")) == "user://cluster/org/user/rest" @pytest.mark.parametrize("org_name", (None, "org")) def test_global_uri_formatter(org_name: Optional[str]) -> None: - fmtr = uri_formatter(username="user", cluster_name="cluster", org_name=org_name) + fmtr = uri_formatter( + project_name="test-project", cluster_name="cluster", org_name=org_name + ) assert fmtr(URL("user://cluster/user/rest")) == "user://cluster/user/rest" assert fmtr(URL("user://cluster/org/user/rest")) == "user://cluster/org/user/rest" @pytest.mark.parametrize("scheme", ("storage", "image")) def test_uri_formatter_special_chars_without_org(scheme: str) -> None: - fmtr = uri_formatter(username="user", cluster_name="cluster", org_name=None) + fmtr = uri_formatter( + project_name="test-project", cluster_name="cluster", org_name=None + ) assert ( - fmtr(URL(f"{scheme}://cluster/user/путь/к/файлу")) + fmtr(URL(f"{scheme}://cluster/test-project/путь/к/файлу")) == f"{scheme}:%D0%BF%D1%83%D1%82%D1%8C/%D0%BA/%D1%84%D0%B0%D0%B9%D0%BB%D1%83" ) assert ( - fmtr(URL(f"{scheme}://cluster/otheruser/путь/к/файлу")) - == f"{scheme}:/otheruser/" + fmtr(URL(f"{scheme}://cluster/other-project/путь/к/файлу")) + == f"{scheme}:/other-project/" "%D0%BF%D1%83%D1%82%D1%8C/%D0%BA/%D1%84%D0%B0%D0%B9%D0%BB%D1%83" ) assert ( - fmtr(URL(f"{scheme}://othercluster/user/путь/к/файлу")) - == f"{scheme}://othercluster/user/" + fmtr(URL(f"{scheme}://othercluster/test-project/путь/к/файлу")) + == f"{scheme}://othercluster/test-project/" "%D0%BF%D1%83%D1%82%D1%8C/%D0%BA/%D1%84%D0%B0%D0%B9%D0%BB%D1%83" ) - assert fmtr(URL(f"{scheme}://cluster/user/%2525%3f%23")) == f"{scheme}:%2525%3F%23" assert ( - fmtr(URL(f"{scheme}://cluster/otheruser/%2525%3f%23")) - == f"{scheme}:/otheruser/%2525%3F%23" + fmtr(URL(f"{scheme}://cluster/test-project/%2525%3f%23")) + == f"{scheme}:%2525%3F%23" ) assert ( - fmtr(URL(f"{scheme}://othercluster/user/%2525%3f%23")) - == f"{scheme}://othercluster/user/%2525%3F%23" + fmtr(URL(f"{scheme}://cluster/other-project/%2525%3f%23")) + == f"{scheme}:/other-project/%2525%3F%23" + ) + assert ( + fmtr(URL(f"{scheme}://othercluster/other-project/%2525%3f%23")) + == f"{scheme}://othercluster/other-project/%2525%3F%23" ) @pytest.mark.parametrize("scheme", ("storage", "image")) def test_uri_formatter_special_chars_with_org(scheme: str) -> None: - fmtr = uri_formatter(username="user", cluster_name="cluster", org_name="org") + fmtr = uri_formatter( + project_name="test-project", cluster_name="cluster", org_name="org" + ) assert ( - fmtr(URL(f"{scheme}://cluster/org/user/путь/к/файлу")) + fmtr(URL(f"{scheme}://cluster/org/test-project/путь/к/файлу")) == f"{scheme}:%D0%BF%D1%83%D1%82%D1%8C/%D0%BA/%D1%84%D0%B0%D0%B9%D0%BB%D1%83" ) assert ( - fmtr(URL(f"{scheme}://cluster/org/otheruser/путь/к/файлу")) - == f"{scheme}:/otheruser/" + fmtr(URL(f"{scheme}://cluster/org/other-project/путь/к/файлу")) + == f"{scheme}:/other-project/" "%D0%BF%D1%83%D1%82%D1%8C/%D0%BA/%D1%84%D0%B0%D0%B9%D0%BB%D1%83" ) assert ( - fmtr(URL(f"{scheme}://othercluster/org/user/путь/к/файлу")) - == f"{scheme}://othercluster/org/user/" + fmtr(URL(f"{scheme}://othercluster/org/test-project/путь/к/файлу")) + == f"{scheme}://othercluster/org/test-project/" "%D0%BF%D1%83%D1%82%D1%8C/%D0%BA/%D1%84%D0%B0%D0%B9%D0%BB%D1%83" ) assert ( - fmtr(URL(f"{scheme}://cluster/org/user/%2525%3f%23")) == f"{scheme}:%2525%3F%23" + fmtr(URL(f"{scheme}://cluster/org/test-project/%2525%3f%23")) + == f"{scheme}:%2525%3F%23" ) assert ( - fmtr(URL(f"{scheme}://cluster/org/otheruser/%2525%3f%23")) - == f"{scheme}:/otheruser/%2525%3F%23" + fmtr(URL(f"{scheme}://cluster/org/other-project/%2525%3f%23")) + == f"{scheme}:/other-project/%2525%3F%23" ) assert ( - fmtr(URL(f"{scheme}://othercluster/org/user/%2525%3f%23")) - == f"{scheme}://othercluster/org/user/%2525%3F%23" + fmtr(URL(f"{scheme}://othercluster/org/test-project/%2525%3f%23")) + == f"{scheme}://othercluster/org/test-project/%2525%3F%23" )