From 81cc1fb9238539a23d1d2ba77bb410c851f0e62b Mon Sep 17 00:00:00 2001 From: ptoohill1 Date: Tue, 4 Oct 2016 12:09:39 -0500 Subject: [PATCH] Add defaults for health monitor object There is a bug when Octavia's API is called directly causing failures. Neutron-LBaaS has defaults on API request that properly generates the health monitor request. Similar requests fail directly in Octavia due to no defaults. Change-Id: Ic7694825e5ace0362ecd5ce21d9b63c5c92c6a23 Closes-Bug: #1630287 --- octavia/api/v1/types/health_monitor.py | 9 ++++++--- octavia/common/constants.py | 3 +++ .../tests/functional/api/v1/test_health_monitor.py | 5 +++++ .../tests/unit/api/v1/types/test_health_monitors.py | 12 ++++++++++++ 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/octavia/api/v1/types/health_monitor.py b/octavia/api/v1/types/health_monitor.py index b260add3e2..6a0ede51b6 100644 --- a/octavia/api/v1/types/health_monitor.py +++ b/octavia/api/v1/types/health_monitor.py @@ -41,9 +41,12 @@ class HealthMonitorPOST(base.BaseType): timeout = wtypes.wsattr(wtypes.IntegerType(), mandatory=True) fall_threshold = wtypes.wsattr(wtypes.IntegerType(), mandatory=True) rise_threshold = wtypes.wsattr(wtypes.IntegerType(), mandatory=True) - http_method = wtypes.wsattr(wtypes.text) - url_path = wtypes.wsattr(wtypes.text) - expected_codes = wtypes.wsattr(wtypes.text) + http_method = wtypes.wsattr( + wtypes.text, default=constants.HEALTH_MONITOR_HTTP_DEFAULT_METHOD) + url_path = wtypes.wsattr( + wtypes.text, default=constants.HEALTH_MONITOR_DEFAULT_URL_PATH) + expected_codes = wtypes.wsattr( + wtypes.text, default=constants.HEALTH_MONITOR_DEFAULT_EXPECTED_CODES) enabled = wtypes.wsattr(bool, default=True) project_id = wtypes.wsattr(wtypes.StringType(max_length=36)) diff --git a/octavia/common/constants.py b/octavia/common/constants.py index 5e2c6db0b2..7aaab0d965 100644 --- a/octavia/common/constants.py +++ b/octavia/common/constants.py @@ -32,6 +32,9 @@ HEALTH_MONITOR_HTTP = 'HTTP' HEALTH_MONITOR_HTTPS = 'HTTPS' SUPPORTED_HEALTH_MONITOR_TYPES = (HEALTH_MONITOR_HTTP, HEALTH_MONITOR_HTTPS, HEALTH_MONITOR_PING, HEALTH_MONITOR_TCP) +HEALTH_MONITOR_HTTP_DEFAULT_METHOD = 'GET' +HEALTH_MONITOR_DEFAULT_EXPECTED_CODES = '200' +HEALTH_MONITOR_DEFAULT_URL_PATH = '/' UPDATE_STATS = 'UPDATE_STATS' UPDATE_HEALTH = 'UPDATE_HEALTH' diff --git a/octavia/tests/functional/api/v1/test_health_monitor.py b/octavia/tests/functional/api/v1/test_health_monitor.py index 85eecc03e6..9dc42f602a 100644 --- a/octavia/tests/functional/api/v1/test_health_monitor.py +++ b/octavia/tests/functional/api/v1/test_health_monitor.py @@ -99,6 +99,11 @@ class TestHealthMonitor(base.BaseAPITest): self.assertEqual(1, api_hm.get('timeout')) self.assertEqual(1, api_hm.get('fall_threshold')) self.assertEqual(1, api_hm.get('rise_threshold')) + # Verify optional field defaults + self.assertEqual('GET', api_hm.get('http_method')) + self.assertEqual('/', api_hm.get('url_path')) + self.assertEqual('200', api_hm.get('expected_codes')) + self.assert_correct_lb_status(self.lb.get('id'), constants.ACTIVE, constants.ONLINE) diff --git a/octavia/tests/unit/api/v1/types/test_health_monitors.py b/octavia/tests/unit/api/v1/types/test_health_monitors.py index f655ca7ef8..7fa340f2da 100644 --- a/octavia/tests/unit/api/v1/types/test_health_monitors.py +++ b/octavia/tests/unit/api/v1/types/test_health_monitors.py @@ -109,6 +109,18 @@ class TestHealthMonitorPOST(base.BaseTypesTest, TestHealthMonitor): self.assertRaises(exc.InvalidInput, wsme_json.fromjson, self._type, body) + def test_default_health_monitor_values(self): + # http_method = 'GET' + # url_path = '/' + # expected_codes = '200' + # The above are not required but should have the above example defaults + body = {"type": constants.HEALTH_MONITOR_HTTP, "delay": 1, + "timeout": 1, "fall_threshold": 1, "rise_threshold": 1} + hmpost = wsme_json.fromjson(self._type, body) + self.assertEqual('GET', hmpost.http_method) + self.assertEqual('/', hmpost.url_path) + self.assertEqual('200', hmpost.expected_codes) + def test_non_uuid_project_id(self): body = {"type": constants.HEALTH_MONITOR_HTTP, "delay": 1, "timeout": 1, "fall_threshold": 1, "rise_threshold": 1,