[MGM]: Add floating IP test
Tests to see if floating IP actually works after it is assigned. Change-Id: I18c6e699ad11528d1b04d33885cdea7b4b381569
This commit is contained in:
parent
1803a153a0
commit
5bdeb038f9
@ -127,3 +127,9 @@ Command Line Options
|
||||
|
||||
When removing a floating IP, ignore the HTTP 500 error and treat it as
|
||||
a successful response.
|
||||
|
||||
.. option:: --tcp_check_port <PORT>
|
||||
|
||||
After a floating IP has been assigned use this port to do a TCP connect
|
||||
test to see if the assign was successful. If not specified the check
|
||||
will not take place.
|
||||
|
@ -12,6 +12,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import socket
|
||||
import time
|
||||
from novaclient import exceptions
|
||||
from libra.mgm.nova import Node
|
||||
|
||||
@ -77,6 +79,8 @@ class AssignIpController(object):
|
||||
try:
|
||||
node_id = nova.get_node(self.msg['name'])
|
||||
nova.vip_assign(node_id, self.msg['ip'])
|
||||
if self.args.tcp_check_port:
|
||||
self.check_ip(self.msg['ip'], self.args.tcp_check_port)
|
||||
except:
|
||||
self.logger.exception(
|
||||
'Error assigning Floating IP {0} to {1}'
|
||||
@ -88,6 +92,25 @@ class AssignIpController(object):
|
||||
self.msg[self.RESPONSE_FIELD] = self.RESPONSE_SUCCESS
|
||||
return self.msg
|
||||
|
||||
def check_ip(self, ip, port):
|
||||
# TCP connect check to see if floating IP was assigned correctly
|
||||
sock = socket.socket()
|
||||
sock.settimeout(5)
|
||||
loop_count = 0
|
||||
while True:
|
||||
try:
|
||||
sock.connect((ip, port))
|
||||
return True
|
||||
except socket.error:
|
||||
loop_count += 1
|
||||
if loop_count >= 5:
|
||||
self.logger.error(
|
||||
"TCP connect error after floating IP assign {0}"
|
||||
.format(ip)
|
||||
)
|
||||
raise
|
||||
time.sleep(2)
|
||||
|
||||
|
||||
class RemoveIpController(object):
|
||||
|
||||
|
@ -159,6 +159,10 @@ def main():
|
||||
dest='threads', type=int, default=4,
|
||||
help='Number of worker threads to spawn'
|
||||
)
|
||||
options.parser.add_argument(
|
||||
'--tcp_check_port', type=int,
|
||||
help='Port number to ping to check floating IP assign worked'
|
||||
)
|
||||
options.parser.add_argument(
|
||||
'--rm_fip_ignore_500', action='store_true',
|
||||
help='Ignore HTTP 500 error when removing a floating IP'
|
||||
|
Loading…
x
Reference in New Issue
Block a user