def delete_network(self, context, fixed_range, require_disassociated=True): network = db.network_get_by_cidr(context, fixed_range) if require_disassociated and network.project_id is not None: raise ValueError(_("Network must be disassociated from project %s" " before delete" % network.project_id)) db.network_delete_safe(context, network.id)
def setUp(self): super(QuantumNovaTestCase, self).setUp() # Create an actual project -- with this we will touch more of # the code in QuantumManager (related to fetching networks, etc) for x in ['fake_project1', 'fake_project2']: values = {'id': x, 'name': x} project = db.project_create(context.get_admin_context(), values) self.net_man = quantum_manager.QuantumManager( ipam_lib="nova.network.quantum.nova_ipam_lib", q_conn=FakeQuantumClientConnection()) # Tests seem to create some networks by default, which # we don't want. So we delete them. ctx = context.RequestContext('user1', 'fake_project1').elevated() for n in db.network_get_all(ctx): db.network_delete_safe(ctx, n['id']) # Other unit tests (e.g., test_compute.py) have a nasty # habit of of creating fixed IPs and not cleaning up, which # can confuse these tests, so we remove all existing fixed # ips before starting. session = get_session() result = session.query(models.FixedIp).all() with session.begin(): for fip_ref in result: session.delete(fip_ref)
def setUp(self): super(QuantumNovaTestCase, self).setUp() # Create an actual project -- with this we will touch more of # the code in QuantumManager (related to fetching networks, etc) for x in ["fake_project1", "fake_project2"]: values = {"id": x, "name": x} project = db.project_create(context.get_admin_context(), values) self.net_man = quantum_manager.QuantumManager( ipam_lib="nova.network.quantum.nova_ipam_lib", q_conn=FakeQuantumClientConnection() ) # Tests seem to create some networks by default, which # we don't want. So we delete them. ctx = context.RequestContext("user1", "fake_project1").elevated() for n in db.network_get_all(ctx): db.network_delete_safe(ctx, n["id"]) # Other unit tests (e.g., test_compute.py) have a nasty # habit of of creating fixed IPs and not cleaning up, which # can confuse these tests, so we remove all existing fixed # ips before starting. session = get_session() result = session.query(models.FixedIp).all() with session.begin(): for fip_ref in result: session.delete(fip_ref)
def delete_subnets_by_net_id(self, context, net_id, project_id): """Find Melange block associated with the Quantum UUID, then tell Melange to delete that block. """ admin_context = context.elevated() tenant_id = project_id or FLAGS.quantum_default_tenant_id all_blocks = self.m_conn.get_blocks(tenant_id) for b in all_blocks['ip_blocks']: if b['network_id'] == net_id: self.m_conn.delete_block(b['id'], tenant_id) network = db.network_get_by_uuid(admin_context, net_id) db.network_delete_safe(context, network['id'])
def test_delete_subnets_by_net_id_deletes_block(self): context = self.mox.CreateMockAnything() context.elevated().AndReturn('elevated') self.m_conn.get_blocks('project_id').AndReturn( self._block_list(id='block_id')) self.m_conn.delete_block('block_id', 'project_id') self.mox.StubOutWithMock(db, 'network_get_by_uuid') db.network_get_by_uuid('elevated', 'network_id').AndReturn({'id': 'network_id'}) self.mox.StubOutWithMock(db, 'network_delete_safe') db.network_delete_safe(context, 'network_id') self.mox.ReplayAll() self.ipam.delete_subnets_by_net_id(context, 'network_id', 'project_id')
def test_delete_subnets_by_net_id_deletes_block(self): context = self.mox.CreateMockAnything() context.elevated().AndReturn('elevated') self.m_conn.get_blocks('project_id').AndReturn( self._block_list(id='block_id')) self.m_conn.delete_block('block_id', 'project_id') self.mox.StubOutWithMock(db, 'network_get_by_uuid') db.network_get_by_uuid('elevated', 'network_id').AndReturn( {'id': 'network_id'}) self.mox.StubOutWithMock(db, 'network_delete_safe') db.network_delete_safe(context, 'network_id') self.mox.ReplayAll() self.ipam.delete_subnets_by_net_id(context, 'network_id', 'project_id')
def setUp(self): super(QuantumNovaTestCase, self).setUp() self.flags(quantum_use_dhcp=True) self.flags(l3_lib="nova.network.l3.LinuxNetL3") linuxdrv = "nova.network.linux_net.LinuxOVSInterfaceDriver" self.flags(linuxnet_interface_driver=linuxdrv) fc = fake_client.FakeClient(LOG) qc = quantum_connection.QuantumClientConnection(client=fc) self.net_man = quantum_manager.QuantumManager( ipam_lib="nova.network.quantum.nova_ipam_lib", q_conn=qc) def func(arg1, arg2): pass def func2(arg1, arg2, arg3): pass def func1(arg1): pass self.net_man.driver.update_dhcp_hostfile_with_text = func self.net_man.driver.restart_dhcp = func2 self.net_man.driver.kill_dhcp = func1 # Tests seem to create some networks by default, which # we don't want. So we delete them. ctx = context.RequestContext('user1', 'fake_project1').elevated() for n in db.network_get_all(ctx): db.network_delete_safe(ctx, n['id']) # Other unit tests (e.g., test_compute.py) have a nasty # habit of of creating fixed IPs and not cleaning up, which # can confuse these tests, so we remove all existing fixed # ips before starting. session = sql_session.get_session() result = session.query(models.FixedIp).all() with session.begin(): for fip_ref in result: session.delete(fip_ref) self.net_man.init_host()
def setUp(self): super(QuantumNovaTestCase, self).setUp() self.net_man = quantum_manager.QuantumManager( ipam_lib="nova.network.quantum.nova_ipam_lib", q_conn=FakeQuantumClientConnection() ) # Tests seem to create some networks by default, which # we don't want. So we delete them. ctx = context.RequestContext("user1", "fake_project1").elevated() for n in db.network_get_all(ctx): db.network_delete_safe(ctx, n["id"]) # Other unit tests (e.g., test_compute.py) have a nasty # habit of of creating fixed IPs and not cleaning up, which # can confuse these tests, so we remove all existing fixed # ips before starting. session = get_session() result = session.query(models.FixedIp).all() with session.begin(): for fip_ref in result: session.delete(fip_ref)
def setUp(self): super(QuantumNovaTestCase, self).setUp() self.net_man = quantum_manager.QuantumManager( ipam_lib="nova.network.quantum.nova_ipam_lib", q_conn=FakeQuantumClientConnection()) # Tests seem to create some networks by default, which # we don't want. So we delete them. ctx = context.RequestContext('user1', 'fake_project1').elevated() for n in db.network_get_all(ctx): db.network_delete_safe(ctx, n['id']) # Other unit tests (e.g., test_compute.py) have a nasty # habit of of creating fixed IPs and not cleaning up, which # can confuse these tests, so we remove all existing fixed # ips before starting. session = get_session() result = session.query(models.FixedIp).all() with session.begin(): for fip_ref in result: session.delete(fip_ref)
def test_network_delete_safe(self): ctxt = context.get_admin_context() values = {"host": "localhost", "project_id": "project1"} network = db.network_create_safe(ctxt, values) db_network = db.network_get(ctxt, network.id) values = {"network_id": network["id"], "address": "fake1"} address1 = db.fixed_ip_create(ctxt, values) values = {"network_id": network["id"], "address": "fake2", "allocated": True} address2 = db.fixed_ip_create(ctxt, values) self.assertRaises(exception.NetworkInUse, db.network_delete_safe, ctxt, network["id"]) db.fixed_ip_update(ctxt, address2, {"allocated": False}) network = db.network_delete_safe(ctxt, network["id"]) ctxt = ctxt.elevated(read_deleted="yes") fixed_ip = db.fixed_ip_get_by_address(ctxt, address1) self.assertTrue(fixed_ip["deleted"])
def test_network_delete_safe(self): ctxt = context.get_admin_context() values = {'host': 'localhost', 'project_id': 'project1'} network = db.network_create_safe(ctxt, values) db_network = db.network_get(ctxt, network.id) values = {'network_id': network['id'], 'address': 'fake1'} address1 = db.fixed_ip_create(ctxt, values) values = {'network_id': network['id'], 'address': 'fake2', 'allocated': True} address2 = db.fixed_ip_create(ctxt, values) self.assertRaises(exception.NetworkInUse, db.network_delete_safe, ctxt, network['id']) db.fixed_ip_update(ctxt, address2, {'allocated': False}) network = db.network_delete_safe(ctxt, network['id']) ctxt = ctxt.elevated(read_deleted='yes') fixed_ip = db.fixed_ip_get_by_address(ctxt, address1) self.assertTrue(fixed_ip['deleted'])
def test_network_delete_safe(self): ctxt = context.get_admin_context() values = {'host': 'localhost', 'project_id': 'project1'} network = db.network_create_safe(ctxt, values) db_network = db.network_get(ctxt, network.id) values = {'network_id': network['id'], 'address': 'fake1'} address1 = db.fixed_ip_create(ctxt, values) values = { 'network_id': network['id'], 'address': 'fake2', 'allocated': True } address2 = db.fixed_ip_create(ctxt, values) self.assertRaises(exception.NetworkInUse, db.network_delete_safe, ctxt, network['id']) db.fixed_ip_update(ctxt, address2, {'allocated': False}) network = db.network_delete_safe(ctxt, network['id']) ctxt = ctxt.elevated(read_deleted='yes') fixed_ip = db.fixed_ip_get_by_address(ctxt, address1) self.assertTrue(fixed_ip['deleted'])
def tearDown(self): db.network_delete_safe(context.get_admin_context(), self.network['id']) super(FixedIpCommandsTestCase, self).tearDown()
def destroy(self, context): db.network_delete_safe(context, self.id) self.deleted = True self.obj_reset_changes(['deleted'])
def delete_subnets_by_net_id(self, context, net_id, project_id): admin_context = context.elevated() tenant_id = project_id or FLAGS.quantum_default_tenant_id network = db.network_get_by_uuid(admin_context, net_id) db.network_delete_safe(context, network['id'])
def delete_subnets_by_net_id(self, context, net_id, project_id): admin_context = context.elevated() tenant_id = project_id or FLAGS.quantum_default_tenant_id network = db.network_get_by_uuid(admin_context, net_id) db.network_delete_safe(context, network["id"])