Skip to content

Commit c341781

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Normalise format of OVN agent heartbeat timestamp" into stable/yoga
2 parents f8f9f1b + 1d611f4 commit c341781

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ def as_dict(self):
8181
return {
8282
'binary': self.binary,
8383
'host': self.chassis.hostname,
84-
'heartbeat_timestamp': self.updated_at,
84+
'heartbeat_timestamp': timeutils.normalize_time(
85+
self.updated_at.replace(microsecond=0)),
8586
'availability_zone': ', '.join(
8687
ovn_utils.get_chassis_availability_zones(self.chassis)),
8788
'topic': 'n/a',

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1148,7 +1148,7 @@ def test_agent_show_real_heartbeat_timestamp(self):
11481148
'Chassis_Private', self.chassis, 'nb_cfg_timestamp'
11491149
).execute(check_error=True)
11501150
updated_at = datetime.datetime.fromtimestamp(
1151-
int(chassis_ts / 1000), datetime.timezone.utc)
1151+
int(chassis_ts / 1000))
11521152
# if table Chassis_Private present, agent.updated_at is
11531153
# Chassis_Private.nb_cfg_timestamp
11541154
self.assertEqual(updated_at, heartbeat_timestamp)

neutron/tests/unit/plugins/ml2/drivers/ovn/agent/test_neutron_agent.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
1414

15+
import datetime
1516
from unittest import mock
1617

1718
import eventlet
@@ -67,3 +68,19 @@ def test_agents_by_chassis_private(self):
6768
agents = list(agents)
6869
self.assertEqual(1, len(agents))
6970
self.assertEqual('chassis5', agents[0].agent_id)
71+
72+
@mock.patch.object(neutron_agent.ControllerAgent, 'alive')
73+
def test_heartbeat_timestamp_format(self, agent_alive):
74+
chassis_private = fakes.FakeOvsdbRow.create_one_ovsdb_row(
75+
attrs={'name': 'chassis5'})
76+
agents = self.agent_cache.agents_by_chassis_private(chassis_private)
77+
agent = list(agents)[0]
78+
agent.chassis.hostname = 'fake-hostname'
79+
agent.updated_at = datetime.datetime(
80+
year=2023, month=2, day=23, hour=1, minute=2, second=3,
81+
microsecond=456789).replace(tzinfo=datetime.timezone.utc)
82+
agent_alive.return_value = True
83+
84+
# Verify that both microseconds and timezone are dropped
85+
self.assertEqual(str(agent.as_dict()['heartbeat_timestamp']),
86+
'2023-02-23 01:02:03')
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
fixes:
3+
- |
4+
Normalise OVN agent heartbeat timestamp format to match other agent types.
5+
This fixes parsing of ``GET /v2.0/agents`` for some clients, such as
6+
gophercloud.

0 commit comments

Comments
 (0)