Example #1
0
def test_endpoint_healthy_state(monkeypatch):
    kube_aws_autoscaler.main.Healthy = False
    autoscale = MagicMock()
    monkeypatch.setattr('kube_aws_autoscaler.main.autoscale', autoscale)
    monkeypatch.setattr('sys.argv', ['foo', '--once', '--dry-run'])
    main()
    assert kube_aws_autoscaler.main.Healthy == True
Example #2
0
def test_main(monkeypatch):
    autoscale = MagicMock()
    monkeypatch.setattr('kube_aws_autoscaler.main.autoscale', autoscale)
    monkeypatch.setattr('sys.argv', ['foo', '--once', '--dry-run'])
    main()
    autoscale.assert_called_once_with({
        'memory': 10,
        'pods': 10,
        'cpu': 10
    }, {
        'memory': 209715200,
        'pods': 10,
        'cpu': 0.2
    },
                                      buffer_spare_nodes=1,
                                      include_master_nodes=False,
                                      dry_run=True,
                                      disable_scale_down=False,
                                      scale_down_step_fixed=1,
                                      scale_down_step_percentage=0.0,
                                      scale_up_step_fixed=0,
                                      scale_up_step_percentage=0)

    autoscale.side_effect = ValueError

    monkeypatch.setattr('sys.argv', ['foo', '--dry-run'])
    monkeypatch.setattr('time.sleep', MagicMock(side_effect=Exception))
    with pytest.raises(Exception):
        main()
Example #3
0
def test_main_step_down(monkeypatch):
    monkeypatch.setattr(
        'sys.argv',
        ['foo', '--once', '--dry-run', '--scale-down-step-fixed=0'])
    with pytest.raises(ValueError) as err:
        main()
    assert 'Invalid scale-down-step-fixed value: 0' in str(err.value)

    monkeypatch.setattr(
        'sys.argv',
        ['foo', '--once', '--dry-run', '--scale-down-step-fixed=-1'])
    with pytest.raises(ValueError) as err:
        main()
    assert 'Invalid scale-down-step-fixed value: -1' in str(err.value)

    monkeypatch.setattr(
        'sys.argv',
        ['foo', '--once', '--dry-run', '--scale-down-step-percentage=-0.0001'])
    with pytest.raises(ValueError) as err:
        main()
    assert 'Invalid scale-down-step-percentage value: -0.0001' in str(
        err.value)

    monkeypatch.setattr(
        'sys.argv',
        ['foo', '--once', '--dry-run', '--scale-down-step-percentage=1.0001'])
    with pytest.raises(ValueError) as err:
        main()
    assert 'Invalid scale-down-step-percentage value: 1.0001' in str(err.value)