From f6f121ca82fa5a2227ff337ec697803aeba56c3c Mon Sep 17 00:00:00 2001 From: Daniel Nichter Date: Mon, 23 Sep 2013 11:55:27 -0700 Subject: [PATCH] Make init_agent() stop on 403 (too many agents). --- bin/pt-agent | 8 +++++++- t/pt-agent/init_agent.t | 44 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/bin/pt-agent b/bin/pt-agent index b788b0a3..d5c21342 100755 --- a/bin/pt-agent +++ b/bin/pt-agent @@ -5788,13 +5788,19 @@ sub init_agent { if ( $api_ok ) { $logger->fatal("API reports agent not found: the agent has been " . "deleted, or its UUID (" . ($agent->uuid || '?') . ") " - . "is wrong. Check https://cloud.percona.com/agents for a " + . "is wrong. Check https://cloud.percona.com/agents for the " . "list of active agents."); } else { $logger->warning("API is down."); } } + elsif ( $code && $code == 403 ) { + $logger->error("API reports too many agents. Check " + . "https://cloud.percona.com/agents for the list of " + . "installed agents, delete unused agents, and try again."); + last; + } else { $logger->warning($EVAL_ERROR); } diff --git a/t/pt-agent/init_agent.t b/t/pt-agent/init_agent.t index 2b60c39e..dc83d885 100644 --- a/t/pt-agent/init_agent.t +++ b/t/pt-agent/init_agent.t @@ -274,6 +274,50 @@ is_deeply( "PUT then GET Agent" ) or diag(Dumper($ua->{requests})); +# ############################################################################# +# Status 403 (too many agents) should abort further attempts. +# ############################################################################# + +$ua->{responses}->{post} = [ + { # 1, the fake error + code => 403, + }, +]; + +@ok = qw(1 1 0); +@wait = (); +@log = (); +$ua->{requests} = []; + +$output = output( + sub { + ($got_agent) = pt_agent::init_agent( + agent => $post_agent, + action => 'post', + link => "/agents", + client => $client, + interval => $interval, + tries => 3, + oktorun => $oktorun, + ); + }, + stderr => 1, +); + +is( + scalar @wait, + 0, + "Too many agents (403): no wait" +); + +is_deeply( + $ua->{requests}, + [ + 'POST /agents', + ], + "Too many agents (403): no further requests" +) or diag(Dumper($ua->{requests})); + # ############################################################################# # Done. # #############################################################################