Skip to content

Commit 9340b4d

Browse files
author
Ruslan Gainutdinov
committed
fix: add test for spot
1 parent dea5950 commit 9340b4d

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import logging
2+
import os
3+
import time
4+
5+
import pytest
6+
7+
from verda import VerdaClient
8+
from verda.constants import Locations
9+
from verda.instances import OSVolume
10+
11+
IN_GITHUB_ACTIONS = os.getenv('GITHUB_ACTIONS') == 'true'
12+
13+
logging.basicConfig(level=logging.DEBUG)
14+
logger = logging.getLogger()
15+
16+
17+
@pytest.mark.skipif(IN_GITHUB_ACTIONS, reason="Test doesn't work in Github Actions.")
18+
@pytest.mark.withoutresponses
19+
class TestInstances:
20+
def test_create_spot(self, verda_client: VerdaClient):
21+
# get ssh key
22+
ssh_key = verda_client.ssh_keys.get()[0]
23+
24+
# create instance
25+
instance = verda_client.instances.create(
26+
hostname='test-instance',
27+
location=Locations.FIN_03,
28+
instance_type='CPU.4V.16G',
29+
description='test cpu instance',
30+
image='ubuntu-22.04',
31+
is_spot=True,
32+
ssh_key_ids=[ssh_key.id],
33+
os_volume=OSVolume(name='test-os-volume-spot', size=56, on_spot_discontinue='delete_permanently'),
34+
)
35+
36+
# assert instance is created
37+
assert instance.id is not None
38+
assert instance.status == verda_client.constants.instance_status.PROVISIONING
39+
40+
while instance.status != verda_client.constants.instance_status.RUNNING:
41+
time.sleep(2)
42+
logger.debug('Waiting for instance to be running... %s', instance.status)
43+
instance = verda_client.instances.get_by_id(instance.id)
44+
45+
logger.debug('Instance is running... %s', instance.status)
46+
logger.debug('Instance ID: %s', instance.id)
47+
logger.debug('Instance OS Volume ID: %s', instance.os_volume_id)
48+
logger.debug('Instance IP: %s', instance.ip)
49+
50+
# assert os volume is created
51+
assert instance.os_volume_id is not None
52+
53+
# get os volume
54+
os_volume = verda_client.volumes.get_by_id(instance.os_volume_id)
55+
assert os_volume.id is not None
56+
assert os_volume.name == 'test-os-volume-spot'
57+
assert os_volume.size == 56

0 commit comments

Comments
 (0)