def test_delete_hp_switch_port(self):
     """Test delete_hp_switch_port method."""
     rec_dict = self._get_switch_port_dict()
     db.add_hp_switch_port(self.ctx, rec_dict)
     db.delete_hp_switch_port(self.ctx, rec_dict)
     count = self.ctx.session.query(models.HPSwitchPort).count()
     self.assertEqual(count, 0)
Example #2
0
 def test_delete_hp_switch_port(self):
     """Test delete_hp_switch_port method."""
     rec_dict = self._get_switch_port_dict()
     db.add_hp_switch_port(self.ctx, rec_dict)
     db.delete_hp_switch_port(self.ctx, rec_dict)
     count = self.ctx.session.query(models.HPSwitchPort).count()
     self.assertEqual(count, 0)
    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 _delete_lag_ports(self, ir_ports):
     for ironic_port in ir_ports:
         hp_sw_port_id = ironic_port.switch_port_id
         hp_sw_port_dict = {'id': hp_sw_port_id}
         lag_id = ironic_port.lag_id
         db.delete_hp_switch_port(self.context, hp_sw_port_dict)
     if lag_id:
         lag_dict = {'id': lag_id}
         db.delete_hp_switch_lag_port(self.context, lag_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}
        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")