Merge "Move a local function into a library"
This commit is contained in:
commit
e95558088c
|
@ -82,6 +82,14 @@ function set_status(service, value, alarms)
|
|||
}
|
||||
end
|
||||
|
||||
function max_status(current, status)
|
||||
if not status or STATUS_WEIGHTS[current] > STATUS_WEIGHTS[status] then
|
||||
return current
|
||||
else
|
||||
return status
|
||||
end
|
||||
end
|
||||
|
||||
-- The service status depends on the status of the level-1 dependencies.
|
||||
-- The status of the level-2 dependencies don't modify the overall status
|
||||
-- but their alarms are returned.
|
||||
|
@ -89,14 +97,6 @@ function resolve_status(name)
|
|||
local service_status = consts.UNKW
|
||||
local alarms = {}
|
||||
|
||||
function max(other_status)
|
||||
if not other_status or STATUS_WEIGHTS[service_status] >= STATUS_WEIGHTS[other_status] then
|
||||
return service_status
|
||||
else
|
||||
return other_status
|
||||
end
|
||||
end
|
||||
|
||||
for _, level_1_dep in ipairs(level_1_deps[name] or {}) do
|
||||
if facts[level_1_dep] then
|
||||
local status = STATUS_MAPPING_FOR_LEVEL_1[facts[level_1_dep].status]
|
||||
|
@ -110,7 +110,7 @@ function resolve_status(name)
|
|||
alarms[#alarms].tags['dependency_level'] = 'direct'
|
||||
end
|
||||
end
|
||||
service_status = max(status)
|
||||
service_status = max_status(service_status, status)
|
||||
end
|
||||
|
||||
for _, level_2_dep in ipairs(level_2_deps[level_1_dep] or {}) do
|
||||
|
|
|
@ -151,6 +151,17 @@ TestGse = {}
|
|||
assertEquals(metric.Payload, '{"alarms":[]}')
|
||||
end
|
||||
|
||||
function TestGse:test_max_status()
|
||||
local status = gse.max_status(consts.DOWN, consts.WARN)
|
||||
assertEquals(consts.DOWN, status)
|
||||
local status = gse.max_status(consts.OKAY, consts.WARN)
|
||||
assertEquals(consts.WARN, status)
|
||||
local status = gse.max_status(consts.OKAY, consts.DOWN)
|
||||
assertEquals(consts.DOWN, status)
|
||||
local status = gse.max_status(consts.UNKW, consts.DOWN)
|
||||
assertEquals(consts.DOWN, status)
|
||||
end
|
||||
|
||||
lu = LuaUnit
|
||||
lu = LuaUnit
|
||||
lu:setVerbosity( 1 )
|
||||
|
|
Loading…
Reference in New Issue