def _update_hp_sw_lag_id(self, context, lag_dict): """Update hp switch lag_id .""" switch_ports = db.get_hp_ironic_swport_map_by_id(context, lag_dict) for switch_port in switch_ports: sw_port_id = switch_port.switch_port_id rec_dict = {'id': sw_port_id, 'lag_id': lag_dict['id']} db.update_hp_switch_ports_with_lag_id(context, rec_dict)
def delete_port(self, port_id): """delete_port. This call makes the REST request to the external SDN controller for un provision VLAN for the switch port where bare metal is connected. """ LOG.debug("delete_port with port_id %(port_id)s", {'port_id': port_id}) rec_dict = {'neutron_port_id': port_id} ironic_port_map = db.get_hp_ironic_swport_map_by_id(self.context, rec_dict) hp_switch_port_id = ironic_port_map.switch_port_id hp_sw_port_dict = {'id': hp_switch_port_id} switch_port_map = db.get_hp_switch_port_by_id(self.context, hp_sw_port_dict) switch_id = switch_port_map.switch_id port_name = switch_port_map.port_name inner_switchports_dict = {'port_id': port_name, 'switch_id': switch_id} switchports_list = [] switchports_list.append(inner_switchports_dict) switchports_dict = {'switchports': switchports_list} switchports_dict['segmentation_id'] = ironic_port_map.segmentation_id switchports_dict['access_type'] = hp_const.ACCESS LOG.debug(" switchports_dict %(switchports_dict)s ", {'switchports_dict': switchports_dict}) delete_port_dict = {'port': switchports_dict} resp = self._do_vlan_provisioning(delete_port_dict, False) if resp and resp.status_code == 204: db.delete_hp_switch_port(self.context, hp_sw_port_dict) else: LOG.error("Could not delete the switch port due to invalid" "response")
def delete_port(self, port_id): """delete_port. This call makes the REST request to the external SDN controller for un provision VLAN for the switch port where bare metal is connected. """ LOG.debug("delete_port with port_id %(port_id)s", {'port_id': port_id}) rec_dict = {'neutron_port_id': port_id} ironic_port_map = db.get_hp_ironic_swport_map_by_id( self.context, rec_dict) hp_switch_port_id = ironic_port_map.switch_port_id hp_sw_port_dict = {'id': hp_switch_port_id} switch_port_map = db.get_hp_switch_port_by_id(self.context, hp_sw_port_dict) switch_id = switch_port_map.switch_id port_name = switch_port_map.port_name inner_switchports_dict = {'port_id': port_name, 'switch_id': switch_id} switchports_list = [] switchports_list.append(inner_switchports_dict) switchports_dict = {'switchports': switchports_list} switchports_dict['segmentation_id'] = ironic_port_map.segmentation_id switchports_dict['access_type'] = hp_const.ACCESS LOG.debug(" switchports_dict %(switchports_dict)s ", {'switchports_dict': switchports_dict}) delete_port_dict = {'port': switchports_dict} resp = self._do_vlan_provisioning(delete_port_dict, False) if resp and resp.status_code == 204: db.delete_hp_switch_port(self.context, hp_sw_port_dict) else: LOG.error("Could not delete the switch port due to invalid" "response")
def test_get_hp_ironic_swport_map_by_id(self): """Test get_hp_ironic_swport_map_by_id method.""" self._add_switch_and_lag_port() rec_dict = self._get_ironic_switch_port_map_dict() db.add_hp_ironic_switch_port_mapping(self.ctx, rec_dict) result = db.get_hp_ironic_swport_map_by_id( self.ctx, {'neutron_port_id': "n1234"}) self.assertEqual("n1234", result[0].neutron_port_id)
def delete_port(self, port_id): """delete_port. This call makes the REST request to the external SDN controller for un provision VLAN for the switch port where bare metal is connected. """ LOG.debug("delete_port with port_id %(port_id)s", {'port_id': port_id}) rec_dict = {'neutron_port_id': port_id} ir_ports = db.get_hp_ironic_swport_map_by_id(self.context, rec_dict) if len(ir_ports) > 1: is_lag = True else: is_lag = False if not ir_ports: return host_id = ir_ports[0].host_id seg_id = ir_ports[0].segmentation_id if is_lag: if not host_id and not seg_id: self._delete_lag_ports(ir_ports) return ext_lag_id = self._get_ext_lag_id_by_port_id(port_id) resp = self._do_lag_request(None, False, ext_lag_id) if resp and resp.status_code == 204: self._delete_lag_ports(ir_ports) else: LOG.error("Could not delete the switch port due to invalid" "response") else: hp_switch_port_id = ir_ports[0].switch_port_id hp_sw_port_dict = {'id': hp_switch_port_id} switch_port_map = db.get_hp_switch_port_by_id(self.context, hp_sw_port_dict) switch_id = switch_port_map.switch_id port_name = switch_port_map.port_name inner_switchports_dict = {'port_id': port_name, 'switch_id': switch_id} switchports_list = [] switchports_list.append(inner_switchports_dict) switchports_dict = {'switchports': switchports_list} switchports_dict['segmentation_id'] = ir_ports[0].segmentation_id switchports_dict['access_type'] = hp_const.ACCESS LOG.debug(" switchports_dict %(switchports_dict)s ", {'switchports_dict': switchports_dict}) delete_port_dict = {'port': switchports_dict} if not host_id and not seg_id: db.delete_hp_switch_port(self.context, hp_sw_port_dict) return resp = self._do_vlan_provisioning(delete_port_dict, False) if resp and resp.status_code == 204: db.delete_hp_switch_port(self.context, hp_sw_port_dict) else: LOG.error("Could not delete the switch port due to invalid" "response")
def _roll_back_created_ports(self, neutron_port_id): rec_dict = {"neutron_port_id": neutron_port_id} hp_sw_ports = db.get_hp_ironic_swport_map_by_id(self.context, rec_dict) if not hp_sw_ports: return for hp_sw_port in hp_sw_ports: hp_sw_port_id = hp_sw_port.switch_port_id hp_sw_port_dict = {'id': hp_sw_port_id} db.delete_hp_switch_port(self.context, hp_sw_port_dict) LOG.debug("Roll back for the created ports succeeded")
def test_update_hp_ironic_swport_map_with_bind_req(self): """Test update_hp_ironic_swport_map_with_bind_req method.""" rec_dict = self._get_ironic_switch_port_map_dict() db.add_hp_ironic_switch_port_mapping(self.ctx, rec_dict) db.update_hp_ironic_swport_map_with_bind_req( self.ctx, {'neutron_port_id': "n1234", 'bind_requested': False}) result = db.get_hp_ironic_swport_map_by_id( self.ctx, {'neutron_port_id': "n1234"}) self.assertEqual(False, result.bind_requested)
def update_port(self, port_dict): """update_port. This call makes the REST request to the external SDN controller for provision VLAN on switch port where bare metal is connected. """ LOG.debug("update_port with port dict %(port_dict)s", {'port_dict': port_dict}) port_id = port_dict['port']['id'] host_id = port_dict['port']['host_id'] rec_dict = {'neutron_port_id': port_id} ironic_port_list = db.get_hp_ironic_swport_map_by_id(self.context, rec_dict) switchports = port_dict['port']['switchports'] if not ironic_port_list: # We are creating the switch ports because initial ironic # port-create will not supply local link information for tenant . # networks . Later ironic port-update , the local link information # value will be supplied. self.create_switch_port(port_dict) return if not len(switchports) == len(ironic_port_list): err_msg = "given switchports dict does not match" self._raise_hp_net_provisioning_error(wexc.HTTPConflict, 'update_port', err_msg) for ironic_port in ironic_port_list: hp_switch_port_id = ironic_port.switch_port_id hp_sw_port_dict = {'id': hp_switch_port_id} switch_port_map = db.get_hp_switch_port_by_id(self.context, hp_sw_port_dict) switch_id_db = switch_port_map.switch_id port_name_db = switch_port_map.port_name if not any(d['port_id'] == port_name_db for d in switchports): err_msg = "given port does not exists" self._raise_hp_net_provisioning_error(wexc.HTTPNotFound, 'update_port', err_msg) if not any(d['switch_id'] == switch_id_db for d in switchports): err_msg = "given switch does not exists" self._raise_hp_net_provisioning_error(wexc.HTTPNotFound, 'update_port', err_msg) rec_dict = {'switch_id': switch_id_db, 'port_name': port_name_db} switch_ports = db.get_all_hp_sw_port_by_swchid_portname( self.context, rec_dict) if len(switch_ports) > 1 and host_id: for switch_port in switch_ports: self._is_port_already_bound(switch_port, port_id) update_dict = {'neutron_port_id': port_id, 'host_id': host_id} db.update_hp_ironic_swport_map_with_host_id(self.context, update_dict)
def test_update_hp_ironic_swport_map_with_bind_req(self): """Test update_hp_ironic_swport_map_with_bind_req method.""" rec_dict = self._get_ironic_switch_port_map_dict() db.add_hp_ironic_switch_port_mapping(self.ctx, rec_dict) db.update_hp_ironic_swport_map_with_bind_req(self.ctx, { 'neutron_port_id': "n1234", 'bind_requested': False }) result = db.get_hp_ironic_swport_map_by_id( self.ctx, {'neutron_port_id': "n1234"}) self.assertEqual(False, result.bind_requested)
def test_update_hp_ironic_swport_map_with_seg_id(self): """Test update_hp_ironic_swport_map_with_seg_id method.""" rec_dict = self._get_ironic_switch_port_map_dict() db.add_hp_ironic_switch_port_mapping(self.ctx, rec_dict) db.update_hp_ironic_swport_map_with_seg_id( self.ctx, {'neutron_port_id': "n1234", 'access_type': "access", 'segmentation_id': 200, 'bind_requested': True}) result = db.get_hp_ironic_swport_map_by_id( self.ctx, {'neutron_port_id': "n1234"}) self.assertEqual(200, result.segmentation_id)
def test_get_hp_ironic_swport_map_by_id(self): """Test get_hp_ironic_swport_map_by_id method.""" with self.ctx.session.begin(subtransactions=True): entry = models.HPIronicSwitchPortMapping(neutron_port_id="n1234", switch_port_id=None, lag_id=None, access_type="access", segmentation_id=100, bind_requested=True) self.ctx.session.add(entry) result = db.get_hp_ironic_swport_map_by_id( self.ctx, {'neutron_port_id': "n1234"}) self.assertEqual(entry, result)
def test_update_hp_ironic_swport_map_with_lag_id(self): """Test update_hp_ironic_swport_map_with_lag_id method.""" self._add_switch_and_lag_port() rec_dict = self._get_ironic_switch_port_map_dict() lag_dict = {'id': "lag1234", 'external_lag_id': "1234", 'neutron_port_id': "n1234"} db.add_hp_ironic_switch_port_mapping(self.ctx, rec_dict) db.update_hp_ironic_swport_map_with_lag_id( self.ctx, lag_dict) result = db.get_hp_ironic_swport_map_by_id( self.ctx, {'neutron_port_id': "n1234"}) self.assertEqual("lag1234", result[0].lag_id)
def test_update_hp_ironic_swport_map_with_seg_id(self): """Test update_hp_ironic_swport_map_with_seg_id method.""" self._add_switch_and_lag_port() rec_dict = self._get_ironic_switch_port_map_dict() db.add_hp_ironic_switch_port_mapping(self.ctx, rec_dict) db.update_hp_ironic_swport_map_with_seg_id( self.ctx, {'neutron_port_id': "n1234", 'access_type': "access", 'segmentation_id': 200, 'host_id': 'ironic'}) result = db.get_hp_ironic_swport_map_by_id( self.ctx, {'neutron_port_id': "n1234"}) self.assertEqual(200, result[0].segmentation_id)
def test_get_hp_ironic_swport_map_by_id(self): """Test get_hp_ironic_swport_map_by_id method.""" with self.ctx.session.begin(subtransactions=True): entry = models.HPIronicSwitchPortMapping( neutron_port_id="n1234", switch_port_id=None, lag_id=None, access_type="access", segmentation_id=100, bind_requested=True) self.ctx.session.add(entry) result = db.get_hp_ironic_swport_map_by_id( self.ctx, {'neutron_port_id': "n1234"}) self.assertEqual(entry, result)
def test_update_hp_ironic_swport_map_with_seg_id(self): """Test update_hp_ironic_swport_map_with_seg_id method.""" rec_dict = self._get_ironic_switch_port_map_dict() db.add_hp_ironic_switch_port_mapping(self.ctx, rec_dict) db.update_hp_ironic_swport_map_with_seg_id( self.ctx, { 'neutron_port_id': "n1234", 'access_type': "access", 'segmentation_id': 200, 'bind_requested': True }) result = db.get_hp_ironic_swport_map_by_id( self.ctx, {'neutron_port_id': "n1234"}) self.assertEqual(200, result.segmentation_id)