Skip to content

Commit 820b25a

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "remove unused updated_at parameter for AgentCache.update" into stable/yoga
2 parents 089fdcc + ef3729e commit 820b25a

File tree

2 files changed

+51
-57
lines changed

2 files changed

+51
-57
lines changed

neutron/plugins/ml2/drivers/ovn/agent/neutron_agent.py

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -38,27 +38,26 @@ def __init_subclass__(cls):
3838
# Register the subclasses to be looked up by their type
3939
NeutronAgent.types[cls.agent_type] = cls
4040

41-
def __init__(self, chassis_private, driver, updated_at=None):
41+
def __init__(self, chassis_private, driver):
4242
self.driver = driver
4343
self.set_down = False
44-
self.update(chassis_private, updated_at)
44+
self.update(chassis_private)
4545

46-
def update(self, chassis_private, updated_at=None, clear_down=False):
46+
def update(self, chassis_private, clear_down=False):
4747
self.chassis_private = chassis_private
48-
if not updated_at:
49-
# When use the Chassis_Private table for agents health check,
50-
# chassis_private has attribute nb_cfg_timestamp.
51-
# nb_cfg_timestamp: the timestamp when ovn-controller finishes
52-
# processing the change corresponding to nb_cfg(
53-
# https://www.ovn.org/support/dist-docs/ovn-sb.5.html).
54-
# it can better reflect the status of chassis.
55-
# nb_cfg_timestamp is milliseconds, need to convert to datetime.
56-
if hasattr(chassis_private, 'nb_cfg_timestamp'):
57-
updated_at = datetime.datetime.fromtimestamp(
58-
chassis_private.nb_cfg_timestamp / 1000,
59-
datetime.timezone.utc)
60-
else:
61-
updated_at = timeutils.utcnow(with_timezone=True)
48+
# When use the Chassis_Private table for agents health check,
49+
# chassis_private has attribute nb_cfg_timestamp.
50+
# nb_cfg_timestamp: the timestamp when ovn-controller finishes
51+
# processing the change corresponding to nb_cfg(
52+
# https://www.ovn.org/support/dist-docs/ovn-sb.5.html).
53+
# it can better reflect the status of chassis.
54+
# nb_cfg_timestamp is milliseconds, need to convert to datetime.
55+
if hasattr(chassis_private, 'nb_cfg_timestamp'):
56+
updated_at = datetime.datetime.fromtimestamp(
57+
chassis_private.nb_cfg_timestamp / 1000,
58+
datetime.timezone.utc)
59+
else:
60+
updated_at = timeutils.utcnow(with_timezone=True)
6261
self.updated_at = updated_at
6362
if clear_down:
6463
self.set_down = False
@@ -112,8 +111,8 @@ def alive(self):
112111
return False
113112

114113
@classmethod
115-
def from_type(cls, _type, chassis_private, driver, updated_at=None):
116-
return cls.types[_type](chassis_private, driver, updated_at)
114+
def from_type(cls, _type, chassis_private, driver):
115+
return cls.types[_type](chassis_private, driver)
117116

118117
@property
119118
@abc.abstractmethod
@@ -141,7 +140,7 @@ class ControllerAgent(NeutronAgent):
141140
binary = 'ovn-controller'
142141

143142
@staticmethod # it is by default, but this makes pep8 happy
144-
def __new__(cls, chassis_private, driver, updated_at=None):
143+
def __new__(cls, chassis_private, driver):
145144
external_ids = cls.chassis_from_private(chassis_private).external_ids
146145
if ('enable-chassis-as-gw' in
147146
external_ids.get('ovn-cms-options', [])):
@@ -165,8 +164,8 @@ def description(self):
165164
return self.chassis_private.external_ids.get(
166165
ovn_const.OVN_AGENT_DESC_KEY, '')
167166

168-
def update(self, chassis_private, updated_at=None, clear_down=False):
169-
super().update(chassis_private, updated_at, clear_down)
167+
def update(self, chassis_private, clear_down=False):
168+
super().update(chassis_private, clear_down)
170169
external_ids = self.chassis_from_private(chassis_private).external_ids
171170
if 'enable-chassis-as-gw' in external_ids.get('ovn-cms-options', []):
172171
self.__class__ = ControllerGatewayAgent
@@ -175,8 +174,8 @@ def update(self, chassis_private, updated_at=None, clear_down=False):
175174
class ControllerGatewayAgent(ControllerAgent):
176175
agent_type = ovn_const.OVN_CONTROLLER_GW_AGENT
177176

178-
def update(self, chassis_private, updated_at=None, clear_down=False):
179-
super().update(chassis_private, updated_at, clear_down)
177+
def update(self, chassis_private, clear_down=False):
178+
super().update(chassis_private, clear_down)
180179
external_ids = self.chassis_from_private(chassis_private).external_ids
181180
if ('enable-chassis-as-gw' not in
182181
external_ids.get('ovn-cms-options', [])):
@@ -238,14 +237,13 @@ def __iter__(self):
238237
def __getitem__(self, key):
239238
return self.agents[key]
240239

241-
def update(self, agent_type, row, updated_at=None, clear_down=False):
240+
def update(self, agent_type, row, clear_down=False):
242241
cls = NeutronAgent.types[agent_type]
243242
try:
244243
agent = self.agents[cls.id_from_chassis_private(row)]
245-
agent.update(row, updated_at=updated_at, clear_down=clear_down)
244+
agent.update(row, clear_down=clear_down)
246245
except KeyError:
247-
agent = NeutronAgent.from_type(agent_type, row, self.driver,
248-
updated_at=updated_at)
246+
agent = NeutronAgent.from_type(agent_type, row, self.driver)
249247
self.agents[agent.agent_id] = agent
250248
return agent
251249

neutron/tests/unit/plugins/ml2/drivers/ovn/mech_driver/test_mech_driver.py

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -100,37 +100,25 @@ def _add_chassis(self, nb_cfg, name=None):
100100
chassis_private.name = name if name else str(uuid.uuid4())
101101
return chassis_private
102102

103-
def _add_chassis_agent(self, nb_cfg, agent_type, chassis_private=None,
104-
updated_at=None):
103+
def _add_chassis_agent(self, nb_cfg, agent_type, chassis_private=None):
105104
chassis_private = chassis_private or self._add_chassis(nb_cfg)
106105
if hasattr(chassis_private, 'nb_cfg_timestamp') and isinstance(
107106
chassis_private.nb_cfg_timestamp, mock.Mock):
108107
del chassis_private.nb_cfg_timestamp
109108
chassis_private.external_ids = {}
110-
if updated_at:
111-
chassis_private.external_ids = {
112-
ovn_const.OVN_LIVENESS_CHECK_EXT_ID_KEY:
113-
datetime.datetime.isoformat(updated_at)}
114109
if agent_type == ovn_const.OVN_METADATA_AGENT:
115110
chassis_private.external_ids.update({
116111
ovn_const.OVN_AGENT_METADATA_SB_CFG_KEY: nb_cfg,
117112
ovn_const.OVN_AGENT_METADATA_ID_KEY: str(uuid.uuid4())})
118113
chassis_private.chassis = [chassis_private]
119-
return neutron_agent.AgentCache().update(agent_type, chassis_private,
120-
updated_at)
114+
return neutron_agent.AgentCache().update(agent_type, chassis_private)
121115

122-
def _add_agent(self, name, alive=True):
116+
def _add_agent(self, name, nb_cfg_offset=0):
123117
nb_cfg = 5
124-
now = timeutils.utcnow(with_timezone=True)
125-
if not alive:
126-
updated_at = now - datetime.timedelta(cfg.CONF.agent_down_time + 1)
127-
self.mech_driver.nb_ovn.nb_global.nb_cfg = nb_cfg
128-
else:
129-
updated_at = now
130-
self.mech_driver.nb_ovn.nb_global.nb_cfg = nb_cfg + 2
118+
self.mech_driver.nb_ovn.nb_global.nb_cfg = nb_cfg + nb_cfg_offset
131119
chassis = self._add_chassis(nb_cfg, name=name)
132120
return self._add_chassis_agent(
133-
nb_cfg, ovn_const.OVN_CONTROLLER_AGENT, chassis, updated_at)
121+
nb_cfg, ovn_const.OVN_CONTROLLER_AGENT, chassis)
134122

135123

136124
class TestOVNMechanismDriverBase(MechDriverSetupBase,
@@ -1253,9 +1241,13 @@ def test_bind_port_physnet_not_found(self):
12531241
self._test_bind_port_failed(fake_segments)
12541242

12551243
def test_bind_port_host_not_alive(self):
1256-
agent = self._add_agent('agent_no_alive', False)
1257-
neutron_agent.AgentCache().get_agents.return_value = [agent]
1258-
self._test_bind_port_failed([])
1244+
agent = self._add_agent('agent_no_alive', 2)
1245+
now = timeutils.utcnow(with_timezone=True)
1246+
fake_now = now + datetime.timedelta(cfg.CONF.agent_down_time + 1)
1247+
with mock.patch.object(timeutils, 'utcnow') as get_now:
1248+
get_now.return_value = fake_now
1249+
neutron_agent.AgentCache().get_agents.return_value = [agent]
1250+
self._test_bind_port_failed([])
12591251

12601252
def _test_bind_port(self, fake_segments):
12611253
fake_port = fakes.FakePort.create_one_port().info()
@@ -2244,12 +2236,14 @@ def test_agent_alive_true_one_diff(self):
22442236
for agent_type in (ovn_const.OVN_CONTROLLER_AGENT,
22452237
ovn_const.OVN_METADATA_AGENT):
22462238
self.mech_driver.nb_ovn.nb_global.nb_cfg = nb_cfg + 1
2247-
now = timeutils.utcnow()
2248-
updated_at = now - datetime.timedelta(cfg.CONF.agent_down_time + 1)
22492239
agent = self._add_chassis_agent(nb_cfg, agent_type,
2250-
chassis_private, updated_at)
2251-
self.assertTrue(agent.alive, "Agent of type %s alive=%s" %
2252-
(agent.agent_type, agent.alive))
2240+
chassis_private)
2241+
now = timeutils.utcnow()
2242+
fake_now = now + datetime.timedelta(cfg.CONF.agent_down_time + 1)
2243+
with mock.patch.object(timeutils, 'utcnow') as get_now:
2244+
get_now.return_value = fake_now
2245+
self.assertTrue(agent.alive, "Agent of type %s alive=%s" %
2246+
(agent.agent_type, agent.alive))
22532247

22542248
def test_agent_alive_not_timed_out(self):
22552249
nb_cfg = 3
@@ -2269,11 +2263,13 @@ def test_agent_alive_timed_out(self):
22692263
ovn_const.OVN_METADATA_AGENT):
22702264
self.mech_driver.nb_ovn.nb_global.nb_cfg = nb_cfg + 2
22712265
now = timeutils.utcnow(with_timezone=True)
2272-
updated_at = now - datetime.timedelta(cfg.CONF.agent_down_time + 1)
22732266
agent = self._add_chassis_agent(nb_cfg, agent_type,
2274-
chassis_private, updated_at)
2275-
self.assertFalse(agent.alive, "Agent of type %s alive=%s" %
2276-
(agent.agent_type, agent.alive))
2267+
chassis_private)
2268+
fake_now = now + datetime.timedelta(cfg.CONF.agent_down_time + 1)
2269+
with mock.patch.object(timeutils, 'utcnow') as get_now:
2270+
get_now.return_value = fake_now
2271+
self.assertFalse(agent.alive, "Agent of type %s alive=%s" %
2272+
(agent.agent_type, agent.alive))
22772273

22782274
def test_agent_with_nb_cfg_timestamp_timeout(self):
22792275
nb_cfg = 3

0 commit comments

Comments
 (0)