def test_server_set_metadata_with_exception_reraise(self, mock_nova): """ Test that an OpenStackCloudException exception gets re-raised in set_server_metadata. """ mock_nova.servers.set_meta.side_effect = OpenStackCloudException("") self.assertRaises(OpenStackCloudException, self.cloud.set_server_metadata, 'server-id', {'meta': 'data'})
def test_server_delete_metadata_with_exception_reraise(self, mock_nova): """ Test that an OpenStackCloudException exception gets re-raised in delete_server_metadata. """ mock_nova.servers.delete_meta.side_effect = OpenStackCloudException("") self.assertRaises(OpenStackCloudException, self.cloud.delete_server_metadata, 'server-id', ['key'])
def _cleanup_projects(self): exception_list = list() for p in self.operator_cloud.list_projects(): if p['name'].startswith(self.new_project_name): try: self.operator_cloud.delete_project(p['id']) except Exception as e: exception_list.append(str(e)) continue if exception_list: raise OpenStackCloudException('\n'.join(exception_list))
def _cleanup_networks(self): exception_list = list() for network in self.operator_cloud.list_networks(): if network['name'].startswith(self.network_name): try: self.operator_cloud.delete_network(network['name']) except Exception as e: exception_list.append(str(e)) continue if exception_list: raise OpenStackCloudException('\n'.join(exception_list))
def _cleanup_subnets(self): exception_list = list() for subnet in self.operator_cloud.list_subnets(): if subnet['name'].startswith(self.subnet_prefix): try: self.operator_cloud.delete_subnet(subnet['id']) except Exception as e: exception_list.append(str(e)) continue if exception_list: raise OpenStackCloudException('\n'.join(exception_list))
def _cleanup_routers(self): exception_list = list() for router in self.operator_cloud.list_routers(): if router['name'].startswith(self.router_prefix): try: self.operator_cloud.delete_router(router['name']) except Exception as e: exception_list.append(str(e)) continue if exception_list: raise OpenStackCloudException('\n'.join(exception_list))
def _cleanup_policies(self): exception_list = list() for policy in self.operator_cloud.list_qos_policies(): if policy['name'].startswith(self.policy_name): try: self.operator_cloud.delete_qos_policy(policy['id']) except Exception as e: exception_list.append(str(e)) continue if exception_list: raise OpenStackCloudException('\n'.join(exception_list))
def _cleanup_network(self): exception_list = list() # Delete stale networks as well as networks created for this test if self.user_cloud.has_service('network'): # Delete routers for r in self.user_cloud.list_routers(): try: if r['name'].startswith(self.new_item_name): # ToDo: update_router currently won't allow removing # external_gateway_info router = { 'external_gateway_info': None } self.neutron.update_router( router=r['id'], body={'router': router}) # ToDo: Shade currently doesn't have methods for this for s in self.user_cloud.list_subnets(): if s['name'].startswith(self.new_item_name): try: self.neutron.remove_interface_router( router=r['id'], body={'subnet_id': s['id']}) except Exception: pass self.user_cloud.delete_router(name_or_id=r['id']) except Exception as e: exception_list.append(str(e)) continue # Delete subnets for s in self.user_cloud.list_subnets(): if s['name'].startswith(self.new_item_name): try: self.user_cloud.delete_subnet(name_or_id=s['id']) except Exception as e: exception_list.append(str(e)) continue # Delete networks for n in self.user_cloud.list_networks(): if n['name'].startswith(self.new_item_name): try: self.user_cloud.delete_network(name_or_id=n['id']) except Exception as e: exception_list.append(str(e)) continue if exception_list: # Raise an error: we must make users aware that something went # wrong raise OpenStackCloudException('\n'.join(exception_list))
def _cleanup_ips(self, ips): exception_list = list() for ip in ips: try: self.cloud.delete_floating_ip(ip) except Exception as e: exception_list.append(e) continue if exception_list: # Raise an error: we must make users aware that something went # wrong raise OpenStackCloudException('\n'.join(exception_list))
def _cleanup_flavors(self): exception_list = list() for f in self.operator_cloud.list_flavors(): if f['name'].startswith(self.new_item_name): try: self.operator_cloud.delete_flavor(f['id']) except Exception as e: # We were unable to delete a flavor, let's try with next exception_list.append(e) continue if exception_list: # Raise an error: we must make users aware that something went # wrong raise OpenStackCloudException('\n'.join(exception_list))
def _cleanup_endpoints(self): exception_list = list() for e in self.operator_cloud.list_endpoints(): if e.get('region') is not None and \ e['region'].startswith(self.new_item_name): try: self.operator_cloud.delete_endpoint(id=e['id']) except Exception as e: # We were unable to delete a service, let's try with next exception_list.append(e) continue if exception_list: # Raise an error: we must make users aware that something went # wrong raise OpenStackCloudException('\n'.join(exception_list))
def test_server_delete_metadata_with_exception_reraise(self): """ Test that an OpenStackCloudException exception gets re-raised in delete_server_metadata. """ with patch("shade.OpenStackCloud"): config = { "servers.delete_meta.side_effect": OpenStackCloudException("exception"), } OpenStackCloud.nova_client = Mock(**config) self.assertRaises(OpenStackCloudException, self.cloud.delete_server_metadata, 'server-id', ['key'])
def _cleanup_services(self): exception_list = list() for s in self.operator_cloud.list_services(): if s['name'] is not None and \ s['name'].startswith(self.new_item_name): try: self.operator_cloud.delete_service(name_or_id=s['id']) except Exception as e: # We were unable to delete a service, let's try with next exception_list.append(str(e)) continue if exception_list: # Raise an error: we must make users aware that something went # wrong raise OpenStackCloudException('\n'.join(exception_list))
def _cleanup_servers(self): exception_list = list() # Delete stale servers as well as server created for this test for i in self.user_cloud.list_servers(bare=True): if i.name.startswith(self.new_item_name): try: self.user_cloud.delete_server(i, wait=True) except Exception as e: exception_list.append(str(e)) continue if exception_list: # Raise an error: we must make users aware that something went # wrong raise OpenStackCloudException('\n'.join(exception_list))
def _cleanup_ports(self): exception_list = list() for p in self.operator_cloud.list_ports(): if p['name'].startswith(self.new_port_name): try: self.operator_cloud.delete_port(name_or_id=p['id']) except Exception as e: # We were unable to delete this port, let's try with next exception_list.append(str(e)) continue if exception_list: # Raise an error: we must make users aware that something went # wrong raise OpenStackCloudException('\n'.join(exception_list))
def _cleanup_network(self): exception_list = list() # Delete stale networks as well as networks created for this test if self.user_cloud.has_service('network'): # Delete routers for r in self.user_cloud.list_routers(): try: if r['name'].startswith(self.new_item_name): self.user_cloud.update_router(r['id'], ext_gateway_net_id=None) for s in self.user_cloud.list_subnets(): if s['name'].startswith(self.new_item_name): try: self.user_cloud.remove_router_interface( r, subnet_id=s['id']) except Exception: pass self.user_cloud.delete_router(name_or_id=r['id']) except Exception as e: exception_list.append(str(e)) continue # Delete subnets for s in self.user_cloud.list_subnets(): if s['name'].startswith(self.new_item_name): try: self.user_cloud.delete_subnet(name_or_id=s['id']) except Exception as e: exception_list.append(str(e)) continue # Delete networks for n in self.user_cloud.list_networks(): if n['name'].startswith(self.new_item_name): try: self.user_cloud.delete_network(name_or_id=n['id']) except Exception as e: exception_list.append(str(e)) continue if exception_list: # Raise an error: we must make users aware that something went # wrong raise OpenStackCloudException('\n'.join(exception_list))
def _cleanup_ips(self, server): exception_list = list() fixed_ip = meta.get_server_private_ip(server) for ip in self.user_cloud.list_floating_ips(): if (ip.get('fixed_ip', None) == fixed_ip or ip.get('fixed_ip_address', None) == fixed_ip): try: self.user_cloud.delete_floating_ip(ip['id']) except Exception as e: exception_list.append(str(e)) continue if exception_list: # Raise an error: we must make users aware that something went # wrong raise OpenStackCloudException('\n'.join(exception_list))
def _cleanup_servers(self): exception_list = list() # Delete stale servers as well as server created for this test for i in self.nova.servers.list(): if i.name.startswith(self.new_item_name): self.nova.servers.delete(i) for _ in _utils._iterate_timeout(self.timeout, "Timeout deleting servers"): try: self.nova.servers.get(server=i) except nova_exc.NotFound: break except Exception as e: exception_list.append(str(e)) continue if exception_list: # Raise an error: we must make users aware that something went # wrong raise OpenStackCloudException('\n'.join(exception_list))
def _cleanup_qos_policy(self): try: self.operator_cloud.delete_qos_policy(self.policy['id']) except Exception as e: raise OpenStackCloudException(e)