Commit 61a980a9 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

Add constants for instance status



They've been hardcoded for too long.
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
parent 502b3316
......@@ -7872,9 +7872,9 @@ class LUInstanceConsole(NoHooksLU):
if instance.name not in node_insts.payload:
if instance.admin_up:
state = "ERROR_down"
state = constants.INSTST_ERRORDOWN
else:
state = "ADMIN_down"
state = constants.INSTST_ADMINDOWN
raise errors.OpExecError("Instance %s is not running (state %s)" %
(instance.name, state))
......
......@@ -861,6 +861,24 @@ NV_VGLIST = "vglist"
NV_VMNODES = "vmnodes"
NV_OOB_PATHS = "oob-paths"
# Instance status
INSTST_RUNNING = "running"
INSTST_ADMINDOWN = "ADMIN_down"
INSTST_NODEOFFLINE = "ERROR_nodeoffline"
INSTST_NODEDOWN = "ERROR_nodedown"
INSTST_WRONGNODE = "ERROR_wrongnode"
INSTST_ERRORUP = "ERROR_up"
INSTST_ERRORDOWN = "ERROR_down"
INSTST_ALL = frozenset([
INSTST_RUNNING,
INSTST_ADMINDOWN,
INSTST_NODEOFFLINE,
INSTST_NODEDOWN,
INSTST_WRONGNODE,
INSTST_ERRORUP,
INSTST_ERRORDOWN,
])
# SSL certificate check constants (in days)
SSL_CERT_EXPIRATION_WARN = 30
SSL_CERT_EXPIRATION_ERROR = 7
......
......@@ -779,23 +779,23 @@ def _GetInstStatus(ctx, inst):
"""
if inst.primary_node in ctx.offline_nodes:
return "ERROR_nodeoffline"
return constants.INSTST_NODEOFFLINE
if inst.primary_node in ctx.bad_nodes:
return "ERROR_nodedown"
return constants.INSTST_NODEDOWN
if bool(ctx.live_data.get(inst.name)):
if inst.name in ctx.wrongnode_inst:
return "ERROR_wrongnode"
return constants.INSTST_WRONGNODE
elif inst.admin_up:
return "running"
return constants.INSTST_RUNNING
else:
return "ERROR_up"
return constants.INSTST_ERRORUP
if inst.admin_up:
return "ERROR_down"
return constants.INSTST_ERRORDOWN
return "ADMIN_down"
return constants.INSTST_ADMINDOWN
def _GetInstDiskSize(index):
......
......@@ -62,8 +62,8 @@ MAXTRIES = 5
# 5 minutes, so it takes around half an hour to exceed the retry
# counter, so 8 hours (16*1/2h) seems like a reasonable reset time
RETRY_EXPIRATION = 8 * 3600
BAD_STATES = ['ERROR_down']
HELPLESS_STATES = ['ERROR_nodedown', 'ERROR_nodeoffline']
BAD_STATES = [constants.INSTST_ERRORDOWN]
HELPLESS_STATES = [constants.INSTST_NODEDOWN, constants.INSTST_NODEOFFLINE]
NOTICE = 'NOTICE'
ERROR = 'ERROR'
KEY_RESTART_COUNT = "restart_count"
......
......@@ -743,20 +743,20 @@ class TestInstanceQuery(unittest.TestCase):
(constants.RS_NORMAL, inst.name))
if inst.primary_node in offline_nodes:
exp_status = "ERROR_nodeoffline"
exp_status = constants.INSTST_NODEOFFLINE
elif inst.primary_node in bad_nodes:
exp_status = "ERROR_nodedown"
exp_status = constants.INSTST_NODEDOWN
elif inst.name in live_data:
if inst.name in wrongnode_inst:
exp_status = "ERROR_wrongnode"
exp_status = constants.INSTST_WRONGNODE
elif inst.admin_up:
exp_status = "running"
exp_status = constants.INSTST_RUNNING
else:
exp_status = "ERROR_up"
exp_status = constants.INSTST_ERRORUP
elif inst.admin_up:
exp_status = "ERROR_down"
exp_status = constants.INSTST_ERRORDOWN
else:
exp_status = "ADMIN_down"
exp_status = constants.INSTST_ADMINDOWN
self.assertEqual(row[fieldidx["status"]],
(constants.RS_NORMAL, exp_status))
......@@ -830,10 +830,7 @@ class TestInstanceQuery(unittest.TestCase):
self._CheckInstanceConsole(inst, row[fieldidx["console"]])
# Ensure all possible status' have been tested
self.assertEqual(tested_status,
set(["ERROR_nodeoffline", "ERROR_nodedown",
"running", "ERROR_up", "ERROR_down",
"ADMIN_down", "ERROR_wrongnode"]))
self.assertEqual(tested_status, constants.INSTST_ALL)
def _CheckInstanceConsole(self, instance, (status, consdata)):
if instance.name == "inst7":
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment