def test_list_swicth_port(self): self.data = {'vendor': "hpe", 'name': "switch1", 'family': "hp5900", 'management_protocol': "snmpv1", 'port_provisioning': "ENABLED", 'mac_address': "44:31:92:61:89:d2", 'credentials': "cred1", 'ip_address': "105.0.1.109", 'validation_result': "success"} self.mapping_dict = {'neutron_port_id': "24", 'switch_port_name': "TenGigabitEthernet", 'lag_id': None, 'access_type': "access", 'segmentation_id': 3, 'bind_status': 0, 'ifindex': "8"} sw = db.add_bnp_phys_switch(self.ctx, self.data) self.mapping_dict['switch_id'] = sw['id'] db.add_bnp_switch_port_map(self.ctx, self.mapping_dict) db.add_bnp_neutron_port(self.ctx, self.mapping_dict) list_req = self.new_list_request('bnp-switch-ports') result = self.bnp_wsgi_controller.index(list_req) result = result.pop('bnp_switch_ports') self.assertEqual(1, len(result))
def test_list_swicth_port(self): self.data = { 'vendor': "hpe", 'name': "switch1", 'family': "hp5900", 'management_protocol': "snmpv1", 'port_provisioning': "ENABLED", 'mac_address': "44:31:92:61:89:d2", 'credentials': "cred1", 'ip_address': "105.0.1.109", 'validation_result': "success" } self.mapping_dict = { 'neutron_port_id': "24", 'switch_port_name': "TenGigabitEthernet", 'lag_id': None, 'access_type': "access", 'segmentation_id': 3, 'bind_status': 0, 'ifindex': "8" } sw = db.add_bnp_phys_switch(self.ctx, self.data) self.mapping_dict['switch_id'] = sw['id'] db.add_bnp_switch_port_map(self.ctx, self.mapping_dict) db.add_bnp_neutron_port(self.ctx, self.mapping_dict) list_req = self.new_list_request('bnp-switch-ports') result = self.bnp_wsgi_controller.index(list_req) result = result.pop('bnp_switch_ports') self.assertEqual(1, len(result))
def bind_port_to_segment(self, port): """bind_port_to_segment .""" db_context = neutron_context.get_admin_context() LOG.info(_LI('bind_port_to_segment called from back-end mech driver')) switchports = port['port']['switchports'] for switchport in switchports: switch_id = switchport['switch_id'] bnp_switch = db.get_bnp_phys_switch_by_mac(db_context, switch_id) port_name = switchport['port_id'] if not bnp_switch: self._raise_ml2_error(wexc.HTTPNotFound, 'create_port') credentials_dict = port.get('port') cred_dict = self._get_credentials_dict(bnp_switch, 'create_port') credentials_dict['credentials'] = cred_dict try: prov_protocol = bnp_switch.management_protocol vendor = bnp_switch.vendor family = bnp_switch.family prov_driver = self._provisioning_driver(prov_protocol, vendor, family) if not prov_driver: LOG.error(_LE("No suitable provisioning driver found" )) self._raise_ml2_error(wexc.HTTPNotFound, 'create_port') port_list = prov_driver.obj.get_device_info(port) ifindex = self._get_if_index(port_list, port_name) switchport['ifindex'] = ifindex if not port_list: LOG.error(_LE("No physical port found for '%s' "), switch_id) self._raise_ml2_error(wexc.HTTPNotFound, 'create_port') prov_driver.obj.set_isolation(port) port_id = port['port']['id'] segmentation_id = port['port']['segmentation_id'] mapping_dict = {'neutron_port_id': port_id, 'switch_port_name': port_name, 'switch_id': bnp_switch.id, 'lag_id': None, 'access_type': hp_const.ACCESS, 'segmentation_id': int(segmentation_id), 'bind_status': 0, 'ifindex': ifindex } db.add_bnp_switch_port_map(db_context, mapping_dict) db.add_bnp_neutron_port(db_context, mapping_dict) if bnp_switch.validation_result != hp_const.SUCCESS: db.update_bnp_phys_switch_result_status(db_context, bnp_switch.id, hp_const.SUCCESS) return hp_const.BIND_SUCCESS except Exception as e: LOG.error(_LE("Exception in configuring VLAN '%s' "), e) return hp_const.BIND_FAILURE
def test_get_all_bnp_switch_port_maps(self): """Test get_all_bnp_switch_port_maps method.""" sw_dict = self._get_bnp_phys_switch_dict() phy_switch = db.add_bnp_phys_switch(self.ctx, sw_dict) port_dict = self._get_bnp_neutron_port_dict() db.add_bnp_neutron_port(self.ctx, port_dict) port_map = self._get_bnp_switch_port_map_dict() port_map['switch_id'] = phy_switch['id'] db.add_bnp_switch_port_map(self.ctx, port_map) ports = db.get_all_bnp_switch_port_maps(self.ctx) self.assertEqual(ports[0][0], port_map['neutron_port_id'])
def bind_port_to_segment(self, port): """bind_port_to_segment .""" LOG.info(_LI('bind_port_to_segment called from back-end mech driver')) switchports = port['port']['switchports'] for switchport in switchports: switch_id = switchport['switch_id'] bnp_switch = db.get_bnp_phys_switch_by_mac(self.context, switch_id) port_name = switchport['port_id'] if not bnp_switch: self._raise_ml2_error(wexc.HTTPNotFound, 'create_port') phys_port = db.get_bnp_phys_port(self.context, bnp_switch.id, port_name) if not phys_port: self._raise_ml2_error(wexc.HTTPNotFound, 'create_port') # port_maps = db.get_all_bnp_swport_mappings(self.context) # for port_map in port_maps: # if phys_port.id == port_map.switch_port_id: # self._raise_ml2_error(wexc.HTTPConflict, 'create_port') switchport['ifindex'] = phys_port.ifindex credentials_dict = port.get('port') cred_dict = self._get_credentials_dict(bnp_switch, 'create_port') credentials_dict['credentials'] = cred_dict try: self.protocol_driver.set_isolation(port) port_id = port['port']['id'] segmentation_id = port['port']['segmentation_id'] mapping_dict = {'neutron_port_id': port_id, 'switch_port_id': phys_port.id, 'switch_id': bnp_switch.id, 'lag_id': None, 'access_type': constants.ACCESS, 'segmentation_id': int(segmentation_id), 'bind_status': 0 } db.add_bnp_switch_port_map(self.context, mapping_dict) db.add_bnp_neutron_port(self.context, mapping_dict) return constants.BIND_SUCCESS except Exception as e: LOG.error(_LE("Exception in configuring VLAN '%s' "), e) return constants.BIND_FAILURE
def bind_port_to_segment(self, port): """bind_port_to_segment .""" LOG.info(_LI("bind_port_to_segment called from back-end mech driver")) switchports = port["port"]["switchports"] for switchport in switchports: switch_id = switchport["switch_id"] bnp_switch = db.get_bnp_phys_switch_by_mac(self.context, switch_id) port_name = switchport["port_id"] if not bnp_switch: self._raise_ml2_error(wexc.HTTPNotFound, "create_port") phys_port = db.get_bnp_phys_port(self.context, bnp_switch.id, port_name) if not phys_port: self._raise_ml2_error(wexc.HTTPNotFound, "create_port") switchport["ifindex"] = phys_port.ifindex credentials_dict = port.get("port") cred_dict = self._get_credentials_dict(bnp_switch, "create_port") credentials_dict["credentials"] = cred_dict try: self.protocol_driver.set_isolation(port) port_id = port["port"]["id"] segmentation_id = port["port"]["segmentation_id"] mapping_dict = { "neutron_port_id": port_id, "switch_port_id": phys_port.id, "switch_id": bnp_switch.id, "lag_id": None, "access_type": constants.ACCESS, "segmentation_id": int(segmentation_id), "bind_status": 0, } db.add_bnp_switch_port_map(self.context, mapping_dict) db.add_bnp_neutron_port(self.context, mapping_dict) return constants.BIND_SUCCESS except Exception as e: LOG.error(_LE("Exception in configuring VLAN '%s' "), e) return constants.BIND_FAILURE
def test_add_bnp_switch_port_map(self): """Test add_bnp_switch_port_map method.""" port_map = self._get_bnp_switch_port_map_dict() db.add_bnp_switch_port_map(self.ctx, port_map) count = self.ctx.session.query(models.BNPSwitchPortMapping).count() self.assertEqual(1, count)