proximl 0.5.4__py3-none-any.whl → 0.5.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -269,7 +269,7 @@ class JobAPIDataValidationTests:
269
269
  ),
270
270
  )
271
271
  assert (
272
- "Invalid Request - Only regional datastore are allowed for Notebook and Endpoint output locations"
272
+ "Invalid Request - output_type invalid for Notebook and Endpoint jobs"
273
273
  in error.value.message
274
274
  )
275
275
 
@@ -298,7 +298,45 @@ class JobAPIDataValidationTests:
298
298
  ),
299
299
  )
300
300
  assert (
301
- "Invalid Request - Only regional datastore are allowed for Notebook and Endpoint output locations"
301
+ "Invalid Request - output_type invalid for Notebook and Endpoint jobs"
302
+ in error.value.message
303
+ )
304
+
305
+ async def test_invalid_volumes_for_training(self, proximl):
306
+ with raises(ApiError) as error:
307
+ await proximl.jobs.create(
308
+ name="Invalid Volumes for Training",
309
+ type="training",
310
+ gpu_types=["rtx3090"],
311
+ disk_size=10,
312
+ data=dict(
313
+ output_uri="s3://proximl-examples/output/resnet_cifar10",
314
+ output_type="aws",
315
+ volumes=["volume-id"],
316
+ ),
317
+ workers=["python train.py"],
318
+ )
319
+ assert (
320
+ "Invalid Request - Only Notebook and Endpoint job types can use writable volumes"
321
+ in error.value.message
322
+ )
323
+
324
+ async def test_invalid_volumes_for_inference(self, proximl):
325
+ with raises(ApiError) as error:
326
+ await proximl.jobs.create(
327
+ name="Invalid Volumes for Inference",
328
+ type="inference",
329
+ gpu_types=["rtx3090"],
330
+ disk_size=10,
331
+ data=dict(
332
+ output_uri="s3://proximl-examples/output/resnet_cifar10",
333
+ output_type="aws",
334
+ volumes=["volume-id"],
335
+ ),
336
+ workers=["python predict.py"],
337
+ )
338
+ assert (
339
+ "Invalid Request - Only Notebook and Endpoint job types can use writable volumes"
302
340
  in error.value.message
303
341
  )
304
342
 
@@ -43,29 +43,27 @@ class GetModelTests:
43
43
 
44
44
  async def test_model_repr(self, model):
45
45
  string = repr(model)
46
- regex = (
47
- r"^Model\( proximl , \*\*{.*'model_uuid': '"
48
- + model.id
49
- + r"'.*}\)$"
50
- )
46
+ regex = r"^Model\( proximl , \*\*{.*'model_uuid': '" + model.id + r"'.*}\)$"
51
47
  assert isinstance(string, str)
52
48
  assert re.match(regex, string)
53
49
 
54
50
 
55
51
  @mark.create
56
52
  @mark.asyncio
57
- async def test_model_aws(proximl, capsys):
53
+ async def test_model_wasabi(proximl, capsys):
58
54
  model = await proximl.models.create(
59
- name="CLI Automated AWS",
60
- source_type="aws",
61
- source_uri="s3://proximl-examples/models/mxnet-model.zip",
55
+ name="CLI Automated Wasabi",
56
+ source_type="wasabi",
57
+ source_uri="s3://proximl-example/models/proximl-examples",
58
+ capacity="10G",
59
+ source_options=dict(endpoint_url="https://s3.wasabisys.com"),
62
60
  )
63
61
  model = await model.wait_for("ready", 300)
64
62
  status = model.status
65
63
  size = model.size
66
64
  await model.remove()
67
65
  assert status == "ready"
68
- assert size >= 1000000
66
+ assert size >= 500000
69
67
 
70
68
 
71
69
  @mark.create
@@ -11,9 +11,7 @@ pytestmark = [mark.sdk, mark.integration, mark.projects]
11
11
  class GetProjectsTests:
12
12
  @fixture(scope="class")
13
13
  async def project(self, proximl):
14
- project = await proximl.projects.create(
15
- name="New Project", copy_keys=False
16
- )
14
+ project = await proximl.projects.create(name="New Project", copy_keys=False)
17
15
  yield project
18
16
  await project.remove()
19
17
 
@@ -41,8 +39,6 @@ class GetProjectsTests:
41
39
 
42
40
  async def test_project_repr(self, project):
43
41
  string = repr(project)
44
- regex = (
45
- r"^Project\( proximl , \*\*{.*'id': '" + project.id + r"'.*}\)$"
46
- )
42
+ regex = r"^Project\( proximl , \*\*{.*'id': '" + project.id + r"'.*}\)$"
47
43
  assert isinstance(string, str)
48
44
  assert re.match(regex, string)
@@ -0,0 +1,100 @@
1
+ import re
2
+ import sys
3
+ import asyncio
4
+ from pytest import mark, fixture
5
+
6
+ pytestmark = [mark.sdk, mark.integration, mark.volumes]
7
+
8
+
9
+ @mark.create
10
+ @mark.asyncio
11
+ class GetVolumeTests:
12
+ @fixture(scope="class")
13
+ async def volume(self, proximl):
14
+ volume = await proximl.volumes.create(
15
+ name="CLI Automated",
16
+ source_type="git",
17
+ source_uri="git@github.com:proxiML/environment-tests.git",
18
+ capacity="10G",
19
+ )
20
+ volume = await volume.wait_for("ready", 120)
21
+ yield volume
22
+ await volume.remove()
23
+ volume = await volume.wait_for("archived", 60)
24
+
25
+ async def test_get_volumes(self, proximl, volume):
26
+ volumes = await proximl.volumes.list()
27
+ assert len(volumes) > 0
28
+
29
+ async def test_get_volume(self, proximl, volume):
30
+ response = await proximl.volumes.get(volume.id)
31
+ assert response.id == volume.id
32
+
33
+ async def test_volume_properties(self, volume):
34
+ assert isinstance(volume.id, str)
35
+ assert isinstance(volume.status, str)
36
+ assert isinstance(volume.name, str)
37
+ assert isinstance(volume.capacity, str)
38
+ assert isinstance(volume.used_size, int)
39
+ assert isinstance(volume.billed_size, int)
40
+
41
+ async def test_volume_str(self, volume):
42
+ string = str(volume)
43
+ regex = r"^{.*\"id\": \"" + volume.id + r"\".*}$"
44
+ assert isinstance(string, str)
45
+ assert re.match(regex, string)
46
+
47
+ async def test_volume_repr(self, volume):
48
+ string = repr(volume)
49
+ regex = r"^Volume\( proximl , \*\*{.*'id': '" + volume.id + r"'.*}\)$"
50
+ assert isinstance(string, str)
51
+ assert re.match(regex, string)
52
+
53
+
54
+ @mark.create
55
+ @mark.asyncio
56
+ async def test_volume_wasabi(proximl, capsys):
57
+ volume = await proximl.volumes.create(
58
+ name="CLI Automated Wasabi",
59
+ source_type="wasabi",
60
+ source_uri="s3://proximl-example/models/proximl-examples",
61
+ capacity="10G",
62
+ source_options=dict(endpoint_url="https://s3.wasabisys.com"),
63
+ )
64
+ volume = await volume.wait_for("ready", 300)
65
+ status = volume.status
66
+ billed_size = volume.billed_size
67
+ used_size = volume.used_size
68
+ await volume.remove()
69
+ assert status == "ready"
70
+ assert billed_size >= 10000000
71
+ assert used_size >= 500000
72
+
73
+
74
+ @mark.create
75
+ @mark.asyncio
76
+ async def test_volume_local(proximl, capsys):
77
+ volume = await proximl.volumes.create(
78
+ name="CLI Automated Local",
79
+ source_type="local",
80
+ source_uri="~/tensorflow-model",
81
+ capacity="10G",
82
+ )
83
+ attach_task = asyncio.create_task(volume.attach())
84
+ connect_task = asyncio.create_task(volume.connect())
85
+ await asyncio.gather(attach_task, connect_task)
86
+ await volume.disconnect()
87
+ await volume.refresh()
88
+ status = volume.status
89
+ billed_size = volume.billed_size
90
+ used_size = volume.used_size
91
+ await volume.remove()
92
+ assert status == "ready"
93
+ assert billed_size >= 10000000
94
+ assert used_size >= 1000000
95
+ captured = capsys.readouterr()
96
+ sys.stdout.write(captured.out)
97
+ sys.stderr.write(captured.err)
98
+ assert "Starting data upload from local" in captured.out
99
+ assert "official/LICENSE 11456 bytes" in captured.out
100
+ assert "Upload complete" in captured.out
@@ -0,0 +1,20 @@
1
+ import re
2
+ import json
3
+ import click
4
+ from unittest.mock import AsyncMock, patch
5
+ from pytest import mark, fixture, raises
6
+
7
+ pytestmark = [mark.cli, mark.unit, mark.volumes]
8
+
9
+ from proximl.cli import volume as specimen
10
+ from proximl.volumes import Volume
11
+
12
+
13
+ def test_list(runner, mock_my_volumes):
14
+ with patch("proximl.cli.ProxiML", new=AsyncMock) as mock_proximl:
15
+ mock_proximl.volumes = AsyncMock()
16
+ mock_proximl.volumes.list = AsyncMock(return_value=mock_my_volumes)
17
+ result = runner.invoke(specimen, ["list"])
18
+ print(result)
19
+ assert result.exit_code == 0
20
+ mock_proximl.volumes.list.assert_called_once()
@@ -0,0 +1,161 @@
1
+ import re
2
+ import json
3
+ import logging
4
+ from unittest.mock import AsyncMock, patch
5
+ from pytest import mark, fixture, raises
6
+ from aiohttp import WSMessage, WSMsgType
7
+
8
+ import proximl.cloudbender.services as specimen
9
+ from proximl.exceptions import (
10
+ ApiError,
11
+ SpecificationError,
12
+ ProxiMLException,
13
+ )
14
+
15
+ pytestmark = [mark.sdk, mark.unit, mark.cloudbender, mark.services]
16
+
17
+
18
+ @fixture
19
+ def services(mock_proximl):
20
+ yield specimen.Services(mock_proximl)
21
+
22
+
23
+ @fixture
24
+ def service(mock_proximl):
25
+ yield specimen.Service(
26
+ mock_proximl,
27
+ provider_uuid="1",
28
+ region_uuid="a",
29
+ service_id="x",
30
+ name="On-Prem Service",
31
+ public=False,
32
+ hostname="app1.proximl.cloud",
33
+ )
34
+
35
+
36
+ class RegionsTests:
37
+ @mark.asyncio
38
+ async def test_get_service(
39
+ self,
40
+ services,
41
+ mock_proximl,
42
+ ):
43
+ api_response = dict()
44
+ mock_proximl._query = AsyncMock(return_value=api_response)
45
+ await services.get("1234", "5687", "91011")
46
+ mock_proximl._query.assert_called_once_with(
47
+ "/provider/1234/region/5687/service/91011", "GET", {}
48
+ )
49
+
50
+ @mark.asyncio
51
+ async def test_list_services(
52
+ self,
53
+ services,
54
+ mock_proximl,
55
+ ):
56
+ api_response = dict()
57
+ mock_proximl._query = AsyncMock(return_value=api_response)
58
+ await services.list("1234", "5687")
59
+ mock_proximl._query.assert_called_once_with(
60
+ "/provider/1234/region/5687/service", "GET", {}
61
+ )
62
+
63
+ @mark.asyncio
64
+ async def test_remove_service(
65
+ self,
66
+ services,
67
+ mock_proximl,
68
+ ):
69
+ api_response = dict()
70
+ mock_proximl._query = AsyncMock(return_value=api_response)
71
+ await services.remove("1234", "4567", "8910")
72
+ mock_proximl._query.assert_called_once_with(
73
+ "/provider/1234/region/4567/service/8910", "DELETE", {}
74
+ )
75
+
76
+ @mark.asyncio
77
+ async def test_create_service(self, services, mock_proximl):
78
+ requested_config = dict(
79
+ provider_uuid="provider-id-1",
80
+ region_uuid="region-id-1",
81
+ name="On-Prem Service",
82
+ public=False,
83
+ )
84
+ expected_payload = dict(
85
+ name="On-Prem Service",
86
+ public=False,
87
+ )
88
+ api_response = {
89
+ "provider_uuid": "provider-id-1",
90
+ "region_uuid": "region-id-1",
91
+ "service_id": "service-id-1",
92
+ "name": "On-Prem Service",
93
+ "public": False,
94
+ "hostname": "app1.proximl.cloud",
95
+ "createdAt": "2020-12-31T23:59:59.000Z",
96
+ }
97
+
98
+ mock_proximl._query = AsyncMock(return_value=api_response)
99
+ response = await services.create(**requested_config)
100
+ mock_proximl._query.assert_called_once_with(
101
+ "/provider/provider-id-1/region/region-id-1/service",
102
+ "POST",
103
+ None,
104
+ expected_payload,
105
+ )
106
+ assert response.id == "service-id-1"
107
+
108
+
109
+ class serviceTests:
110
+ def test_service_properties(self, service):
111
+ assert isinstance(service.id, str)
112
+ assert isinstance(service.provider_uuid, str)
113
+ assert isinstance(service.region_uuid, str)
114
+ assert isinstance(service.public, bool)
115
+ assert isinstance(service.name, str)
116
+ assert isinstance(service.hostname, str)
117
+
118
+ def test_service_str(self, service):
119
+ string = str(service)
120
+ regex = r"^{.*\"service_id\": \"" + service.id + r"\".*}$"
121
+ assert isinstance(string, str)
122
+ assert re.match(regex, string)
123
+
124
+ def test_service_repr(self, service):
125
+ string = repr(service)
126
+ regex = r"^Service\( proximl , \*\*{.*'service_id': '" + service.id + r"'.*}\)$"
127
+ assert isinstance(string, str)
128
+ assert re.match(regex, string)
129
+
130
+ def test_service_bool(self, service, mock_proximl):
131
+ empty_service = specimen.Service(mock_proximl)
132
+ assert bool(service)
133
+ assert not bool(empty_service)
134
+
135
+ @mark.asyncio
136
+ async def test_service_remove(self, service, mock_proximl):
137
+ api_response = dict()
138
+ mock_proximl._query = AsyncMock(return_value=api_response)
139
+ await service.remove()
140
+ mock_proximl._query.assert_called_once_with(
141
+ "/provider/1/region/a/service/x", "DELETE"
142
+ )
143
+
144
+ @mark.asyncio
145
+ async def test_service_refresh(self, service, mock_proximl):
146
+ api_response = {
147
+ "provider_uuid": "provider-id-1",
148
+ "region_uuid": "region-id-1",
149
+ "service_id": "service-id-1",
150
+ "name": "On-Prem Service",
151
+ "public": False,
152
+ "hostname": "app1.proximl.cloud",
153
+ "createdAt": "2020-12-31T23:59:59.000Z",
154
+ }
155
+ mock_proximl._query = AsyncMock(return_value=api_response)
156
+ response = await service.refresh()
157
+ mock_proximl._query.assert_called_once_with(
158
+ f"/provider/1/region/a/service/x", "GET"
159
+ )
160
+ assert service.id == "service-id-1"
161
+ assert response.id == "service-id-1"
tests/unit/conftest.py CHANGED
@@ -7,6 +7,7 @@ from proximl.proximl import ProxiML
7
7
  from proximl.auth import Auth
8
8
  from proximl.datasets import Dataset, Datasets
9
9
  from proximl.checkpoints import Checkpoint, Checkpoints
10
+ from proximl.volumes import Volume, Volumes
10
11
  from proximl.models import Model, Models
11
12
  from proximl.gpu_types import GpuType, GpuTypes
12
13
  from proximl.environments import Environment, Environments
@@ -258,6 +259,79 @@ def mock_models():
258
259
  ]
259
260
 
260
261
 
262
+ @fixture(scope="session")
263
+ def mock_my_volumes():
264
+ proximl = Mock()
265
+ yield [
266
+ Volume(
267
+ proximl,
268
+ id="1",
269
+ project_uuid="proj-id-1",
270
+ name="first one",
271
+ status="ready",
272
+ capacity="10G",
273
+ used_size=100000000,
274
+ billed_size=100000000,
275
+ createdAt="2020-12-31T23:59:59.000Z",
276
+ ),
277
+ Volume(
278
+ proximl,
279
+ id="2",
280
+ project_uuid="proj-id-1",
281
+ name="second one",
282
+ status="ready",
283
+ capacity="10G",
284
+ used_size=100000000,
285
+ billed_size=100000000,
286
+ createdAt="2021-01-01T00:00:01.000Z",
287
+ ),
288
+ Volume(
289
+ proximl,
290
+ id="3",
291
+ project_uuid="proj-id-1",
292
+ name="first one",
293
+ status="ready",
294
+ capacity="10G",
295
+ used_size=100000000,
296
+ billed_size=100000000,
297
+ createdAt="2021-01-01T00:00:01.000Z",
298
+ ),
299
+ Volume(
300
+ proximl,
301
+ id="4",
302
+ project_uuid="proj-id-1",
303
+ name="other one",
304
+ status="ready",
305
+ capacity="10G",
306
+ used_size=100000000,
307
+ billed_size=100000000,
308
+ createdAt="2020-12-31T23:59:59.000Z",
309
+ ),
310
+ Volume(
311
+ proximl,
312
+ id="5",
313
+ project_uuid="proj-id-1",
314
+ name="not ready",
315
+ status="new",
316
+ capacity="10G",
317
+ used_size=100000000,
318
+ billed_size=100000000,
319
+ createdAt="2021-01-01T00:00:01.000Z",
320
+ ),
321
+ Volume(
322
+ proximl,
323
+ id="6",
324
+ project_uuid="proj-id-1",
325
+ name="failed",
326
+ status="failed",
327
+ capacity="10G",
328
+ used_size=100000000,
329
+ billed_size=100000000,
330
+ createdAt="2021-01-01T00:00:01.000Z",
331
+ ),
332
+ ]
333
+
334
+
261
335
  @fixture(scope="session")
262
336
  def mock_gpu_types():
263
337
  proximl = Mock()
@@ -903,6 +977,9 @@ def mock_device_configs():
903
977
  def mock_proximl(
904
978
  mock_my_datasets,
905
979
  mock_public_datasets,
980
+ mock_my_checkpoints,
981
+ mock_public_checkpoints,
982
+ mock_my_volumes,
906
983
  mock_models,
907
984
  mock_gpu_types,
908
985
  mock_environments,
@@ -921,6 +998,7 @@ def mock_proximl(
921
998
  proximl.project = "proj-id-1"
922
999
  proximl.datasets = create_autospec(Datasets)
923
1000
  proximl.checkpoints = create_autospec(Checkpoints)
1001
+ proximl.volumes = create_autospec(Volumes)
924
1002
  proximl.models = create_autospec(Models)
925
1003
  proximl.gpu_types = create_autospec(GpuTypes)
926
1004
  proximl.environments = create_autospec(Environments)
@@ -930,10 +1008,9 @@ def mock_proximl(
930
1008
  proximl.datasets.list = AsyncMock(return_value=mock_my_datasets)
931
1009
  proximl.datasets.list_public = AsyncMock(return_value=mock_public_datasets)
932
1010
  proximl.checkpoints.list = AsyncMock(return_value=mock_my_checkpoints)
933
- proximl.checkpoints.list_public = AsyncMock(
934
- return_value=mock_public_checkpoints
935
- )
1011
+ proximl.checkpoints.list_public = AsyncMock(return_value=mock_public_checkpoints)
936
1012
  proximl.models.list = AsyncMock(return_value=mock_models)
1013
+ proximl.volumes.list = AsyncMock(return_value=mock_my_volumes)
937
1014
  proximl.gpu_types.list = AsyncMock(return_value=mock_gpu_types)
938
1015
  proximl.environments.list = AsyncMock(return_value=mock_environments)
939
1016
  proximl.jobs.list = AsyncMock(return_value=mock_jobs)
@@ -950,13 +1027,9 @@ def mock_proximl(
950
1027
  proximl.cloudbender.devices = create_autospec(Nodes)
951
1028
  proximl.cloudbender.devices.list = AsyncMock(return_value=mock_devices)
952
1029
  proximl.cloudbender.datastores = create_autospec(Datastores)
953
- proximl.cloudbender.datastores.list = AsyncMock(
954
- return_value=mock_datastores
955
- )
1030
+ proximl.cloudbender.datastores.list = AsyncMock(return_value=mock_datastores)
956
1031
  proximl.cloudbender.reservations = create_autospec(Reservations)
957
- proximl.cloudbender.reservations.list = AsyncMock(
958
- return_value=mock_reservations
959
- )
1032
+ proximl.cloudbender.reservations.list = AsyncMock(return_value=mock_reservations)
960
1033
  proximl.cloudbender.device_configs = create_autospec(DeviceConfigs)
961
1034
  proximl.cloudbender.device_configs.list = AsyncMock(
962
1035
  return_value=mock_device_configs