def test_add_hp_ironic_switch_port_mapping(self): """Test hp_ironic_switch_port_mapping.""" rec_dict = self._get_ironic_switch_port_map_dict() db.add_hp_ironic_switch_port_mapping(self.ctx, rec_dict) count = self.ctx.session.query( models.HPIronicSwitchPortMapping).count() self.assertEqual(1, count)
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 test_delete_hp_ironic_switch_port_mapping(self): """Test delete_hp_ironic_switch_port_mapping.""" 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.delete_hp_ironic_switch_port_mapping(self.ctx, rec_dict) count = self.ctx.session.query( models.HPIronicSwitchPortMapping).count() self.assertEqual(count, 0)
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_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 create_port(self, port_dict): """create_port. This call makes the REST request to the external SDN controller for provision VLAN for the switch port where bare metal is connected. """ LOG.debug("create_port port_dict %(port_dict)s", {'port_dict': port_dict}) lag_id = None switch_port_id = uuidutils.generate_uuid() switchport = port_dict['port']['switchports'] switch_mac_id = switchport[0]['switch_id'] rec_dict = { 'id': switch_port_id, 'switch_id': switch_mac_id, 'port_name': switchport[0]['port_id'], 'lag_id': None } switch_url = self._frame_switch_url(switch_mac_id) try: resp = self._do_request('GET', switch_url, None) LOG.debug("response from SDN controller %(resp)s ", {'resp': resp}) resp.raise_for_status() except requests.exceptions.Timeout as e: LOG.error(" Request timed out in SDN controller : %s", e) raise hp_exec.HPNetProvisioningDriverError(msg="Timed Out" "with SDN" "controller: %s" % e) except requests.exceptions.SSLError as e: LOG.error(" SSLError to SDN controller : %s", e) raise hp_exec.SslCertificateValidationError(msg=e) except Exception as e: LOG.error(" ConnectionFailed to SDN controller : %s", e) raise hp_exec.ConnectionFailed(msg=e) mapping_dict = { 'neutron_port_id': port_dict['port']['id'], 'switch_port_id': switch_port_id, 'lag_id': lag_id, 'access_type': None, 'segmentation_id': None, 'bind_requested': False } session = self.context.session if resp.status_code == requests.codes.OK: with session.begin(subtransactions=True): db.add_hp_switch_port(self.context, rec_dict) db.add_hp_ironic_switch_port_mapping(self.context, mapping_dict) else: LOG.error(" Given physical switch does not exists") raise hp_exec.HPNetProvisioningDriverError(msg="Failed to" "communicate with" "SDN Controller:")
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 create_port(self, port_dict): """create_port. This call makes the REST request to the external SDN controller for provision VLAN for the switch port where bare metal is connected. """ LOG.debug("create_port port_dict %(port_dict)s", {'port_dict': port_dict}) lag_id = None switch_port_id = uuidutils.generate_uuid() switchport = port_dict['port']['switchports'] switch_mac_id = switchport[0]['switch_id'] rec_dict = {'id': switch_port_id, 'switch_id': switch_mac_id, 'port_name': switchport[0]['port_id'], 'lag_id': None} switch_url = self._frame_switch_url(switch_mac_id) try: resp = self._do_request('GET', switch_url, None) LOG.debug("response from SDN controller %(resp)s ", {'resp': resp}) resp.raise_for_status() except requests.exceptions.Timeout as e: LOG.error(" Request timed out in SDN controller : %s", e) raise hp_exec.HPNetProvisioningDriverError(msg="Timed Out" "with SDN" "controller: %s" % e) except requests.exceptions.SSLError as e: LOG.error(" SSLError to SDN controller : %s", e) raise hp_exec.SslCertificateValidationError(msg=e) except Exception as e: LOG.error(" ConnectionFailed to SDN controller : %s", e) raise hp_exec.ConnectionFailed(msg=e) mapping_dict = {'neutron_port_id': port_dict['port']['id'], 'switch_port_id': switch_port_id, 'lag_id': lag_id, 'access_type': None, 'segmentation_id': None, 'bind_requested': False} session = self.context.session if resp.status_code == requests.codes.OK: with session.begin(subtransactions=True): db.add_hp_switch_port(self.context, rec_dict) db.add_hp_ironic_switch_port_mapping(self.context, mapping_dict) else: LOG.error(" Given physical switch does not exists") raise hp_exec.HPNetProvisioningDriverError(msg="Failed to" "communicate with" "SDN Controller:")
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 create_switch_port(self, port_dict): switchports = port_dict['port']['switchports'] neutron_port_id = port_dict['port']['id'] host_id = port_dict['port']['host_id'] for switchport in switchports: switch_port_id = uuidutils.generate_uuid() switch_mac_id = switchport['switch_id'] port_id = switchport['port_id'] rec_dict = {'id': switch_port_id, 'switch_id': switch_mac_id, 'port_name': port_id, 'lag_id': None} sw_ports = db.get_all_hp_sw_port_by_swchid_portname(self.context, rec_dict) if sw_ports and host_id: for sw_port in sw_ports: self._is_port_already_bound(sw_port, neutron_port_id) switch_url = self._frame_switch_url(switch_mac_id) try: resp = self._do_request('GET', switch_url, None) LOG.info("response from SDN controller %(resp)s ", {'resp': resp}) if not resp: self._raise_ml2_error(wexc.HTTPNotFound, 'create_port') port_list = resp.json()['ports'] if port_id not in port_list: self._roll_back_created_ports(neutron_port_id) LOG.error("Given port is not found") self._raise_ml2_error(wexc.HTTPNotFound, 'create_port') resp.raise_for_status() mapping_dict = {'neutron_port_id': neutron_port_id, 'switch_port_id': switch_port_id, 'lag_id': None, 'access_type': None, 'segmentation_id': None, 'host_id': None} session = self.context.session if resp.status_code == requests.codes.OK: with session.begin(subtransactions=True): db.add_hp_switch_port(self.context, rec_dict) db.add_hp_ironic_switch_port_mapping(self.context, mapping_dict) else: LOG.error(" Given physical switch does not exists") self._raise_ml2_error(wexc.HTTPNotFound, 'create_port') except requests.exceptions.Timeout as e: LOG.error(" Request timed out in SDN controller : %s", e) self._roll_back_created_ports(neutron_port_id) self._raise_ml2_error(wexc.HTTPRequestTimeout, 'create_port') except requests.exceptions.SSLError as e: LOG.error(" SSLError to SDN controller : %s", e) self._roll_back_created_ports(neutron_port_id) self._raise_ml2_error(wexc.HTTPBadRequest, 'create_port') except requests.exceptions.HTTPError as e: LOG.error(" HTTPError : %s", e) self._roll_back_created_ports(neutron_port_id) self._raise_ml2_error(wexc.HTTPNotFound, 'create_port') except requests.exceptions.URLRequired as e: LOG.error(" Invalid URL : %s", e) self._roll_back_created_ports(neutron_port_id) self._raise_ml2_error(wexc.HTTPNotFound, 'create_port') except Exception as e: LOG.error(" Bad request : %s", e) self._roll_back_created_ports(neutron_port_id) self._raise_ml2_error(wexc.HTTPBadRequest, 'create_port')