diff options
author | Zuul <zuul@review.opendev.org> | 2022-10-06 12:00:51 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2022-10-06 12:00:51 +0000 |
commit | 2e3c89a509b3b1a9e15bfecfa71b91b16adbb6af (patch) | |
tree | b52f1c942732dfa47f26898cf189a31c3d22bd21 | |
parent | c458c2086d070469664b2f7ef9fcf5cbbf94381c (diff) | |
parent | 847ddbb358cdc491526ac8f9f94e04ba8a347bbe (diff) | |
download | neutron-2e3c89a509b3b1a9e15bfecfa71b91b16adbb6af.tar.gz |
Merge "Simplify OVN Agent API implementation" into stable/ussuri
-rw-r--r-- | neutron/plugins/ml2/drivers/ovn/agent/neutron_agent.py | 44 | ||||
-rw-r--r-- | neutron/plugins/ml2/drivers/ovn/mech_driver/mech_driver.py | 6 |
2 files changed, 33 insertions, 17 deletions
diff --git a/neutron/plugins/ml2/drivers/ovn/agent/neutron_agent.py b/neutron/plugins/ml2/drivers/ovn/agent/neutron_agent.py index d2e33f6c42..1fab00ca52 100644 --- a/neutron/plugins/ml2/drivers/ovn/agent/neutron_agent.py +++ b/neutron/plugins/ml2/drivers/ovn/agent/neutron_agent.py @@ -25,16 +25,19 @@ class NeutronAgent(abc.ABC): def __init_subclass__(cls): # Register the subclasses to be looked up by their type - for _type in cls.types: - NeutronAgent.types[_type] = cls + NeutronAgent.types[cls.agent_type] = cls def __init__(self, chassis_private): self.chassis_private = chassis_private + self.chassis = self.get_chassis(chassis_private) + + @staticmethod + def get_chassis(chassis_private): try: - self.chassis = self.chassis_private.chassis[0] + return chassis_private.chassis[0] except (AttributeError, IndexError): # No Chassis_Private support, just use Chassis - self.chassis = self.chassis_private + return chassis_private @property def updated_at(self): @@ -67,8 +70,15 @@ class NeutronAgent(abc.ABC): return cls.types[_type](chassis_private) @staticmethod - def agent_types(): - return NeutronAgent.__subclasses__() + def matches_chassis(chassis): + """Is this Agent type found on the passed in chassis?""" + return True + + @classmethod + def agents_from_chassis(cls, chassis_private): + return [AgentCls(chassis_private) + for AgentCls in cls.types.values() + if AgentCls.matches_chassis(cls.get_chassis(chassis_private))] @property @abc.abstractmethod @@ -77,16 +87,14 @@ class NeutronAgent(abc.ABC): class ControllerAgent(NeutronAgent): - types = [ovn_const.OVN_CONTROLLER_AGENT, ovn_const.OVN_CONTROLLER_GW_AGENT] + agent_type = ovn_const.OVN_CONTROLLER_AGENT binary = 'ovn-controller' key = ovn_const.OVN_LIVENESS_CHECK_EXT_ID_KEY - @property - def agent_type(self): - if ('enable-chassis-as-gw' in - self.chassis.external_ids.get('ovn-cms-options', [])): - return ovn_const.OVN_CONTROLLER_GW_AGENT - return ovn_const.OVN_CONTROLLER_AGENT + @staticmethod + def matches_chassis(chassis): + return ('enable-chassis-as-gw' not in + chassis.external_ids.get('ovn-cms-options', [])) @property def nb_cfg(self): @@ -102,9 +110,17 @@ class ControllerAgent(NeutronAgent): ovn_const.OVN_AGENT_DESC_KEY, '') +class ControllerGatewayAgent(ControllerAgent): + agent_type = ovn_const.OVN_CONTROLLER_GW_AGENT + + @staticmethod + def matches_chassis(chassis): + return ('enable-chassis-as-gw' in + chassis.external_ids.get('ovn-cms-options', [])) + + class MetadataAgent(NeutronAgent): agent_type = ovn_const.OVN_METADATA_AGENT - types = [agent_type] binary = 'networking-ovn-metadata-agent' key = ovn_const.METADATA_LIVENESS_CHECK_EXT_ID_KEY diff --git a/neutron/plugins/ml2/drivers/ovn/mech_driver/mech_driver.py b/neutron/plugins/ml2/drivers/ovn/mech_driver/mech_driver.py index c79c7ded4b..061f714d05 100644 --- a/neutron/plugins/ml2/drivers/ovn/mech_driver/mech_driver.py +++ b/neutron/plugins/ml2/drivers/ovn/mech_driver/mech_driver.py @@ -1213,9 +1213,9 @@ class OVNMechanismDriver(api.MechanismDriver): def agents_from_chassis(self, chassis_private, update_db=True): agent_dict = {} - # Iterate over each unique Agent subclass - for agent in [a(chassis_private) - for a in n_agent.NeutronAgent.agent_types()]: + # For each Chassis there will possibly be a Metadata agent and either + # a Controller or Controller Gateway agent. + for agent in n_agent.NeutronAgent.agents_from_chassis(chassis_private): if not agent.agent_id: continue alive = self.agent_alive(agent, update_db) |