Permalink
Browse files

changed to assert on 100% failure on pinging. also changed from 4.4.4…

….4 to 4.2.2.1
  • Loading branch information...
1 parent b30d569 commit a4d64e8a45e745ed9febcd344521bc572e8bf382 @andrewsben committed Jan 31, 2012
Showing with 14 additions and 16 deletions.
  1. +14 −16 launch.py
View
@@ -13,6 +13,8 @@
def check_sec_group():
+ """see if port 22 is opened in securitry group for ping cmd over ssh"""
+
try:
sec_group_name = "default"
sec_group_object = False
@@ -38,6 +40,7 @@ def check_sec_group():
def get_key():
"""create ssh keys to connect to server"""
+
key_name = "key-%d-%d" % (time.time(), random.randint(0, 99999999))
dummy = os.popen('ssh-keygen -t rsa -P "" -f %s' % key_name).readlines()
public_key = open('%s.pub' % key_name, 'r').readlines()[0]
@@ -46,6 +49,7 @@ def get_key():
def assign_floating_ip(server_name):
+ """assign or create a floating ip for instance wrapper"""
server = False
for s in nc.servers.list():
@@ -62,9 +66,9 @@ def assign_floating_ip(server_name):
def get_floating_ip():
+ """assign or create a floating ip for instance"""
dont_use = ['50.56.12.240', '50.56.12.241', '50.56.12.242', '50.56.12.243']
-
for floating_ip in nc.floating_ips.list():
if floating_ip.instance_id == None and floating_ip.ip not in dont_use:
return floating_ip.ip
@@ -80,18 +84,6 @@ def get_floating_ip():
return False
-def check_rate_limited(message):
-
- redo = False
- msg_check = ['This request was rate-limited. (HTTP 413)',
- 'This request was rate-limited. (HTTP 403)']
-
- if str(message) in msg_check:
- time.sleep(rate_limit_sleep_time)
- redo = True
- return redo
-
-
def connect_to_server(ssh_connect_info, port=22):
"""return ssh connection"""
@@ -118,9 +110,11 @@ def connect_to_server(ssh_connect_info, port=22):
def ping_thing(ssh_connection_dict):
+ """do some pingin"""
check_sec_group()
- pingers = ['4.4.4.4', 'www.google.com']
+ pingers = ['4.2.2.1', 'www.google.com']
+ ping_good = True
for pingee in pingers:
ssh, return_str = connect_to_server(ssh_connection_dict)
if ssh:
@@ -135,8 +129,11 @@ def ping_thing(ssh_connection_dict):
packet_loss = line.split(',')[2].lstrip().split(' ')[0]
print "Ping Results %s: %s/%s %s loss" % (pingee,
received, transmitted, packet_loss)
+ if packet_loss == "100%":
+ ping_good = False
ssh.close()
channel.close()
+ return ping_good
def launch(auth_url, tenant, user, password, destroy_time=60, boot_time=60):
@@ -188,12 +185,12 @@ def get_flavor(max_cores):
else:
time.sleep(3)
- #create or assign floating ip
+ ping_worked = False
floating_ip = assign_floating_ip(name)
if floating_ip:
ssh_connect_info = {'ip': floating_ip, 'login': 'ubuntu',
'key': local_key}
- ping_thing(ssh_connect_info)
+ ping_worked = ping_thing(ssh_connect_info)
nc.servers.delete(server_id)
is_del = False
@@ -214,6 +211,7 @@ def get_flavor(max_cores):
assert is_del, "Server %s not deleted within %d sec" % (name, destroy_time)
assert booted, "Server %s not booted within %d sec" % (name, boot_time)
assert floating_ip, "Could not get floating ip"
+ assert ping_worked, "Pinging test had 100% loss on one of the pingees"
if __name__ == '__main__':
try:

0 comments on commit a4d64e8

Please sign in to comment.