Commit edd49f9b authored by Agata Murawska's avatar Agata Murawska
Browse files

Group query now calculates ipolicy


Signed-off-by: default avatarAgata Murawska <agatamurawska@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 38c37a51
......@@ -12957,6 +12957,7 @@ class _GroupQuery(_QueryBase):
lu.needed_locks = {}
 
self._all_groups = lu.cfg.GetAllNodeGroupsInfo()
self._cluster = lu.cfg.GetClusterInfo()
name_to_uuid = dict((g.name, g.uuid) for g in self._all_groups.values())
 
if not self.names:
......@@ -13022,7 +13023,8 @@ class _GroupQuery(_QueryBase):
# Do not pass on node information if it was not requested.
group_to_nodes = None
 
return query.GroupQueryData([self._all_groups[uuid]
return query.GroupQueryData(self._cluster,
[self._all_groups[uuid]
for uuid in self.wanted],
group_to_nodes, group_to_instances)
 
......
......@@ -1941,9 +1941,10 @@ class GroupQueryData:
"""Data container for node group data queries.
"""
def __init__(self, groups, group_to_nodes, group_to_instances):
def __init__(self, cluster, groups, group_to_nodes, group_to_instances):
"""Initializes this class.
@param cluster: Cluster object
@param groups: List of node group objects
@type group_to_nodes: dict; group UUID as key
@param group_to_nodes: Per-group list of nodes
......@@ -1954,12 +1955,21 @@ class GroupQueryData:
self.groups = groups
self.group_to_nodes = group_to_nodes
self.group_to_instances = group_to_instances
self.cluster = cluster
# Used for individual rows
self.group_ipolicy = None
def __iter__(self):
"""Iterate over all node groups.
This function has side-effects and only one instance of the resulting
generator should be used at a time.
"""
return iter(self.groups)
for group in self.groups:
self.group_ipolicy = self.cluster.SimpleFillIPolicy(group.ipolicy)
yield group
_GROUP_SIMPLE_FIELDS = {
......@@ -2011,6 +2021,12 @@ def _BuildGroupFields():
fields.extend([
(_MakeField("tags", "Tags", QFT_OTHER, "Tags"), GQ_CONFIG, 0,
lambda ctx, group: list(group.GetTags())),
(_MakeField("ipolicy", "InstancePolicy", QFT_OTHER,
"Instance policy limitations (merged)"),
GQ_CONFIG, 0, lambda ctx, _: ctx.group_ipolicy),
(_MakeField("custom_ipolicy", "CustomInstancePolicy", QFT_OTHER,
"Custom instance policy limitations"),
GQ_CONFIG, 0, _GetItemAttr("ipolicy")),
])
fields.extend(_GetItemTimestampFields(GQ_CONFIG))
......
......@@ -94,6 +94,7 @@ G_FIELDS = [
"name",
"node_cnt",
"node_list",
"ipolicy",
] + _COMMON_FIELDS
J_FIELDS_BULK = [
......
......@@ -932,18 +932,31 @@ class TestGroupQuery(unittest.TestCase):
self.groups = [
objects.NodeGroup(name="default",
uuid="c0e89160-18e7-11e0-a46e-001d0904baeb",
alloc_policy=constants.ALLOC_POLICY_PREFERRED),
alloc_policy=constants.ALLOC_POLICY_PREFERRED,
ipolicy=objects.MakeEmptyIPolicy()),
objects.NodeGroup(name="restricted",
uuid="d2a40a74-18e7-11e0-9143-001d0904baeb",
alloc_policy=constants.ALLOC_POLICY_LAST_RESORT),
alloc_policy=constants.ALLOC_POLICY_LAST_RESORT,
ipolicy=objects.MakeEmptyIPolicy()),
]
self.cluster = objects.Cluster(cluster_name="testcluster",
hvparams=constants.HVC_DEFAULTS,
beparams={
constants.PP_DEFAULT: constants.BEC_DEFAULTS,
},
nicparams={
constants.PP_DEFAULT: constants.NICC_DEFAULTS,
},
ndparams=constants.NDC_DEFAULTS,
ipolicy=constants.IPOLICY_DEFAULTS,
)
def _Create(self, selected):
return query.Query(query.GROUP_FIELDS, selected)
def testSimple(self):
q = self._Create(["name", "uuid", "alloc_policy"])
gqd = query.GroupQueryData(self.groups, None, None)
gqd = query.GroupQueryData(self.cluster, self.groups, None, None)
self.assertEqual(q.RequestedData(), set([query.GQ_CONFIG]))
......@@ -965,7 +978,7 @@ class TestGroupQuery(unittest.TestCase):
}
q = self._Create(["name", "node_cnt", "node_list"])
gqd = query.GroupQueryData(self.groups, groups_to_nodes, None)
gqd = query.GroupQueryData(self.cluster, self.groups, groups_to_nodes, None)
self.assertEqual(q.RequestedData(), set([query.GQ_CONFIG, query.GQ_NODE]))
......@@ -987,7 +1000,8 @@ class TestGroupQuery(unittest.TestCase):
}
q = self._Create(["pinst_cnt", "pinst_list"])
gqd = query.GroupQueryData(self.groups, None, groups_to_instances)
gqd = query.GroupQueryData(self.cluster, self.groups, None,
groups_to_instances)
self.assertEqual(q.RequestedData(), set([query.GQ_INST]))
......
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