Commit c81b97f2 authored by Iustin Pop's avatar Iustin Pop
Browse files

Make gnt-node list -o(p|s)inst_list output stable



Currently, both the Python and Haskell code return the internal
instance list unsorted, which means the output can vary depending on
the phase of the moon (well, the Haskell code actually uses internally
a tree, sorted by the instance name, but it's implementation detail).

By adding an explicit sort step, we guarantee both stability of the
output and consistency between the two query paths.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarHelga Velroyen <helgav@google.com>
parent 7c17db26
......@@ -1362,7 +1362,7 @@ def _BuildNodeFields():
return lambda ctx, node: len(getter(ctx)[node.name])
def _GetList(getter):
return lambda ctx, node: list(getter(ctx)[node.name])
return lambda ctx, node: utils.NiceSort(list(getter(ctx)[node.name]))
# Add fields operating on instance lists
for prefix, titleprefix, docword, getter in \
......
......@@ -42,6 +42,7 @@ import Ganeti.Rpc
import Ganeti.Query.Language
import Ganeti.Query.Common
import Ganeti.Query.Types
import Ganeti.Utils (niceSort)
-- | Runtime is the resulting type for NodeInfo call.
type Runtime = Either RpcError RpcResultNodeInfo
......@@ -182,11 +183,11 @@ nodeFields =
QffNormal)
, (FieldDefinition "pinst_list" "PriInstances" QFTOther
"List of instances with this node as primary",
FieldConfig (\cfg -> rsNormal . map instName . fst .
FieldConfig (\cfg -> rsNormal . niceSort . map instName . fst .
getNodeInstances cfg . nodeName), QffNormal)
, (FieldDefinition "sinst_list" "SecInstances" QFTOther
"List of instances with this node as secondary",
FieldConfig (\cfg -> rsNormal . map instName . snd .
FieldConfig (\cfg -> rsNormal . niceSort . map instName . snd .
getNodeInstances cfg . nodeName), QffNormal)
, (FieldDefinition "role" "Role" QFTText nodeRoleDoc,
FieldConfig ((rsNormal .) . getNodeRole), QffNormal)
......
#!/usr/bin/python
#
# Copyright (C) 2010, 2011, 2012 Google Inc.
# Copyright (C) 2010, 2011, 2012, 2013 Google Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......@@ -524,7 +524,7 @@ class TestNodeQuery(unittest.TestCase):
list(node_to_primary[master_name])))
self.assertEqual(live_data_row[field_index["sinst_list"]],
(constants.RS_NORMAL,
list(node_to_secondary[live_data_name])))
utils.NiceSort(list(node_to_secondary[live_data_name]))))
def testGetLiveNodeField(self):
nodes = [
......
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