def __init__(self, q_conn=None, ipam_lib=None, *args, **kwargs): """Initialize two key libraries, the connection to a Quantum service, and the library for implementing IPAM. Calls inherited FlatManager constructor. """ if not q_conn: q_conn = quantum_connection.QuantumClientConnection() self.q_conn = q_conn if not ipam_lib: ipam_lib = FLAGS.quantum_ipam_lib self.ipam = utils.import_object(ipam_lib).get_ipam_lib(self) super(QuantumManager, self).__init__(*args, **kwargs) # Initialize forwarding rules for anything specified in # FLAGS.fixed_range() self.driver.init_host() # Set up all the forwarding rules for any network that has a # gateway set. networks = self.get_all_networks() for net in networks: LOG.debug("Initializing network: %s (cidr: %s, gw: %s)" % (net['label'], net['cidr'], net['gateway'])) if net['gateway']: self.driver.init_host(net['cidr']) self.driver.ensure_metadata_ip() self.driver.metadata_forward()
def setUp(self): super(QuantumMelangeTestCase, self).setUp() 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 __init__(self, q_conn=None, ipam_lib=None, *args, **kwargs): """Initialize two key libraries, the connection to a Quantum service, and the library for implementing IPAM. Calls inherited FlatManager constructor. """ if not q_conn: q_conn = quantum_connection.QuantumClientConnection() self.q_conn = q_conn if not ipam_lib: ipam_lib = FLAGS.quantum_ipam_lib self.ipam = utils.import_object(ipam_lib).get_ipam_lib(self) super(QuantumManager, self).__init__(*args, **kwargs)
def test_connection(self): fc = fake_client.FakeClient(LOG) qc = quantum_connection.QuantumClientConnection(client=fc) t = "tenant1" net1_name = "net1" net1_uuid = qc.create_network(t, net1_name) self.assertEquals(net1_name, qc.get_network_name(t, net1_uuid)) self.assertTrue(qc.network_exists(t, net1_uuid)) self.assertFalse(qc.network_exists(t, "fake-uuid")) self.assertFalse(qc.network_exists("fake-tenant", net1_uuid)) nets = qc.get_networks(t)['networks'] self.assertEquals(len(nets), 1) self.assertEquals(nets[0]['id'], net1_uuid) num_ports = 10 for i in range(0, num_ports): qc.create_and_attach_port(t, net1_uuid, 'iface' + str(i), state='ACTIVE') self.assertEquals(len(qc.get_attached_ports(t, net1_uuid)), num_ports) for i in range(0, num_ports): port_uuid = qc.get_port_by_attachment(t, net1_uuid, 'iface' + str(i)) self.assertTrue(port_uuid) qc.detach_and_delete_port(t, net1_uuid, port_uuid) self.assertEquals(len(qc.get_attached_ports(t, net1_uuid)), 0) # test port not found qc.create_and_attach_port(t, net1_uuid, 'foo', state='ACTIVE') port_uuid = qc.get_port_by_attachment(t, net1_uuid, 'foo') qc.detach_and_delete_port(t, net1_uuid, port_uuid) self.assertRaises(quantum_client.QuantumNotFoundException, qc.detach_and_delete_port, t, net1_uuid, port_uuid) qc.delete_network(t, net1_uuid) self.assertFalse(qc.network_exists(t, net1_uuid)) self.assertEquals(len(qc.get_networks(t)['networks']), 0) self.assertRaises(quantum_client.QuantumNotFoundException, qc.get_network_name, t, net1_uuid)
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()