def test_modify_instance_groups_shrink_policy(self, aws_client):
        mocked_response = read_configs("list_instance_groups_1.json")
        client = MagicMock()
        aws_client.return_value = client
        client.list_instance_groups.return_value = mocked_response
        client.modify_instance_groups.return_value = None

        # modify RequestedInstanceCount and assert changed value
        params = {
            "cluster_id": self.cluster_id,
            "group_id": self.group_id,
            "decommission_timeout": 180,
            "terminate_instances": ["i-123456789123"],
            "protect_instances": ["i-111111111111"],
            "termination_timeout": 500,
        }
        modify_instance_groups_shrink_policy(**params)
        client.modify_instance_groups.assert_called_with(
            ClusterId=self.cluster_id,
            InstanceGroups=[{
                "InstanceGroupId": self.group_id,
                "ShrinkPolicy": {
                    "DecommissionTimeout": 180,
                    "InstanceResizePolicy": {
                        "InstancesToTerminate": ["i-123456789123"],
                        "InstancesToProtect": ["i-111111111111"],
                        "InstanceTerminationTimeout": 500,
                    },
                },
            }],
        )
Пример #2
0
    def test_modify_instance_groups_shrink_policy(self, aws_client):
        mocked_response = read_configs('list_instance_groups_1.json')
        client = MagicMock()
        aws_client.return_value = client
        client.list_instance_groups.return_value = mocked_response
        client.modify_instance_groups.return_value = None

        # modify RequestedInstanceCount and assert changed value
        params = {
            'cluster_id': self.cluster_id,
            'group_id': self.group_id,
            'decommission_timeout': 180,
            'terminate_instances': ['i-123456789123'],
            'protect_instances': ['i-111111111111'],
            'termination_timeout': 500
        }
        modify_instance_groups_shrink_policy(**params)
        client.modify_instance_groups.assert_called_with(
            ClusterId=self.cluster_id,
            InstanceGroups=[{
                'InstanceGroupId': self.group_id,
                'ShrinkPolicy': {
                    'DecommissionTimeout': 180,
                    'InstanceResizePolicy': {
                        'InstancesToTerminate': ['i-123456789123'],
                        'InstancesToProtect': ['i-111111111111'],
                        'InstanceTerminationTimeout': 500
                    }
                }
            }])
 def test_modify_instance_groups_shrink_policy_bad_args_2(self):
     params = {
         "cluster_id": self.cluster_id,
         "group_id": self.group_id,
         "decommission_timeout": 180,
         "termination_timeout": 500,
     }
     with pytest.raises(FailedActivity) as e:
         modify_instance_groups_shrink_policy(**params)
     assert 'Must provide "terminate_instances" when' in str(e)
Пример #4
0
    def test_modify_instance_groups_shrink_policy_bad_group(self, aws_client):
        group_id = 'i-INVALIDGROUP'
        mocked_response = mock_client_error(
            op='ModifyInstanceGroups',
            Code='ValidationException',
            Message="Group id '%s' is not valid." % group_id)
        client = MagicMock()
        aws_client.return_value = client
        client.modify_instance_groups.side_effect = mocked_response

        params = {
            'cluster_id': self.cluster_id,
            'group_id': group_id,
            'decommission_timeout': 180,
            'terminate_instances': ['i-123456789123'],
            'protect_instances': ['i-111111111111'],
            'termination_timeout': 500
        }
        with pytest.raises(FailedActivity) as e:
            modify_instance_groups_shrink_policy(**params)

        assert "Group id '%s' is not valid" % group_id in str(e.value)
    def test_modify_instance_groups_shrink_policy_bad_group(self, aws_client):
        group_id = "i-INVALIDGROUP"
        mocked_response = mock_client_error(
            op="ModifyInstanceGroups",
            Code="ValidationException",
            Message="Group id '%s' is not valid." % group_id,
        )
        client = MagicMock()
        aws_client.return_value = client
        client.modify_instance_groups.side_effect = mocked_response

        params = {
            "cluster_id": self.cluster_id,
            "group_id": group_id,
            "decommission_timeout": 180,
            "terminate_instances": ["i-123456789123"],
            "protect_instances": ["i-111111111111"],
            "termination_timeout": 500,
        }
        with pytest.raises(FailedActivity) as e:
            modify_instance_groups_shrink_policy(**params)

        assert "Group id '%s' is not valid" % group_id in str(e.value)
 def test_modify_instance_groups_shrink_policy_bad_args_1(self):
     params = {"cluster_id": self.cluster_id, "group_id": self.group_id}
     with pytest.raises(FailedActivity) as e:
         modify_instance_groups_shrink_policy(**params)
     assert "Must provide at least one of" in str(e)