[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
This commit is contained in:
@@ -82,7 +82,7 @@ class NeutronAgent(abc.ABC):
|
||||
return {
|
||||
'binary': self.binary,
|
||||
'host': self.chassis.hostname,
|
||||
'heartbeat_timestamp': timeutils.utcnow(),
|
||||
'heartbeat_timestamp': self.updated_at,
|
||||
'availability_zone': ', '.join(
|
||||
ovn_utils.get_chassis_availability_zones(self.chassis)),
|
||||
'topic': 'n/a',
|
||||
|
@@ -13,8 +13,10 @@
|
||||
# under the License.
|
||||
|
||||
import copy
|
||||
import datetime
|
||||
import functools
|
||||
import re
|
||||
import time
|
||||
from unittest import mock
|
||||
|
||||
import netaddr
|
||||
@@ -1055,6 +1057,25 @@ class TestAgentApi(base.TestOVNFunctionalBase):
|
||||
for agent_id in self.agent_types.values():
|
||||
self.assertTrue(self.plugin.get_agent(self.context, agent_id))
|
||||
|
||||
def test_agent_show_real_heartbeat_timestamp(self):
|
||||
agent_id = self.agent_types[ovn_const.OVN_CONTROLLER_AGENT]
|
||||
agent = self.plugin.get_agent(self.context, agent_id)
|
||||
heartbeat_timestamp = agent['heartbeat_timestamp']
|
||||
if self.sb_api.is_table_present('Chassis_Private'):
|
||||
chassis_ts = self.sb_api.db_get(
|
||||
'Chassis_Private', self.chassis, 'nb_cfg_timestamp'
|
||||
).execute(check_error=True)
|
||||
updated_at = datetime.datetime.fromtimestamp(
|
||||
int(chassis_ts / 1000), datetime.timezone.utc)
|
||||
# if table Chassis_Private present, agent.updated_at is
|
||||
# Chassis_Private.nb_cfg_timestamp
|
||||
self.assertEqual(updated_at, heartbeat_timestamp)
|
||||
time.sleep(1)
|
||||
# if chassis is not updated, agent's heartbeat_timestamp shouldn't
|
||||
# be updated.
|
||||
n_agent = self.plugin.get_agent(self.context, agent['id'])
|
||||
self.assertEqual(heartbeat_timestamp, n_agent['heartbeat_timestamp'])
|
||||
|
||||
def test_agent_list(self):
|
||||
agent_ids = [a['id'] for a in self.plugin.get_agents(
|
||||
self.context, filters={'host': self.host})]
|
||||
|
Reference in New Issue
Block a user