def delete_domain_subnet_resources(cls): #delete the l3domain on VSD and the l3domain-template #from default and non-default enterprise has_exception = False try: cls.nuage_vsd_client.delete_domain(cls.vsd_l3dom[0]['ID']) except Exception as exc: LOG.exception(exc) has_exception = True if has_exception: raise exceptions.TearDownException() try: cls.nuage_vsd_client.delete_domain(cls.nondef_vsd_l3dom[0]['ID']) except Exception as exc: LOG.exception(exc) has_exception = True if has_exception: raise exceptions.TearDownException() try: cls.nuage_vsd_client.delete_l3domaintemplate( cls.vsd_l3dom_tmplt[0]['ID']) except Exception as exc: LOG.exception(exc) has_exception = True if has_exception: raise exceptions.TearDownException() try: cls.nuage_vsd_client.delete_l3domaintemplate( cls.nondef_vsd_l3dom_tmplt[0]['ID']) except Exception as exc: LOG.exception(exc) has_exception = True if has_exception: raise exceptions.TearDownException()
def resource_cleanup(cls): has_exception = False for vport in cls.gatewayvports: try: if vport['type'] == n_constants.HOST_VPORT: cls.nuage_vsd_client.delete_host_interface( vport['interface']) elif vport['type'] == n_constants.BRIDGE_VPORT: cls.nuage_vsd_client.delete_bridge_interface( vport['interface']) cls.nuage_vsd_client.delete_host_vport(vport['id']) except Exception as exc: LOG.exception(exc) has_exception = True if has_exception: raise exceptions.TearDownException() for vlan in cls.gatewayvlans: try: if 'id' in vlan: vlan_id = vlan['id'] else: vlan_id = vlan[0]['ID'] cls.nuage_vsd_client.delete_vlan_permission(vlan_id) cls.nuage_vsd_client.delete_gateway_vlan(vlan_id) except Exception as exc: LOG.exception(exc) has_exception = True if has_exception: raise exceptions.TearDownException() for port in cls.gatewayports: try: cls.nuage_vsd_client.delete_gateway_port(port[0]['ID']) except Exception as exc: LOG.exception(exc) has_exception = True if has_exception: raise exceptions.TearDownException() for gateway in cls.gateways: try: cls.nuage_vsd_client.delete_gateway(gateway[0]['ID']) except Exception as exc: LOG.exception(exc) has_exception = True if has_exception: raise exceptions.TearDownException() cls.delete_test_gateway_redundancy_topology() super(NuageGatewayTestJSON, cls).resource_cleanup() cls.delete_domain_subnet_resources() cls.client.delete_netpartition(cls.nondef_netpart['id'])
def delete_test_gateway_redundancy_topology(cls): has_exception = False for port in cls.rdn_gw_ports_vrsg: try: cls.nuage_vsd_client.delete_gateway_port(port[0]['ID']) except Exception as exc: LOG.exception(exc) has_exception = True if has_exception: raise exceptions.TearDownException() for port in cls.rdn_gw_ports_vsg_combn: try: cls.nuage_vsd_client.delete_vsg_redundancy_ports(port[0]['ID']) except Exception as exc: LOG.exception(exc) has_exception = True if has_exception: raise exceptions.TearDownException() for port in cls.rdn_gw_ports_vsg: try: cls.nuage_vsd_client.delete_gateway_port(port[0]['ID']) except Exception as exc: LOG.exception(exc) has_exception = True if has_exception: raise exceptions.TearDownException() for grp in cls.rdn_groups: try: cls.nuage_vsd_client.delete_redundancy_group(grp[0]['ID']) except Exception as exc: LOG.exception(exc) has_exception = True if has_exception: raise exceptions.TearDownException() for gateway in cls.rdn_gateways: try: cls.nuage_vsd_client.delete_gateway(gateway[0]['ID']) except Exception as exc: LOG.exception(exc) has_exception = True if has_exception: raise exceptions.TearDownException()
def destroy_volume_wait(cls, volume): """Delete volume, tries 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/attaching not valid EC2 status def _volume_state(): volume.update(validate=True) try: # NOTE(gmann): Make sure volume is attached. # Checking status as 'not "available"' is not enough to make # sure volume is attached as it can be in "error" state if volume.status == "in-use": volume.detach(force=True) except BaseException: LOG.exception("Failed to detach volume %s" % volume) # exc_num += 1 "nonlocal" not in python2 return volume.status try: wait.re_search_wait(_volume_state, "available") # not validates status LOG.info(_volume_state()) volume.delete() except BaseException: LOG.exception("Failed to delete volume %s" % volume) 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) is None: return "_GONE" # NOTE(afazekas): incorrect code, # but the resource must be destroyed if exc.error_code == "InstanceNotFound": return "_GONE" return instance.state for instance in reservation.instances: try: instance.terminate() wait.re_search_wait(_instance_state, "_GONE") except BaseException: LOG.exception("Failed to terminate instance %s " % instance) exc_num += 1 if exc_num: raise exceptions.TearDownException(num=exc_num)
def resource_cleanup(cls): """Calls the callables added by addResourceCleanUp when you overwrite this function don't forget to call this too. """ fail_count = 0 trash_keys = sorted(cls._resource_trash_bin, reverse=True) for key in trash_keys: (function, pos_args, kw_args) = cls._resource_trash_bin[key] try: func_name = friendly_function_call_str(function, *pos_args, **kw_args) LOG.debug("Cleaning up: %s" % func_name) function(*pos_args, **kw_args) except BaseException: fail_count += 1 LOG.exception("Cleanup failed %s" % func_name) finally: del cls._resource_trash_bin[key] super(BotoTestCase, cls).resource_cleanup() # NOTE(afazekas): let the super called even on exceptions # The real exceptions already logged, if the super throws another, # does not causes hidden issues if fail_count: raise exceptions.TearDownException(num=fail_count)
def resource_cleanup(cls): has_exception = False for vport in cls.group_vports: try: if vport['type'] == n_constants.HOST_VPORT: cls.nuage_vsd_client.delete_host_interface( vport['interface']) elif vport['type'] == n_constants.BRIDGE_VPORT: cls.nuage_vsd_client.delete_bridge_interface( vport['interface']) cls.nuage_vsd_client.delete_host_vport(vport['id']) except Exception as exc: LOG.exception(exc) has_exception = True for vlan in cls.group_vlans: try: if 'id' in vlan: vlan_id = vlan['id'] else: vlan_id = vlan[0]['ID'] cls.nuage_vsd_client.delete_vlan_permission(vlan_id) cls.nuage_vsd_client.delete_gateway_vlan(vlan_id) except Exception as exc: LOG.exception(exc) has_exception = True for grp in cls.gatewaygroups: try: cls.nuage_vsd_client.delete_gateway_redundancy_group( grp[0]['ID']) except Exception as exc: LOG.exception(exc) has_exception = True for port in cls.redundant_ports: try: cls.nuage_vsd_client.delete_gateway_port(port[0]['ID']) except Exception as exc: LOG.exception(exc) has_exception = True for gateway in cls.redundant_gateways: try: cls.nuage_vsd_client.delete_gateway(gateway[0]['ID']) except Exception as exc: LOG.exception(exc) has_exception = True super(NuageGatewayTestRedundancy, cls).resource_cleanup() if has_exception: raise exceptions.TearDownException()
def resource_cleanup(cls): super(NetPartitionTestJSON, cls).resource_cleanup() has_exception = False for netpartition in cls.net_partitions: try: cls.client.delete_netpartition(netpartition['id']) except Exception as exc: LOG.exception(exc) has_exception = True if has_exception: raise exceptions.TearDownException()
def tearDownClass(cls): """Calls the callables added by addResourceCleanUp, when you overwire this function dont't forget to call this too. """ fail_count = 0 trash_keys = sorted(cls._resource_trash_bin, reverse=True) for key in trash_keys: (function, pos_args, kw_args) = cls._resource_trash_bin[key] try: LOG.debug( "Cleaning up: %s" % friendly_function_call_str(function, *pos_args, **kw_args)) function(*pos_args, **kw_args) except BaseException as exc: fail_count += 1 LOG.exception(exc) finally: del cls._resource_trash_bin[key] super(MagnetoDBTestCase, cls).tearDownClass() if fail_count: raise exceptions.TearDownException(num=fail_count)
def destroy_bucket(cls, connection_data, bucket): """Destroys the bucket and its content, just for teardown.""" exc_num = 0 try: with contextlib.closing( boto.connect_s3(**connection_data)) as conn: if isinstance(bucket, basestring): bucket = conn.lookup(bucket) assert isinstance(bucket, s3.bucket.Bucket) for obj in bucket.list(): try: bucket.delete_key(obj.key) obj.close() except BaseException: LOG.exception("Failed to delete key %s " % obj.key) exc_num += 1 conn.delete_bucket(bucket) except BaseException: LOG.exception("Failed to destroy bucket %s " % bucket) exc_num += 1 if exc_num: raise exceptions.TearDownException(num=exc_num)
def resource_cleanup(cls): has_exception = False for vport in cls.gatewayvports: try: if vport['type'] == n_constants.HOST_VPORT: cls.nuage_vsd_client.delete_host_interface( vport['interface']) elif vport['type'] == n_constants.BRIDGE_VPORT: cls.nuage_vsd_client.delete_bridge_interface( vport['interface']) cls.nuage_vsd_client.delete_host_vport(vport['id']) except Exception as exc: LOG.exception(exc) has_exception = True for vlan in cls.gatewayvlans: try: if 'id' in vlan: vlan_id = vlan['id'] else: vlan_id = vlan[0]['ID'] cls.nuage_vsd_client.delete_vlan_permission(vlan_id) cls.nuage_vsd_client.delete_gateway_vlan(vlan_id) except Exception as exc: LOG.exception(exc) has_exception = True for port in cls.gatewayports: try: cls.nuage_vsd_client.delete_gateway_port(port[0]['ID']) except Exception as exc: LOG.exception(exc) has_exception = True for gateway in cls.gateways: try: cls.nuage_vsd_client.delete_gateway(gateway[0]['ID']) except Exception as exc: LOG.exception(exc) has_exception = True for router_interface in cls.router_interfaces: try: cls.admin_routers_client.remove_router_interface( router_interface['id'], subnet_id=router_interface['subnet_id']) except Exception as exc: LOG.exception(exc) has_exception = True for router in cls.routers: try: cls.admin_routers_client.delete_router(router['id']) except Exception as exc: LOG.exception(exc) has_exception = True super(BaseNuageGatewayTest, cls).resource_cleanup() try: cls.client.delete_netpartition(cls.nondef_netpart['id']) except Exception as exc: LOG.exception(exc) has_exception = True if has_exception: raise exceptions.TearDownException()
def resource_cleanup(cls): has_exception = False for flow in cls.flow: try: uri = '/flows/' + flow['id'] cls.client.delete_resource(uri) except Exception as exc: LOG.exception(exc) has_exception = True for appdport in cls.appdport: try: uri = '/appdports/' + appdport['id'] cls.client.delete_resource(uri) except Exception as exc: LOG.exception(exc) has_exception = True for tier in cls.tier: try: uri = '/tiers/' + tier['id'] cls.client.delete_resource(uri) except Exception as exc: LOG.exception(exc) has_exception = True for app in cls.application: try: uri = '/applications/' + app['id'] cls.client.delete_resource(uri) except Exception as exc: LOG.exception(exc) has_exception = True for app_domain in cls.app_domain: try: uri = '/application-domains/' + app_domain['id'] cls.client.delete_resource(uri) except Exception as exc: LOG.exception(exc) has_exception = True for vsd_l3dom_template in cls.vsd_l3dom_template: try: cls.nuageclient.delete_l3domaintemplate( vsd_l3dom_template[0]['ID']) except Exception as exc: LOG.exception(exc) has_exception = True for svc in cls.service: try: uri = '/services/' + svc['id'] cls.client.delete_resource(uri) except Exception as exc: LOG.exception(exc) has_exception = True if has_exception: raise exceptions.TearDownException() super(NuageAppdTestJSON, cls).resource_cleanup()