def test_stop_instance_can_be_forced(aws_client):
    client = MagicMock()
    aws_client.return_value = client
    inst_id = "i-1234567890abcdef0"
    client.describe_instances.return_value = {'Reservations':
                                              [{'Instances': [{'InstanceId': inst_id, 'InstanceLifecycle': 'normal'}]}]}
    stop_instance(inst_id, force=True)
    client.stop_instances.assert_called_with(
        InstanceIds=[inst_id], Force=True)
def test_stop_random_instance_in_az(aws_client):
    client = MagicMock()
    aws_client.return_value = client
    inst_id = "i-987654321fedcba"
    client.describe_instances.return_value = {'Reservations':
                                              [{'Instances': [{'InstanceId': inst_id, 'InstanceLifecycle': 'normal'}]}]}

    stop_instance(az="us-west-1")
    client.stop_instances.assert_called_with(
        InstanceIds=[inst_id], Force=False)
Exemple #3
0
def test_stop_instance_with_no_lifecycle(aws_client):
    client = MagicMock()
    aws_client.return_value = client
    inst_id = "i-1234567890abcdef0"
    client.describe_instances.return_value = {
        'Reservations':
        [{'Instances': [{'InstanceId': inst_id}]}]
    }
    stop_instance(inst_id)
    client.stop_instances.assert_called_with(
        InstanceIds=[inst_id], Force=False)
def test_stop_spot_instance_can_be_forced(aws_client):
    client = MagicMock()
    aws_client.return_value = client
    inst_id = "i-1234567890abcdef0"
    spot_request_id = 'sir-abcdef01'
    client.describe_instances.return_value = {'Reservations':
                                              [{'Instances': [{'InstanceId': inst_id, 'InstanceLifecycle': 'spot', 'SpotInstanceRequestId': spot_request_id}]}]}
    stop_instance(inst_id, force=True)
    client.cancel_spot_instance_requests.assert_called_with(
        SpotInstanceRequestIds=[spot_request_id])
    client.terminate_instances.assert_called_with(
        InstanceIds=[inst_id])
Exemple #5
0
def test_stop_normal_instance(aws_client):
    client = MagicMock()
    aws_client.return_value = client
    inst_id = "i-1234567890abcdef0"
    client.describe_instances.return_value = {
        "Reservations": [{
            "Instances": [{
                "InstanceId": inst_id,
                "InstanceLifecycle": "normal"
            }]
        }]
    }
    stop_instance(inst_id)
    client.stop_instances.assert_called_with(InstanceIds=[inst_id],
                                             Force=False)
Exemple #6
0
def test_stop_instance(aws_client):
    client = MagicMock()
    aws_client.return_value = client
    inst_id = "i-1234567890abcdef0"
    response = stop_instance(inst_id)
    client.stop_instances.assert_called_with(InstanceIds=[inst_id],
                                             Force=False)
Exemple #7
0
def test_stop_spot_instance_can_be_forced(aws_client):
    client = MagicMock()
    aws_client.return_value = client
    inst_id = "i-1234567890abcdef0"
    spot_request_id = "sir-abcdef01"
    client.describe_instances.return_value = {
        "Reservations": [{
            "Instances": [{
                "InstanceId": inst_id,
                "InstanceLifecycle": "spot",
                "SpotInstanceRequestId": spot_request_id,
            }]
        }]
    }
    stop_instance(inst_id, force=True)
    client.cancel_spot_instance_requests.assert_called_with(
        SpotInstanceRequestIds=[spot_request_id])
    client.terminate_instances.assert_called_with(InstanceIds=[inst_id])
def test_stop_random_needs_instance_id_or_az():
    with pytest.raises(FailedActivity) as x:
        stop_instance()
    assert "stop an EC2 instance, you must specify either the instance id," \
           " an AZ to pick a random instance from, or a set of filters." in \
           str(x.value)