TT#152901 prosody provision ignore error on timeout

* when a domain is provisionined in prosody and there is
  no connection to the host/port, the error is ignored and ok
  response is returned instead. Prosody does not have a persistent
  database and rather loads vhosts from kamailio.domain on startup
  and if it is down during domain creation/removal where will be
  no discrepancies when it starts. The new error checking behaviour
  benefits the CARRIER setups where a proxy host is still in xmlhosts
  but is not available (powered off) or prosody is not running there
  for some reason.

Change-Id: Idaaaf2b31985873db9228958b60ff14fca5d1bf6
mr10.3
Kirill Solomko 4 years ago
parent 37f748cb76
commit 55a8d5568f

@ -6,23 +6,28 @@ use Net::Telnet;
sub activate_domain {
my ($c, $domain) = @_;
$domain = lc $domain;
my $t = Net::Telnet->new(Timeout => 5);
my $t = Net::Telnet->new(Timeout => 5, ErrMode => 'die');
my $hosts = _load_servers($c);
my $ok = 1;
foreach my $host(@{ $hosts }) {
$t->open(Host => $host->{ip}, Port => $host->{port});
$t->waitfor('/http:\/\/prosody.im\/doc\/console/');
$t->print("host:activate('$domain')");
my ($res, $amatch) = $t->waitfor(
Match => '/(Result: \w+)|(Message: .+)/',
Timeout => 20
);
if($amatch =~ /Result:\s*true/) {
# fine
} else {
$ok = 0;
eval {
$t->open(Host => $host->{ip}, Port => $host->{port});
$t->waitfor('/http:\/\/prosody.im\/doc\/console/');
$t->print("host:activate('$domain')");
my ($res, $amatch) = $t->waitfor(
Match => '/(Result: \w+)|(Message: .+)/',
Timeout => 20
);
if($amatch =~ /Result:\s*true/) {
# fine
} else {
$ok = 0;
}
$t->print("quit");
};
if ($@) {
$ok = $@ =~ /problem connecting to/ ? $ok : 0;
}
$t->print("quit");
}
return $ok if($ok);
@ -32,23 +37,28 @@ sub activate_domain {
sub deactivate_domain {
my ($c, $domain) = @_;
my $t = Net::Telnet->new(Timeout => 5);
my $t = Net::Telnet->new(Timeout => 5, ErrMode => 'die');
my $hosts = _load_servers($c);
my $ok = 1;
foreach my $host(@{ $hosts }) {
$t->open(Host => $host->{ip}, Port => $host->{port});
$t->waitfor('/http:\/\/prosody.im\/doc\/console/');
$t->print("host:deactivate('$domain')");
my ($res, $amatch) = $t->waitfor(
Match => '/(Result: \w+)|(Message: .+)/',
Timeout => 20
);
if($amatch =~ /Result:\s*true/) {
# fine
} else {
$ok = 0;
eval {
$t->open(Host => $host->{ip}, Port => $host->{port});
$t->waitfor('/http:\/\/prosody.im\/doc\/console/');
$t->print("host:deactivate('$domain')");
my ($res, $amatch) = $t->waitfor(
Match => '/(Result: \w+)|(Message: .+)/',
Timeout => 20
);
if($amatch =~ /Result:\s*true/) {
# fine
} else {
$ok = 0;
}
$t->print("quit");
};
if ($@) {
$ok = $@ =~ /problem connecting to/ ? $ok : 0;
}
$t->print("quit");
}
return $ok if($ok);

Loading…
Cancel
Save