Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

Commit

Permalink
ElasticIps fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
viglesiasce committed Aug 24, 2013
1 parent 2feb1fd commit 3065632
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
29 changes: 15 additions & 14 deletions eucaops/ec2ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -2136,15 +2136,18 @@ def disassociate_address_from_instance(self, instance, timeout=75):

start = time.time()
### Ensure instance gets correct address
while instance.ip_address != address.public_ip:
### When private addressing is enabled the pub address should be equal to the priv address
### Otherwise we want to the pub address to be anything but its current and not the priv address
while (not instance.private_addressing and instance.ip_address != address.public_ip and instance.ip_address != address.private_ip_address) or \
(instance.private_addressing and instance.ip_address == instance.private_ip_address):
self.debug('Instance {0} has IP "{1}" still using address "{2}" after {3} seconds'.format(instance.id, instance.ip_address, address.public_ip, str(elapsed)) )
if elapsed > timeout:
raise Exception('Address ' + str(address) + ' never disassociated with instance after '+str(elapsed)+' seconds')
instance.update()
self.sleep(5)
elapsed = int(time.time()-start)
address = self.ec2.get_all_addresses(addresses=[address.public_ip])[0]
self.debug("Disassociated IP successfully")
self.debug("Disassociated IP successfully")

def release_address(self, address):
"""
Expand Down Expand Up @@ -2363,7 +2366,7 @@ def run_instance(self,

if not private_addressing:
try:
self.wait_for_valid_ip(instance, private_addressing=private_addressing)
self.wait_for_valid_ip(instance)
except Exception, e:
ip_err = "WARNING in wait_for_valid_ip: "+str(e)
self.debug(ip_err)
Expand All @@ -2379,7 +2382,7 @@ def run_instance(self,
#if we can establish an SSH session convert the instances to the test class euinstance for access to instance specific test methods
if is_reachable:
self.debug("Converting " + str(reservation) + " into euinstances")
return self.convert_reservation_to_euinstance(reservation, username=username, password=password,
return self.convert_reservation_to_euinstance(reservation, username=username, password=password, private_addressing=private_addressing,
keyname=keypair, timeout=timeout)
else:
return reservation
Expand Down Expand Up @@ -2836,11 +2839,7 @@ def monitor_euinstances_to_state(self,
raise Exception(failmsg)
else:
self.debug(failmsg)





def print_euinstance_list(self,
euinstance_list=None,
state=None,
Expand Down Expand Up @@ -2889,11 +2888,11 @@ def print_euinstance_list(self,
for instance in plist:
buf += instance.printself(title=False, footer=False)
self.debug("\n"+str(buf)+"\n")

@Eutester.printinfo
def wait_for_valid_ip(self, instances, private_addressing=False, poll_interval=10, timeout = 60):
def wait_for_valid_ip(self, instances, regex="0.0.0.0", poll_interval=10, timeout = 60):
"""
Wait for instance public DNS name to clear from 0.0.0.0
Wait for instance public DNS name to clear from regex
:param instances:
:param private_addressing: boolean for whether instance has private addressing enabled
Expand All @@ -2911,7 +2910,7 @@ def wait_for_valid_ip(self, instances, private_addressing=False, poll_interval=1
elapsed = 0
good = []
start = time.time()
zeros = re.compile("0.0.0.0")
zeros = re.compile(regex)
while monitoring and (elapsed <= timeout):
elapsed = int(time.time()- start)
for instance in monitoring:
Expand Down Expand Up @@ -2986,7 +2985,7 @@ def check_system_for_dup_ip(self, instances=None):
self.debug("Done with check_system_for_dup_ip")


def convert_reservation_to_euinstance(self, reservation, username="root", password=None, keyname=None, timeout=60):
def convert_reservation_to_euinstance(self, reservation, username="root", password=None, keyname=None, private_addressing=False, timeout=60):
"""
Convert all instances in an entire reservation into eutester.euinstance.Euinstance objects.
Expand All @@ -3009,7 +3008,8 @@ def convert_reservation_to_euinstance(self, reservation, username="root", passwo
keypair=keypair,
username = username,
password=password,
timeout=timeout ))
timeout=timeout,
private_addressing=private_addressing))
except Exception, e:
self.debug(self.get_traceback())
euinstance_list.append(instance)
Expand Down Expand Up @@ -3607,3 +3607,4 @@ def __init__(self, value):

def __str__(self):
return repr(self.value)

2 changes: 2 additions & 0 deletions testcases/cloud_user/instances/instancetest.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ def ElasticIps(self):
self.tester.disassociate_address_from_instance(instance)
self.tester.release_address(self.address)
self.address = None
assert isinstance(instance, EuInstance)
self.tester.sleep(5)
instance.update()
self.assertTrue( self.tester.ping(instance.ip_address), "Could not ping after dissassociate")
self.set_reservation(reservation)
Expand Down

0 comments on commit 3065632

Please sign in to comment.