aboutsummaryrefslogtreecommitdiffstats
path: root/testcases/vPing/CI/libraries/vPing2.py
diff options
context:
space:
mode:
authorMorgan Richomme <morgan.richomme@orange.com>2016-01-26 10:45:10 +0000
committerGerrit Code Review <gerrit@172.30.200.206>2016-01-26 10:45:10 +0000
commit3a562b1ebabfe4d6f032bb4287624a2fe146de59 (patch)
tree721c1eeb24aed3a4e12d3e0e00ddf2b555510023 /testcases/vPing/CI/libraries/vPing2.py
parent1b0826f0134ad1863453b3e416600818d4b84e12 (diff)
parente4b116d2054966e158ac647eea332aba8b84b89f (diff)
Merge "Use paramiko library to SSH and SCP the instances in vPing2"
Diffstat (limited to 'testcases/vPing/CI/libraries/vPing2.py')
-rw-r--r--testcases/vPing/CI/libraries/vPing2.py83
1 files changed, 57 insertions, 26 deletions
diff --git a/testcases/vPing/CI/libraries/vPing2.py b/testcases/vPing/CI/libraries/vPing2.py
index b103febf1..b358cb716 100644
--- a/testcases/vPing/CI/libraries/vPing2.py
+++ b/testcases/vPing/CI/libraries/vPing2.py
@@ -13,16 +13,17 @@
# 0.2: measure test duration and publish results under json format
#
#
-
-import os
-import time
import argparse
+import datetime
+import logging
+import os
+import paramiko
import pprint
+import subprocess
import sys
-import logging
+import time
import yaml
-import datetime
-import subprocess
+from scp import SCPClient
from novaclient import client as novaclient
from neutronclient.v2_0 import client as neutronclient
from keystoneclient.v2_0 import client as keystoneclient
@@ -431,51 +432,81 @@ def main():
floatip = functest_utils.create_floating_ip(neutron_client)
if floatip == None:
logger.error("Cannot create floating IP.")
+ cleanup(nova_client, neutron_client, image_id, network_dic,
+ port_id1, port_id2)
return (EXIT_CODE)
logger.info("Floating IP created: '%s'" % floatip)
logger.info("Associating floating ip: '%s' to VM2 " % floatip)
if not functest_utils.add_floating_ip(nova_client, vm2.id, floatip):
logger.error("Cannot associate floating IP to VM.")
+ cleanup(nova_client, neutron_client, image_id, network_dic,
+ port_id1, port_id2)
return (EXIT_CODE)
- timeout = 30
+ logger.info("Trying to stablish SSH connection to %s..." % floatip)
+ username='cirros'
+ password='cubswin:)'
+ ssh = paramiko.SSHClient()
+ ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
+
+ timeout = 50
while timeout > 0:
- response = os.system("ping -c 1 " + floatip)
- if response == 0:
- logger.debug("Floating IP '%s' is reachable!" % floatip)
- time.sleep(5) # the VM still needs to do some bootup actions
+ try:
+ ssh.connect(floatip, username=username, password=password)
+ logger.debug("Floating IP '%s' is ssh-able!" % floatip)
break
- timeout -= 1
- time.sleep(2)
+ except Exception, e:
+ #print e
+ logger.debug("Waiting for %s..." % floatip)
+ time.sleep(6)
+ timeout -= 1
- if timeout == 0:
+ if timeout == 0: # 300 sec timeout (5 min)
logger.error("Cannot ping the floating IP '%s'." % floatip)
+ cleanup(nova_client, neutron_client, image_id, network_dic,
+ port_id1, port_id2)
return (EXIT_CODE)
- logger.info("SCP ping script to VM2...")
- SSH_OPTS="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "+\
- "-o LogLevel=quiet"
+ scp = SCPClient(ssh.get_transport())
+
ping_script = REPO_PATH + "testcases/vPing/CI/libraries/ping.sh"
- cmd1 = "sshpass -p 'cubswin:)' scp " + SSH_OPTS + " " + \
- ping_script + " cirros@"+floatip+":~/ping.sh"
- cmd2 = "sshpass -p 'cubswin:)' ssh " + SSH_OPTS + \
- " cirros@"+floatip+" 'chmod 755 ~/ping.sh '"
- cmd3 = "sshpass -p 'cubswin:)' ssh " + SSH_OPTS + \
- " cirros@"+floatip+" '~/ping.sh "+IP_1+"'"
+ try:
+ scp.put(ping_script,"~/")
+ except Exception, e:
+ logger.error("Cannot SCP the file '%s' to VM '%s'" % (ping_script,floatip))
+
+
+ #SSH_OPTS="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "+\
+ # "-o LogLevel=quiet"
+
+ #cmd1 = "sshpass -p 'cubswin:)' scp " + SSH_OPTS + " " + \
+ # ping_script + " cirros@"+floatip+":~/ping.sh"
+ #cmd2 = "sshpass -p 'cubswin:)' ssh " + SSH_OPTS + \
+ # " cirros@"+floatip+" 'chmod 755 ~/ping.sh '"
+ #cmd3 = "sshpass -p 'cubswin:)' ssh " + SSH_OPTS + \
+ # " cirros@"+floatip+" '~/ping.sh "+IP_1+"'"
+
+ cmd = 'chmod 755 ~/ping.sh'
+ (stdin, stdout, stderr) = ssh.exec_command(cmd)
+ for line in stdout.readlines():
+ print line
logger.info("Waiting for ping...")
sec = 0
duration = 0
+ cmd = '~/ping.sh' + IP_1
while True:
time.sleep(1)
# we do the SCP every time in the loop because while testing, I observed
# that for some strange reason, the cirros VM was deleting the file if
# do the scp only once
- subprocess.Popen(cmd1, shell=True, stdout=subprocess.PIPE).stdout.read()
- subprocess.Popen(cmd2, shell=True, stdout=subprocess.PIPE).stdout.read()
- output=subprocess.Popen(cmd3, shell=True, stdout=subprocess.PIPE).stdout.read()
+ (stdin, stdout, stderr) = ssh.exec_command(cmd)
+ output = stdout.readlines()
+ for line in output:
+ print line
+
# print "--"+console_log
# report if the test is failed
if "vPing OK" in output: