def test_nexusportvlanswitchbinding_get(self): """Tests get of port bindings based on port, vlan, and switch.""" npb11 = self._npb_test_obj(10, 100) npb21 = self._npb_test_obj(20, 100) self._add_bindings_to_db([npb11, npb21]) npb = self._get_port_vlan_switch_binding(npb11) self.assertEqual(len(npb), 1) self._assert_bindings_match(npb[0], npb11) with testtools.ExpectedException(exceptions.NexusPortBindingNotFound): nexus_db_v2.get_port_vlan_switch_binding( npb21.port, npb21.vlan, "dummySwitch")
def _delete_switch_entry(self, vlan_id, device_id, host_id, vni, is_provider_vlan): """Delete the nexus switch entry. By accessing the current db entries determine if switch configuration can be removed. Called during delete postcommit port event. """ host_connections = self._get_switch_info(host_id) # (nexus_port,switch_ip) will be unique in each iteration. # But switch_ip will repeat if host has >1 connection to same switch. # So track which switch_ips already have vlan removed in this loop. vlan_already_removed = [] for switch_ip, intf_type, nexus_port in host_connections: # if there are no remaining db entries using this vlan on this # nexus switch port then remove vlan from the switchport trunk. port_id = '%s:%s' % (intf_type, nexus_port) auto_create = True auto_trunk = True if is_provider_vlan: auto_create = cfg.CONF.ml2_cisco.provider_vlan_auto_create auto_trunk = cfg.CONF.ml2_cisco.provider_vlan_auto_trunk try: nxos_db.get_port_vlan_switch_binding(port_id, vlan_id, switch_ip) except excep.NexusPortBindingNotFound: pass else: continue if auto_trunk: self.driver.disable_vlan_on_trunk_int(switch_ip, vlan_id, intf_type, nexus_port) # if there are no remaining db entries using this vlan on this # nexus switch then remove the vlan. if auto_create: try: nxos_db.get_nexusvlan_binding(vlan_id, switch_ip) except excep.NexusPortBindingNotFound: # Do not perform a second time on same switch if switch_ip not in vlan_already_removed: self.driver.delete_vlan(switch_ip, vlan_id) vlan_already_removed.append(switch_ip)
def _delete_switch_entry(self, vlan_id, device_id, host_id, vni, is_provider_vlan): """Delete the nexus switch entry. By accessing the current db entries determine if switch configuration can be removed. Called during delete postcommit port event. """ host_connections = self._get_switch_info(host_id) # (nexus_port,switch_ip) will be unique in each iteration. # But switch_ip will repeat if host has >1 connection to same switch. # So track which switch_ips already have vlan removed in this loop. vlan_already_removed = [] for switch_ip, intf_type, nexus_port in host_connections: # if there are no remaining db entries using this vlan on this # nexus switch port then remove vlan from the switchport trunk. port_id = '%s:%s' % (intf_type, nexus_port) auto_create = True auto_trunk = True if is_provider_vlan: auto_create = cfg.CONF.ml2_cisco.provider_vlan_auto_create auto_trunk = cfg.CONF.ml2_cisco.provider_vlan_auto_trunk try: nxos_db.get_port_vlan_switch_binding(port_id, vlan_id, switch_ip) except excep.NexusPortBindingNotFound: pass else: continue if auto_trunk: self.driver.disable_vlan_on_trunk_int( switch_ip, vlan_id, intf_type, nexus_port) # if there are no remaining db entries using this vlan on this # nexus switch then remove the vlan. if auto_create: try: nxos_db.get_nexusvlan_binding(vlan_id, switch_ip) except excep.NexusPortBindingNotFound: # Do not perform a second time on same switch if switch_ip not in vlan_already_removed: self.driver.delete_vlan(switch_ip, vlan_id) vlan_already_removed.append(switch_ip)
def _get_port_vlan_switch_binding(self, npb): """Gets port bindings based on port, vlan, and switch.""" return nexus_db_v2.get_port_vlan_switch_binding( npb.port, npb.vlan, npb.switch)