Skip to content

Commit 4f1db13

Browse files
authored
Merge pull request #10 from DataCrunch-io/feature/add-spot-support-for-availability-check
Feature/add spot support for availability check
2 parents 3b59926 + 2441674 commit 4f1db13

File tree

5 files changed

+32
-8
lines changed

5 files changed

+32
-8
lines changed

.github/workflows/code_style.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ on: [push, pull_request]
88

99
jobs:
1010
build:
11-
runs-on: ubuntu-latest
11+
runs-on: ubuntu-20.04
1212
strategy:
1313
matrix:
14-
python-version: [3.6, 3.7, 3.8, 3.9]
14+
python-version: [3.6, 3.7, 3.8, 3.9, '3.10', 3.11]
1515

1616
steps:
1717
- uses: actions/checkout@v2

.github/workflows/unit_tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ on: [push, pull_request]
88

99
jobs:
1010
build:
11-
runs-on: ubuntu-latest
11+
runs-on: ubuntu-20.04
1212
strategy:
1313
matrix:
14-
python-version: [3.6, 3.7, 3.8, 3.9]
14+
python-version: [3.6, 3.7, 3.8, 3.9, '3.10', 3.11]
1515

1616
steps:
1717
- uses: actions/checkout@v2
@@ -30,7 +30,7 @@ jobs:
3030
run: |
3131
pytest --cov=datacrunch
3232
33-
- name: "Upload coverage to Codecov"
33+
- name: 'Upload coverage to Codecov'
3434
uses: codecov/codecov-action@v1
3535
with:
3636
fail_ci_if_error: true

CHANGELOG.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
Changelog
22
=========
33

4+
* Added support for checking availability for a spot instance
5+
* Updated two github actions to run on fixed version of ubuntu because the latest one is missing python 3.6
6+
* Added more version of python to be used on two github actions
7+
48
v1.0.10 (2022-10-18)
59
-------------------
610

datacrunch/instances/instances.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ def create(self,
375375
:param is_spot: Is spot instance
376376
:type is_spot: bool, optional
377377
:param coupon: coupon code
378-
:type is_spot: str, optional
378+
:type coupon: str, optional
379379
:return: the new instance object
380380
:rtype: id
381381
"""
@@ -418,13 +418,16 @@ def action(self, id_list: Union[List[str], str], action: str, volume_ids: Option
418418
self._http_client.put(INSTANCES_ENDPOINT, json=payload)
419419
return
420420

421-
def is_available(self, instance_type: str) -> bool:
421+
def is_available(self, instance_type: str, is_spot: bool = None) -> bool:
422422
"""Returns True if a specific instance type is now available for deployment
423423
424424
:param instance_type: instance type
425425
:type instance_type: str
426+
:param is_spot: Is spot instance
427+
:type is_spot: bool, optional
426428
:return: True if available to deploy, False otherwise
427429
:rtype: bool
428430
"""
429-
url = f'/instance-availability/{instance_type}'
431+
query_param = '?isSpot=true' if is_spot else ''
432+
url = f'/instance-availability/{instance_type}{query_param}'
430433
return self._http_client.get(url).json()

tests/unit_tests/instances/test_instances.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,23 @@ def test_is_available_successful(self, instances_service):
439439
assert is_available is True
440440
assert responses.assert_call_count(url, 1) is True
441441

442+
def test_is_spot_available_successful(self, instances_service):
443+
# arrange - add response mock
444+
url = instances_service._http_client._base_url + '/instance-availability/' + INSTANCE_TYPE + '?isSpot=true'
445+
responses.add(
446+
responses.GET,
447+
url,
448+
json=True,
449+
status=200
450+
)
451+
452+
# act
453+
is_available = instances_service.is_available(INSTANCE_TYPE, is_spot=True)
454+
455+
# assert
456+
assert is_available is True
457+
assert responses.assert_call_count(url, 1) is True
458+
442459
def test_is_available_failed(self, instances_service):
443460
# arrange - add response mock
444461
url = instances_service._http_client._base_url + '/instance-availability/x'

0 commit comments

Comments
 (0)