Skip to content

Commit

Permalink
[src] Add field strategy to group roll request
Browse files Browse the repository at this point in the history
  • Loading branch information
caduri committed Feb 22, 2021
1 parent 7032d9d commit 2c02d06
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ venv*/
ENV/
env.bak/
venv.bak/
Pipfile*

# Spyder project settings
.spyderproject
Expand Down
40 changes: 39 additions & 1 deletion docs/classes/elastigroup.md
Original file line number Diff line number Diff line change
Expand Up @@ -1204,7 +1204,45 @@ __Arguments__
- __batch_size_percentage__: str
- __grace_period__: xstr
- __health_check_type__: str
- __strategy__: str
- __strategy__: RollStrategy

<h2 id="spotinst_sdk.aws_elastigroup.RollStrategy">RollStrategy</h2>

```python
RollStrategy(
self,
action='d3043820717d74d9a17694c176d39733',
should_drain_instances='d3043820717d74d9a17694c176d39733',
batch_min_healthy_percentage='d3043820717d74d9a17694c176d39733',
on_failure='d3043820717d74d9a17694c176d39733')
```

__Arguments__

- __action__: str,
- __should_drain_instances__: bool,
- __batch_min_healthy_percentage__: int,
- __on_failure__: OnFailure

<h2 id="spotinst_sdk.aws_elastigroup.OnFailure">OnFailure</h2>

```python
OnFailure(
self,
action_type='d3043820717d74d9a17694c176d39733',
should_handle_all_batches='d3043820717d74d9a17694c176d39733',
batch_num='d3043820717d74d9a17694c176d39733',
draining_timeout='d3043820717d74d9a17694c176d39733',
should_decrement_target_capacity='d3043820717d74d9a17694c176d39733')
```

__Arguments__

- __action_type__: str
- __should_handle_all_batches__: bool
- __batch_num__: int
- __draining_timeout__: int
- __should_decrement_target_capacity__: bool

<h2 id="spotinst_sdk.aws_elastigroup.DetachConfiguration">DetachConfiguration</h2>

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
PyYaml
requests
pydoc-markdown
pydoc-markdown==2.1.3
45 changes: 44 additions & 1 deletion spotinst_sdk/aws_elastigroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -1361,7 +1361,7 @@ class Roll:
batch_size_percentage: str
grace_period: xstr
health_check_type: str
strategy: str
strategy: RollStrategy
"""
def __init__(
self,
Expand All @@ -1375,6 +1375,49 @@ def __init__(
self.strategy = strategy


class RollStrategy:
"""
# Arguments
action: str,
should_drain_instances: bool,
batch_min_healthy_percentage: int,
on_failure: OnFailure
"""
def __init__(
self,
action=none,
should_drain_instances=none,
batch_min_healthy_percentage=none,
on_failure=none):
self.action = action
self.should_drain_instances = should_drain_instances
self.batch_min_healthy_percentage = batch_min_healthy_percentage
self.on_failure = on_failure


class OnFailure:
"""
# Arguments
action_type: str
should_handle_all_batches: bool
batch_num: int
draining_timeout: int
should_decrement_target_capacity: bool
"""
def __init__(
self,
action_type=none,
should_handle_all_batches=none,
batch_num=none,
draining_timeout=none,
should_decrement_target_capacity=none):
self.action_type = action_type
self.should_handle_all_batches = should_handle_all_batches
self.batch_num = batch_num
self.draining_timeout = draining_timeout
self.should_decrement_target_capacity = should_decrement_target_capacity


class DetachConfiguration:
"""
# Arguments
Expand Down
40 changes: 40 additions & 0 deletions spotinst_sdk/test/test_aws_elastigroup_roll.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import os
import unittest

from spotinst_sdk import SpotinstClient
from spotinst_sdk.aws_elastigroup import *


class AwsElastigroupRollTestCase(unittest.TestCase):

def setUp(self):
self.client = SpotinstClient(
auth_token='dummy-token',
account_id='dummy-account')
self.mock_group_roll_json = self.load_group_roll_json()

def create_formatted_group_roll_request(self, group_roll):
group_roll_request = ElastigroupRollRequest(group_roll=group_roll)
excluded_group_roll_dict = self.client.exclude_missing(
json.loads(group_roll_request.toJSON()))
formatted_group_roll_dict = self.client.convert_json(
excluded_group_roll_dict, self.client.underscore_to_camel)
return formatted_group_roll_dict

@staticmethod
def load_group_roll_json():
with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'test_lib/input/group_roll.json')) as group_roll_json:
return json.load(group_roll_json)


# region Roll
class AwsElastigroupRoleTest(AwsElastigroupRollTestCase):
def runTest(self):
on_failure = OnFailure(action_type="DETACH_OLD", should_handle_all_batches=True, batch_num=2, draining_timeout=300, should_decrement_target_capacity=False)
strategy = RollStrategy(action="REPLACE_SERVER", should_drain_instances=True, batch_min_healthy_percentage=100, on_failure=on_failure)
roll = Roll(batch_size_percentage="20", grace_period=500, health_check_type="NONE", strategy=strategy)

formatted_group_roll_dict = self.create_formatted_group_roll_request(roll)

self.assertDictEqual(formatted_group_roll_dict, self.mock_group_roll_json)
# endregion
17 changes: 17 additions & 0 deletions spotinst_sdk/test/test_lib/input/group_roll.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"batchSizePercentage":"20",
"gracePeriod": 500,
"healthCheckType": "NONE",
"strategy": {
"action": "REPLACE_SERVER",
"shouldDrainInstances": true,
"batchMinHealthyPercentage": 100,
"onFailure": {
"actionType": "DETACH_OLD",
"shouldHandleAllBatches": true,
"batchNum": 2,
"drainingTimeout": 300,
"shouldDecrementTargetCapacity": false
}
}
}

0 comments on commit 2c02d06

Please sign in to comment.