def test_get_service_autoscale_pause_time_error(mock_client): mock_client.get_paasta_api_client.return_value = None return_code = get_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)) mock_api.service_autoscaler.get_service_autoscaler_pause.return_value = mock.Mock(result=mock_result) return_code = get_service_autoscale_pause_time('cluster1') assert return_code == 2
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_get_service_autoscale_pause_time_paused(mock_client, mock_time, mock_print): mock_api = mock.Mock() mock_client.get_paasta_api_client.return_value = mock_api mock_http_result = mock.Mock(status_code=200) mock_result = mock.Mock(return_value=('3', mock_http_result)) mock_api.service_autoscaler.get_service_autoscaler_pause.return_value = mock.Mock(result=mock_result) mock_time.time.return_value = 2 return_code = get_service_autoscale_pause_time('cluster1') mock_print.assert_called_with('Service autoscaler is paused until 1970-01-01 00:00:03 UTC') assert return_code == 0
def test_get_service_autoscale_pause_time_not(mock_client, mock_time, mock_print): mock_api = mock.Mock() mock_client.get_paasta_api_client.return_value = mock_api mock_http_result = mock.Mock(status_code=200) mock_result = mock.Mock(return_value=("3", mock_http_result)) mock_api.service_autoscaler.get_service_autoscaler_pause.return_value = mock.Mock( result=mock_result) mock_time.time.return_value = 4 return_code = get_service_autoscale_pause_time("cluster1") mock_print.assert_called_with("Service autoscaler is not paused") assert return_code == 0