def test_is_port_valid_to_reflect_on_oneview_not_baremetal( self, mock_oneview_client): port = copy.deepcopy(test_oneview_mech_driver.FAKE_PORT) port["binding:vnic_type"] = "not_baremetal" lli = port.get("binding:profile").get("local_link_information") self.assertFalse( common.is_port_valid_to_reflect_on_oneview( mock.MagicMock(), port, lli))
def test_is_port_valid_to_reflect_on_oneview( self, mock_get_network, mock_oneview_client): local_link_information = ( test_oneview_mech_driver.FAKE_PORT.get("binding:profile") .get("local_link_information")) self.assertTrue( common.is_port_valid_to_reflect_on_oneview( mock.MagicMock(), test_oneview_mech_driver.FAKE_PORT, local_link_information))
def test_is_port_valid_to_reflect_on_oneview_not_bootable( self, mock_get_network, mock_oneview_client): port = copy.deepcopy(test_oneview_mech_driver.FAKE_PORT) lli = port['binding:profile']['local_link_information'] lli[0]['switch_info']['bootable'] = False self.assertTrue( common.is_port_valid_to_reflect_on_oneview( mock.MagicMock(), port, lli))
def test_is_port_valid_to_reflect_on_oneview_not_in_database( self, mock_get_network, mock_oneview_client): mock_get_network.return_value = None local_link_information = ( test_oneview_mech_driver.FAKE_PORT.get("binding:profile") .get("local_link_information")) self.assertFalse( common.is_port_valid_to_reflect_on_oneview( mock.MagicMock(), test_oneview_mech_driver.FAKE_PORT, local_link_information))
def delete(self, session, port_dict): local_link_information_list = common.local_link_information_from_port( port_dict) neutron_port_id = port_dict.get('id') if not common.is_port_valid_to_reflect_on_oneview( session, port_dict, local_link_information_list): LOG.warning("Port %s is not valid to reflect on OneView.", neutron_port_id) return server_hardware = ( common.server_hardware_from_local_link_information_list( self.oneview_client, local_link_information_list)) if common.is_rack_server(server_hardware): LOG.warning("The server hardware: %s is a rack server.", server_hardware.get('uuid')) return server_profile = common.server_profile_from_server_hardware( self.oneview_client, server_hardware) if server_profile: LOG.info("There is Server Profile %s available.", server_profile) mac_address = port_dict.get('mac_address') connection = common.connection_with_mac_address( server_profile.get('connections'), mac_address) if connection: LOG.debug("There is Connection %s available.", connection) server_profile.get('connections').remove(connection) else: LOG.debug("There is no Connection available.") common.check_oneview_entities_availability(self.oneview_client, server_hardware) self._update_oneview_entities(server_hardware, server_profile) LOG.info("The requested port was deleted successfully.")
def create(self, session, port_dict): network_id = port_dict.get('network_id') neutron_port_id = port_dict.get('id') network_segment = database_manager.get_network_segment( session, network_id) physical_network = network_segment.get('physical_network') network_type = network_segment.get('network_type') if not self.is_uplinkset_mapping(physical_network, network_type): LOG.warning( "The port's network %s is not mapping in OneView " "configuration file", network_id) return local_link_information_list = common.local_link_information_from_port( port_dict) if not common.is_port_valid_to_reflect_on_oneview( session, port_dict, local_link_information_list): LOG.warning("Port %s is not valid to reflect on OneView.", neutron_port_id) return neutron_oneview_network = database_manager.get_neutron_oneview_network( session, network_id) network_uri = common.network_uri_from_id( neutron_oneview_network.oneview_network_id) server_hardware = ( common.server_hardware_from_local_link_information_list( self.oneview_client, local_link_information_list)) server_profile = common.server_profile_from_server_hardware( self.oneview_client, server_hardware) if server_profile: LOG.info("There is Server Profile %s available.", server_profile) mac_address = port_dict.get('mac_address') if common.is_rack_server(server_hardware): LOG.warning("The server hardware %s is a rack server.", server_hardware.get('uuid')) return port_id = common.port_id_from_mac(server_hardware, mac_address) connections = server_profile.get('connections') existing_connections = [ connection for connection in connections if connection.get('portId') == port_id ] switch_info = common.switch_info_from_local_link_information_list( local_link_information_list) bootable = switch_info.get('bootable') boot_priority = common.get_boot_priority(server_profile, bootable) if not boot_priority: LOG.warning("The server profile: %s already has PXE primary " "and secondary bootable connections." % server_profile.get('uuid')) return create_new_connection = True for connection in existing_connections: if connection.get('mac').upper() == mac_address.upper(): connection['networkUri'] = network_uri create_new_connection = False if create_new_connection: server_profile['connections'].append({ 'name': "NeutronPort[%s]" % mac_address, 'portId': port_id, 'networkUri': network_uri, 'boot': { 'priority': boot_priority }, 'functionType': 'Ethernet' }) common.check_oneview_entities_availability(self.oneview_client, server_hardware) self._update_oneview_entities(server_hardware, server_profile) LOG.info("The requested connection %s was updated/created.", port_id)
def test_is_port_valid_to_reflect_on_oneview_multiple_llis( self, mock_get_network, mock_oneview_client): lli = [{}, {}] self.assertFalse( common.is_port_valid_to_reflect_on_oneview( mock.MagicMock(), test_oneview_mech_driver.FAKE_PORT, lli))