def _delete_port(self, port_config): """Tests deletion of a virtual port.""" nexus_ip_addr = port_config.nexus_ip_addr host_name = port_config.host_name nexus_port = port_config.nexus_port instance_id = port_config.instance_id vlan_id = port_config.vlan_id vxlan_id = port_config.vxlan_id mcast_group = port_config.mcast_group device_owner = port_config.device_owner network_context = FakeNetworkContext(vlan_id, NETWORK_TYPE) if vxlan_id != NO_VXLAN_ID: vxlan_network_context = FakeNetworkContext( vlan_id, NEXUS_VXLAN_NETWORK_TYPE, mcast_group) port_context = FakePortContext(instance_id, host_name, device_owner, vxlan_network_context, network_context) else: port_context = FakePortContext(instance_id, host_name, device_owner, network_context) self._cisco_mech_driver.delete_port_precommit(port_context) self._cisco_mech_driver.delete_port_postcommit(port_context) for port_id in nexus_port.split(','): with testtools.ExpectedException( exceptions.NexusPortBindingNotFound): nexus_db_v2.get_nexusport_binding(port_id, vlan_id, nexus_ip_addr, instance_id)
def _delete_port(self, port_config): """Tests deletion of a virtual port.""" port_context = self._generate_port_context(port_config) self._cisco_mech_driver.delete_port_precommit(port_context) self._cisco_mech_driver.delete_port_postcommit(port_context) if self._cisco_mech_driver._is_baremetal(port_context.current): connections = self._cisco_mech_driver._get_port_connections( port_context.current, '') else: connections = self._cisco_mech_driver._get_port_connections( port_context.current, port_config.host_name) # for port_id in port_config.nexus_port.split(','): for switch_ip, intf_type, port, is_p_vlan in connections: if switch_ip is not port_config.nexus_ip_addr: continue port_id = intf_type + ':' + port with testtools.ExpectedException( exceptions.NexusPortBindingNotFound): nexus_db_v2.get_nexusport_binding( port_id, port_config.vlan_id, port_config.nexus_ip_addr, port_config.instance_id)
def _delete_port(self, port_config): """Tests deletion of a virtual port.""" nexus_ip_addr = port_config.nexus_ip_addr host_name = port_config.host_name nexus_port = port_config.nexus_port instance_id = port_config.instance_id vlan_id = port_config.vlan_id vxlan_id = port_config.vxlan_id mcast_group = port_config.mcast_group device_owner = port_config.device_owner network_context = FakeNetworkContext(vlan_id, NETWORK_TYPE) if vxlan_id != NO_VXLAN_ID: vxlan_network_context = FakeNetworkContext(vlan_id, NEXUS_VXLAN_NETWORK_TYPE, mcast_group) port_context = FakePortContext(instance_id, host_name, device_owner, vxlan_network_context, network_context) else: port_context = FakePortContext(instance_id, host_name, device_owner, network_context) self._cisco_mech_driver.delete_port_precommit(port_context) self._cisco_mech_driver.delete_port_postcommit(port_context) for port_id in nexus_port.split(','): with testtools.ExpectedException( exceptions.NexusPortBindingNotFound): nexus_db_v2.get_nexusport_binding(port_id, vlan_id, nexus_ip_addr, instance_id)
def _create_port(self, port_config): """Tests creation of a virtual port.""" nexus_ip_addr = port_config.nexus_ip_addr host_name = port_config.host_name nexus_port = port_config.nexus_port instance_id = port_config.instance_id vlan_id = port_config.vlan_id vxlan_id = port_config.vxlan_id mcast_group = port_config.mcast_group device_owner = port_config.device_owner network_context = FakeNetworkContext(vlan_id, NETWORK_TYPE) if vxlan_id != NO_VXLAN_ID: vxlan_network_context = FakeNetworkContext( vlan_id, NEXUS_VXLAN_NETWORK_TYPE, mcast_group) port_context = FakePortContext(instance_id, host_name, device_owner, vxlan_network_context, network_context) else: port_context = FakePortContext(instance_id, host_name, device_owner, network_context) self._cisco_mech_driver.update_port_precommit(port_context) self._cisco_mech_driver.update_port_postcommit(port_context) for port_id in nexus_port.split(','): bindings = nexus_db_v2.get_nexusport_binding( port_id, vlan_id, nexus_ip_addr, instance_id) self.assertEqual(len(bindings), 1)
def _create_port(self, port_config, override_netid=None): """Tests creation of a virtual port.""" port_context = self._generate_port_context( port_config, override_netid=override_netid) self._cisco_mech_driver.create_port_postcommit(port_context) self._cisco_mech_driver.update_port_precommit(port_context) self._cisco_mech_driver.update_port_postcommit(port_context) if self._cisco_mech_driver._is_baremetal(port_context.current): connections = self._cisco_mech_driver._get_port_connections( port_context.current, '') else: connections = self._cisco_mech_driver._get_port_connections( port_context.current, port_config.host_name) # for port_id in port_config.nexus_port.split(','): for switch_ip, intf_type, port, is_p_vlan in connections: if switch_ip is not port_config.nexus_ip_addr: continue port_id = intf_type + ':' + port bindings = nexus_db_v2.get_nexusport_binding( port_id, port_config.vlan_id, port_config.nexus_ip_addr, port_config.instance_id) self.assertEqual(1, len(bindings))
def _create_port(self, port_config): """Tests creation of a virtual port.""" nexus_ip_addr = port_config.nexus_ip_addr host_name = port_config.host_name nexus_port = port_config.nexus_port instance_id = port_config.instance_id vlan_id = port_config.vlan_id vxlan_id = port_config.vxlan_id mcast_group = port_config.mcast_group device_owner = port_config.device_owner network_context = FakeNetworkContext(vlan_id, NETWORK_TYPE) if vxlan_id != NO_VXLAN_ID: vxlan_network_context = FakeNetworkContext(vlan_id, NEXUS_VXLAN_NETWORK_TYPE, mcast_group) port_context = FakePortContext(instance_id, host_name, device_owner, vxlan_network_context, network_context) else: port_context = FakePortContext(instance_id, host_name, device_owner, network_context) self._cisco_mech_driver.create_port_postcommit(port_context) self._cisco_mech_driver.update_port_precommit(port_context) self._cisco_mech_driver.update_port_postcommit(port_context) for port_id in nexus_port.split(','): bindings = nexus_db_v2.get_nexusport_binding(port_id, vlan_id, nexus_ip_addr, instance_id) self.assertEqual(len(bindings), 1)
def _configure_nxos_db(self, vlan_id, device_id, host_id, vni, is_provider_vlan): """Create the nexus database entry. Called during update precommit port event. """ host_connections = self._get_switch_info(host_id) for switch_ip, intf_type, nexus_port in host_connections: port_id = '%s:%s' % (intf_type, nexus_port) try: nxos_db.get_nexusport_binding(port_id, vlan_id, switch_ip, device_id) except excep.NexusPortBindingNotFound: nxos_db.add_nexusport_binding(port_id, str(vlan_id), str(vni), switch_ip, device_id, is_provider_vlan)
def _create_port(self, port_config): """Tests creation of a virtual port.""" port_context = self._generate_port_context(port_config) self._cisco_mech_driver.create_port_postcommit(port_context) self._cisco_mech_driver.update_port_precommit(port_context) self._cisco_mech_driver.update_port_postcommit(port_context) if self._cisco_mech_driver._is_baremetal(port_context.current): connections = self._cisco_mech_driver._get_port_connections( port_context.current, '') else: connections = self._cisco_mech_driver._get_port_connections( port_context.current, port_config.host_name) # for port_id in port_config.nexus_port.split(','): for switch_ip, intf_type, port, is_p_vlan in connections: if switch_ip is not port_config.nexus_ip_addr: continue port_id = intf_type + ':' + port bindings = nexus_db_v2.get_nexusport_binding( port_id, port_config.vlan_id, port_config.nexus_ip_addr, port_config.instance_id) self.assertEqual(len(bindings), 1)
def test_nexusportbinding_get(self): """Tests get of specific port bindings from the database.""" npb11 = self._npb_test_obj(10, 100) npb21 = self._npb_test_obj(20, 100) npb22 = self._npb_test_obj(20, 200) self._add_bindings_to_db([npb11, npb21, npb22]) npb = self._get_nexusport_binding(npb11) self.assertEqual(len(npb), 1) self._assert_bindings_match(npb[0], npb11) npb = self._get_nexusport_binding(npb21) self.assertEqual(len(npb), 1) self._assert_bindings_match(npb[0], npb21) npb = self._get_nexusport_binding(npb22) self.assertEqual(len(npb), 1) self._assert_bindings_match(npb[0], npb22) with testtools.ExpectedException(exceptions.NexusPortBindingNotFound): nexus_db_v2.get_nexusport_binding( npb21.port, npb21.vlan, npb21.switch, "dummyInstance")
def _get_nexusport_binding(self, npb): """Gets a port binding based on port, vlan, switch, and instance.""" return nexus_db_v2.get_nexusport_binding( npb.port, npb.vlan, npb.switch, npb.instance)