Merge "Don't index DHCP ports"

This commit is contained in:
Jenkins 2016-03-24 15:19:16 +00:00 committed by Gerrit Code Review
commit ce4d859f07
5 changed files with 55 additions and 2 deletions

View File

@ -116,6 +116,10 @@ Release Notes
0.2.0.0 (Mitaka)
-----------------
DHCP ports are *not* indexed. Neutron doesn't provide a reliable way for
Searchlight to index these ports since they are created and modified
asynchronously from the subnets that they're attached to.
All provider:* properties of networks are exposed to administrators only.
All binding:* properties of ports are also visible only to administrators.
The 'distributed' and 'ha' router properties are available only to

View File

@ -28,6 +28,7 @@ from searchlight import i18n
LOG = logging.getLogger(__name__)
_LW = i18n._LW
_LE = i18n._LE
_LI = i18n._LI
class NetworkHandler(base.NotificationBase):
@ -83,6 +84,17 @@ class PortHandler(base.NotificationBase):
def create_or_update(self, payload, timestamp):
port_id = payload['port']['id']
if payload['port'].get('device_owner', None) == 'network:dhcp':
# TODO(sjmc7): Remove this once we can get proper notifications
# about DHCP ports.
# See https://bugs.launchpad.net/searchlight/+bug/1558790
LOG.info(_LI("Skipping notification for DHCP port %s. If neutron "
"is sending notifications for DHCP ports, the "
"Searchlight plugin should be updated to process "
"them.") % port_id)
return
LOG.debug("Updating port information for %s", port_id)
# Version doesn't really make a huge amount of sense here but

View File

@ -135,6 +135,12 @@ class PortIndex(base.IndexBase):
def get_objects(self):
neutron_client = openstack_clients.get_neutronclient()
for port in neutron_client.list_ports()['ports']:
# TODO(sjmc7): Remove this once we can get proper notifications
# about DHCP ports.
# See https://bugs.launchpad.net/searchlight/+bug/1558790
if port['device_owner'] == 'network:dhcp':
continue
yield port
def serialize(self, port):

View File

@ -13,7 +13,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import copy
import mock
import uuid
from searchlight.listener import NotificationEndpoint
from searchlight.tests import functional
@ -525,3 +527,20 @@ class TestNeutronListeners(test_listener.TestSearchListenerBase):
response, json_content = self._search_request(query,
EV_TENANT)
self.assertEqual(0, json_content['hits']['total'])
def test_ignore_neutron_dhcp_port(self):
create_event = self.port_events['port.create.end']
self._send_event_to_listener(create_event, self.listener_alias)
dhcp_event = copy.deepcopy(create_event)
dhcp_event['payload']['port']['id'] = str(uuid.uuid4())
dhcp_event['payload']['port']['device_owner'] = 'network:dhcp'
self._send_event_to_listener(dhcp_event, self.listener_alias)
query = {"type": "OS::Neutron::Port", "query": {"match_all": {}}}
response, json_content = self._search_request(query,
EV_TENANT)
self.assertEqual(200, response.status)
self.assertEqual(1, json_content['hits']['total'])
self.assertEqual(create_event['payload']['port']['id'],
json_content['hits']['hits'][0]['_source']['id'])

View File

@ -14,7 +14,9 @@
# limitations under the License.
import datetime
import mock
from oslo_utils import timeutils
import uuid
from searchlight.elasticsearch.plugins.neutron import\
ports as port_plugin
@ -26,6 +28,7 @@ USER1 = u'27f4d76b-be62-4e4e-aa33bb11cc55'
ID1 = u'813dd936-663e-4e5b-877c-986021b73e2c'
TENANT1 = u'8eaac046b2c44ab99246cb0850c7f06d'
NETWORK1 = u'bc0adf22-3aef-4e7b-8b99-12670b5a76b5'
UUID_PORT_ID = str(uuid.uuid4())
_now_str = timeutils.isotime(datetime.datetime.utcnow())
@ -39,8 +42,8 @@ def _create_port_fixture(port_id, tenant_id, network_id, **kwargs):
u'port_filter': True},
u'binding:vif_type': u'ovs',
u'binding:vnic_type': u'normal',
u'device_id': u'881d8582-abe1-4c8f-8c5a-2925fc421e8b',
u'device_owner': u'network:router_interface',
u'device_id': None,
u'device_owner': None,
u'dns_assignment': [{
u'fqdn': u'host-fd70-b64a-666f--1.openstacklocal.',
u'hostname': u'host-fd70-b64a-666f--1',
@ -75,6 +78,9 @@ class TestPortLoaderPlugin(test_utils.BaseTestCase):
def _create_fixtures(self):
self.port1 = _create_port_fixture(ID1, TENANT1, NETWORK1)
self.dhcp_port = _create_port_fixture(UUID_PORT_ID, TENANT1, NETWORK1,
device_owner='network:dhcp')
self.ports = [self.port1, self.dhcp_port]
def test_default_index_name(self):
self.assertEqual('searchlight', self.plugin.resource_group_name)
@ -125,3 +131,9 @@ class TestPortLoaderPlugin(test_utils.BaseTestCase):
def test_admin_only_fields(self):
admin_only_fields = self.plugin.admin_only_fields
self.assertEqual(['binding:*'], admin_only_fields)
def test_no_dhcp_ports(self):
with mock.patch('neutronclient.v2_0.client.Client.list_ports',
return_value={'ports': self.ports}):
listed_objects = list(self.plugin.get_objects())
self.assertEqual([self.port1], listed_objects)