Commit 20529708 authored by Helga Velroyen's avatar Helga Velroyen

iallocator: computation of storage data

This patch extracts the processing of the storage-related
data from the RPC call 'node_info' in a separate function
to increase testability. In addition, this patch contains
unit tests for this function.
Signed-off-by: default avatarHelga Velroyen <helgav@google.com>
Reviewed-by: default avatarKlaus Aehlig <aehlig@google.com>
parent b844311b
......@@ -543,6 +543,37 @@ class IAllocator(object):
(node_name, attr, value))
return value
@staticmethod
def _ComputeStorageData(node_info, node_name, has_lvm):
"""Extract storage data from the node info.
@type node_info: see result of RPC call 'node info'
@param node_info: the node's live information
@type node_name: string
@param node_name: the node's name
@type has_lvm: boolean
@param has_lvm: whether or not lvm storage info was requested
@rtype: 4-tuple of integers
@return: tuple of storage info (total_disk, free_disk, total_spindles,
free_spindles)
"""
# TODO: replace this with proper storage reporting
if has_lvm:
total_disk = IAllocator._GetAttributeFromNodeData(node_info, node_name,
"storage_size")
free_disk = IAllocator._GetAttributeFromNodeData(node_info, node_name,
"storage_free")
total_spindles = IAllocator._GetAttributeFromNodeData(
node_info, node_name, "spindles_total")
free_spindles = IAllocator._GetAttributeFromNodeData(
node_info, node_name, "spindles_free")
else:
# we didn't even ask the node for VG status, so use zeros
total_disk = free_disk = 0
total_spindles = free_spindles = 0
return (total_disk, free_disk, total_spindles, free_spindles)
def _ComputeDynamicNodeData(self, node_cfg, node_data, node_iinfo, i_list,
node_results, has_lvm):
"""Compute global node data.
......@@ -583,20 +614,8 @@ class IAllocator(object):
if iinfo.admin_state == constants.ADMINST_UP:
i_p_up_mem += beinfo[constants.BE_MAXMEM]
# TODO: replace this with proper storage reporting
if has_lvm:
total_disk = self._GetAttributeFromNodeData(remote_info, ninfo.name,
"storage_size")
free_disk = self._GetAttributeFromNodeData(remote_info, ninfo.name,
"storage_free")
total_spindles = self._GetAttributeFromNodeData(
remote_info, ninfo.name, "spindles_total")
free_spindles = self._GetAttributeFromNodeData(
remote_info, ninfo.name, "spindles_free")
else:
# we didn't even ask the node for VG status, so use zeros
total_disk = free_disk = 0
total_spindles = free_spindles = 0
(total_disk, free_disk, total_spindles, free_spindles) = \
self._ComputeStorageData(remote_info, ninfo.name, has_lvm)
# compute memory used by instances
pnr_dyn = {
......
......@@ -22,12 +22,14 @@
"""Script for testing ganeti.masterd.iallocator"""
import unittest
import mock
from ganeti import compat
from ganeti import constants
from ganeti import errors
from ganeti import objects
from ganeti import ht
from ganeti import rpc
from ganeti.masterd import iallocator
import testutils
......@@ -177,6 +179,49 @@ class TestComputeBasicNodeData(unittest.TestCase):
else:
self.assertTrue(result["node1"]["offline"])
class TestProcessStorageInfo(unittest.TestCase):
def setUp(self):
self.free_storage_file = 23
self.total_storage_file = 42
self.free_storage_lvm = 69
self.total_storage_lvm = 666
self.space_info = [{"name": "mynode",
"type": constants.ST_FILE,
"storage_free": self.free_storage_file,
"storage_size": self.total_storage_file},
{"name": "mynode",
"type": constants.ST_LVM_VG,
"storage_free": self.free_storage_lvm,
"storage_size": self.total_storage_lvm},
{"name": "mynode",
"type": constants.ST_LVM_PV,
"storage_free": 33,
"storage_size": 44}]
self.node_info = ("123", self.space_info, ({},))
def testComputeStorageDataLvm(self):
has_lvm = True
node_name = "mynode"
remote_info = rpc.MakeLegacyNodeInfo(self.node_info,
require_vg_info=has_lvm)
(total_disk, free_disk, total_spindles, free_spindles) = \
iallocator.IAllocator._ComputeStorageData(remote_info, node_name, has_lvm)
self.assertEqual(self.free_storage_lvm, free_disk)
self.assertEqual(self.total_storage_lvm, total_disk)
def testComputeStorageDataDefault(self):
has_lvm = False
node_name = "mynode"
remote_info = rpc.MakeLegacyNodeInfo(self.node_info,
require_vg_info=has_lvm)
(total_disk, free_disk, total_spindles, free_spindles) = \
iallocator.IAllocator._ComputeStorageData(remote_info, node_name, has_lvm)
# FIXME: right now, iallocator ignores anything else than LVM, adjust
# this test once that arbitrary storage is supported
self.assertEqual(0, free_disk)
self.assertEqual(0, total_disk)
if __name__ == "__main__":
testutils.GanetiTestProgram()
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