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 <>
Reviewed-by: default avatarHelga Velroyen <>
parent 7c17db26
......@@ -1362,7 +1362,7 @@ def _BuildNodeFields():
return lambda ctx, node: len(getter(ctx)[])
def _GetList(getter):
return lambda ctx, node: list(getter(ctx)[])
return lambda ctx, node: utils.NiceSort(list(getter(ctx)[]))
# 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 =
, (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)
# 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):
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