Merge "Update neutron agent listing"

This commit is contained in:
Zuul 2019-07-25 12:36:10 +00:00 committed by Gerrit Code Review
commit 8f54245d04
3 changed files with 23 additions and 14 deletions

View File

@ -30,6 +30,7 @@ check_valid_type = _exception.check_valid_type
exc_info = _exception.exc_info
find_by_attributes = _find.find_by_attributes
find_by_items = _find.find_by_items
is_fixture = _fixture.is_fixture
get_fixture = _fixture.get_fixture

View File

@ -14,14 +14,31 @@
from __future__ import absolute_import
def find_by_attributes(objects, **attributes):
def find_by_attributes(objects, exclude=False, **attributes):
exclude = bool(exclude)
if attributes:
selection = []
for obj in objects:
for key, value in attributes.items():
if value != getattr(obj, key):
matching = value == getattr(obj, key)
if matching is exclude:
break
else:
selection.append(obj)
objects = selection
return objects
def find_by_items(mappings, exclude=False, **items):
exclude = bool(exclude)
if items:
selection = []
for mapping in mappings:
for key, value in items.items():
matching = value == mapping[key]
if matching is exclude:
break
else:
selection.append(mapping)
mappings = selection
return mappings

View File

@ -18,7 +18,7 @@ import tobiko
from tobiko.openstack.neutron import _client
class NetworkingAgentaFixture(tobiko.SharedFixture):
class NetworkingAgentFixture(tobiko.SharedFixture):
client = None
agents = None
@ -35,17 +35,8 @@ class NetworkingAgentaFixture(tobiko.SharedFixture):
def get_networking_agents(**params):
agents = tobiko.setup_fixture(NetworkingAgentaFixture).agents
if params:
selected_agents = []
for agent in agents:
for key, value in params.items():
if value != agent[key]:
break
else:
selected_agents.append(agent)
agents = selected_agents
return agents
agents = tobiko.setup_fixture(NetworkingAgentFixture).agents
return tobiko.find_by_items(agents, **params)
def missing_networking_agents(count=1, **params):