Skip to content

Commit 7261730

Browse files
author
Nguyen Ngoc Hieu
committed
Fix health monitor information retrieval in API response
Closes bug: #2038367 Behavior: In the response body of the LB API when creating a new load balancer, the information about the health monitor is always null, even though it has been configured. Reproduce: Using the Octavia API to create a new LB with all components. You cannot see any information about the health monitor that will be returned. Proposed Fix: Modify the assignment to use `data_model.health_monitor` instead of `pool.healthmonitor`. Change-Id: Ia914ad89b6fdf3606c3d4bff0a4c425348c15e0c
1 parent 860d2f6 commit 7261730

File tree

3 files changed

+79
-1
lines changed

3 files changed

+79
-1
lines changed

octavia/api/v2/types/pool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def from_data_model(cls, data_model, children=False):
106106
if cls._full_response():
107107
del pool.loadbalancers
108108
member_model = member.MemberFullResponse
109-
if pool.healthmonitor:
109+
if data_model.health_monitor:
110110
pool.healthmonitor = (
111111
health_monitor.HealthMonitorFullResponse
112112
.from_data_model(data_model.health_monitor))

octavia/tests/unit/api/v2/types/test_pool.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@
1717
from wsme.rest import json as wsme_json
1818
from wsme import types as wsme_types
1919

20+
from octavia.api.common import types
21+
from octavia.api.v2.types import health_monitor as health_monitor_type
22+
from octavia.api.v2.types import member as member_type
2023
from octavia.api.v2.types import pool as pool_type
2124
from octavia.common import constants
25+
from octavia.common import data_models
2226
from octavia.tests.unit.api.common import base
2327

2428

@@ -224,3 +228,70 @@ def test_invalid_app_cookie_name(self):
224228
body = {"cookie_name": "cookie\nmonster"}
225229
self.assertRaises(exc.InvalidInput, wsme_json.fromjson, self._type,
226230
body)
231+
232+
233+
class TestPoolResponse(base.BaseTypesTest):
234+
235+
_type = pool_type.PoolResponse
236+
237+
def test_pool_response_with_health_monitor(self):
238+
health_monitor_id = uuidutils.generate_uuid()
239+
health_monitor_model = data_models.HealthMonitor(id=health_monitor_id)
240+
pool_model = data_models.Pool(health_monitor=health_monitor_model)
241+
pool = self._type.from_data_model(data_model=pool_model)
242+
self.assertEqual(pool.healthmonitor_id, health_monitor_id)
243+
244+
def test_pool_response_with_members(self):
245+
member_id = uuidutils.generate_uuid()
246+
members = [data_models.Member(id=member_id)]
247+
pool_model = data_models.Pool(members=members)
248+
pool = self._type.from_data_model(data_model=pool_model)
249+
self.assertIsInstance(pool.members[0], types.IdOnlyType)
250+
self.assertEqual(pool.members[0].id, member_id)
251+
252+
def test_pool_response_with_load_balancer(self):
253+
load_balancer_id = uuidutils.generate_uuid()
254+
load_balancer = data_models.LoadBalancer(id=load_balancer_id)
255+
pool_model = data_models.Pool(load_balancer=load_balancer)
256+
pool = self._type.from_data_model(data_model=pool_model)
257+
self.assertIsInstance(pool.loadbalancers[0], types.IdOnlyType)
258+
self.assertEqual(pool.loadbalancers[0].id, load_balancer_id)
259+
260+
def test_pool_response_with_session_persistence(self):
261+
session_persistence = data_models.SessionPersistence(
262+
cookie_name="test"
263+
)
264+
pool_model = data_models.Pool(session_persistence=session_persistence)
265+
pool = self._type.from_data_model(data_model=pool_model)
266+
self.assertEqual(pool.session_persistence.cookie_name, "test")
267+
268+
def test_pool_response_without_children(self):
269+
pool = self._type.from_data_model(data_model=data_models.Pool())
270+
self.assertEqual(len(pool.loadbalancers), 0)
271+
self.assertIsNone(pool.session_persistence)
272+
self.assertEqual(len(pool.members), 0)
273+
self.assertEqual(len(pool.listeners), 0)
274+
self.assertEqual(pool.healthmonitor_id, wsme_types.Unset)
275+
276+
277+
class TestPoolFullResponse(base.BaseTypesTest):
278+
279+
_type = pool_type.PoolFullResponse
280+
281+
def test_pool_full_response_with_health_monitor(self):
282+
health_monitor_model = data_models.HealthMonitor()
283+
pool_model = data_models.Pool(health_monitor=health_monitor_model)
284+
pool = self._type.from_data_model(data_model=pool_model)
285+
self.assertIsInstance(
286+
pool.healthmonitor, health_monitor_type.HealthMonitorFullResponse
287+
)
288+
289+
def test_pool_full_response_with_members(self):
290+
members = [data_models.Member()]
291+
pool_model = data_models.Pool(members=members)
292+
pool = self._type.from_data_model(data_model=pool_model)
293+
self.assertIsInstance(pool.members[0], member_type.MemberFullResponse)
294+
295+
def test_pool_full_response_without_children(self):
296+
pool = self._type.from_data_model(data_model=data_models.Pool())
297+
self.assertIsNone(pool.healthmonitor)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
fixes:
3+
- |
4+
Bug fix: The response body of the LB API, when creating a new load
5+
balancer, now correctly includes information about the health monitor.
6+
Previously, this information was consistently null, despite configuring
7+
a health monitor.

0 commit comments

Comments
 (0)