Commit 2e04d454 authored by Agata Murawska's avatar Agata Murawska
Browse files

Introduce admin_state as 3-values data type


Signed-off-by: default avatarAgata Murawska <agatamurawska@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 9ca8a7c5
This diff is collapsed.
...@@ -1175,7 +1175,7 @@ class ConfigWriter: ...@@ -1175,7 +1175,7 @@ class ConfigWriter:
"""Set the instance's status to a given value. """Set the instance's status to a given value.
""" """
assert isinstance(status, bool), \ assert status in constants.ADMINST_ALL, \
"Invalid status '%s' passed to SetInstanceStatus" % (status,) "Invalid status '%s' passed to SetInstanceStatus" % (status,)
if instance_name not in self._config_data.instances: if instance_name not in self._config_data.instances:
...@@ -1242,7 +1242,7 @@ class ConfigWriter: ...@@ -1242,7 +1242,7 @@ class ConfigWriter:
"""Mark the status of an instance to down in the configuration. """Mark the status of an instance to down in the configuration.
""" """
self._SetInstanceStatus(instance_name, False) self._SetInstanceStatus(instance_name, constants.ADMINST_DOWN)
def _UnlockedGetInstanceList(self): def _UnlockedGetInstanceList(self):
"""Get the list of instances. """Get the list of instances.
......
...@@ -1256,6 +1256,7 @@ NV_USERSCRIPTS = "user-scripts" ...@@ -1256,6 +1256,7 @@ NV_USERSCRIPTS = "user-scripts"
# Instance status # Instance status
INSTST_RUNNING = "running" INSTST_RUNNING = "running"
INSTST_ADMINDOWN = "ADMIN_down" INSTST_ADMINDOWN = "ADMIN_down"
INSTST_ADMINOFFLINE = "ADMIN_offline"
INSTST_NODEOFFLINE = "ERROR_nodeoffline" INSTST_NODEOFFLINE = "ERROR_nodeoffline"
INSTST_NODEDOWN = "ERROR_nodedown" INSTST_NODEDOWN = "ERROR_nodedown"
INSTST_WRONGNODE = "ERROR_wrongnode" INSTST_WRONGNODE = "ERROR_wrongnode"
...@@ -1264,6 +1265,7 @@ INSTST_ERRORDOWN = "ERROR_down" ...@@ -1264,6 +1265,7 @@ INSTST_ERRORDOWN = "ERROR_down"
INSTST_ALL = frozenset([ INSTST_ALL = frozenset([
INSTST_RUNNING, INSTST_RUNNING,
INSTST_ADMINDOWN, INSTST_ADMINDOWN,
INSTST_ADMINOFFLINE,
INSTST_NODEOFFLINE, INSTST_NODEOFFLINE,
INSTST_NODEDOWN, INSTST_NODEDOWN,
INSTST_WRONGNODE, INSTST_WRONGNODE,
......
...@@ -1348,15 +1348,17 @@ def _GetInstStatus(ctx, inst): ...@@ -1348,15 +1348,17 @@ def _GetInstStatus(ctx, inst):
if bool(ctx.live_data.get(inst.name)): if bool(ctx.live_data.get(inst.name)):
if inst.name in ctx.wrongnode_inst: if inst.name in ctx.wrongnode_inst:
return constants.INSTST_WRONGNODE return constants.INSTST_WRONGNODE
elif inst.admin_state: elif inst.admin_state == constants.ADMINST_UP:
return constants.INSTST_RUNNING return constants.INSTST_RUNNING
else: else:
return constants.INSTST_ERRORUP return constants.INSTST_ERRORUP
if inst.admin_state: if inst.admin_state == constants.ADMINST_UP:
return constants.INSTST_ERRORDOWN return constants.INSTST_ERRORDOWN
elif inst.admin_state == constants.ADMINST_DOWN:
return constants.INSTST_ADMINDOWN
return constants.INSTST_ADMINDOWN return constants.INSTST_ADMINOFFLINE
def _GetInstDiskSize(index): def _GetInstDiskSize(index):
...@@ -1775,9 +1777,8 @@ def _BuildInstanceFields(): ...@@ -1775,9 +1777,8 @@ def _BuildInstanceFields():
IQ_NODES, 0, IQ_NODES, 0,
lambda ctx, inst: map(compat.partial(_GetInstNodeGroup, ctx, None), lambda ctx, inst: map(compat.partial(_GetInstNodeGroup, ctx, None),
inst.secondary_nodes)), inst.secondary_nodes)),
(_MakeField("admin_state", "Autostart", QFT_BOOL, (_MakeField("admin_state", "InstanceState", QFT_TEXT,
"Desired state of instance (if set, the instance should be" "Desired state of instance"),
" up)"),
IQ_CONFIG, 0, _GetItemAttr("admin_state")), IQ_CONFIG, 0, _GetItemAttr("admin_state")),
(_MakeField("tags", "Tags", QFT_OTHER, "Tags"), IQ_CONFIG, 0, (_MakeField("tags", "Tags", QFT_OTHER, "Tags"), IQ_CONFIG, 0,
lambda ctx, inst: list(inst.GetTags())), lambda ctx, inst: list(inst.GetTags())),
...@@ -1808,15 +1809,16 @@ def _BuildInstanceFields(): ...@@ -1808,15 +1809,16 @@ def _BuildInstanceFields():
status_values = (constants.INSTST_RUNNING, constants.INSTST_ADMINDOWN, status_values = (constants.INSTST_RUNNING, constants.INSTST_ADMINDOWN,
constants.INSTST_WRONGNODE, constants.INSTST_ERRORUP, constants.INSTST_WRONGNODE, constants.INSTST_ERRORUP,
constants.INSTST_ERRORDOWN, constants.INSTST_NODEDOWN, constants.INSTST_ERRORDOWN, constants.INSTST_NODEDOWN,
constants.INSTST_NODEOFFLINE) constants.INSTST_NODEOFFLINE, constants.INSTST_ADMINOFFLINE)
status_doc = ("Instance status; \"%s\" if instance is set to be running" status_doc = ("Instance status; \"%s\" if instance is set to be running"
" and actually is, \"%s\" if instance is stopped and" " and actually is, \"%s\" if instance is stopped and"
" is not running, \"%s\" if instance running, but not on its" " is not running, \"%s\" if instance running, but not on its"
" designated primary node, \"%s\" if instance should be" " designated primary node, \"%s\" if instance should be"
" stopped, but is actually running, \"%s\" if instance should" " stopped, but is actually running, \"%s\" if instance should"
" run, but doesn't, \"%s\" if instance's primary node is down," " run, but doesn't, \"%s\" if instance's primary node is down,"
" \"%s\" if instance's primary node is marked offline" % " \"%s\" if instance's primary node is marked offline,"
status_values) " \"%s\" if instance is offline and does not use dynamic"
" resources" % status_values)
fields.append((_MakeField("status", "Status", QFT_TEXT, status_doc), fields.append((_MakeField("status", "Status", QFT_TEXT, status_doc),
IQ_LIVE, 0, _GetInstStatus)) IQ_LIVE, 0, _GetInstStatus))
assert set(status_values) == constants.INSTST_ALL, \ assert set(status_values) == constants.INSTST_ALL, \
......
...@@ -644,7 +644,8 @@ class TestInstanceQuery(unittest.TestCase): ...@@ -644,7 +644,8 @@ class TestInstanceQuery(unittest.TestCase):
objects.Instance(name="inst1", hvparams={}, beparams={}, nics=[], objects.Instance(name="inst1", hvparams={}, beparams={}, nics=[],
uuid="f90eccb3-e227-4e3c-bf2a-94a21ca8f9cd", uuid="f90eccb3-e227-4e3c-bf2a-94a21ca8f9cd",
ctime=1291244000, mtime=1291244400, serial_no=30, ctime=1291244000, mtime=1291244400, serial_no=30,
admin_state=True, hypervisor=constants.HT_XEN_PVM, os="linux1", admin_state=constants.ADMINST_UP, hypervisor=constants.HT_XEN_PVM,
os="linux1",
primary_node="node1", primary_node="node1",
disk_template=constants.DT_PLAIN, disk_template=constants.DT_PLAIN,
disks=[], disks=[],
...@@ -652,7 +653,8 @@ class TestInstanceQuery(unittest.TestCase): ...@@ -652,7 +653,8 @@ class TestInstanceQuery(unittest.TestCase):
objects.Instance(name="inst2", hvparams={}, nics=[], objects.Instance(name="inst2", hvparams={}, nics=[],
uuid="73a0f8a7-068c-4630-ada2-c3440015ab1a", uuid="73a0f8a7-068c-4630-ada2-c3440015ab1a",
ctime=1291211000, mtime=1291211077, serial_no=1, ctime=1291211000, mtime=1291211077, serial_no=1,
admin_state=True, hypervisor=constants.HT_XEN_HVM, os="deb99", admin_state=constants.ADMINST_UP, hypervisor=constants.HT_XEN_HVM,
os="deb99",
primary_node="node5", primary_node="node5",
disk_template=constants.DT_DISKLESS, disk_template=constants.DT_DISKLESS,
disks=[], disks=[],
...@@ -663,7 +665,8 @@ class TestInstanceQuery(unittest.TestCase): ...@@ -663,7 +665,8 @@ class TestInstanceQuery(unittest.TestCase):
objects.Instance(name="inst3", hvparams={}, beparams={}, objects.Instance(name="inst3", hvparams={}, beparams={},
uuid="11ec8dff-fb61-4850-bfe0-baa1803ff280", uuid="11ec8dff-fb61-4850-bfe0-baa1803ff280",
ctime=1291011000, mtime=1291013000, serial_no=1923, ctime=1291011000, mtime=1291013000, serial_no=1923,
admin_state=False, hypervisor=constants.HT_KVM, os="busybox", admin_state=constants.ADMINST_DOWN, hypervisor=constants.HT_KVM,
os="busybox",
primary_node="node6", primary_node="node6",
disk_template=constants.DT_DRBD8, disk_template=constants.DT_DRBD8,
disks=[], disks=[],
...@@ -678,7 +681,8 @@ class TestInstanceQuery(unittest.TestCase): ...@@ -678,7 +681,8 @@ class TestInstanceQuery(unittest.TestCase):
objects.Instance(name="inst4", hvparams={}, beparams={}, objects.Instance(name="inst4", hvparams={}, beparams={},
uuid="68dab168-3ef5-4c9d-b4d3-801e0672068c", uuid="68dab168-3ef5-4c9d-b4d3-801e0672068c",
ctime=1291244390, mtime=1291244395, serial_no=25, ctime=1291244390, mtime=1291244395, serial_no=25,
admin_state=False, hypervisor=constants.HT_XEN_PVM, os="linux1", admin_state=constants.ADMINST_DOWN, hypervisor=constants.HT_XEN_PVM,
os="linux1",
primary_node="nodeoff2", primary_node="nodeoff2",
disk_template=constants.DT_DRBD8, disk_template=constants.DT_DRBD8,
disks=[], disks=[],
...@@ -702,7 +706,8 @@ class TestInstanceQuery(unittest.TestCase): ...@@ -702,7 +706,8 @@ class TestInstanceQuery(unittest.TestCase):
objects.Instance(name="inst5", hvparams={}, nics=[], objects.Instance(name="inst5", hvparams={}, nics=[],
uuid="0e3dca12-5b42-4e24-98a2-415267545bd0", uuid="0e3dca12-5b42-4e24-98a2-415267545bd0",
ctime=1231211000, mtime=1261200000, serial_no=3, ctime=1231211000, mtime=1261200000, serial_no=3,
admin_state=True, hypervisor=constants.HT_XEN_HVM, os="deb99", admin_state=constants.ADMINST_UP, hypervisor=constants.HT_XEN_HVM,
os="deb99",
primary_node="nodebad2", primary_node="nodebad2",
disk_template=constants.DT_DISKLESS, disk_template=constants.DT_DISKLESS,
disks=[], disks=[],
...@@ -713,7 +718,8 @@ class TestInstanceQuery(unittest.TestCase): ...@@ -713,7 +718,8 @@ class TestInstanceQuery(unittest.TestCase):
objects.Instance(name="inst6", hvparams={}, nics=[], objects.Instance(name="inst6", hvparams={}, nics=[],
uuid="72de6580-c8d5-4661-b902-38b5785bb8b3", uuid="72de6580-c8d5-4661-b902-38b5785bb8b3",
ctime=7513, mtime=11501, serial_no=13390, ctime=7513, mtime=11501, serial_no=13390,
admin_state=False, hypervisor=constants.HT_XEN_HVM, os="deb99", admin_state=constants.ADMINST_DOWN, hypervisor=constants.HT_XEN_HVM,
os="deb99",
primary_node="node7", primary_node="node7",
disk_template=constants.DT_DISKLESS, disk_template=constants.DT_DISKLESS,
disks=[], disks=[],
...@@ -726,7 +732,18 @@ class TestInstanceQuery(unittest.TestCase): ...@@ -726,7 +732,18 @@ class TestInstanceQuery(unittest.TestCase):
objects.Instance(name="inst7", hvparams={}, nics=[], objects.Instance(name="inst7", hvparams={}, nics=[],
uuid="ceec5dc4-b729-4f42-ae28-69b3cd24920e", uuid="ceec5dc4-b729-4f42-ae28-69b3cd24920e",
ctime=None, mtime=None, serial_no=1947, ctime=None, mtime=None, serial_no=1947,
admin_state=False, hypervisor=constants.HT_XEN_HVM, os="deb99", admin_state=constants.ADMINST_DOWN, hypervisor=constants.HT_XEN_HVM,
os="deb99",
primary_node="node6",
disk_template=constants.DT_DISKLESS,
disks=[],
beparams={},
osparams={}),
objects.Instance(name="inst8", hvparams={}, nics=[],
uuid="ceec5dc4-b729-4f42-ae28-69b3cd24920f",
ctime=None, mtime=None, serial_no=19478,
admin_state=constants.ADMINST_OFFLINE, hypervisor=constants.HT_XEN_HVM,
os="deb99",
primary_node="node6", primary_node="node6",
disk_template=constants.DT_DISKLESS, disk_template=constants.DT_DISKLESS,
disks=[], disks=[],
...@@ -799,14 +816,16 @@ class TestInstanceQuery(unittest.TestCase): ...@@ -799,14 +816,16 @@ class TestInstanceQuery(unittest.TestCase):
elif inst.name in live_data: elif inst.name in live_data:
if inst.name in wrongnode_inst: if inst.name in wrongnode_inst:
exp_status = constants.INSTST_WRONGNODE exp_status = constants.INSTST_WRONGNODE
elif inst.admin_state: elif inst.admin_state == constants.ADMINST_UP:
exp_status = constants.INSTST_RUNNING exp_status = constants.INSTST_RUNNING
else: else:
exp_status = constants.INSTST_ERRORUP exp_status = constants.INSTST_ERRORUP
elif inst.admin_state: elif inst.admin_state == constants.ADMINST_UP:
exp_status = constants.INSTST_ERRORDOWN exp_status = constants.INSTST_ERRORDOWN
else: elif inst.admin_state == constants.ADMINST_DOWN:
exp_status = constants.INSTST_ADMINDOWN exp_status = constants.INSTST_ADMINDOWN
else:
exp_status = constants.INSTST_ADMINOFFLINE
self.assertEqual(row[fieldidx["status"]], self.assertEqual(row[fieldidx["status"]],
(constants.RS_NORMAL, exp_status)) (constants.RS_NORMAL, exp_status))
......
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