Make init_agent() stop on 403 (too many agents).

This commit is contained in:
Daniel Nichter
2013-09-23 11:55:27 -07:00
parent 53d494ad0b
commit f6f121ca82
2 changed files with 51 additions and 1 deletions

View File

@@ -5788,13 +5788,19 @@ sub init_agent {
if ( $api_ok ) { if ( $api_ok ) {
$logger->fatal("API reports agent not found: the agent has been " $logger->fatal("API reports agent not found: the agent has been "
. "deleted, or its UUID (" . ($agent->uuid || '?') . ") " . "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."); . "list of active agents.");
} }
else { else {
$logger->warning("API is down."); $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 { else {
$logger->warning($EVAL_ERROR); $logger->warning($EVAL_ERROR);
} }

View File

@@ -274,6 +274,50 @@ is_deeply(
"PUT then GET Agent" "PUT then GET Agent"
) or diag(Dumper($ua->{requests})); ) 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. # Done.
# ############################################################################# # #############################################################################