Merge "Add defaults for health monitor object"

This commit is contained in:
Jenkins 2016-10-05 20:21:32 +00:00 committed by Gerrit Code Review
commit a26d76b144
4 changed files with 26 additions and 3 deletions

View File

@ -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))

View File

@ -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'

View File

@ -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)

View File

@ -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,