diff --git a/eucaops/ec2ops.py b/eucaops/ec2ops.py index 085e1d42..d1c2c9e0 100644 --- a/eucaops/ec2ops.py +++ b/eucaops/ec2ops.py @@ -2136,7 +2136,10 @@ 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') @@ -2144,7 +2147,7 @@ def disassociate_address_from_instance(self, instance, timeout=75): 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): """ @@ -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) @@ -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 @@ -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, @@ -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 @@ -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: @@ -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. @@ -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) @@ -3607,3 +3607,4 @@ def __init__(self, value): def __str__(self): return repr(self.value) + diff --git a/testcases/cloud_user/instances/instancetest.py b/testcases/cloud_user/instances/instancetest.py index 70dab471..e0faf221 100755 --- a/testcases/cloud_user/instances/instancetest.py +++ b/testcases/cloud_user/instances/instancetest.py @@ -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)