Merge "Normalise format of OVN agent heartbeat timestamp" into stable/zed

This commit is contained in:
Zuul 2023-02-28 16:49:07 +00:00 committed by Gerrit Code Review
commit 1bf8d3340e
4 changed files with 26 additions and 2 deletions

View File

@ -81,7 +81,8 @@ class NeutronAgent(abc.ABC):
return {
'binary': self.binary,
'host': self.chassis.hostname,
'heartbeat_timestamp': self.updated_at,
'heartbeat_timestamp': timeutils.normalize_time(
self.updated_at.replace(microsecond=0)),
'availability_zone': ', '.join(
ovn_utils.get_chassis_availability_zones(self.chassis)),
'topic': 'n/a',

View File

@ -1148,7 +1148,7 @@ class TestAgentApi(base.TestOVNFunctionalBase):
'Chassis_Private', self.chassis, 'nb_cfg_timestamp'
).execute(check_error=True)
updated_at = datetime.datetime.fromtimestamp(
int(chassis_ts / 1000), datetime.timezone.utc)
int(chassis_ts / 1000))
# if table Chassis_Private present, agent.updated_at is
# Chassis_Private.nb_cfg_timestamp
self.assertEqual(updated_at, heartbeat_timestamp)

View File

@ -12,6 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import datetime
from unittest import mock
import eventlet
@ -67,3 +68,19 @@ class AgentCacheTestCase(base.BaseTestCase):
agents = list(agents)
self.assertEqual(1, len(agents))
self.assertEqual('chassis5', agents[0].agent_id)
@mock.patch.object(neutron_agent.ControllerAgent, 'alive')
def test_heartbeat_timestamp_format(self, agent_alive):
chassis_private = fakes.FakeOvsdbRow.create_one_ovsdb_row(
attrs={'name': 'chassis5'})
agents = self.agent_cache.agents_by_chassis_private(chassis_private)
agent = list(agents)[0]
agent.chassis.hostname = 'fake-hostname'
agent.updated_at = datetime.datetime(
year=2023, month=2, day=23, hour=1, minute=2, second=3,
microsecond=456789).replace(tzinfo=datetime.timezone.utc)
agent_alive.return_value = True
# Verify that both microseconds and timezone are dropped
self.assertEqual(str(agent.as_dict()['heartbeat_timestamp']),
'2023-02-23 01:02:03')

View File

@ -0,0 +1,6 @@
---
fixes:
- |
Normalise OVN agent heartbeat timestamp format to match other agent types.
This fixes parsing of ``GET /v2.0/agents`` for some clients, such as
gophercloud.