def paasta_pause_service_autoscaler(args): """With a given cluster and duration, pauses the paasta service autoscaler in that cluster for duration minutes""" if args.duration > MAX_PAUSE_DURATION: if not args.force: paasta_print('Specified duration: {d} longer than max: {m}'.format( d=args.duration, m=MAX_PAUSE_DURATION, )) paasta_print('If you are really sure, run again with --force') return 3 if args.info: return_code = get_service_autoscale_pause_time(args.cluster) elif args.resume: return_code = delete_service_autoscale_pause_time(args.cluster) _log_audit( action='resume-service-autoscaler', cluster=args.cluster, ) else: minutes = args.duration return_code = update_service_autoscale_pause_time( args.cluster, minutes) _log_audit( action='pause-service-autoscaler', action_details={'duration': minutes}, cluster=args.cluster, ) return return_code
def test_delete_service_autoscale_pause_time(mock_client): mock_client.get_paasta_api_client.return_value = None return_code = delete_service_autoscale_pause_time('cluster1') assert return_code == 1 mock_client.get_paasta_api_client.assert_called_with(cluster='cluster1', http_res=True) mock_api = mock.Mock() mock_client.get_paasta_api_client.return_value = mock_api mock_http_result = mock.Mock(status_code=500) mock_result = mock.Mock(return_value=(None, mock_http_result)) delete_mock = mock.Mock(return_value=mock.Mock(result=mock_result)) mock_api.service_autoscaler.delete_service_autoscaler_pause = delete_mock return_code = delete_service_autoscale_pause_time('cluster1') delete_mock.assert_called_once_with() assert return_code == 2 mock_http_result = mock.Mock(status_code=200) mock_result = mock.Mock(return_value=(None, mock_http_result)) mock_api.service_autoscaler.delete_service_autoscaler_pause.return_value = mock.Mock(result=mock_result) return_code = delete_service_autoscale_pause_time('cluster1') assert return_code == 0