Skip to content

Commit 4303039

Browse files
zhouhenglcralonsoh
authored andcommitted
[ovn]neutron agent show real heartbeat_timestamp
agent's heartbeat_timestamp returns the current time, not conducive to agent status troubleshooting. this patch use agent's updated_at as heartbeat_timestamp. Closes-bug: #1977629 Change-Id: Idf522a20f9735829ee568020bfed46345a95e294 (cherry picked from commit 411ecc4)
1 parent 4c93b29 commit 4303039

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def as_dict(self):
8282
return {
8383
'binary': self.binary,
8484
'host': self.chassis.hostname,
85-
'heartbeat_timestamp': timeutils.utcnow(),
85+
'heartbeat_timestamp': self.updated_at,
8686
'availability_zone': ', '.join(
8787
ovn_utils.get_chassis_availability_zones(self.chassis)),
8888
'topic': 'n/a',

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
# under the License.
1414

1515
import copy
16+
import datetime
1617
import functools
1718
import re
19+
import time
1820
from unittest import mock
1921

2022
import netaddr
@@ -1054,6 +1056,25 @@ def test_agent_show(self):
10541056
for agent_id in self.agent_types.values():
10551057
self.assertTrue(self.plugin.get_agent(self.context, agent_id))
10561058

1059+
def test_agent_show_real_heartbeat_timestamp(self):
1060+
agent_id = self.agent_types[ovn_const.OVN_CONTROLLER_AGENT]
1061+
agent = self.plugin.get_agent(self.context, agent_id)
1062+
heartbeat_timestamp = agent['heartbeat_timestamp']
1063+
if self.sb_api.is_table_present('Chassis_Private'):
1064+
chassis_ts = self.sb_api.db_get(
1065+
'Chassis_Private', self.chassis, 'nb_cfg_timestamp'
1066+
).execute(check_error=True)
1067+
updated_at = datetime.datetime.fromtimestamp(
1068+
int(chassis_ts / 1000), datetime.timezone.utc)
1069+
# if table Chassis_Private present, agent.updated_at is
1070+
# Chassis_Private.nb_cfg_timestamp
1071+
self.assertEqual(updated_at, heartbeat_timestamp)
1072+
time.sleep(1)
1073+
# if chassis is not updated, agent's heartbeat_timestamp shouldn't
1074+
# be updated.
1075+
n_agent = self.plugin.get_agent(self.context, agent['id'])
1076+
self.assertEqual(heartbeat_timestamp, n_agent['heartbeat_timestamp'])
1077+
10571078
def test_agent_list(self):
10581079
agent_ids = [a['id'] for a in self.plugin.get_agents(
10591080
self.context, filters={'host': self.host})]

0 commit comments

Comments
 (0)