def destroy_volume_wait(cls, volume): """Delete volume, tryies to detach first. Use just for teardown! """ exc_num = 0 snaps = volume.snapshots() if len(snaps): LOG.critical("%s Volume has %s snapshot(s)", volume.id, map(snaps.id, snaps)) # NOTE(afazekas): detaching/attching not valid EC2 status def _volume_state(): volume.update(validate=True) try: if volume.status != "available": volume.detach(force=True) except BaseException as exc: LOG.exception(exc) # exc_num += 1 "nonlocal" not in python2 return volume.status try: re_search_wait(_volume_state, "available") # not validates status LOG.info(_volume_state()) volume.delete() except BaseException as exc: LOG.exception(exc) exc_num += 1 if exc_num: raise exceptions.TearDownException(num=exc_num)
def destroy_volume_wait(cls, volume): """Delete volume, tryies to detach first. Use just for teardown! """ exc_num = 0 snaps = volume.snapshots() if len(snaps): LOG.critical("%s Volume has %s snapshot(s)", volume.id, map(snaps.id, snaps)) # NOTE(afazekas): detaching/attching not valid EC2 status def _volume_state(): volume.update(validate=True) try: if volume.status != "available": volume.detach(force=True) except BaseException as exc: LOG.exception(exc) # exc_num += 1 "nonlocal" not in python2 return volume.status try: re_search_wait(_volume_state, "available") # not validates status LOG.info(_volume_state()) volume.delete() except BaseException as exc: LOG.exception(exc) exc_num += 1 if exc_num: raise exceptions.TearDownException(num=exc_num)
def destroy_reservation(cls, reservation): """Terminate instances in a reservation, just for teardown.""" exc_num = 0 def _instance_state(): try: instance.update(validate=True) except ValueError: return "_GONE" except exception.EC2ResponseError as exc: if cls.ec2_error_code.client.InvalidInstanceID.NotFound.match(exc): return "_GONE" # NOTE(afazekas): incorrect code, # but the resource must be destoreyd if exc.error_code == "InstanceNotFound": return "_GONE" return instance.state for instance in reservation.instances: try: instance.terminate() re_search_wait(_instance_state, "_GONE") except BaseException as exc: LOG.exception(exc) exc_num += 1 if exc_num: raise exceptions.TearDownException(num=exc_num)
def destroy_reservation(cls, reservation): """Terminate instances in a reservation, just for teardown.""" exc_num = 0 def _instance_state(): try: instance.update(validate=True) except ValueError: return "_GONE" except exception.EC2ResponseError as exc: if cls.ec2_error_code.\ client.InvalidInstanceID.NotFound.match(exc): return "_GONE" # NOTE(afazekas): incorrect code, # but the resource must be destoreyd if exc.error_code == "InstanceNotFound": return "_GONE" return instance.state for instance in reservation.instances: try: instance.terminate() re_search_wait(_instance_state, "_GONE") except BaseException as exc: LOG.exception(exc) exc_num += 1 if exc_num: raise exceptions.TearDownException(num=exc_num)