def test_expand_expected_codes(self): exp_codes = '' self.assertEqual(utils.expand_expected_codes(exp_codes), set()) exp_codes = '200' self.assertEqual(utils.expand_expected_codes(exp_codes), {'200'}) exp_codes = '200, 201' self.assertEqual(utils.expand_expected_codes(exp_codes), {'200', '201'}) exp_codes = '200, 201,202' self.assertEqual(utils.expand_expected_codes(exp_codes), {'200', '201', '202'}) exp_codes = '200-202' self.assertEqual(utils.expand_expected_codes(exp_codes), {'200', '201', '202'}) exp_codes = '200-202, 205' self.assertEqual(utils.expand_expected_codes(exp_codes), {'200', '201', '202', '205'}) exp_codes = '200, 201-203' self.assertEqual(utils.expand_expected_codes(exp_codes), {'200', '201', '202', '203'}) exp_codes = '200, 201-203, 205' self.assertEqual(utils.expand_expected_codes(exp_codes), {'200', '201', '202', '203', '205'}) exp_codes = '201-200, 205' self.assertEqual(utils.expand_expected_codes(exp_codes), {'205'})
def _transform_health_monitor(self, monitor): """Transforms a health monitor into an object that will be processed by the templating system """ return_val = { 'id': monitor.id, 'type': monitor.type, 'delay': monitor.delay, 'timeout': monitor.timeout, 'enabled': monitor.enabled, 'fall_threshold': monitor.fall_threshold, 'check_script_path': (self._get_default_lvs_check_script_path() if monitor.type == constants.HEALTH_MONITOR_UDP_CONNECT else None) } if monitor.type == constants.HEALTH_MONITOR_HTTP: return_val.update({ 'rise_threshold': monitor.rise_threshold, 'url_path': monitor.url_path, 'http_method': (monitor.http_method if monitor.http_method == constants.HEALTH_MONITOR_HTTP_METHOD_GET else None), 'expected_codes': (sorted( list( octavia_utils.expand_expected_codes( monitor.expected_codes))) if monitor.expected_codes else []) }) return return_val
def _transform_health_monitor(self, monitor, feature_compatibility): """Transforms a health monitor into an object that will be processed by the templating system """ codes = None if monitor.expected_codes: codes = '|'.join( octavia_utils.expand_expected_codes(monitor.expected_codes)) return { 'id': monitor.id, 'type': monitor.type, 'delay': monitor.delay, 'timeout': monitor.timeout, 'fall_threshold': monitor.fall_threshold, 'rise_threshold': monitor.rise_threshold, 'http_method': monitor.http_method, 'url_path': monitor.url_path, 'expected_codes': codes, 'enabled': monitor.enabled, 'http_version': monitor.http_version, 'domain_name': monitor.domain_name, }