Skip to content

Commit faa1d66

Browse files
committed
basic tests added
1 parent e722362 commit faa1d66

17 files changed

+454
-305
lines changed

.pre-commit-config.yaml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
repos:
2+
- repo: https://github.com/timothycrosley/isort
3+
rev: 5.4.2
4+
hooks:
5+
- id: isort
6+
language_version: python3.7
7+
args: [--line-length=127]
8+
- repo: https://github.com/python/black
9+
rev: 20.8b1
10+
hooks:
11+
- id: black
12+
language_version: python3.7
13+
args: [--line-length=127]
14+
- repo: https://gitlab.com/pycqa/flake8
15+
rev: 3.8.3
16+
hooks:
17+
- id: flake8
18+
additional_dependencies: [
19+
flake8-docstrings,
20+
flake8-builtins,
21+
flake8-comprehensions,
22+
flake8-print,
23+
flake8-eradicate,
24+
]
25+
language_version: python3.7
26+
args: [
27+
--max-line-length=127,
28+
'--ignore=D100,D101,D102,D103,D104,D105,D106,D107,D200,D210,D401,W503,E203'
29+
]
30+
# See https://stackoverflow.com/questions/61238318/pylint-and-pre-commit-hook-unable-to-import/61238571#61238571
31+
- repo: local
32+
hooks:
33+
- id: pylint
34+
name: pylint
35+
entry: pylint
36+
language: system
37+
types: [python]
38+
args: [
39+
--max-line-length=127,
40+
--max-public-methods=32,
41+
--max-args=8,
42+
'--disable=too-few-public-methods,logging-fstring-interpolation,too-many-instance-attributes,no-else-return,too-many-locals,no-self-use,duplicate-code,broad-except,logging-not-lazy,unspecified-encoding',
43+
'--good-names=ip,rc,eval'
44+
]

build/lib/cloudshell/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
__author__ = 'quali'
1+
__author__ = "quali"
22
from pkgutil import extend_path
3-
__path__ = extend_path(__path__, __name__)
3+
4+
__path__ = extend_path(__path__, __name__)
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
__author__ = 'quali'
1+
__author__ = "quali"
22
from pkgutil import extend_path
3-
__path__ = extend_path(__path__, __name__)
3+
4+
__path__ = extend_path(__path__, __name__)

build/lib/cloudshell/sandbox_rest/sandbox_api.py

Lines changed: 77 additions & 70 deletions
Large diffs are not rendered by default.

cloudshell/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
__author__ = 'quali'
1+
__author__ = "quali"
22
from pkgutil import extend_path
3-
__path__ = extend_path(__path__, __name__)
3+
4+
__path__ = extend_path(__path__, __name__)
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
__author__ = 'quali'
1+
__author__ = "quali"
22
from pkgutil import extend_path
3-
__path__ = extend_path(__path__, __name__)
3+
4+
__path__ = extend_path(__path__, __name__)

cloudshell/sandbox_rest/helpers/polling_helpers.py

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
Using 'retrying' library to do polling:
44
https://pypi.org/project/retrying/
55
"""
6-
from typing import List, Callable
7-
from retrying import retry, RetryError # pip install retrying
8-
from cloudshell.sandbox_rest.sandbox_api import SandboxRestApiSession
96
from enum import Enum
7+
from typing import Callable, List
8+
9+
from retrying import RetryError, retry # pip install retrying
10+
11+
from cloudshell.sandbox_rest.sandbox_api import SandboxRestApiSession
1012

1113

1214
class OrchestrationPollingTimeout(Exception):
@@ -18,8 +20,8 @@ class CommandPollingTimeout(Exception):
1820

1921

2022
class SandboxStates(Enum):
21-
before_setup_state = "BeforeSetup"
22-
running_setup_state = "Setup"
23+
BEFORE_SETUP_STATE = "BeforeSetup"
24+
RUNNING_SETUP_STATE = "Setup"
2325
error_state = "Error"
2426
ready_state = "Ready"
2527
teardown_state = "Teardown"
@@ -33,19 +35,16 @@ class ExecutionStatuses(Enum):
3335
failed_status = "Failed"
3436

3537

36-
SANDBOX_SETUP_STATES = [SandboxStates.before_setup_state.value,
37-
SandboxStates.running_setup_state.value]
38+
SANDBOX_SETUP_STATES = [SandboxStates.BEFORE_SETUP_STATE.value, SandboxStates.RUNNING_SETUP_STATE.value]
3839

39-
SANDBOX_ACTIVE_STATES = [SandboxStates.ready_state.value,
40-
SandboxStates.error_state.value]
40+
SANDBOX_ACTIVE_STATES = [SandboxStates.ready_state.value, SandboxStates.error_state.value]
4141

42-
UNFINISHED_EXECUTION_STATUSES = [ExecutionStatuses.running_status.value,
43-
ExecutionStatuses.pending_status.value]
42+
UNFINISHED_EXECUTION_STATUSES = [ExecutionStatuses.running_status.value, ExecutionStatuses.pending_status.value]
4443

4544

4645
def _should_we_keep_polling_setup(sandbox_details: dict) -> bool:
4746
""" if still in setup keep polling """
48-
setup_states = [SandboxStates.before_setup_state.value, SandboxStates.running_setup_state.value]
47+
setup_states = [SandboxStates.BEFORE_SETUP_STATE.value, SandboxStates.RUNNING_SETUP_STATE.value]
4948
if sandbox_details["state"] in setup_states:
5049
return True
5150
return False
@@ -58,13 +57,19 @@ def _should_we_keep_polling_teardown(sandbox_details: dict) -> bool:
5857
return False
5958

6059

61-
def _poll_sandbox_state(api: SandboxRestApiSession, reservation_id: str, polling_func: Callable,
62-
max_polling_minutes: int, polling_frequency_seconds: int) -> str:
60+
def _poll_sandbox_state(
61+
api: SandboxRestApiSession,
62+
reservation_id: str,
63+
polling_func: Callable,
64+
max_polling_minutes: int,
65+
polling_frequency_seconds: int,
66+
) -> str:
6367
""" Create blocking polling process """
6468

6569
# retry wait times are in milliseconds
66-
@retry(retry_on_result=polling_func, wait_fixed=polling_frequency_seconds * 1000,
67-
stop_max_delay=max_polling_minutes * 60000)
70+
@retry(
71+
retry_on_result=polling_func, wait_fixed=polling_frequency_seconds * 1000, stop_max_delay=max_polling_minutes * 60000
72+
)
6873
def get_sandbox_details():
6974
return api.get_sandbox_details(reservation_id)
7075

@@ -75,19 +80,23 @@ def get_sandbox_details():
7580
return sandbox_details
7681

7782

78-
def poll_sandbox_setup(api: SandboxRestApiSession, reservation_id: str, max_polling_minutes=20,
79-
polling_frequency_seconds=30) -> dict:
83+
def poll_sandbox_setup(
84+
api: SandboxRestApiSession, reservation_id: str, max_polling_minutes=20, polling_frequency_seconds=30
85+
) -> dict:
8086
""" poll until completion """
81-
sandbox_details = _poll_sandbox_state(api, reservation_id, _should_we_keep_polling_setup, max_polling_minutes,
82-
polling_frequency_seconds)
87+
sandbox_details = _poll_sandbox_state(
88+
api, reservation_id, _should_we_keep_polling_setup, max_polling_minutes, polling_frequency_seconds
89+
)
8390
return sandbox_details
8491

8592

86-
def poll_sandbox_teardown(api: SandboxRestApiSession, reservation_id: str, max_polling_minutes=20,
87-
polling_frequency_seconds=30) -> dict:
93+
def poll_sandbox_teardown(
94+
api: SandboxRestApiSession, reservation_id: str, max_polling_minutes=20, polling_frequency_seconds=30
95+
) -> dict:
8896
""" poll until completion """
89-
sandbox_details = _poll_sandbox_state(api, reservation_id, _should_we_keep_polling_teardown, max_polling_minutes,
90-
polling_frequency_seconds)
97+
sandbox_details = _poll_sandbox_state(
98+
api, reservation_id, _should_we_keep_polling_teardown, max_polling_minutes, polling_frequency_seconds
99+
)
91100
return sandbox_details
92101

93102

@@ -98,15 +107,19 @@ def _should_we_keep_polling_execution(exc_data: dict) -> bool:
98107
return False
99108

100109

101-
def poll_execution_for_completion(sandbox_rest: SandboxRestApiSession, command_execution_id: str,
102-
max_polling_in_minutes=20, polling_frequency_in_seconds=30) -> str:
110+
def poll_execution_for_completion(
111+
sandbox_rest: SandboxRestApiSession, command_execution_id: str, max_polling_in_minutes=20, polling_frequency_in_seconds=30
112+
) -> str:
103113
"""
104114
poll execution for "Completed" status, then return the execution output
105115
"""
106116

107117
# retry wait times are in milliseconds
108-
@retry(retry_on_result=_should_we_keep_polling_execution, wait_fixed=polling_frequency_in_seconds * 1000,
109-
stop_max_delay=max_polling_in_minutes * 60000)
118+
@retry(
119+
retry_on_result=_should_we_keep_polling_execution,
120+
wait_fixed=polling_frequency_in_seconds * 1000,
121+
stop_max_delay=max_polling_in_minutes * 60000,
122+
)
110123
def get_execution_data():
111124
exc_data = sandbox_rest.get_execution_details(command_execution_id)
112125
return exc_data

0 commit comments

Comments
 (0)